This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Separate Listener from PatternRewriter
AbandonedPublic

Authored by Mogball on Dec 21 2021, 10:40 PM.

Details

Summary

Introduce a new RewriteListener class that replaces the previous OpBuilder::Listener and takes some of the methods that were in PatternRewriter. Moving the listening logic out of PatternRewriter and consolidating it in a new class gives users and developers more control over listening to rewrite events and makes listeners more composable.

For example, this patch also adds a ListenerList which is just a RewriteListener that forwards events to multiple listeners. Rewrite drivers that were previously implemented by subclassing PatternRewriter can be implemented by subclassing RewriteListener instead, and then they can accept a user-provided listener that will also be notified of any rewrite events.

Also adds an optional listener to the greedy rewrite driver. Previously, there was no way to be made aware of IR changes made by the greedy rewriter, which makes it difficult to pass information about the IR through multiple rewrite passes, e.g. tracking whether a certain operation was deleted.

For example, with listeners I can

  1. Apply pattern set A, and keep track of every foo.op that is created.
  2. Apply canonicalization patterns, and track which foo.op are deleted.
  3. Do something with the foo.op that remain.

Diff Detail

Event Timeline

Mogball created this revision.Dec 21 2021, 10:40 PM
Mogball requested review of this revision.Dec 21 2021, 10:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2021, 10:40 PM

FYI I might change this to accept a more limited RewriteListener class that only has the notify operations.

rriddle requested changes to this revision.Dec 21 2021, 10:56 PM

This is giving off a really bad design smell. It would be good to articulate the exact use cases you are trying to support. Intermixing multiple pattern rewriters does not sound like a good idea.

This revision now requires changes to proceed.Dec 21 2021, 10:56 PM
Mogball updated this revision to Diff 395883.Dec 22 2021, 8:50 AM

Yeah I agree. I reworked the design to split out listener from pattern rewriter and hopefully got rid of some of the smell.

Mogball retitled this revision from [mlir] Greedy pattern driver accepts a listener to [mlir] Separate Listener from PatternRewriter.Dec 22 2021, 8:50 AM
Mogball edited the summary of this revision. (Show Details)
Mogball edited the summary of this revision. (Show Details)
Mogball edited the summary of this revision. (Show Details)
Mogball updated this revision to Diff 395885.Dec 22 2021, 8:55 AM

Removed unused constructor arg

I'd prefer to have proper design discussions about this (preferably when I'm not OOO) the direction here isn't obvious that it's something to support.

uenoku added a subscriber: uenoku.Dec 29 2021, 2:36 AM
Mogball abandoned this revision.Jan 28 2022, 3:00 PM