This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpBuilder] Remove the vtable from OpBuilder in favor of using the listener pattern
ClosedPublic

Authored by rriddle on Apr 30 2020, 2:06 PM.

Details

Summary

The current OpBuilder has a set of virtual functions required by the fact that the PatternRewriter inherits from it for convenience. The PatternRewriter is required to know about IR mutations for correctness. This revision changes the relationship to be explicit by having users register a listener with the builder instead of using inheritance/vtables. This still requires that users properly transfer the listener when creating new builders, but has several benefits:

  • More than one builder can be created during pattern rewrites(assuming that the listener is properly forwarded)
  • OpBuilder no longer requires a vtable, and thus does not incur the cost when a listener isn't present.

Diff Detail

Event Timeline

rriddle created this revision.Apr 30 2020, 2:06 PM
rriddle updated this revision to Diff 261352.Apr 30 2020, 2:09 PM

Update comment to use ///

nicolasvasilache accepted this revision.Apr 30 2020, 2:46 PM
This revision is now accepted and ready to land.Apr 30 2020, 2:46 PM
ftynse accepted this revision.Apr 30 2020, 3:12 PM

Thanks, River!

I am not sure I completely understand the relation of this with EDSC/ScopedContext (I expect it to be just transparent), but we intend to clean the ScopedContext soon anyway.

mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
389 ↗(On Diff #261354)

Could you please elaborate why this is necessary? There are other uses of GenericLoopNestRangeBuilder in LinalgToLoops that are not modified...

Harbormaster completed remote builds in B55370: Diff 261352.
Harbormaster failed remote builds in B55372: Diff 261354!
rriddle marked 2 inline comments as done.Apr 30 2020, 3:58 PM
rriddle added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
389 ↗(On Diff #261354)

b is being copied, so wasn't previously notifying the PatterRewriter of any generated operations. One of the tests relied on this behavior and broke, but Nicolas removed that test so this can be removed now. This was the only builder that a test relied on for the old(incorrect) behavior, so it was the only one I updated.

rriddle marked an inline comment as done.Apr 30 2020, 3:59 PM
rriddle updated this revision to Diff 261429.Apr 30 2020, 9:29 PM

Remove FIXME that is no longer necessary

This revision was automatically updated to reflect the committed changes.