Skip to content

Commit 651d9f7

Browse files
committed
[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
1 parent ebb1e90 commit 651d9f7

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

mlir/lib/Tools/PDLL/Parser/Parser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ void Parser::processTdIncludeRecords(llvm::RecordKeeper &tdRecords,
847847
StringRef className = def->getValueAsString("cppClassName");
848848
StringRef cppNamespace = def->getValueAsString("cppNamespace");
849849
std::string codeBlock =
850-
llvm::formatv("llvm::isa<{0}::{1}>(self)", cppNamespace, className)
850+
llvm::formatv("return ::mlir::success(llvm::isa<{0}::{1}>(self));",
851+
cppNamespace, className)
851852
.str();
852853

853854
if (def->isSubClassOf("OpInterface")) {
@@ -892,8 +893,9 @@ Parser::createODSNativePDLLConstraintDecl(const tblgen::Constraint &constraint,
892893
// Format the condition template.
893894
tblgen::FmtContext fmtContext;
894895
fmtContext.withSelf("self");
895-
std::string codeBlock =
896-
tblgen::tgfmt(constraint.getConditionTemplate(), &fmtContext);
896+
std::string codeBlock = tblgen::tgfmt(
897+
"return ::mlir::success(" + constraint.getConditionTemplate() + ");",
898+
&fmtContext);
897899

898900
return createODSNativePDLLConstraintDecl<ConstraintT>(
899901
constraint.getUniqueDefName(), codeBlock, loc, type);

mlir/test/lib/Tools/PDLL/TestPDLL.pdll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "TestOps.td"
10+
#include "mlir/Interfaces/CastInterfaces.td"
1011

1112
/// A simple pattern that matches and replaces an operation.
1213
Pattern TestSimplePattern => replace op<test.simple> with op<test.success>;
14+
15+
// Test the import of interfaces.
16+
Pattern TestInterface => replace _: CastOpInterface with op<test.success>;

mlir/test/mlir-pdll/Integration/test-pdll.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ func @simpleTest() {
66
"test.simple"() : () -> ()
77
return
88
}
9+
10+
// CHECK-LABEL: func @testImportedInterface
11+
func @testImportedInterface() {
12+
// CHECK: test.non_cast
13+
// CHECK: test.success
14+
"test.non_cast"() : () -> ()
15+
"builtin.unrealized_conversion_cast"() : () -> (i1)
16+
return
17+
}

mlir/test/mlir-pdll/Parser/include_td.pdll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
// CHECK-NEXT: CppClass: ::mlir::IntegerType
3333
// CHECK-NEXT: }
3434

35-
// CHECK: UserConstraintDecl {{.*}} Name<TestAttrInterface> ResultType<Tuple<>> Code<llvm::isa<::TestAttrInterface>(self)>
35+
// CHECK: UserConstraintDecl {{.*}} Name<TestAttrInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestAttrInterface>(self));>
3636
// CHECK: `Inputs`
3737
// CHECK: `-VariableDecl {{.*}} Name<self> Type<Attr>
3838
// CHECK: `Constraints`
3939
// CHECK: `-AttrConstraintDecl
4040

41-
// CHECK: UserConstraintDecl {{.*}} Name<TestOpInterface> ResultType<Tuple<>> Code<llvm::isa<::TestOpInterface>(self)>
41+
// CHECK: UserConstraintDecl {{.*}} Name<TestOpInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestOpInterface>(self));>
4242
// CHECK: `Inputs`
4343
// CHECK: `-VariableDecl {{.*}} Name<self> Type<Op>
4444
// CHECK: `Constraints`
4545
// CHECK: `-OpConstraintDecl
4646
// CHECK: `-OpNameDecl
4747

48-
// CHECK: UserConstraintDecl {{.*}} Name<TestTypeInterface> ResultType<Tuple<>> Code<llvm::isa<::TestTypeInterface>(self)>
48+
// CHECK: UserConstraintDecl {{.*}} Name<TestTypeInterface> ResultType<Tuple<>> Code<return ::mlir::success(llvm::isa<::TestTypeInterface>(self));>
4949
// CHECK: `Inputs`
5050
// CHECK: `-VariableDecl {{.*}} Name<self> Type<Type>
5151
// CHECK: `Constraints`

0 commit comments

Comments
 (0)