mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-20 10:24:12 +00:00
DebugInfo: Use distinct inlinedAt MDLocations to avoid separate inlined calls being coalesced
When two calls from the same MDLocation are inlined they currently get treated as one inlined function call (creating difficulty debugging, duplicate variables, etc). Clang worked around this by including column information on inline calls which doesn't address LTO inlining or calls to the same function from the same line and column (such as through a macro). It also didn't address ctor and member function calls. By making the inlinedAt locations distinct, every call site has an explicitly distinct location that cannot be coalesced with any other call. This can produce linearly (2x in the worst case where every call is inlined and the call instruction has a non-call instruction at the same location) more debug locations. Any increase beyond that are in cases where the Clang workaround was insufficient and the new scheme is creating necessary distinct nodes that were being erroneously coalesced previously. After this change to LLVM the incomplete workarounds in Clang. That should reduce the number of debug locations (in a build without column info, the default on Darwin, not the default on Linux) by not creating pseudo-distinct locations for every call to an inline function. (oh, and I made the inlined-at chain rebuilding iterative instead of recursive because I was having trouble wrapping my head around it the way it was - open to discussion on the right design for that function (including going back to a recursive solution)) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226736 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -823,20 +823,42 @@ static bool hasLifetimeMarkers(AllocaInst *AI) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// updateInlinedAtInfo - Helper function used by fixupLineNumbers to
|
||||
/// recursively update InlinedAtEntry of a DebugLoc.
|
||||
static DebugLoc updateInlinedAtInfo(const DebugLoc &DL,
|
||||
const DebugLoc &InlinedAtDL,
|
||||
LLVMContext &Ctx) {
|
||||
if (MDNode *IA = DL.getInlinedAt(Ctx)) {
|
||||
DebugLoc NewInlinedAtDL
|
||||
= updateInlinedAtInfo(DebugLoc::getFromDILocation(IA), InlinedAtDL, Ctx);
|
||||
return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx),
|
||||
NewInlinedAtDL.getAsMDNode(Ctx));
|
||||
/// Rebuild the entire inlined-at chain for this instruction so that the top of
|
||||
/// the chain now is inlined-at the new call site.
|
||||
static DebugLoc
|
||||
updateInlinedAtInfo(DebugLoc DL, MDLocation *InlinedAtNode,
|
||||
LLVMContext &Ctx,
|
||||
DenseMap<const MDLocation *, MDLocation *> &IANodes) {
|
||||
SmallVector<MDLocation*, 3> InlinedAtLocations;
|
||||
MDLocation *Last = InlinedAtNode;
|
||||
DebugLoc CurInlinedAt = DL;
|
||||
|
||||
// Gather all the inlined-at nodes
|
||||
while (MDLocation *IA =
|
||||
cast_or_null<MDLocation>(CurInlinedAt.getInlinedAt(Ctx))) {
|
||||
// Skip any we've already built nodes for
|
||||
if (MDLocation *Found = IANodes[IA]) {
|
||||
Last = Found;
|
||||
break;
|
||||
}
|
||||
|
||||
InlinedAtLocations.push_back(IA);
|
||||
CurInlinedAt = DebugLoc::getFromDILocation(IA);
|
||||
}
|
||||
|
||||
return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx),
|
||||
InlinedAtDL.getAsMDNode(Ctx));
|
||||
// Starting from the top, rebuild the nodes to point to the new inlined-at
|
||||
// location (then rebuilding the rest of the chain behind it) and update the
|
||||
// map of already-constructed inlined-at nodes.
|
||||
for (auto I = InlinedAtLocations.rbegin(), E = InlinedAtLocations.rend();
|
||||
I != E; ++I) {
|
||||
const MDLocation *MD = *I;
|
||||
Last = IANodes[MD] = MDLocation::getDistinct(
|
||||
Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last);
|
||||
}
|
||||
|
||||
// And finally create the normal location for this instruction, referring to
|
||||
// the new inlined-at chain.
|
||||
return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx), Last);
|
||||
}
|
||||
|
||||
/// fixupLineNumbers - Update inlined instructions' line numbers to
|
||||
@ -847,6 +869,20 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
|
||||
if (TheCallDL.isUnknown())
|
||||
return;
|
||||
|
||||
auto &Ctx = Fn->getContext();
|
||||
auto *InlinedAtNode = cast<MDLocation>(TheCallDL.getAsMDNode(Ctx));
|
||||
|
||||
// Create a unique call site, not to be confused with any other call from the
|
||||
// same location.
|
||||
InlinedAtNode = MDLocation::getDistinct(
|
||||
Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(),
|
||||
InlinedAtNode->getScope(), InlinedAtNode->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
|
||||
// other.
|
||||
DenseMap<const MDLocation *, MDLocation *> IANodes;
|
||||
|
||||
for (; FI != Fn->end(); ++FI) {
|
||||
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
|
||||
BI != BE; ++BI) {
|
||||
@ -864,7 +900,7 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
|
||||
|
||||
BI->setDebugLoc(TheCallDL);
|
||||
} else {
|
||||
BI->setDebugLoc(updateInlinedAtInfo(DL, TheCallDL, BI->getContext()));
|
||||
BI->setDebugLoc(updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes));
|
||||
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) {
|
||||
LLVMContext &Ctx = BI->getContext();
|
||||
MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx);
|
||||
|
Reference in New Issue
Block a user