[Mlir-commits] [mlir] Reland: [MLIR][Transforms] Fix Mem2Reg removal order to respect dominance (PR #68877)

Johannes de Fine Licht llvmlistbot at llvm.org
Thu Oct 12 04:39:01 PDT 2023


================
@@ -515,15 +519,37 @@ void MemorySlotPromoter::computeReachingDefInRegion(Region *region,
   }
 }
 
+/// Sorts `ops` according to dominance. Relies on the topological order of basic
+/// blocks to get a deterministic ordering.
+static void dominanceSort(SmallVector<Operation *> &ops, Region &region) {
+  // Produce a topological block order and construct a map to lookup the indices
+  // of blocks.
+  DenseMap<Block *, size_t> topoBlockIndices;
+  SetVector<Block *> topologicalOrder = getTopologicallySortedBlocks(region);
+  for (auto [index, block] : llvm::enumerate(topologicalOrder))
+    topoBlockIndices[block] = index;
+
+  // Combining the topological order of the basic blocks together with block
+  // internal operation order guarentees a deterministic, dominance respecting
----------------
definelicht wrote:

```suggestion
  // internal operation order guarantees a deterministic, dominance respecting
```

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


More information about the Mlir-commits mailing list