This is an archive of the discontinued LLVM Phabricator instance.

[PDLL] Add support for parsing pattern metadata
ClosedPublic

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

Details

Summary

This allows for overriding the metadata of a pattern and
providing information such as the benefit, bounded recursion,
and more in the future.

Depends On D115093

Diff Detail

Event Timeline

rriddle created this revision.Dec 7 2021, 3:18 PM
rriddle requested review of this revision.Dec 7 2021, 3:18 PM
Mogball accepted this revision.Dec 7 2021, 3:38 PM
This revision is now accepted and ready to land.Dec 7 2021, 3:38 PM
nicolasvasilache accepted this revision.Dec 7 2021, 11:51 PM
nicolasvasilache added inline comments.
mlir/lib/Tools/PDLL/Parser/Parser.cpp
454–455

Enclose these in a Metadata helper struct?

552

Side note, it feels somewhat strange to me that we still have to explicitly manipulate loc information so intrusively everywhere (either here or other places in MLIR).
I would have expected that by now we'd have a bunch of Loc-implicit methods and types that just do the right thing and we'd put more efforts in tests to really ensure this is the case.

jpienaar accepted this revision.Dec 12 2021, 6:00 PM
jpienaar added inline comments.
mlir/lib/Tools/PDLL/Parser/Parser.cpp
454–455

In DRR currently the benefit is a heuristic based on number of nodes matched (so that preference is given to larger matches in case of ties) and one can specify additional benefit to refine the matching, but it isn't an absolute but a diff on the heuristic. Is all explicit and fixed here?

552

That would seem to work for 1-N and N-1 patterns (well and this one you'd want to potentially record the pass name too), not sure in general how one could avoid being explicit in ensuring good tracing.

578

Are you also checking signed or not?

585

Line exceeding 80?

mlir/test/mlir-pdll/Parser/pattern-failure.pdll
73

nl ?

mlir/test/mlir-pdll/Parser/pattern.pdll
23

Would it be possible to have the example show recursion? (in isolation this revision doesn't show it)

rriddle updated this revision to Diff 394165.Dec 14 2021, 12:29 AM
rriddle marked 8 inline comments as done.

update

rriddle added inline comments.Dec 14 2021, 12:33 AM
mlir/lib/Tools/PDLL/Parser/Parser.cpp
454–455

Yeah, for now benefit is the explicit final benefit. We will likely want to add another construct for added benefit (addBenefit or something), but I want to ensure that we can ditch the heuristics in cases where we want explicit control.

552

Explicitly managing locations is just part of writing a frontend and getting good diagnostics. There are a lot of cases that we need to explicitly manage where a specific token or construct came from, and moving any of that to implicit will lead to less ideal error messages. There isn't any way that I can think of that would remove the need of explicit location handling in a frontend, it's just one of the things you have to deal with.

578

The integer token doesn't support a leading -, so it can't be signed.

mlir/test/mlir-pdll/Parser/pattern.pdll
23

Yeah, but I should note that these are not and don't intend to be end-user examples. These are tests that ensure that we structurally build the expected AST nodes, which may or may not make sense as real patterns.

The revision with the end user doc will have actual examples that showcase the more end to end things, just getting the structural constructs down here.

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.