[Mlir-commits] [mlir] [mlir][Transforms] Add a utility method to move value definitions. (PR #130874)

Ian Wood llvmlistbot at llvm.org
Tue Mar 11 20:27:11 PDT 2025


================
@@ -1115,3 +1115,72 @@ LogicalResult mlir::moveOperationDependencies(RewriterBase &rewriter,
   DominanceInfo dominance(op);
   return moveOperationDependencies(rewriter, op, insertionPoint, dominance);
 }
+
+LogicalResult mlir::moveValueDefinitions(RewriterBase &rewriter,
+                                         ValueRange values,
+                                         Operation *insertionPoint,
+                                         DominanceInfo &dominance) {
+  // Remove the values that already dominate the insertion point.
+  SmallVector<Value> prunedValues;
+  for (auto value : values) {
+    if (dominance.properlyDominates(value, insertionPoint)) {
+      continue;
+    }
+    // Block arguments are not supported.
+    if (isa<BlockArgument>(value)) {
+      return rewriter.notifyMatchFailure(
+          insertionPoint,
+          "unsupported case of moving block argument before insertion point");
+    }
+    // Check for currently unsupported case if the insertion point is in a
+    // different block.
+    if (value.getDefiningOp()->getBlock() != insertionPoint->getBlock()) {
+      return rewriter.notifyMatchFailure(
+          insertionPoint,
+          "unsupported case of moving definition of value before an insertion "
+          "point in a different basic block");
+    }
----------------
IanWood1 wrote:

I think can be simplified to just use `getParentBlock()`

```suggestion
    // Check for currently unsupported case if the insertion point is in a
    // different block.
    if (value.getParentBlock() != insertionPoint->getBlock()) {
      return rewriter.notifyMatchFailure(
          insertionPoint,
          "unsupported case of moving definition of value before an insertion "
          "point in a different basic block");
    }
```



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


More information about the Mlir-commits mailing list