[all-commits] [llvm/llvm-project] ec10f0: [mlir][Pattern] Create a new IRRewriter class to e...

River Riddle via All-commits all-commits at lists.llvm.org
Tue Feb 2 12:08:04 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ec10f0660963c77413f31a9b232b453f09425387
      https://github.com/llvm/llvm-project/commit/ec10f0660963c77413f31a9b232b453f09425387
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-02-02 (Tue, 02 Feb 2021)

  Changed paths:
    M mlir/include/mlir/IR/PatternMatch.h
    M mlir/lib/IR/PatternMatch.cpp

  Log Message:
  -----------
  [mlir][Pattern] Create a new IRRewriter class to enable sharing code with pattern rewrites

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, ...);
}
```

Differential Revision: https://reviews.llvm.org/D94638




More information about the All-commits mailing list