Skip to content

Commit

Permalink
[CodeGen] Add a -trap-unreachable option for debugging
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davemgreen committed Feb 12, 2018
1 parent 3cfaf3d commit 6d9f8c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/LLVMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -79,6 +83,9 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
this->RM = RM;
this->CMModel = CM;
this->OptLevel = OL;

if (EnableTrapUnreachable)
this->Options.TrapUnreachable = true;
}

TargetTransformInfo
Expand Down
6 changes: 0 additions & 6 deletions llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ static cl::opt<bool> EnableVectorPrint("enable-hexagon-vector-print",
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
Expand Down Expand Up @@ -219,8 +215,6 @@ HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT,
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();
}
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/CodeGen/ARM/trap-unreachable.ll
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/Hexagon/trap-unreachable.ll
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 6d9f8c9

Please sign in to comment.