Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -103,18 +103,32 @@ /// Helper type for DanglingDebugInfoMap. class DanglingDebugInfo { - const DbgValueInst* DI = nullptr; - DebugLoc dl; + const DbgValueInst *DI = nullptr; unsigned SDNodeOrder = 0; public: DanglingDebugInfo() = default; DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) - : DI(di), dl(std::move(DL)), SDNodeOrder(SDNO) {} + : DI(di), SDNodeOrder(SDNO) {} - const DbgValueInst* getDI() { return DI; } - DebugLoc getdl() { return dl; } - unsigned getSDNodeOrder() { return SDNodeOrder; } + DILocalVariable *getVariable() const { return DI->getVariable(); } + DIExpression *getExpression() const { return DI->getExpression(); } + Value *getVariableLocationOp(unsigned Idx) const { + assert(Idx == 0 && "variadic not supported yet"); + return DI->getVariableLocationOp(0); + } + DebugLoc getdl() const { return DI->getDebugLoc(); } + unsigned getSDNodeOrder() const { return SDNodeOrder; } + + friend raw_ostream &operator<<(raw_ostream &OS, + const DanglingDebugInfo &Info) { + OS << "DDI(var=" << *Info.getVariable() + << ", val= " << *Info.getVariableLocationOp(0) + << ", expr=" << *Info.getExpression() + << ", order=" << Info.getSDNodeOrder() << ", loc=" << Info.getdl() + << ")"; + return OS; + } }; /// Helper type for DanglingDebugInfoMap. Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1185,11 +1185,10 @@ void SelectionDAGBuilder::dropDanglingDebugInfo(const DILocalVariable *Variable, const DIExpression *Expr) { auto isMatchingDbgValue = [&](DanglingDebugInfo &DDI) { - const DbgValueInst *DI = DDI.getDI(); - DIVariable *DanglingVariable = DI->getVariable(); - DIExpression *DanglingExpr = DI->getExpression(); + DIVariable *DanglingVariable = DDI.getVariable(); + DIExpression *DanglingExpr = DDI.getExpression(); if (DanglingVariable == Variable && Expr->fragmentsOverlap(DanglingExpr)) { - LLVM_DEBUG(dbgs() << "Dropping dangling debug info for " << *DI << "\n"); + LLVM_DEBUG(dbgs() << "Dropping dangling debug info for " << DDI << "\n"); return true; } return false; @@ -1218,14 +1217,11 @@ DanglingDebugInfoVector &DDIV = DanglingDbgInfoIt->second; for (auto &DDI : DDIV) { - const DbgValueInst *DI = DDI.getDI(); - assert(!DI->hasArgList() && "Not implemented for variadic dbg_values"); - assert(DI && "Ill-formed DanglingDebugInfo"); DebugLoc dl = DDI.getdl(); unsigned ValSDNodeOrder = Val.getNode()->getIROrder(); unsigned DbgSDNodeOrder = DDI.getSDNodeOrder(); - DILocalVariable *Variable = DI->getVariable(); - DIExpression *Expr = DI->getExpression(); + DILocalVariable *Variable = DDI.getVariable(); + DIExpression *Expr = DDI.getExpression(); assert(Variable->isValidLocationForIntrinsic(dl) && "Expected inlined-at fields to agree"); SDDbgValue *SDV; @@ -1237,8 +1233,7 @@ // have some test case that prove this to be correct we should avoid // calling EmitFuncArgumentDbgValue here. if (!EmitFuncArgumentDbgValue(V, Variable, Expr, dl, false, Val)) { - LLVM_DEBUG(dbgs() << "Resolve dangling debug info [order=" - << DbgSDNodeOrder << "] for:\n " << *DI << "\n"); + LLVM_DEBUG(dbgs() << "Resolve dangling debug info for " << DDI << "\n"); LLVM_DEBUG(dbgs() << " By mapping to:\n "; Val.dump()); // Increase the SDNodeOrder for the DbgValue here to make sure it is // inserted after the definition of Val when emitting the instructions @@ -1251,11 +1246,11 @@ std::max(DbgSDNodeOrder, ValSDNodeOrder)); DAG.AddDbgValue(SDV, false); } else - LLVM_DEBUG(dbgs() << "Resolved dangling debug info for " << *DI + LLVM_DEBUG(dbgs() << "Resolved dangling debug info for " << DDI << "in EmitFuncArgumentDbgValue\n"); } else { - LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n"); - auto Undef = UndefValue::get(DDI.getDI()->getValue(0)->getType()); + LLVM_DEBUG(dbgs() << "Dropping debug info for " << DDI << "\n"); + auto Undef = UndefValue::get(V->getType()); auto SDV = DAG.getConstantDbgValue(Variable, Expr, Undef, dl, DbgSDNodeOrder); DAG.AddDbgValue(SDV, false); @@ -1269,16 +1264,15 @@ // state of `handleDebugValue`, we need know specifically which values were // invalid, so that we attempt to salvage only those values when processing // a DIArgList. - assert(!DDI.getDI()->hasArgList() && - "Not implemented for variadic dbg_values"); - Value *V = DDI.getDI()->getValue(0); - DILocalVariable *Var = DDI.getDI()->getVariable(); - DIExpression *Expr = DDI.getDI()->getExpression(); + Value *V = DDI.getVariableLocationOp(0); + Value *OrigV = V; + DILocalVariable *Var = DDI.getVariable(); + DIExpression *Expr = DDI.getExpression(); DebugLoc DL = DDI.getdl(); unsigned SDOrder = DDI.getSDNodeOrder(); + // Currently we consider only dbg.value intrinsics -- we tell the salvager // that DW_OP_stack_value is desired. - assert(isa(DDI.getDI())); bool StackValue = true; // Can this Value can be encoded without any further work? @@ -1312,8 +1306,9 @@ // Some kind of simplification occurred: check whether the operand of the // salvaged debug expression can be encoded in this DAG. if (handleDebugValue(V, Var, Expr, DL, SDOrder, /*IsVariadic=*/false)) { - LLVM_DEBUG(dbgs() << "Salvaged debug location info for:\n " - << DDI.getDI() << "\nBy stripping back to:\n " << V); + LLVM_DEBUG( + dbgs() << "Salvaged debug location info for:\n " << *Var << "\n" + << *OrigV << "\nBy stripping back to:\n " << *V << "\n"); return; } } @@ -1321,14 +1316,12 @@ // This was the final opportunity to salvage this debug information, and it // couldn't be done. Place an undef DBG_VALUE at this location to terminate // any earlier variable location. - auto Undef = UndefValue::get(DDI.getDI()->getValue(0)->getType()); + assert(OrigV && "V shouldn't be null"); + auto Undef = UndefValue::get(OrigV->getType()); auto SDV = DAG.getConstantDbgValue(Var, Expr, Undef, DL, SDNodeOrder); DAG.AddDbgValue(SDV, false); - LLVM_DEBUG(dbgs() << "Dropping debug value info for:\n " << DDI.getDI() - << "\n"); - LLVM_DEBUG(dbgs() << " Last seen at:\n " << *DDI.getDI()->getOperand(0) - << "\n"); + LLVM_DEBUG(dbgs() << "Dropping debug value info for:\n " << DDI << "\n"); } bool SelectionDAGBuilder::handleDebugValue(ArrayRef Values,