Skip to content

Commit

Permalink
Merge pull request #96 from Xilinx/matthias.parentheses
Browse files Browse the repository at this point in the history
PDLL: Allow to implictly convert Tuple<Attr> with a single element to Attr
  • Loading branch information
mgehre-amd authored Feb 21, 2024
2 parents b7f8652 + 846d97b commit fa6f736
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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 @@ -831,6 +831,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 @@ -128,6 +128,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

0 comments on commit fa6f736

Please sign in to comment.