From 9b4b8c8d7b7a2b249e2947a570385a6740c7dade Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Sun, 19 Mar 2017 13:54:57 +0000 Subject: Enable stripping of multiple DILocation on !llvm.loop metadata Summary: I found that stripDebugInfo was still leaving significant amounts of debug info due to !llvm.loop that contained DILocation after stripping. The support for stripping debug info on !llvm.loop added in r293377 only removes a single DILocation. Enhance that to remove all DILocation from !llvm.loop. Reviewers: hfinkel, aprantl, dsanders Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31117 llvm-svn: 298213 --- llvm/lib/IR/DebugInfo.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 5e14723c3af..918fdc26068 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -241,26 +241,29 @@ bool DebugInfoFinder::addScope(DIScope *Scope) { 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(Op.get()); - }); - // No debug location, we do not have to rewrite this MDNode. - if (DebugLocOp == N->op_end()) + // if there is no debug location, we do not have to rewrite this MDNode. + if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { + return isa(Op.get()); + })) return N; - // There is only the debug location without any actual loop metadata, hence we + // If there is only the debug location without any actual loop metadata, we // can remove the metadata. - if (N->getNumOperands() == 2) + if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { + return !isa(Op.get()); + })) return nullptr; SmallVector 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()); + // Add all non-debug location operands back. + for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) { + if (!isa(*Op)) + Args.push_back(*Op); + } // Set the first operand to itself. MDNode *LoopID = MDNode::get(N->getContext(), Args); -- cgit v1.2.3