[Mlir-commits] [mlir] d658a4b - [mlir][ir] OpRewritePattern should accept generatedNames

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Dec 10 11:35:09 PST 2021


Author: Mogball
Date: 2021-12-10T19:35:05Z
New Revision: d658a4bb97bed5db0b52e1e4dee2e0f1e6d006a5

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

LOG: [mlir][ir] OpRewritePattern should accept generatedNames

Reviewed By: rriddle

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

Added: 
    mlir/unittests/IR/PatternMatchTest.cpp

Modified: 
    mlir/include/mlir/IR/PatternMatch.h
    mlir/unittests/IR/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index 7aedec1b15f08..1b5679dc5c299 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -355,10 +355,12 @@ template <typename SourceOp>
 struct OpRewritePattern
     : public detail::OpOrInterfaceRewritePatternBase<SourceOp> {
   /// Patterns must specify the root operation name they match against, and can
-  /// also specify the benefit of the pattern matching.
-  OpRewritePattern(MLIRContext *context, PatternBenefit benefit = 1)
+  /// also specify the benefit of the pattern matching and a list of generated
+  /// ops.
+  OpRewritePattern(MLIRContext *context, PatternBenefit benefit = 1,
+                   ArrayRef<StringRef> generatedNames = {})
       : detail::OpOrInterfaceRewritePatternBase<SourceOp>(
-            SourceOp::getOperationName(), benefit, context) {}
+            SourceOp::getOperationName(), benefit, context, generatedNames) {}
 };
 
 /// OpInterfaceRewritePattern is a wrapper around RewritePattern that allows for

diff  --git a/mlir/unittests/IR/CMakeLists.txt b/mlir/unittests/IR/CMakeLists.txt
index d45ca41c843fe..326fc0a0cd47c 100644
--- a/mlir/unittests/IR/CMakeLists.txt
+++ b/mlir/unittests/IR/CMakeLists.txt
@@ -3,6 +3,7 @@ add_mlir_unittest(MLIRIRTests
   DialectTest.cpp
   InterfaceAttachmentTest.cpp
   OperationSupportTest.cpp
+  PatternMatchTest.cpp
   ShapedTypeTest.cpp
   SubElementInterfaceTest.cpp
 

diff  --git a/mlir/unittests/IR/PatternMatchTest.cpp b/mlir/unittests/IR/PatternMatchTest.cpp
new file mode 100644
index 0000000000000..6454f05fbf2fa
--- /dev/null
+++ b/mlir/unittests/IR/PatternMatchTest.cpp
@@ -0,0 +1,30 @@
+//===- PatternMatchTest.cpp - PatternMatch unit tests ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/IR/PatternMatch.h"
+#include "gtest/gtest.h"
+
+#include "../../test/lib/Dialect/Test/TestDialect.h"
+
+using namespace mlir;
+
+namespace {
+struct AnOpRewritePattern : OpRewritePattern<test::OpA> {
+  AnOpRewritePattern(MLIRContext *context)
+      : OpRewritePattern(context, /*benefit=*/1,
+                         /*generatedNames=*/{test::OpB::getOperationName()}) {}
+};
+TEST(OpRewritePatternTest, GetGeneratedNames) {
+  MLIRContext context;
+  AnOpRewritePattern pattern(&context);
+  ArrayRef<OperationName> ops = pattern.getGeneratedOps();
+
+  ASSERT_EQ(ops.size(), 1u);
+  ASSERT_EQ(ops.front().getStringRef(), test::OpB::getOperationName());
+}
+} // end anonymous namespace


        


More information about the Mlir-commits mailing list