[Mlir-commits] [mlir] 651d9f7 - [mlir:PDLL] Fix the import of native constraints from ODS

River Riddle llvmlistbot at llvm.org
Thu Apr 28 12:58:49 PDT 2022


Author: River Riddle
Date: 2022-04-28T12:58:00-07:00
New Revision: 651d9f70ed75e360b0a166ddca40526c2df43fe3

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

LOG: [mlir:PDLL] Fix the import of native constraints from ODS

We weren't properly returning the result of the constraint,
which leads to errors when actually trying to use the generated
C++.

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

Added: 
    

Modified: 
    mlir/lib/Tools/PDLL/Parser/Parser.cpp
    mlir/test/lib/Tools/PDLL/TestPDLL.pdll
    mlir/test/mlir-pdll/Integration/test-pdll.mlir
    mlir/test/mlir-pdll/Parser/include_td.pdll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
index 53d54174fe126..e6c526ee2bc22 100644
--- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp
+++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
@@ -847,7 +847,8 @@ void Parser::processTdIncludeRecords(llvm::RecordKeeper &tdRecords,
     StringRef className = def->getValueAsString("cppClassName");
     StringRef cppNamespace = def->getValueAsString("cppNamespace");
     std::string codeBlock =
-        llvm::formatv("llvm::isa<{0}::{1}>(self)", cppNamespace, className)
+        llvm::formatv("return ::mlir::success(llvm::isa<{0}::{1}>(self));",
+                      cppNamespace, className)
             .str();
 
     if (def->isSubClassOf("OpInterface")) {
@@ -892,8 +893,9 @@ Parser::createODSNativePDLLConstraintDecl(const tblgen::Constraint &constraint,
   // Format the condition template.
   tblgen::FmtContext fmtContext;
   fmtContext.withSelf("self");
-  std::string codeBlock =
-      tblgen::tgfmt(constraint.getConditionTemplate(), &fmtContext);
+  std::string codeBlock = tblgen::tgfmt(
+      "return ::mlir::success(" + constraint.getConditionTemplate() + ");",
+      &fmtContext);
 
   return createODSNativePDLLConstraintDecl<ConstraintT>(
       constraint.getUniqueDefName(), codeBlock, loc, type);

diff  --git a/mlir/test/lib/Tools/PDLL/TestPDLL.pdll b/mlir/test/lib/Tools/PDLL/TestPDLL.pdll
index 865f9375a805b..9715b556bbe21 100644
--- a/mlir/test/lib/Tools/PDLL/TestPDLL.pdll
+++ b/mlir/test/lib/Tools/PDLL/TestPDLL.pdll
@@ -7,6 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "TestOps.td"
+#include "mlir/Interfaces/CastInterfaces.td"
 
 /// A simple pattern that matches and replaces an operation.
 Pattern TestSimplePattern => replace op<test.simple> with op<test.success>;
+
+// Test the import of interfaces.
+Pattern TestInterface => replace _: CastOpInterface with op<test.success>;

diff  --git a/mlir/test/mlir-pdll/Integration/test-pdll.mlir b/mlir/test/mlir-pdll/Integration/test-pdll.mlir
index ccfd007a46b2f..7118a2ad4aa12 100644
--- a/mlir/test/mlir-pdll/Integration/test-pdll.mlir
+++ b/mlir/test/mlir-pdll/Integration/test-pdll.mlir
@@ -6,3 +6,12 @@ func @simpleTest() {
   "test.simple"() : () -> ()
   return
 }
+
+// CHECK-LABEL: func @testImportedInterface
+func @testImportedInterface() {
+  // CHECK: test.non_cast
+  // CHECK: test.success
+  "test.non_cast"() : () -> ()
+  "builtin.unrealized_conversion_cast"() : () -> (i1)
+  return
+}

diff  --git a/mlir/test/mlir-pdll/Parser/include_td.pdll b/mlir/test/mlir-pdll/Parser/include_td.pdll
index a7a02e9323e36..f90f7ab8a4126 100644
--- a/mlir/test/mlir-pdll/Parser/include_td.pdll
+++ b/mlir/test/mlir-pdll/Parser/include_td.pdll
@@ -32,20 +32,20 @@
 // CHECK-NEXT:   CppClass: ::mlir::IntegerType
 // CHECK-NEXT: }
 
-// CHECK: UserConstraintDecl {{.*}} Name<TestAttrInterface> ResultType<Tuple<>> Code<llvm::isa<::TestAttrInterface>(self)>
+// CHECK: UserConstraintDecl {{.*}} Name<TestAttrInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestAttrInterface>(self));>
 // CHECK:  `Inputs`
 // CHECK:    `-VariableDecl {{.*}} Name<self> Type<Attr>
 // CHECK:      `Constraints`
 // CHECK:        `-AttrConstraintDecl
 
-// CHECK: UserConstraintDecl {{.*}} Name<TestOpInterface> ResultType<Tuple<>> Code<llvm::isa<::TestOpInterface>(self)>
+// CHECK: UserConstraintDecl {{.*}} Name<TestOpInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestOpInterface>(self));>
 // CHECK:  `Inputs`
 // CHECK:    `-VariableDecl {{.*}} Name<self> Type<Op>
 // CHECK:      `Constraints`
 // CHECK:        `-OpConstraintDecl
 // CHECK:          `-OpNameDecl
 
-// CHECK: UserConstraintDecl {{.*}} Name<TestTypeInterface> ResultType<Tuple<>> Code<llvm::isa<::TestTypeInterface>(self)>
+// CHECK: UserConstraintDecl {{.*}} Name<TestTypeInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestTypeInterface>(self));>
 // CHECK:  `Inputs`
 // CHECK:    `-VariableDecl {{.*}} Name<self> Type<Type>
 // CHECK:      `Constraints`


        


More information about the Mlir-commits mailing list