[all-commits] [llvm/llvm-project] 687472: [PatternMatching] Add convenience insert method to...

Chris Lattner via All-commits all-commits at lists.llvm.org
Mon Mar 22 11:18:44 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6874726610cc2f9eea7fa828c8585bf84969f9c3
      https://github.com/llvm/llvm-project/commit/6874726610cc2f9eea7fa828c8585bf84969f9c3
  Author: Chris Lattner <clattner at nondot.org>
  Date:   2021-03-22 (Mon, 22 Mar 2021)

  Changed paths:
    M mlir/docs/Tutorials/QuickstartRewrites.md
    M mlir/include/mlir/IR/PatternMatch.h
    M mlir/lib/Dialect/Math/Transforms/ExpandTanh.cpp

  Log Message:
  -----------
  [PatternMatching] Add convenience insert method to OwningRewritePatternList. NFC.

This allows adding a C function pointer as a matchAndRewrite style pattern, which
is a very common case.  This adopts it in ExpandTanh to show how it reduces a level
of nesting.

We could allow C++ lambdas here, but that doesn't work as well with type inference
in the common case.  Instead of:

  patterns.insert(convertTanhOp);

you need to specify:

  patterns.insert<math::TanhOp>(convertTanhOp);

which is boilerplate'y.  Capturing state like this is very uncommon, so we choose
to require clients to define their own structs and use the non-convenience method
when they need to do so.

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




More information about the All-commits mailing list