[Mlir-commits] [mlir] a3ee67a - [PatternMatch] Add a new m_Any that binds a value.

Chris Lattner llvmlistbot at llvm.org
Mon Nov 15 08:38:15 PST 2021


Author: Chris Lattner
Date: 2021-11-15T08:38:07-08:00
New Revision: a3ee67a685143abf40b098906c0375026b1dd819

URL: https://github.com/llvm/llvm-project/commit/a3ee67a685143abf40b098906c0375026b1dd819
DIFF: https://github.com/llvm/llvm-project/commit/a3ee67a685143abf40b098906c0375026b1dd819.diff

LOG: [PatternMatch] Add a new m_Any that binds a value.

This is analogous to what LLVM's PatternMatch.h supports,
but LLVM calls it m_Value for both the binding and
nonbinding versions.

This is an upstream from CIRCT and is used there.

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/Matchers.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Matchers.h b/mlir/include/mlir/IR/Matchers.h
index 1cac3eaa5914..3f6720d0e794 100644
--- a/mlir/include/mlir/IR/Matchers.h
+++ b/mlir/include/mlir/IR/Matchers.h
@@ -176,6 +176,16 @@ struct AnyValueMatcher {
   bool match(Value op) const { return true; }
 };
 
+/// Terminal matcher, always returns true.
+struct AnyCapturedValueMatcher {
+  Value *what;
+  AnyCapturedValueMatcher(Value *what) : what(what) {}
+  bool match(Value op) const {
+    *what = op;
+    return true;
+  }
+};
+
 /// Binds to a specific value and matches it.
 struct PatternMatcherValue {
   PatternMatcherValue(Value val) : value(val) {}
@@ -280,6 +290,7 @@ auto m_Op(Matchers... matchers) {
 
 namespace matchers {
 inline auto m_Any() { return detail::AnyValueMatcher(); }
+inline auto m_Any(Value *val) { return detail::AnyCapturedValueMatcher(val); }
 inline auto m_Val(Value v) { return detail::PatternMatcherValue(v); }
 } // namespace matchers
 


        


More information about the Mlir-commits mailing list