[llvm] r324880 - [CodeGen] Add a -trap-unreachable option for debugging

David Green via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 03:06:27 PST 2018


Author: dmgreen
Date: Mon Feb 12 03:06:27 2018
New Revision: 324880

URL: http://llvm.org/viewvc/llvm-project?rev=324880&view=rev
Log:
[CodeGen] Add a -trap-unreachable option for debugging

Add a common -trap-unreachable option, similar to the target
specific hexagon equivalent, which has been replaced. This
turns unreachable instructions into traps, which is useful for
debugging.

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


Added:
    llvm/trunk/test/CodeGen/ARM/trap-unreachable.ll
Modified:
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.cpp
    llvm/trunk/test/CodeGen/Hexagon/trap-unreachable.ll

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=324880&r1=324879&r2=324880&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Mon Feb 12 03:06:27 2018
@@ -34,6 +34,10 @@
 #include "llvm/Target/TargetOptions.h"
 using namespace llvm;
 
+static cl::opt<bool> EnableTrapUnreachable("trap-unreachable",
+  cl::Hidden, cl::ZeroOrMore, cl::init(false),
+  cl::desc("Enable generating trap for unreachable"));
+
 void LLVMTargetMachine::initAsmInfo() {
   MRI = TheTarget.createMCRegInfo(getTargetTriple().str());
   MII = TheTarget.createMCInstrInfo();
@@ -79,6 +83,9 @@ LLVMTargetMachine::LLVMTargetMachine(con
   this->RM = RM;
   this->CMModel = CM;
   this->OptLevel = OL;
+
+  if (EnableTrapUnreachable)
+    this->Options.TrapUnreachable = true;
 }
 
 TargetTransformInfo

Modified: llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.cpp?rev=324880&r1=324879&r2=324880&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.cpp Mon Feb 12 03:06:27 2018
@@ -97,10 +97,6 @@ static cl::opt<bool> EnableVectorPrint("
 static cl::opt<bool> EnableVExtractOpt("hexagon-opt-vextract", cl::Hidden,
   cl::ZeroOrMore, cl::init(true), cl::desc("Enable vextract optimization"));
 
-static cl::opt<bool> EnableTrapUnreachable("hexagon-trap-unreachable",
-  cl::Hidden, cl::ZeroOrMore, cl::init(false),
-  cl::desc("Enable generating trap for unreachable"));
-
 /// HexagonTargetMachineModule - Note that this is used on hosts that
 /// cannot link in a library unless there are references into the
 /// library.  In particular, it seems that it is not possible to get
@@ -219,8 +215,6 @@ HexagonTargetMachine::HexagonTargetMachi
           TT, CPU, FS, Options, getEffectiveRelocModel(RM),
           getEffectiveCodeModel(CM), (HexagonNoOpt ? CodeGenOpt::None : OL)),
       TLOF(make_unique<HexagonTargetObjectFile>()) {
-  if (EnableTrapUnreachable)
-    this->Options.TrapUnreachable = true;
   initializeHexagonExpandCondsetsPass(*PassRegistry::getPassRegistry());
   initAsmInfo();
 }

Added: llvm/trunk/test/CodeGen/ARM/trap-unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/trap-unreachable.ll?rev=324880&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/trap-unreachable.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/trap-unreachable.ll Mon Feb 12 03:06:27 2018
@@ -0,0 +1,8 @@
+; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s
+; CHECK: .inst.n 0xdefe
+
+define void @test() #0 {
+  unreachable
+}
+
+attributes #0 = { nounwind }

Modified: llvm/trunk/test/CodeGen/Hexagon/trap-unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/trap-unreachable.ll?rev=324880&r1=324879&r2=324880&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/trap-unreachable.ll (original)
+++ llvm/trunk/test/CodeGen/Hexagon/trap-unreachable.ll Mon Feb 12 03:06:27 2018
@@ -1,4 +1,4 @@
-; RUN: llc -march=hexagon -hexagon-trap-unreachable < %s | FileCheck %s
+; RUN: llc -march=hexagon -trap-unreachable < %s | FileCheck %s
 ; CHECK: call abort
 
 define void @fred() #0 {




More information about the llvm-commits mailing list