diff --git a/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h b/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h --- a/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h +++ b/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h @@ -138,7 +138,9 @@ private: LocOpVector LocationOps; - SDNodeVector SDNodes; + // SDNode dependencies will be calculated as SDNodes that appear in + // LocationOps plus these AdditionalDependencies. + SDNodeVector AdditionalDependencies; DIVariable *Var; DIExpression *Expr; DebugLoc DL; @@ -153,8 +155,9 @@ ArrayRef Dependencies, bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic) : LocationOps(L.begin(), L.end()), - SDNodes(Dependencies.begin(), Dependencies.end()), Var(Var), Expr(Expr), - DL(DL), Order(O), IsIndirect(IsIndirect), IsVariadic(IsVariadic) { + AdditionalDependencies(Dependencies.begin(), Dependencies.end()), + Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect), + IsVariadic(IsVariadic) { assert(IsVariadic || L.size() == 1); assert(!(IsVariadic && IsIndirect)); } @@ -170,9 +173,18 @@ LocOpVector copyLocationOps() const { return LocationOps; } // Returns the SDNodes which this SDDbgValue depends on. - ArrayRef getSDNodes() const { return SDNodes; } + SDNodeVector getSDNodes() const { + SDNodeVector Dependencies; + for (SDDbgOperand DbgOp : LocationOps) + if (DbgOp.getKind() == SDDbgOperand::SDNODE) + Dependencies.push_back(DbgOp.getSDNode()); + Dependencies.append(AdditionalDependencies); + return Dependencies; + } - SDNodeVector copySDNodes() const { return SDNodes; } + ArrayRef getAdditionalDependencies() const { + return AdditionalDependencies; + } /// Returns whether this is an indirect value. bool isIndirect() const { return IsIndirect; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -8480,7 +8480,7 @@ assert(cast(Var)->isValidLocationForIntrinsic(DL) && "Expected inlined-at fields to agree"); return new (DbgInfo->getAlloc()) - SDDbgValue(Var, Expr, SDDbgOperand::fromNode(N, R), N, IsIndirect, DL, O, + SDDbgValue(Var, Expr, SDDbgOperand::fromNode(N, R), {}, IsIndirect, DL, O, /*IsVariadic=*/false); } @@ -8604,12 +8604,10 @@ Expr = *Fragment; } - auto NewDependencies = Dbg->copySDNodes(); - std::replace(NewDependencies.begin(), NewDependencies.end(), FromNode, - ToNode); + auto AdditionalDependencies = Dbg->getAdditionalDependencies(); // Clone the SDDbgValue and move it to To. SDDbgValue *Clone = getDbgValueList( - Var, Expr, NewLocOps, NewDependencies, Dbg->isIndirect(), + Var, Expr, NewLocOps, AdditionalDependencies, Dbg->isIndirect(), Dbg->getDebugLoc(), std::max(ToNode->getIROrder(), Dbg->getOrder()), Dbg->isVariadic()); ClonedDVs.push_back(Clone); @@ -8669,11 +8667,9 @@ (void)Changed; assert(Changed && "Salvage target doesn't use N"); - auto NewDependencies = DV->copySDNodes(); - std::replace(NewDependencies.begin(), NewDependencies.end(), &N, - N0.getNode()); + auto AdditionalDependencies = DV->getAdditionalDependencies(); SDDbgValue *Clone = getDbgValueList(DV->getVariable(), DIExpr, - NewLocOps, NewDependencies, + NewLocOps, AdditionalDependencies, DV->isIndirect(), DV->getDebugLoc(), DV->getOrder(), DV->isVariadic()); ClonedDVs.push_back(Clone); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1340,7 +1340,6 @@ // Only emit func arg dbg value for non-variadic dbg.values for now. if (!IsVariadic && EmitFuncArgumentDbgValue(V, Var, Expr, dl, false, N)) return true; - Dependencies.push_back(N.getNode()); if (auto *FISDN = dyn_cast(N.getNode())) { // Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can // describe stack slot locations. @@ -1352,6 +1351,7 @@ // dbg.value(i32* %px, !"int x", !DIExpression(DW_OP_deref)) // // Both describe the direct values of their associated variables. + Dependencies.push_back(N.getNode()); LocationOps.emplace_back(SDDbgOperand::fromFrameIdx(FISDN->getIndex())); continue; }