[PATCH] D113468: Fix nondeterminism in debuginfo generation

Ilya Yanok via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 00:30:32 PST 2021


yanok created this revision.
Herald added subscribers: mgrang, hiraditya, qcolombet, MatzeB.
yanok requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changes from commit 1db137b1859692ae33228c530d4df9f2431b2151 <https://reviews.llvm.org/rG1db137b1859692ae33228c530d4df9f2431b2151>
added iteration over hash map that can result in non-deterministic
order. Fix that by traversing a vector instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113468

Files:
  llvm/lib/CodeGen/RegAllocFast.cpp


Index: llvm/lib/CodeGen/RegAllocFast.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocFast.cpp
+++ llvm/lib/CodeGen/RegAllocFast.cpp
@@ -436,10 +436,17 @@
       SpilledOperandsMap;
   for (MachineOperand *MO : LRIDbgOperands)
     SpilledOperandsMap[MO->getParent()].push_back(MO);
-  for (auto MISpilledOperands : SpilledOperandsMap) {
-    MachineInstr &DBG = *MISpilledOperands.first;
-    MachineInstr *NewDV = buildDbgValueForSpill(
-        *MBB, Before, *MISpilledOperands.first, FI, MISpilledOperands.second);
+  // We can't iterate over SpilledOperandsMap directly as it can result in
+  // non-deterministic ordering. Instead we iterate over LRIDbgOperands again
+  // but keep track of already processed instructions.
+  SmallDenseSet<MachineInstr *> ProcessedSet;
+  for (MachineOperand *MO : LRIDbgOperands) {
+    auto DBG = MO->getParent();
+    if (ProcessedSet.contains(DBG))
+      continue;
+    ProcessedSet.insert(DBG);
+    MachineInstr *NewDV =
+        buildDbgValueForSpill(*MBB, Before, *DBG, FI, SpilledOperandsMap[DBG]);
     assert(NewDV->getParent() == MBB && "dangling parent pointer");
     (void)NewDV;
     LLVM_DEBUG(dbgs() << "Inserting debug info due to spill:\n" << *NewDV);
@@ -457,10 +464,10 @@
     // Rewrite unassigned dbg_values to use the stack slot.
     // TODO We can potentially do this for list debug values as well if we know
     // how the dbg_values are getting unassigned.
-    if (DBG.isNonListDebugValue()) {
-      MachineOperand &MO = DBG.getDebugOperand(0);
+    if (DBG->isNonListDebugValue()) {
+      MachineOperand &MO = DBG->getDebugOperand(0);
       if (MO.isReg() && MO.getReg() == 0) {
-        updateDbgValueForSpill(DBG, FI, 0);
+        updateDbgValueForSpill(*DBG, FI, 0);
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113468.385720.patch
Type: text/x-patch
Size: 1820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211109/c5c53b5d/attachment.bin>


More information about the llvm-commits mailing list