Finding Rewrite patterns

Hello everyone! I do see that there is documentation on the available MLIR passes here. But is there any documentation or publicly available tool available that lists, or helps one find all (or dialect specific) rewrite patterns available?

This may be useful in two ways:

  • Primarily, to be able to find/check if a pre-existing rewrite pattern exists similar to the required transformation, before implementing one. Having a high-level view of the rewrite patterns similar to the list of passes, would significantly help to improve productivity.
  • Some passes which just apply a series of rewrite patterns to the IR, may have unintended consequences and may be useful to use just a subset of patterns instead of running the entire pass.
1 Like

I try to find patterns / transformation by grepping through test cases.

1 Like

There is no such documentation no. There have been conversations about generating some (and Id actually like a Hoogle esq search for it), but no work. The easiest would be for DRR and PDLL. I was thinking about this yesterday and one could get something approximate for regular C++ ones by hooking into rewrite driver and then running over all the unit tests and tracking what rewrites happen.

I think it would be very useful but no work ongoing AFAIK.

1 Like

Sadly, “discoverability” is quite a pain point for us.

Yes and no. The number of passes is quite small compared to patterns. A list alone wouldn’t be sufficient, IMO. We’d need some way to organise that.

Note that in testing we often apply very narrow set of patterns through the TD dialect, here’s an example:

(note the TD sequence at the end). Also, this made me realise, scanning through the list of TD ops might be helpful:

Many of the TD ops encapsulate a small set of patterns (sometimes a single pattern). You may find that helpful.

-Andrzej

Right around here where pat->getDebugName() is used to check whether a pattern is enabled/disabled.

I have a prototype PR that generates a search index mapping pattern → op here: [mlir][core] Add an MLIR "pattern catalog" generator by j2kun · Pull Request #146228 · llvm/llvm-project · GitHub

I will probably post a separate RFC soliciting feedback.

1 Like

Thanks for all the feedback and comments everyone. @j2kun I do see that the PR is merged, and would be interested in contributing to any future updates if required :grinning_face_with_smiling_eyes:

This PR from @j2kun is bringing it to the website: Add pattern catalog page to MLIR website by j2kun · Pull Request #230 · llvm/mlir-www · GitHub

1 Like

Sorry about that! Gradually finishing this up. Last step is to make some small tweaks and then make the UI compatible with the Hugo theme.

You can run the demo locally in the mean time

1 Like

It landed: Pattern Search - MLIR

2 Likes