Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mlir/lib/Tools/PDLL/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ LogicalResult Parser::convertTupleExpressionTo(
return convertToRange({valueTy, valueRangeTy}, valueRangeTy);
if (type == typeRangeTy)
return convertToRange({typeTy, typeRangeTy}, typeRangeTy);
if (type == attrTy && exprType.size() == 1 &&
exprType.getElementTypes()[0] == type) {
// Parenthesis become tuples. Allow to unpack single element tuples
// to expressions.
expr = ast::MemberAccessExpr::create(ctx, expr->getLoc(), expr,
llvm::to_string(0),
exprType.getElementTypes()[0]);
return success();
}

return emitErrorFn();
}
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/mlir-pdll/Parser/expr-failure.pdll
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ Pattern {

// -----

Constraint checkAttr(attr: Attr);
Pattern {
let tuple = (result1 = value: Value);
// CHECK: unable to convert expression of type `Tuple<result1: Value>` to the expected type of `Attr`
checkAttr(tuple);
erase _: Op;
}

// -----

//===----------------------------------------------------------------------===//
// Range Expr
//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions mlir/test/mlir-pdll/Parser/expr.pdll
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ Pattern {

// -----

// Implicitly convert single element Tuple<Attr> to Attr
// CHECK: Module
// CHECK: `-MemberAccessExpr {{.*}} Member<0> Type<Attr>
// CHECK: `-TupleExpr {{.*}} Type<Tuple<Attr>>
// CHECK: `-AttributeExpr {{.*}} Value<"10: i32">
Constraint checkAttr(attr: Attr);
Pattern {
let tuple = (attr<"10: i32">);
checkAttr(tuple);
erase _: Op;
}

// -----

#include "include/ops.td"

// CHECK: Module
Expand Down