This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Trigger operation/block notification for nested clones in the correct order
Needs ReviewPublic

Authored by springerm on Mar 27 2023, 3:40 AM.

Details

Summary

Fixes an inconsistency where cloneRegionBefore did not notify the listener of "op insertion" (whereas OpBuilder::clone does). Various parts of the core infrastructure such as the GreedyPatternRewriteDriver depend on such notifications.

Also fixes a bug where no notifications were sent about block creation when cloning IR.

Ops/blocks are notified in such an order in which they could have been created one-by-one with an OpBuilder. This ensures that when a listener is notified about an op being created, it was already notified about the defining ops of the operands (unless there is a block cycle/graph region).

As a consequence, this allows us to use the same cloneRegionBefore implementation in the dialect conversion. This makes it possible to make the function non-virtual and to move this function to the OpBuilder (instead of RewriterBase).

Note: This revision subsumes D144194, D144266 and D144000.

Depends On: D144193

Diff Detail

Event Timeline

springerm created this revision.Mar 27 2023, 3:40 AM
springerm requested review of this revision.Mar 27 2023, 3:40 AM
springerm added inline comments.Mar 27 2023, 3:44 AM
mlir/lib/IR/Builders.cpp
532–533

Note: An alternative would be to not even clone dead blocks. But this would require a different Operation::clone implementation.