Skip to content

Commit 736d4a1

Browse files
committed
Adds new tests for array/dict attribute support in rewriter sections.
1 parent 96f54ed commit 736d4a1

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,7 +2882,7 @@ Parser::createNativeCall(SMRange loc, StringRef nativeFuncName,
28822882

28832883
FailureOr<ast::Expr *> nativeFuncExpr = parseDeclRefExpr(nativeFuncName, loc);
28842884
if (failed(nativeFuncExpr))
2885-
return emitError(nativeFuncName + " not found.");
2885+
return failure();
28862886

28872887
if (!(*nativeFuncExpr)->getType().isa<ast::RewriteType>())
28882888
return emitError(nativeFuncName + " should be defined as a rewriter.");
@@ -2892,7 +2892,7 @@ Parser::createNativeCall(SMRange loc, StringRef nativeFuncName,
28922892
if (failed(nativeCall))
28932893
return failure();
28942894

2895-
// Create a unique anonymous name to use, as the name for this decl is not
2895+
// Create a unique anonymous name declaration to use, as its name is not
28962896
// important.
28972897
std::string anonName =
28982898
llvm::formatv("{0}_{1}", nativeFuncName, anonymousDeclNameCounter++)

mlir/test/mlir-pdll/Parser/expr-failure.pdll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,23 @@ Pattern {
234234
let root = op<func.func> -> ();
235235
// CHECK: expected '}]' in string literal
236236
rewrite root with {
237-
let newRoot = op<func.func>() { some_array = [{"firstAttr" = attr<"\"test\"">}, attr<"\"test\"">]} -> ();
237+
let newRoot = op<func.func>() { some_array = [{"firstAttr" = attr<"\"test\"">}, attr<"\"test\"">] } -> ();
238238
replace root with newRoot;
239-
};;
239+
};
240+
}
241+
242+
// -----
243+
244+
Rewrite addElemToArrayAttr(arrayAttr: Attr, newElement: Attr) -> Attr;
245+
246+
Pattern {
247+
let root = op<test.op> -> ();
248+
let attr = attr<"\"test\"">;
249+
rewrite root with {
250+
// CHECK: undefined reference to `createArrayAttr`
251+
let newRoot = op<test.success>() { some_array = [ attr<"\"test\""> ]} -> ();
252+
replace root with newRoot;
253+
};
240254
}
241255

242256
// -----

mlir/test/mlir-pdll/Parser/expr.pdll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ Pattern {
1414

1515
// -----
1616

17+
// CHECK: |-NamedAttributeDecl {{.*}} Name<some_array>
18+
// CHECK: `-UserRewriteDecl {{.*}} Name<addElemToArrayAttr> ResultType<Attr>
19+
// CHECK: `Arguments`
20+
// CHECK: `-CallExpr {{.*}} Type<Attr>
21+
// CHECK: `-UserRewriteDecl {{.*}} Name<createArrayAttr> ResultType<Attr>
22+
// CHECK: `-CallExpr {{.*}} Type<Attr>
23+
// CHECK: `-UserRewriteDecl {{.*}} Name<addEntryToDictionaryAttr> ResultType<Attr>
24+
// CHECK: `Arguments`
25+
// CHECK: `-CallExpr {{.*}} Type<Attr>
26+
// CHECK: `-UserRewriteDecl {{.*}} Name<createDictionaryAttr> ResultType<Attr>
27+
// CHECK: `-AttributeExpr {{.*}} Value<""firstAttr"">
28+
Rewrite createDictionaryAttr() -> Attr;
29+
Rewrite addEntryToDictionaryAttr(dict: Attr, attrName: Attr, attr : Attr) -> Attr;
30+
Rewrite createArrayAttr() -> Attr;
31+
Rewrite addElemToArrayAttr(arrayAttr: Attr, newElement: Attr) -> Attr;
32+
33+
Pattern {
34+
let root = op<test.op> -> ();
35+
let attr = attr<"\"test\"">;
36+
rewrite root with {
37+
let newRoot = op<test.success>() { some_array = [ {"firstAttr" = attr<"\"test\"">}], attr} -> ();
38+
replace root with newRoot;
39+
};
40+
}
41+
42+
// -----
43+
1744
//===----------------------------------------------------------------------===//
1845
// CallExpr
1946
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)