A group of functions in the Affine dialect provides a mechanism for
buliding folded-by-construction operations. These functions used to
accept a RewriterBase reference because they may need to erase the
operations that were folded and notify the rewriter when called from
rewrite patterns. Adopt a different approach: postpone the builder
notification of the op creation until we are certain that the op will
not be folded away. This removes the need to notify the rewriter about
op deletion following op construction in case of successful folding, and
removes a bunch of one-off IRRewriter instances in transform code that
may mess up insertion points.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I hit the exact same issue, and was embarking on a similar change, but I think there is an issue with erasing operations here.
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | ||
---|---|---|
787 | Actually this is pretty dangerous AFAIK. If you send a pattern rewriter objet and it doesnt know that the operation is being erased that can cause some very subtle errors. My rule of thumb is no method that uses OpBuilder should ever erase an operation. That makes it unusable if a PatternRewriter is passed in. @rriddle can thorw more light on this. |
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | ||
---|---|---|
787 | This is a good knee-jerk reaction, but I understand the builder code well enough to claim there is no danger here. The rewriter will not get notified about the op being created in the first place because the listener is reset 5 lines above (PatternRewriter derives from OpBuilder::Listener and sets itself as listener). So it doesn't need to know about the op being erased either. The existence of this op will have been completely opaque to the rewriter. |
Thanks!
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | ||
---|---|---|
787 | Sorry, didnt mean to suggest that you didnt know. Its something I have hit many times and been burnt by it. Should have worded it better. You obviously know this much better than me. Didnt know about the Listener trick above. Handy! |
Actually this is pretty dangerous AFAIK. If you send a pattern rewriter objet and it doesnt know that the operation is being erased that can cause some very subtle errors. My rule of thumb is no method that uses OpBuilder should ever erase an operation. That makes it unusable if a PatternRewriter is passed in.
@rriddle can thorw more light on this.