From: Vedant Kumar Date: Mon, 23 Jul 2018 21:59:04 +0000 (+0000) Subject: [SelectionDAG] Reduce DanglingDebugInfo memory traffic, NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=113fd07750c797025a93dfd128e45af39ed33549;p=llvm [SelectionDAG] Reduce DanglingDebugInfo memory traffic, NFC This avoids approx. 2 x 10^5 DenseMap insertions in both non-debug and debug -O2 builds of the sqlite3 amalgamation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337751 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index f91cf709df5..1e36ea049b1 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1093,30 +1093,35 @@ void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) { void SelectionDAGBuilder::dropDanglingDebugInfo(const DILocalVariable *Variable, const DIExpression *Expr) { - for (auto &DDIMI : DanglingDebugInfoMap) - for (auto &DDI : DDIMI.second) - if (DDI.getDI()) { - const DbgValueInst *DI = DDI.getDI(); - DIVariable *DanglingVariable = DI->getVariable(); - DIExpression *DanglingExpr = DI->getExpression(); - if (DanglingVariable == Variable && - Expr->fragmentsOverlap(DanglingExpr)) { - LLVM_DEBUG(dbgs() - << "Dropping dangling debug info for " << *DI << "\n"); - DDI = DanglingDebugInfo(); - } - } + auto isMatchingDbgValue = [&](DanglingDebugInfo &DDI) { + const DbgValueInst *DI = DDI.getDI(); + DIVariable *DanglingVariable = DI->getVariable(); + DIExpression *DanglingExpr = DI->getExpression(); + if (DanglingVariable == Variable && Expr->fragmentsOverlap(DanglingExpr)) { + LLVM_DEBUG(dbgs() << "Dropping dangling debug info for " << *DI << "\n"); + return true; + } + return false; + }; + + for (auto &DDIMI : DanglingDebugInfoMap) { + DanglingDebugInfoVector &DDIV = DDIMI.second; + DDIV.erase(remove_if(DDIV, isMatchingDbgValue), DDIV.end()); + } } // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V, // generate the debug data structures now that we've seen its definition. void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V, SDValue Val) { - DanglingDebugInfoVector &DDIV = DanglingDebugInfoMap[V]; + auto DanglingDbgInfoIt = DanglingDebugInfoMap.find(V); + if (DanglingDbgInfoIt == DanglingDebugInfoMap.end()) + return; + + DanglingDebugInfoVector &DDIV = DanglingDbgInfoIt->second; for (auto &DDI : DDIV) { - if (!DDI.getDI()) - continue; const DbgValueInst *DI = DDI.getDI(); + assert(DI && "Ill-formed DanglingDebugInfo"); DebugLoc dl = DDI.getdl(); unsigned ValSDNodeOrder = Val.getNode()->getIROrder(); unsigned DbgSDNodeOrder = DDI.getSDNodeOrder(); @@ -1146,7 +1151,7 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V, } else LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n"); } - DanglingDebugInfoMap[V].clear(); + DDIV.clear(); } /// getCopyFromRegs - If there was virtual register allocated for the value V @@ -5320,8 +5325,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) { if (!V->use_empty() ) { // Do not call getValue(V) yet, as we don't want to generate code. // Remember it for later. - DanglingDebugInfo DDI(&DI, dl, SDNodeOrder); - DanglingDebugInfoMap[V].push_back(DDI); + DanglingDebugInfoMap[V].emplace_back(&DI, dl, SDNodeOrder); return nullptr; }