summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2017-01-28 11:22:05 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2017-01-28 11:22:05 +0000
commitb96a945bf57ba645930cfb66f70e38281571378a (patch)
tree1cc62909bc2aba5e8cd3b2ab23fa74da64dc0b02 /llvm/lib/IR
parentf8c804f16372c215396d8d7339f24fa964494dc7 (diff)
downloadbcm5719-llvm-b96a945bf57ba645930cfb66f70e38281571378a.tar.gz
bcm5719-llvm-b96a945bf57ba645930cfb66f70e38281571378a.zip
stripDebugInfo() should remove DILocation's found in !llvm.loop metadata
Summary: Patch by Michele Scandale (with a small tweak to 'CHECK-NOT' the last DILocation in the test) Subscribers: bogner, llvm-commits Differential Revision: https://reviews.llvm.org/D27980 llvm-svn: 293377
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 6b9bc689a44..3bdd5a6bd95 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -239,6 +239,35 @@ bool DebugInfoFinder::addScope(DIScope *Scope) {
return true;
}
+static llvm::MDNode *stripDebugLocFromLoopID(llvm::MDNode *N) {
+ assert(N->op_begin() != N->op_end() && "Missing self reference?");
+ auto DebugLocOp =
+ std::find_if(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
+ return isa<DILocation>(Op.get());
+ });
+
+ // No debug location, we do not have to rewrite this MDNode.
+ if (DebugLocOp == N->op_end())
+ return N;
+
+ // There is only the debug location without any actual loop metadata, hence we
+ // can remove the metadata.
+ if (N->getNumOperands() == 2)
+ return nullptr;
+
+ SmallVector<Metadata *, 4> Args;
+ // Reserve operand 0 for loop id self reference.
+ auto TempNode = MDNode::getTemporary(N->getContext(), None);
+ Args.push_back(TempNode.get());
+ Args.append(N->op_begin() + 1, DebugLocOp);
+ Args.append(DebugLocOp + 1, N->op_end());
+
+ // Set the first operand to itself.
+ MDNode *LoopID = MDNode::get(N->getContext(), Args);
+ LoopID->replaceOperandWith(0, LoopID);
+ return LoopID;
+}
+
bool llvm::stripDebugInfo(Function &F) {
bool Changed = false;
if (F.getSubprogram()) {
@@ -246,6 +275,7 @@ bool llvm::stripDebugInfo(Function &F) {
F.setSubprogram(nullptr);
}
+ llvm::DenseMap<llvm::MDNode*, llvm::MDNode*> LoopIDsMap;
for (BasicBlock &BB : F) {
for (auto II = BB.begin(), End = BB.end(); II != End;) {
Instruction &I = *II++; // We may delete the instruction, increment now.
@@ -259,6 +289,15 @@ bool llvm::stripDebugInfo(Function &F) {
I.setDebugLoc(DebugLoc());
}
}
+
+ auto *TermInst = BB.getTerminator();
+ if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) {
+ auto *NewLoopID = LoopIDsMap.lookup(LoopID);
+ if (!NewLoopID)
+ NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
+ if (NewLoopID != LoopID)
+ TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID);
+ }
}
return Changed;
}
OpenPOWER on IntegriCloud