diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-04-06 10:14:09 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-04-06 10:14:09 +0000 |
commit | b230c763a4858725b72d193c7d7b3da8e77dea53 (patch) | |
tree | 50599c701e88ba47044289637782e5f46ca2403c /llvm/lib/Transforms/Utils | |
parent | d726d04f4523bbf4d439b436757ad91108484904 (diff) | |
download | bcm5719-llvm-b230c763a4858725b72d193c7d7b3da8e77dea53.tar.gz bcm5719-llvm-b230c763a4858725b72d193c7d7b3da8e77dea53.zip |
EntryExitInstrumenter: Handle musttail calls
Inserting instrumentation between a musttail call and ret instruction
would create invalid IR. Instead, treat musttail calls as function
exits.
llvm-svn: 329385
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index d7c11de21a8..569ea58a304 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -91,17 +91,27 @@ static bool runOnFunction(Function &F, bool PostInlining) { if (!ExitFunc.empty()) { for (BasicBlock &BB : F) { - TerminatorInst *T = BB.getTerminator(); + Instruction *T = BB.getTerminator(); + if (!isa<ReturnInst>(T)) + continue; + + // If T is preceded by a musttail call, that's the real terminator. + Instruction *Prev = T->getPrevNode(); + if (BitCastInst *BCI = dyn_cast_or_null<BitCastInst>(Prev)) + Prev = BCI->getPrevNode(); + if (CallInst *CI = dyn_cast_or_null<CallInst>(Prev)) { + if (CI->isMustTailCall()) + T = CI; + } + 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, DL); - Changed = true; - } + insertCall(F, ExitFunc, T, DL); + Changed = true; } F.removeAttribute(AttributeList::FunctionIndex, ExitAttr); } |