[PATCH] D67180: [MIPS GlobalISel] Select llvm.trap intrinsic
Petar Avramovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 08:20:43 PDT 2019
Petar.Avramovic created this revision.
Petar.Avramovic added reviewers: atanasyan, petarj.
Herald added subscribers: llvm-commits, jrtc27, arichardson, rovka, sdardis.
Herald added a project: LLVM.
Select G_INTRINSIC_W_SIDE_EFFECTS for Intrinsic::trap for MIPS32
via legalizeIntrinsic.
Repository:
rL LLVM
https://reviews.llvm.org/D67180
Files:
lib/Target/Mips/MipsLegalizerInfo.cpp
test/CodeGen/Mips/GlobalISel/legalizer/trap.mir
test/CodeGen/Mips/GlobalISel/llvm-ir/trap.ll
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
+ }
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: 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<const MipsSubtarget &>(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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67180.218715.patch
Type: text/x-patch
Size: 2573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/f4dd8ac3/attachment.bin>
More information about the llvm-commits
mailing list