Index: lib/Target/Mips/MipsLegalizerInfo.cpp =================================================================== --- lib/Target/Mips/MipsLegalizerInfo.cpp +++ lib/Target/Mips/MipsLegalizerInfo.cpp @@ -219,8 +219,16 @@ return true; } -bool MipsLegalizerInfo::legalizeIntrinsic(MachineInstr &MI, MachineRegisterInfo &MRI, +bool MipsLegalizerInfo::legalizeIntrinsic(MachineInstr &MI, + MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder) const { + const MipsSubtarget &ST = + static_cast(MI.getMF()->getSubtarget()); + const MipsInstrInfo &TII = *ST.getInstrInfo(); + const MipsRegisterInfo &TRI = *ST.getRegisterInfo(); + const RegisterBankInfo &RBI = *ST.getRegBankInfo(); + MIRBuilder.setInstr(MI); + switch (MI.getIntrinsicID()) { case Intrinsic::memcpy: case Intrinsic::memset: @@ -230,6 +238,11 @@ return false; MI.eraseFromParent(); return true; + case Intrinsic::trap: { + MachineInstr *Trap = MIRBuilder.buildInstr(Mips::TRAP); + MI.eraseFromParent(); + return constrainSelectedInstRegOperands(*Trap, TII, TRI, RBI); + } default: break; } Index: test/CodeGen/Mips/GlobalISel/legalizer/trap.mir =================================================================== --- /dev/null +++ test/CodeGen/Mips/GlobalISel/legalizer/trap.mir @@ -0,0 +1,22 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -O0 -mtriple=mipsel-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=MIPS32 +--- | + + declare void @llvm.trap() + define void @f() { ret void } + +... +--- +name: f +alignment: 2 +body: | + bb.1 (%ir-block.0): + ; MIPS32-LABEL: name: f + ; MIPS32: TRAP + ; MIPS32: RetRA + G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.trap) + RetRA + +... + + Index: test/CodeGen/Mips/GlobalISel/llvm-ir/trap.ll =================================================================== --- /dev/null +++ test/CodeGen/Mips/GlobalISel/llvm-ir/trap.ll @@ -0,0 +1,14 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32 + + declare void @llvm.trap() + + define void @f() { +; MIPS32-LABEL: f: +; MIPS32: # %bb.0: +; MIPS32-NEXT: break +; MIPS32-NEXT: jr $ra +; MIPS32-NEXT: nop + call void @llvm.trap() + ret void + }