[Mlir-commits] [mlir] [flang] [mlir][IR] Add rewriter API for moving operations (PR #78988)

Mehdi Amini llvmlistbot at llvm.org
Tue Jan 23 00:30:43 PST 2024


================
@@ -366,3 +366,31 @@ void RewriterBase::cloneRegionBefore(Region &region, Region &parent,
 void RewriterBase::cloneRegionBefore(Region &region, Block *before) {
   cloneRegionBefore(region, *before->getParent(), before->getIterator());
 }
+
+void RewriterBase::moveOpBefore(Operation *op, Operation *existingOp) {
+  moveOpBefore(op, existingOp->getBlock(), existingOp->getIterator());
+}
+
+void RewriterBase::moveOpBefore(Operation *op, Block *block,
+                                Block::iterator iterator) {
+  Block *currentBlock = op->getBlock();
+  Block::iterator currentIterator = op->getIterator();
+  op->moveBefore(block, iterator);
+  if (listener)
+    listener->notifyOperationInserted(
+        op, /*previous=*/InsertPoint(currentBlock, currentIterator));
----------------
joker-eph wrote:

It's not clear to me what operations should be considered "changed" when we move an op.

For example sinking:
```
A;
for (...) {
  if (...) {
    ...
  }
}
```

to

```
for (...) {
  if (...) {
    A 
    ...
  }
}
```

Is the "if" modified? The "for"?
Is `notifyOperationInserted` really meant to handle arbitrary moves and the handler must handle all this?

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


More information about the Mlir-commits mailing list