[llvm] [DebugInfo][RemoveDIs] Add local-utility plumbing for DPValues (PR #72276)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 09:17:19 PST 2023


================
@@ -2266,6 +2504,33 @@ static bool rewriteDebugUsers(
         UndefOrSalvage.insert(DII);
       }
     }
+
+    // DPValue implementation of the above.
+    // RemoveDIs misery: The above loop of intrinsic-users are ordered by the
+    // use-list of the corresponding metadata-as-value: in reverse order of when
+    // they were added. Wheras DPUsers are ordered by when they were added to
+    // the replaceable-metadata map, i.e., in the order they were added. Thus to
+    // have matching orders between the two, we have to reverse here. For
+    // RemoveDIs we might in the long run need to consider whether this implicit
+    // ordering is relied upon by any other part of LLVM.
+    for (auto *DPV : llvm::reverse(DPUsers)) {
+      Instruction *MarkedInstr = DPV->getMarker()->MarkedInstr;
+      Instruction *NextNonDebug = MarkedInstr;
+      // The next instruction might still be a dbg.declare, skip over it.
+      if (isa<DbgVariableIntrinsic>(NextNonDebug))
+        NextNonDebug = NextNonDebug->getNextNonDebugInstruction();
+
+      if (DomPointAfterFrom && NextNonDebug == &DomPoint) {
+        LLVM_DEBUG(dbgs() << "MOVE:  " << *DPV << '\n');
+        DPV->removeFromParent();
+        // Ensure there's a marker.
+        DomPoint.getParent()->createMarker(std::next(DomPoint.getIterator()));
+        DomPoint.getParent()->insertDPValueAfter(DPV, &DomPoint);
----------------
OCHyams wrote:

Can we move the `createMarker is one doesn't exist` code into `insertDPValueBefore/After` if it's not already done in other patches (in a future patch) - or is there a reason to keep 2 distinct steps?

https://github.com/llvm/llvm-project/pull/72276


More information about the llvm-commits mailing list