Skip to content

Commit fa6f736

Browse files
authored
Merge pull request #96 from Xilinx/matthias.parentheses
PDLL: Allow to implictly convert Tuple<Attr> with a single element to Attr
2 parents b7f8652 + 846d97b commit fa6f736

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,15 @@ LogicalResult Parser::convertTupleExpressionTo(
831831
return convertToRange({valueTy, valueRangeTy}, valueRangeTy);
832832
if (type == typeRangeTy)
833833
return convertToRange({typeTy, typeRangeTy}, typeRangeTy);
834+
if (type == attrTy && exprType.size() == 1 &&
835+
exprType.getElementTypes()[0] == type) {
836+
// Parenthesis become tuples. Allow to unpack single element tuples
837+
// to expressions.
838+
expr = ast::MemberAccessExpr::create(ctx, expr->getLoc(), expr,
839+
llvm::to_string(0),
840+
exprType.getElementTypes()[0]);
841+
return success();
842+
}
834843

835844
return emitErrorFn();
836845
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ Pattern {
124124

125125
// -----
126126

127+
Constraint checkAttr(attr: Attr);
128+
Pattern {
129+
let tuple = (result1 = value: Value);
130+
// CHECK: unable to convert expression of type `Tuple<result1: Value>` to the expected type of `Attr`
131+
checkAttr(tuple);
132+
erase _: Op;
133+
}
134+
135+
// -----
136+
127137
//===----------------------------------------------------------------------===//
128138
// Range Expr
129139
//===----------------------------------------------------------------------===//

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ Pattern {
128128

129129
// -----
130130

131+
// Implicitly convert single element Tuple<Attr> to Attr
132+
// CHECK: Module
133+
// CHECK: `-MemberAccessExpr {{.*}} Member<0> Type<Attr>
134+
// CHECK: `-TupleExpr {{.*}} Type<Tuple<Attr>>
135+
// CHECK: `-AttributeExpr {{.*}} Value<"10: i32">
136+
Constraint checkAttr(attr: Attr);
137+
Pattern {
138+
let tuple = (attr<"10: i32">);
139+
checkAttr(tuple);
140+
erase _: Op;
141+
}
142+
143+
// -----
144+
131145
#include "include/ops.td"
132146

133147
// CHECK: Module

0 commit comments

Comments
 (0)