Original, application specific discussion: CIRCT ECO in the presence of transformations. Not a necessary read for understanding this post.
We have an interesting use case for patten rewriters: we need to monitor IR mutations on one program a
, then do the same thing on a slightly modified version of a
(a'
) and only apply the IR mutations to a'
which were applied to a
. Let’s assume we have already derived a mapping of Operations in a
to Operations in a'
. We define “mutation” as a single call to a canonicalizer or a matchAndRewrite
method.
As I see it, this requires the following capabilities:
- To “listen” to the mutations and record what individual calls into the rewriter are doing.
- To compare the records of two mutations to determine if they are the same.
- To selectively apply or discard the mutation on
a'
based on said comparison.
Digging around the MLIR code, I see that #1 and #3 already exist in DialectConversion.cpp
. Specifically in ConversionPatternRewriterImpl
. Adding the ability to check equality of two of these given an Operation mapping should be relatively straightforward.
Since our requirements are somewhat domain-specific, I don’t expect it to be supported by MLIR proper. IMO, it should live in the CIRCT project (on which I work). It would be ideal to reuse all the bookkeeping in MLIR’s dialect conversion framework which is currently private. What do people think of making the functionality of ConversionPatternRewriterImpl
a public API and being able to subclass it (for adding a comparison method, for instance)?
I see the functionality as generally useful, which implies it should be publicly accessible. I also see, however, that code in DialectConversion.cpp
tends to interact with ConversionPatternRewriterImpl
internal data structures, so just moving it to a header file probably wouldn’t be acceptable.