This revision adds two new classes, RewriterBase and IRRewriter. RewriterBase is a new shared base class between IRRewriter and PatternRewriter. PatternRewriter will continue to be the base class used to perform rewrites within a rewrite pattern. IRRewriter on the other hand, is a new class that allows for tracking IR rewrites from outside of a rewrite pattern. In this revision all of the old API from PatternRewriter is moved to RewriterBase, but the distinction between IRRewriter and PatternRewriter is kept on the chance that a necessary API divergence happens in the future.
Currently if you want to have some utility that transforms a piece of IR and share it between pattern and non-pattern code, you have to duplicate it. This revision enables the creation of utilities that can be invoked from rewrite patterns and normal transformation code:
c++ void someSharedUtility(RewriterBase &rewriter, ...) { // Some interesting IR mutation here. } // Some RewritePattern LogicalResult MyPattern::matchAndRewrite(Operation *op, PatternRewriter &rewriter) { ... someSharedUtility(rewriter, ...); ... } // Some Pass void MyPass::runOnOperation() { ... IRRewriter rewriter(...); someSharedUtility(rewriter, ...); }
Depends On D94632
Does the naming convention here mirror SmallVector / SmallVectorImpl? "impl" makes me think of an implementation detail vs a common base class. This is a "listening builder" or "observed builder" base class (well technically an observable, it is only observed with listeners registered ...)