Teach stripNonLineTableDebugInfo() to remap DILocations in !llvm.loop nodes.

llvm-svn: 299107
This commit is contained in:
Adrian Prantl
2017-03-30 20:10:56 +00:00
parent 9a3e73383b
commit 346dcaf1fa
2 changed files with 90 additions and 10 deletions

View File

@@ -601,17 +601,26 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
}
for (auto &BB : F) {
for (auto &I : BB) {
if (I.getDebugLoc() == DebugLoc())
continue;
auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc {
auto *Scope = DL.getScope();
MDNode *InlinedAt = DL.getInlinedAt();
Scope = remap(Scope);
InlinedAt = remap(InlinedAt);
return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt);
};
// Make a replacement.
auto &DL = I.getDebugLoc();
auto *Scope = DL.getScope();
MDNode *InlinedAt = DL.getInlinedAt();
Scope = remap(Scope);
InlinedAt = remap(InlinedAt);
I.setDebugLoc(
DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt));
if (I.getDebugLoc() != DebugLoc())
I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
// Remap DILocations in untyped MDNodes (e.g., llvm.loop).
SmallVector<std::pair<unsigned, MDNode *>, 2> MDs;
I.getAllMetadata(MDs);
for (auto Attachment : MDs)
if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second))
for (unsigned N = 0; N < T->getNumOperands(); ++N)
if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N)))
if (Loc != DebugLoc())
T->replaceOperandWith(N, remapDebugLoc(Loc));
}
}
}