This is an archive of the discontinued LLVM Phabricator instance.

[mlir][DialectConversion] Add support for mergeBlocks in ConversionPatternRewriter.
ClosedPublic

Authored by mravishankar on Jul 28 2020, 1:30 PM.

Diff Detail

Event Timeline

mravishankar created this revision.Jul 28 2020, 1:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2020, 1:30 PM
mravishankar requested review of this revision.Jul 28 2020, 1:30 PM

Thanks Mahesh!! Looks good, just had some comments on the encoding.

mlir/lib/Transforms/DialectConversion.cpp
627

Assuming all of the other operations are tracked properly, all you really need to do a merge is:

  • The source block
  • The destination block
  • A pointer to the operation that was the previous end of the block destination block. If the destination block was empty, this is just nullptr.

When reverting all you would need to do is splice back (origEnd++, curEnd) to the source block.

644

Please avoid any use of std::distance or random access on these containers, they are intrusive linked lists. These computations all run O(N).

I just noticed that getErase is doing the same thing, it shouldn't.

mlir/test/lib/Dialect/Test/TestPatterns.cpp
559

Can you add a new driver instead? This one is overly bloated at this point.

mravishankar marked 3 inline comments as done.Jul 30 2020, 2:09 AM
mravishankar added inline comments.
mlir/lib/Transforms/DialectConversion.cpp
644

Removed the std::distance from here.

Re: use of std::distance in getErased, does that mean I change BlockPosition to be {Region *, Block*} where the block * is the block erased (it is actually same as sourceBlock, so we only need the Region* then?

mravishankar marked an inline comment as done.

Addressing comments

rriddle accepted this revision.Jul 31 2020, 12:12 PM
rriddle added inline comments.
mlir/lib/Transforms/DialectConversion.cpp
623

Do you actually need this if you are relying on the erase action to do the backtracking?

644

Yeah I would change BlockPosition to use a similar scheme, i.e. keep a pointer to the previous block(or null if the region only has a single block).

1003

destBlockLastInst can be null here.

1335

typo: ezpected

mlir/test/lib/Dialect/Test/TestOps.td
1167

Move the brace to the previous line.

mlir/test/lib/Dialect/Test/TestPatterns.cpp
849

You can initialize the SmallVector with the range directly, no need to use begin/end.

871

Same here.

This revision is now accepted and ready to land.Jul 31 2020, 12:12 PM
mravishankar marked 2 inline comments as done.

Addressing comments

mravishankar marked 5 inline comments as done.

Addressing missed comments

mlir/lib/Transforms/DialectConversion.cpp
623

No, its actually not used anywhere now. Removed.

644

Added a follow up patch to do this.

1003

Handled it now. Thanks.

rriddle added inline comments.Jul 31 2020, 10:39 PM
mlir/lib/Transforms/DialectConversion.cpp
642

block->empty()?

644

nit: Drop the ()

Harbormaster completed remote builds in B66643: Diff 282369.
mravishankar marked 2 inline comments as done.

Address minor comments

This revision was landed with ongoing or failed builds.Aug 3 2020, 10:06 AM
This revision was automatically updated to reflect the committed changes.