[Mlir-commits] [mlir] [mlir][IR] Send missing notifications when inlining a block (PR #79593)

Matthias Springer llvmlistbot at llvm.org
Wed Jan 31 05:20:31 PST 2024


================
@@ -317,7 +317,16 @@ void RewriterBase::inlineBlockBefore(Block *source, Block *dest,
 
   // Move operations from the source block to the dest block and erase the
   // source block.
-  dest->getOperations().splice(before, source->getOperations());
+  if (!listener) {
+    // Fast path: If no listener is attached, move all operations at once.
+    dest->getOperations().splice(before, source->getOperations());
+  } else {
+    while (!source->empty())
----------------
matthias-springer wrote:

I didn't measure it but I expect the current implementation to be slightly slower than a `splice` followed by a loop that sends all the notifications.

However, the current implementation is the only safe way to implement it. The `notifyOperationInserted` notification has a `Block::iterator` for the previous location of the op, and when moving more than one op at once, it may not be possible to pass a valid `Block::iterator` for the previous location of the first op. (Moving the second op could invalidate the iterator for the first op, or make it point somewhere else.)

I added the fast path to make sure that we have the same performance as before in most cases.


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


More information about the Mlir-commits mailing list