From 494814d52ab0091cd1271b02fc8fa701bd479354 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 16 Nov 2017 19:50:24 +0000 Subject: [PATCH] [SelectionDAG] Consolidate (t|T)ransferDbgValues methods, NFC. TransferDbgValues (capital 'T') is wired into ReplaceAllUsesWith, and transferDbgValues (lowercase 't') is used elsewhere (e.g in Legalize). Both functions should be doing the exact same thing. This patch consolidates the logic into one place. Differential Revision: https://reviews.llvm.org/D40104 llvm-svn: 318448 --- llvm/include/llvm/CodeGen/SelectionDAG.h | 9 +-- .../CodeGen/SelectionDAG/LegalizeTypes.cpp | 7 ++- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 62 ++++++++----------- 3 files changed, 33 insertions(+), 45 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h index bb806c064cf3..ba3511d52624 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAG.h +++ b/llvm/include/llvm/CodeGen/SelectionDAG.h @@ -1195,9 +1195,10 @@ public: unsigned O); /// Transfer debug values from one node to another, while optionally - /// generating fragment expressions for split-up values. + /// generating fragment expressions for split-up values. If \p InvalidateDbg + /// is set, debug values are invalidated after they are transferred. void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0, - unsigned SizeInBits = 0); + unsigned SizeInBits = 0, bool InvalidateDbg = true); /// Remove the specified node from the system. If any of its /// operands then becomes dead, remove them as well. Inform UpdateListener @@ -1279,10 +1280,6 @@ public: return DbgInfo->getSDDbgValues(SD); } -private: - /// Transfer SDDbgValues. Called via ReplaceAllUses{OfValue}?With - void TransferDbgValues(SDValue From, SDValue To); - public: /// Return true if there are any SDDbgValue nodes associated /// with this SelectionDAG. diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp index 053d562a2445..73e29969a21f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp @@ -845,13 +845,14 @@ void DAGTypeLegalizer::SetExpandedInteger(SDValue Op, SDValue Lo, AnalyzeNewValue(Lo); AnalyzeNewValue(Hi); - // Transfer debug values. + // Transfer debug values. Don't invalidate the source debug value until it's + // been transferred to the high and low bits. if (DAG.getDataLayout().isBigEndian()) { - DAG.transferDbgValues(Op, Hi, 0, Hi.getValueSizeInBits()); + DAG.transferDbgValues(Op, Hi, 0, Hi.getValueSizeInBits(), false); DAG.transferDbgValues(Op, Lo, Hi.getValueSizeInBits(), Lo.getValueSizeInBits()); } else { - DAG.transferDbgValues(Op, Lo, 0, Lo.getValueSizeInBits()); + DAG.transferDbgValues(Op, Lo, 0, Lo.getValueSizeInBits(), false); DAG.transferDbgValues(Op, Hi, Lo.getValueSizeInBits(), Hi.getValueSizeInBits()); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 1ed982d6baca..e3d136a378ed 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -7027,16 +7027,29 @@ SDDbgValue *SelectionDAG::getFrameIndexDbgValue(DIVariable *Var, } void SelectionDAG::transferDbgValues(SDValue From, SDValue To, - unsigned OffsetInBits, - unsigned SizeInBits) { + unsigned OffsetInBits, unsigned SizeInBits, + bool InvalidateDbg) { SDNode *FromNode = From.getNode(); SDNode *ToNode = To.getNode(); - assert(FromNode != ToNode); + assert(FromNode && ToNode && "Can't modify dbg values"); + + // Remove these checks when ReplaceAllUsesWith gets stricter. + // TODO: assert(From != To && "Redundant dbg value transfer"); + // TODO: assert(FromNode != ToNode && "Intranode dbg value transfer"); + if (From == To || FromNode == ToNode) + return; + + if (!FromNode->getHasDebugValue()) + return; SmallVector ClonedDVs; for (SDDbgValue *Dbg : GetDbgValues(FromNode)) { - if (Dbg->getKind() != SDDbgValue::SDNODE) - break; + // Just transfer the dbg value attached to From. + if (Dbg->getResNo() != From.getResNo()) + continue; + + assert(!Dbg->isInvalidated() && "Invalid dbg value"); + assert(Dbg->getKind() == SDDbgValue::SDNODE && "Can't transfer dbg value"); DIVariable *Var = Dbg->getVariable(); auto *Expr = Dbg->getExpression(); @@ -7059,7 +7072,9 @@ void SelectionDAG::transferDbgValues(SDValue From, SDValue To, getDbgValue(Var, Expr, ToNode, To.getResNo(), Dbg->isIndirect(), Dbg->getDebugLoc(), Dbg->getOrder()); ClonedDVs.push_back(Clone); - Dbg->setIsInvalidated(); + + if (InvalidateDbg) + Dbg->setIsInvalidated(); } for (SDDbgValue *Dbg : ClonedDVs) @@ -7137,7 +7152,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDValue FromN, SDValue To) { assert(From != To.getNode() && "Cannot replace uses of with self"); // Preserve Debug Values - TransferDbgValues(FromN, To); + transferDbgValues(FromN, To); // Iterate over all the existing uses of From. New uses will be added // to the beginning of the use list, which we avoid visiting. @@ -7196,7 +7211,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To) { for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) if (From->hasAnyUseOfValue(i)) { assert((i < To->getNumValues()) && "Invalid To location"); - TransferDbgValues(SDValue(From, i), SDValue(To, i)); + transferDbgValues(SDValue(From, i), SDValue(To, i)); } // Iterate over just the existing users of From. See the comments in @@ -7240,7 +7255,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) { // Preserve Debug Info. for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) - TransferDbgValues(SDValue(From, i), *To); + transferDbgValues(SDValue(From, i), *To); // Iterate over just the existing users of From. See the comments in // the ReplaceAllUsesWith above. @@ -7287,7 +7302,7 @@ void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To){ } // Preserve Debug Info. - TransferDbgValues(From, To); + transferDbgValues(From, To); // Iterate over just the existing users of From. See the comments in // the ReplaceAllUsesWith above. @@ -7365,7 +7380,7 @@ void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From, if (Num == 1) return ReplaceAllUsesOfValueWith(*From, *To); - TransferDbgValues(*From, *To); + transferDbgValues(*From, *To); // Read up all the uses and make records of them. This helps // processing new uses that are introduced during the @@ -7514,31 +7529,6 @@ void SelectionDAG::AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter) { DbgInfo->add(DB, SD, isParameter); } -/// Transfer SDDbgValues. Called in replace nodes. -void SelectionDAG::TransferDbgValues(SDValue From, SDValue To) { - if (From == To || !From.getNode()->getHasDebugValue()) - return; - SDNode *FromNode = From.getNode(); - SDNode *ToNode = To.getNode(); - SmallVector ClonedDVs; - for (auto *Dbg : GetDbgValues(FromNode)) { - // Only add Dbgvalues attached to same ResNo. - if (Dbg->getKind() == SDDbgValue::SDNODE && - Dbg->getSDNode() == From.getNode() && - Dbg->getResNo() == From.getResNo() && !Dbg->isInvalidated()) { - assert(FromNode != ToNode && - "Should not transfer Debug Values intranode"); - SDDbgValue *Clone = getDbgValue(Dbg->getVariable(), Dbg->getExpression(), - ToNode, To.getResNo(), Dbg->isIndirect(), - Dbg->getDebugLoc(), Dbg->getOrder()); - ClonedDVs.push_back(Clone); - Dbg->setIsInvalidated(); - } - } - for (SDDbgValue *I : ClonedDVs) - AddDbgValue(I, ToNode, false); -} - SDValue SelectionDAG::makeEquivalentMemoryOrdering(LoadSDNode *OldLoad, SDValue NewMemOp) { assert(isa(NewMemOp.getNode()) && "Expected a memop node");