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
- Apply pattern set A, and keep track of every foo.op that is created.
- Apply canonicalization patterns, and track which foo.op are deleted.
- Do something with the foo.op that remain.