[llvm] 64d1cea - Add command line option --no-trap-after-noreturn (#67051)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 13:03:26 PDT 2023


Author: Matt Harding
Date: 2023-09-22T22:03:21+02:00
New Revision: 64d1ceaa3884608c97f8457de6ab64a038ea49d8

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

LOG: Add command line option --no-trap-after-noreturn (#67051)

Add the command line option --no-trap-after-noreturn, which exposes the
pre-existing TargetOption `NoTrapAfterNoreturn`.

This pull request was split off from this one:
https://github.com/llvm/llvm-project/pull/65876

Added: 
    

Modified: 
    llvm/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/test/CodeGen/ARM/trap-unreachable.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 7ec8390033fbabc..87a17b88db12433 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -37,6 +37,11 @@ static cl::opt<bool>
     EnableTrapUnreachable("trap-unreachable", cl::Hidden,
                           cl::desc("Enable generating trap for unreachable"));
 
+static cl::opt<bool> EnableNoTrapAfterNoreturn(
+    "no-trap-after-noreturn", cl::Hidden,
+    cl::desc("Do not emit a trap instruction for 'unreachable' IR instructions "
+             "after noreturn calls, even if --trap-unreachable is set."));
+
 void LLVMTargetMachine::initAsmInfo() {
   MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
   assert(MRI && "Unable to create reg info");
@@ -95,6 +100,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
 
   if (EnableTrapUnreachable)
     this->Options.TrapUnreachable = true;
+  if (EnableNoTrapAfterNoreturn)
+    this->Options.NoTrapAfterNoreturn = true;
 }
 
 TargetTransformInfo

diff  --git a/llvm/test/CodeGen/ARM/trap-unreachable.ll b/llvm/test/CodeGen/ARM/trap-unreachable.ll
index 605d5a234291a42..84dbb04c462b450 100644
--- a/llvm/test/CodeGen/ARM/trap-unreachable.ll
+++ b/llvm/test/CodeGen/ARM/trap-unreachable.ll
@@ -1,8 +1,36 @@
-; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s
-; CHECK: .inst.n 0xdefe
+; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s --check-prefixes CHECK,TRAP_UNREACHABLE
+; RUN: llc -mtriple=thumbv7 -trap-unreachable -no-trap-after-noreturn < %s | FileCheck %s --check-prefixes CHECK,NTANR
 
-define void @test() #0 {
+define void @test_trap_unreachable() #0 {
+; CHECK-LABEL: test_trap_unreachable:
+; CHECK:       @ %bb.0:
+; CHECK-NEXT:    .inst.n 0xdefe
   unreachable
 }
 
 attributes #0 = { nounwind }
+
+declare void @no_return() noreturn
+declare void @could_return()
+
+define void @test_ntanr_noreturn() {
+; CHECK-LABEL:           test_ntanr_noreturn:
+; CHECK:                 @ %bb.0:
+; CHECK-NEXT:              push {r7, lr}
+; CHECK-NEXT:              bl no_return
+; TRAP_UNREACHABLE-NEXT:   .inst.n 0xdefe
+; NTANR-NOT:               .inst.n 0xdefe
+;
+  call void @no_return()
+  unreachable
+}
+
+define void @test_ntanr_could_return() {
+; CHECK-LABEL: test_ntanr_could_return:
+; CHECK:       @ %bb.0:
+; CHECK-NEXT:    push {r7, lr}
+; CHECK-NEXT:    bl could_return
+; CHECK-NEXT:    .inst.n 0xdefe
+  call void @could_return()
+  unreachable
+}


        


More information about the llvm-commits mailing list