[llvm] f9d69a0 - [GlobalISel] Implement support for the "trap-func-name" attribute.

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 20 14:32:19 PDT 2021


Author: Amara Emerson
Date: 2021-09-20T14:32:01-07:00
New Revision: f9d69a0ab02567933302602238264a38468f9900

URL: https://github.com/llvm/llvm-project/commit/f9d69a0ab02567933302602238264a38468f9900
DIFF: https://github.com/llvm/llvm-project/commit/f9d69a0ab02567933302602238264a38468f9900.diff

LOG: [GlobalISel] Implement support for the "trap-func-name" attribute.

This attribute calls a function instead of emitting a trap instruction.

Differential Revision: https://reviews.llvm.org/D110098

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
    llvm/test/CodeGen/AArch64/arm64-trap.ll
    llvm/test/CodeGen/AArch64/debugtrap.ll
    llvm/test/CodeGen/AArch64/ubsantrap.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index c7d1c5385337..bb74cb27108d 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2225,6 +2225,24 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
 
     return true;
   }
+  case Intrinsic::trap:
+  case Intrinsic::debugtrap:
+  case Intrinsic::ubsantrap: {
+    StringRef TrapFuncName =
+        CI.getAttributes().getFnAttr("trap-func-name").getValueAsString();
+    if (TrapFuncName.empty())
+      break; // Use the default handling.
+    CallLowering::CallLoweringInfo Info;
+    if (ID == Intrinsic::ubsantrap) {
+      Info.OrigArgs.push_back({getOrCreateVRegs(*CI.getArgOperand(0)),
+                               CI.getArgOperand(0)->getType(), 0});
+    }
+    Info.Callee =
+        MachineOperand::CreateES(MF->createExternalSymbolName(TrapFuncName));
+    Info.CB = &CI;
+    Info.OrigRet = {Register(), Type::getVoidTy(CI.getContext()), 0};
+    return CLI->lowerCall(MIRBuilder, Info);
+  }
 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)  \
   case Intrinsic::INTRINSIC:
 #include "llvm/IR/ConstrainedOps.def"

diff  --git a/llvm/test/CodeGen/AArch64/arm64-trap.ll b/llvm/test/CodeGen/AArch64/arm64-trap.ll
index eb06bddecc13..ffef22782550 100644
--- a/llvm/test/CodeGen/AArch64/arm64-trap.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-trap.ll
@@ -1,8 +1,19 @@
 ; RUN: llc < %s -mtriple=arm64-eabi | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-eabi -global-isel | FileCheck %s
 define void @foo() nounwind {
-; CHECK: foo
+; CHECK-LABEL: foo
 ; CHECK: brk #0x1
   tail call void @llvm.trap()
   ret void
 }
 declare void @llvm.trap() nounwind
+
+; CHECK-LABEL: {{\_?}}foo_trap_func:
+; CHECK: bl	trap_func
+
+define void @foo_trap_func() {
+  call void @llvm.trap() #0
+  unreachable
+}
+
+attributes #0 = { "trap-func-name"="trap_func" }

diff  --git a/llvm/test/CodeGen/AArch64/debugtrap.ll b/llvm/test/CodeGen/AArch64/debugtrap.ll
index ec9027236321..3c4e32fb2335 100644
--- a/llvm/test/CodeGen/AArch64/debugtrap.ll
+++ b/llvm/test/CodeGen/AArch64/debugtrap.ll
@@ -1,12 +1,13 @@
 ; RUN: llc -mtriple=aarch64-windows %s -o -| FileCheck %s
-; RUN: llc -mtriple=aarch64-windows -fast-isel %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-windows -fast-isel %s -o - | FileCheck %s --check-prefix=FASTISEL
 ; RUN: llc -mtriple=aarch64-windows -global-isel %s -o - | FileCheck %s
 ; RUN: llc -mtriple=aarch64-linux-gnu %s -o -| FileCheck %s
 ; RUN: llc -mtriple=arm64-apple-ios -global-isel %s -o - | FileCheck %s
-; RUN: llc -mtriple=arm64-apple-macosx -fast-isel %s -o - | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-macosx -fast-isel %s -o - | FileCheck %s --check-prefix=FASTISEL
 
 ; CHECK-LABEL: test1:
 ; CHECK: brk #0xf000
+; FASTISEL: brk #0xf000
 define void @test1() noreturn nounwind  {
 entry:
   tail call void @llvm.debugtrap( )
@@ -14,3 +15,14 @@ entry:
 }
 
 declare void @llvm.debugtrap() nounwind 
+
+; CHECK-LABEL: test_trap_func:
+; CHECK: bl {{.*}}wibble
+
+; FastISel doesn't handle trap-func-name for debugtrap.
+; FASTISEL: brk
+define void @test_trap_func() noreturn nounwind  {
+entry:
+  tail call void @llvm.debugtrap( ) "trap-func-name"="wibble"
+  ret void
+}
\ No newline at end of file

diff  --git a/llvm/test/CodeGen/AArch64/ubsantrap.ll b/llvm/test/CodeGen/AArch64/ubsantrap.ll
index a51be2e5e1bc..fafc195f04e0 100644
--- a/llvm/test/CodeGen/AArch64/ubsantrap.ll
+++ b/llvm/test/CodeGen/AArch64/ubsantrap.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=arm64-apple-ios %s -o - | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-ios -global-isel %s -o - | FileCheck %s
 
 define void @test_ubsantrap() {
 ; CHECK-LABEL: test_ubsantrap


        


More information about the llvm-commits mailing list