This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Move cloneRegionBefore to OpBuilder
AbandonedPublic

Authored by springerm on Feb 14 2023, 3:47 AM.

Details

Summary

OpBuilder provides helper functions for cloning ops. MLIR also provides helper functions for cloning regions, but they are currently part of RewriterBase. They can be part of OpBuilder because they only insert new IR.

To be compatible with the dialect conversion, blocks (and their containing ops) must be notified according to their successor relationship. Without dialect conversion in mind, this may seem arbitrary, but it is a valid notification order for any listener. For a general listener, the only requirement when cloning IR is that we send out notifications in way that could that have been the result of creating the operations (and blocks) one-by-one through the builder API.

Dialect conversion is simplified: cloneRegionBefore is no longer overridden. Furthermore, regions that are inserted via OpBuilder::clone are now notified in an order that is suitable for dialect conversion. (Dialect conversion used to override RewriterBase::cloneRegionBefore but not OpBuilder::clone; this was a bug.)

Depends On: D144266

Diff Detail

Event Timeline

springerm created this revision.Feb 14 2023, 3:47 AM
springerm requested review of this revision.Feb 14 2023, 3:47 AM
mehdi_amini added inline comments.Feb 14 2023, 10:06 AM
mlir/include/mlir/IR/Builders.h
231

This class is free of a vtable right now and as a default destructor. We're making it not just free anymore to just use freely an OpBuilder anywhere just as a convenient access to the method it provides to get builtin attributes/types.

springerm updated this revision to Diff 498033.Feb 16 2023, 8:20 AM

split revision and rebase

springerm retitled this revision from [mlir][IR] Move cloneRegionBefore to OpBuilder and notify listeners to [mlir][IR][NFC] Move cloneRegionBefore to OpBuilder.Feb 16 2023, 8:21 AM
springerm edited the summary of this revision. (Show Details)
springerm added inline comments.Feb 16 2023, 8:26 AM
mlir/include/mlir/IR/Builders.h
231

I think I can make cloneRegionBefore non-virtual. It is overridden in the rewriter of the dialect conversion. If we insert the ops in the "right" order in the OpBuilder, it should not be necessary to override the function. This may also make the processing a bit more efficient in the GreedyPatternRewriteDriver because the ops would be enqueued following the linking of blocks. (Not really sure about this, maybe it does nothing...)

springerm updated this revision to Diff 498367.Feb 17 2023, 7:29 AM
springerm edited the summary of this revision. (Show Details)

OpBuilder no longer virtual

springerm retitled this revision from [mlir][IR][NFC] Move cloneRegionBefore to OpBuilder to [mlir][IR] Move cloneRegionBefore to OpBuilder.EditedFeb 17 2023, 7:30 AM
springerm edited the summary of this revision. (Show Details)

This needs a test case (for the OpBuilder::clone bug that is fixed in the dialect conversion) but I wanted to gather people's opinions first.

springerm abandoned this revision.Mar 27 2023, 3:41 AM