Rename mlir::match to mlir::matchPattern and add m_Op()
authorLei Zhang <antiagainst@google.com>
Tue, 30 Oct 2018 17:57:50 +0000 (10:57 -0700)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 20:44:47 +0000 (13:44 -0700)
- We already have Pattern::match(). Using mlir::match() in Pattern::match()
  confuses the compiler.
- Created m_Op() to avoid using detailed matcher implementation in
  StandardOps.cpp.

PiperOrigin-RevId: 219328823

mlir/include/mlir/IR/Matchers.h
mlir/lib/StandardOps/StandardOps.cpp

index dfffe2d5da8b7544de82756f899829b001f3f2a3..06013a72097f2699eb6a8522b196a2bdccdb70ce 100644 (file)
@@ -108,7 +108,7 @@ template <typename OpClass> struct op_matcher {
 
 /// Entry point for matching a pattern over an SSAValue.
 template <typename Pattern>
-inline bool match(SSAValue *value, const Pattern &pattern) {
+inline bool matchPattern(SSAValue *value, const Pattern &pattern) {
   // TODO: handle other cases
   if (auto *op = value->getDefiningOperation())
     return const_cast<Pattern &>(pattern).match(op);
@@ -132,6 +132,11 @@ inline detail::constant_int_value_matcher<1> m_One() {
   return detail::constant_int_value_matcher<1>();
 }
 
+/// Matches the given OpClass.
+template <typename OpClass> inline detail::op_matcher<OpClass> m_Op() {
+  return detail::op_matcher<OpClass>();
+}
+
 /// Matches a constant scalar / vector splat / tensor splat integer zero.
 inline detail::constant_int_value_matcher<0> m_Zero() {
   return detail::constant_int_value_matcher<0>();
index 02db8756893c0747b94e4ff785ab620e4067c683..b60d209e1f5db590cac1a9a2afb6ab5bc0a0c6be 100644 (file)
@@ -47,11 +47,6 @@ StandardOpsDialect::StandardOpsDialect(MLIRContext *context)
 //===----------------------------------------------------------------------===//
 
 namespace {
-/// Matches a MemRefCastOp.
-inline detail::op_matcher<MemRefCastOp> m_MemRefCast() {
-  return detail::op_matcher<MemRefCastOp>();
-}
-
 /// This is a common class used for patterns of the form
 /// "someop(memrefcast) -> someop".  It folds the source of any memref_cast
 /// into the root operation directly.
@@ -63,7 +58,7 @@ struct MemRefCastFolder : public Pattern {
   std::pair<PatternBenefit, std::unique_ptr<PatternState>>
   match(Operation *op) const override {
     for (auto *operand : op->getOperands())
-      if (::match(operand, m_MemRefCast()))
+      if (matchPattern(operand, m_Op<MemRefCastOp>()))
         return matchSuccess();
 
     return matchFailure();
@@ -122,7 +117,7 @@ struct SimplifyAddX0 : public Pattern {
   match(Operation *op) const override {
     auto addi = op->cast<AddIOp>();
 
-    if (::match(addi->getOperand(1), m_Zero()))
+    if (matchPattern(addi->getOperand(1), m_Zero()))
       return matchSuccess();
 
     return matchFailure();
@@ -232,7 +227,7 @@ struct SimplifyAllocConst : public Pattern {
     // Check to see if any dimensions operands are constants.  If so, we can
     // substitute and drop them.
     for (auto *operand : alloc->getOperands())
-      if (::match(operand, m_ConstantIndex()))
+      if (matchPattern(operand, m_ConstantIndex()))
         return matchSuccess();
     return matchFailure();
   }
@@ -894,7 +889,7 @@ struct SimplifyMulX1 : public Pattern {
   match(Operation *op) const override {
     auto muli = op->cast<MulIOp>();
 
-    if (::match(muli->getOperand(1), m_One()))
+    if (matchPattern(muli->getOperand(1), m_One()))
       return matchSuccess();
 
     return matchFailure();