diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-11-28 18:44:26 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-11-28 18:44:26 +0000 |
commit | ca46db957daa1be8de63f47391b5c57cace5c124 (patch) | |
tree | cb0e9086b4b128a27de7c9c95f833024eb051123 /llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp | |
parent | 6900de1dfb2aa33e97ebed98628880ffb200a648 (diff) | |
download | bcm5719-llvm-ca46db957daa1be8de63f47391b5c57cace5c124.tar.gz bcm5719-llvm-ca46db957daa1be8de63f47391b5c57cace5c124.zip |
EntryExitInstrumenter: set DebugLocs on the inserted call instructions (PR35412)
Apparently the verifier requires that inlineable calls in a function
with debug info have debug locations.
llvm-svn: 319199
Diffstat (limited to 'llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 064d7d003a9..421663f8256 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -10,6 +10,7 @@ #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" @@ -19,7 +20,7 @@ using namespace llvm; static void insertCall(Function &CurFn, StringRef Func, - Instruction *InsertionPt) { + Instruction *InsertionPt, DebugLoc DL) { Module &M = *InsertionPt->getParent()->getParent()->getParent(); LLVMContext &C = InsertionPt->getParent()->getContext(); @@ -32,7 +33,8 @@ static void insertCall(Function &CurFn, StringRef Func, Func == "_mcount" || Func == "__cyg_profile_func_enter_bare") { Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C)); - CallInst::Create(Fn, "", InsertionPt); + CallInst *Call = CallInst::Create(Fn, "", InsertionPt); + Call->setDebugLoc(DL); return; } @@ -46,11 +48,14 @@ static void insertCall(Function &CurFn, StringRef Func, Intrinsic::getDeclaration(&M, Intrinsic::returnaddress), ArrayRef<Value *>(ConstantInt::get(Type::getInt32Ty(C), 0)), "", InsertionPt); + RetAddr->setDebugLoc(DL); Value *Args[] = {ConstantExpr::getBitCast(&CurFn, Type::getInt8PtrTy(C)), RetAddr}; - CallInst::Create(Fn, ArrayRef<Value *>(Args), "", InsertionPt); + CallInst *Call = + CallInst::Create(Fn, ArrayRef<Value *>(Args), "", InsertionPt); + Call->setDebugLoc(DL); return; } @@ -76,7 +81,11 @@ static bool runOnFunction(Function &F, bool PostInlining) { // run later for some reason. if (!EntryFunc.empty()) { - insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt()); + DebugLoc DL; + if (auto SP = F.getSubprogram()) + DL = DebugLoc::get(SP->getScopeLine(), 0, SP); + + insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL); Changed = true; F.removeAttribute(AttributeList::FunctionIndex, EntryAttr); } @@ -84,8 +93,14 @@ static bool runOnFunction(Function &F, bool PostInlining) { if (!ExitFunc.empty()) { for (BasicBlock &BB : F) { TerminatorInst *T = BB.getTerminator(); + DebugLoc DL; + if (DebugLoc TerminatorDL = T->getDebugLoc()) + DL = TerminatorDL; + else if (auto SP = F.getSubprogram()) + DL = DebugLoc::get(0, 0, SP); + if (isa<ReturnInst>(T)) { - insertCall(F, ExitFunc, T); + insertCall(F, ExitFunc, T, DL); Changed = true; } } |