diff options
author | Adrian Prantl <aprantl@apple.com> | 2017-02-28 16:58:13 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2017-02-28 16:58:13 +0000 |
commit | 80d0c9343642f9e72f6ec6d6d9ceda483adb996c (patch) | |
tree | 7433e65eeea9a9e350d4d7c97eec72d187b19ef0 /llvm/lib/Transforms/Utils/InlineFunction.cpp | |
parent | 431359aa8b04efb50147eb45aa5d157824da26bf (diff) | |
download | bcm5719-llvm-80d0c9343642f9e72f6ec6d6d9ceda483adb996c.tar.gz bcm5719-llvm-80d0c9343642f9e72f6ec6d6d9ceda483adb996c.zip |
Strip debug info when inlining into a nodebug function.
The LLVM backend cannot produce any debug info for an llvm::Function
without a DISubprogram attachment. When inlining a debug-info-carrying
function into a nodebug function, there is therefore no reason to keep
any debug info intrinsic calls or debug locations on the instructions.
This fixes a problem discovered in PR32042.
rdar://problem/30679307
llvm-svn: 296488
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/InlineFunction.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index bd3aa8d3867..9873e8ebebe 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1343,22 +1343,26 @@ static bool allocaWouldBeStaticInEntry(const AllocaInst *AI ) { return isa<Constant>(AI->getArraySize()) && !AI->isUsedWithInAlloca(); } -/// Update inlined instructions' line numbers to -/// to encode location where these instructions are inlined. -static void fixupLineNumbers(Function *Fn, Function::iterator FI, - Instruction *TheCall, bool CalleeHasDebugInfo) { +/// Update inlined instructions' line numbers to to encode location where these +/// instructions are inlined. Also strip all debug intrinsics that were inlined +/// into a nodebug function; there is no debug info the backend could produce +/// for a function without a DISubprogram attachment. +static void fixupDebugInfo(Function *Fn, Function::iterator FI, + Instruction *TheCall, bool CalleeHasDebugInfo) { + bool CallerHasDebugInfo = Fn->getSubprogram(); + bool StripDebugInfo = !CallerHasDebugInfo && CalleeHasDebugInfo; + SmallVector<DbgInfoIntrinsic *, 8> IntrinsicsToErase; const DebugLoc &TheCallDL = TheCall->getDebugLoc(); - if (!TheCallDL) - return; auto &Ctx = Fn->getContext(); - DILocation *InlinedAtNode = TheCallDL; + DILocation *InlinedAtNode = nullptr; // Create a unique call site, not to be confused with any other call from the // same location. - InlinedAtNode = DILocation::getDistinct( - Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(), - InlinedAtNode->getScope(), InlinedAtNode->getInlinedAt()); + if (TheCallDL) + InlinedAtNode = DILocation::getDistinct( + Ctx, TheCallDL->getLine(), TheCallDL->getColumn(), + TheCallDL->getScope(), TheCallDL->getInlinedAt()); // Cache the inlined-at nodes as they're built so they are reused, without // this every instruction's inlined-at chain would become distinct from each @@ -1368,6 +1372,17 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI, for (; FI != Fn->end(); ++FI) { for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) { + if (StripDebugInfo) { + // Inlining into a nodebug function. + if (auto *DI = dyn_cast<DbgInfoIntrinsic>(BI)) + // Mark dead debug intrinsics for deletion. + IntrinsicsToErase.push_back(DI); + else + // Remove the dangling debug location. + BI->setDebugLoc(DebugLoc()); + continue; + } + if (DebugLoc DL = BI->getDebugLoc()) { BI->setDebugLoc( updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes)); @@ -1390,6 +1405,9 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI, BI->setDebugLoc(TheCallDL); } } + + for (auto *DI : IntrinsicsToErase) + DI->eraseFromParent(); } /// Update the block frequencies of the caller after a callee has been inlined. /// @@ -1710,8 +1728,8 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, // For 'nodebug' functions, the associated DISubprogram is always null. // Conservatively avoid propagating the callsite debug location to // instructions inlined from a function whose DISubprogram is not null. - fixupLineNumbers(Caller, FirstNewBlock, TheCall, - CalledFunc->getSubprogram() != nullptr); + fixupDebugInfo(Caller, FirstNewBlock, TheCall, + CalledFunc->getSubprogram() != nullptr); // Clone existing noalias metadata if necessary. CloneAliasScopeMetadata(CS, VMap); |