Skip to content

Commit 6d9f8c9

Browse files
committed
[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 llvm-svn: 324880
1 parent 3cfaf3d commit 6d9f8c9

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include "llvm/Target/TargetOptions.h"
3535
using namespace llvm;
3636

37+
static cl::opt<bool> EnableTrapUnreachable("trap-unreachable",
38+
cl::Hidden, cl::ZeroOrMore, cl::init(false),
39+
cl::desc("Enable generating trap for unreachable"));
40+
3741
void LLVMTargetMachine::initAsmInfo() {
3842
MRI = TheTarget.createMCRegInfo(getTargetTriple().str());
3943
MII = TheTarget.createMCInstrInfo();
@@ -79,6 +83,9 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
7983
this->RM = RM;
8084
this->CMModel = CM;
8185
this->OptLevel = OL;
86+
87+
if (EnableTrapUnreachable)
88+
this->Options.TrapUnreachable = true;
8289
}
8390

8491
TargetTransformInfo

llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ static cl::opt<bool> EnableVectorPrint("enable-hexagon-vector-print",
9797
static cl::opt<bool> EnableVExtractOpt("hexagon-opt-vextract", cl::Hidden,
9898
cl::ZeroOrMore, cl::init(true), cl::desc("Enable vextract optimization"));
9999

100-
static cl::opt<bool> EnableTrapUnreachable("hexagon-trap-unreachable",
101-
cl::Hidden, cl::ZeroOrMore, cl::init(false),
102-
cl::desc("Enable generating trap for unreachable"));
103-
104100
/// HexagonTargetMachineModule - Note that this is used on hosts that
105101
/// cannot link in a library unless there are references into the
106102
/// library. In particular, it seems that it is not possible to get
@@ -219,8 +215,6 @@ HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT,
219215
TT, CPU, FS, Options, getEffectiveRelocModel(RM),
220216
getEffectiveCodeModel(CM), (HexagonNoOpt ? CodeGenOpt::None : OL)),
221217
TLOF(make_unique<HexagonTargetObjectFile>()) {
222-
if (EnableTrapUnreachable)
223-
this->Options.TrapUnreachable = true;
224218
initializeHexagonExpandCondsetsPass(*PassRegistry::getPassRegistry());
225219
initAsmInfo();
226220
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s
2+
; CHECK: .inst.n 0xdefe
3+
4+
define void @test() #0 {
5+
unreachable
6+
}
7+
8+
attributes #0 = { nounwind }

llvm/test/CodeGen/Hexagon/trap-unreachable.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -march=hexagon -hexagon-trap-unreachable < %s | FileCheck %s
1+
; RUN: llc -march=hexagon -trap-unreachable < %s | FileCheck %s
22
; CHECK: call abort
33

44
define void @fred() #0 {

0 commit comments

Comments
 (0)