This is an archive of the discontinued LLVM Phabricator instance.

[PDLL] Add support for tuple types and expressions
ClosedPublic

Authored by rriddle on Dec 7 2021, 3:21 PM.

Details

Summary

Tuples are used to group multiple elements into a single
compound value. The values in a tuple can be of any type, and
do not need to be of the same type. There is also no limit to
the number of elements held by a tuple.

Tuples will be used to support multiple results from
Constraints and Rewrites (added in a followup), and will also
make it easier to support more complex primitives (such as
range based maps that can operate on multiple values).

Depends On D115296

Diff Detail

Event Timeline

rriddle created this revision.Dec 7 2021, 3:21 PM
rriddle requested review of this revision.Dec 7 2021, 3:21 PM
nicolasvasilache accepted this revision.Dec 8 2021, 4:38 AM
nicolasvasilache added inline comments.
mlir/include/mlir/Tools/PDLL/AST/Nodes.h
893

nl

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

some error message for out-of-bounds rather than just crash?

This revision is now accepted and ready to land.Dec 8 2021, 4:38 AM
Mogball added inline comments.
mlir/include/mlir/Tools/PDLL/AST/Nodes.h
459

I'm seeing makeMutableArrayRef(...) and {...} used interchangeably throughout these patches. Should one be preferred for consistency?

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

llvm::to_string?

jpienaar accepted this revision.Dec 12 2021, 6:24 PM
jpienaar added inline comments.
mlir/include/mlir/Tools/PDLL/AST/Types.h
212

I don't see where it is verified that the names are unique.

213

I'm not clear on the value of this tuple/named map construct being added. I can see this from adding constraints/matching side, but as a standalone data entity not so clear.

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

rm ?

1425

So no names can start with digit and there would be an error if this were true?

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

Could you add 2 more tests:

  1. name starting with digit
  2. repeated name use
rriddle updated this revision to Diff 394168.Dec 14 2021, 12:30 AM
rriddle marked 9 inline comments as done.

Update

rriddle added inline comments.Dec 14 2021, 12:33 AM
mlir/include/mlir/Tools/PDLL/AST/Types.h
213

The tuple construct has various uses, outside of just multiple result constraint/rewrites. For one, the range based expressions use tuples to support application on multiple ranges; e.g.:

let range1: ValueRange;
let range2: ValueRange;
let range3: TypeRange;
map((range1, range2, range3), Rewrite(arg1: Value, arg2: Value, type: Type) {

});

IMO we need some struct/tuple like construct to support any kind of functional builtins. I don't think it has much use within a specific pattern/constraint/rewrite, but for enabling higher order builtin constructs (multi-result constraints/rewrites, functional builtins, etc.) it has various benefits.

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

Yep, added a test to ensure it.

1427

There should be an error message already, the index < tupleType.size() handles the bounds check. This is tested in one of the tests:

let tuple = (result1 = value: Value, result2 = value);
let tuple2 = (tuple.0, tuple.2);
> invalid member access `2` on expression of type `Tuple<result1: Value, result2: Value>`
This revision was landed with ongoing or failed builds.Dec 15 2021, 6:17 PM
This revision was automatically updated to reflect the committed changes.