Resources for Pass Infrastructure for Beginners in MLIR

The documentation of MLIR pass infrastructure is impressive with a lot of helpful examples. But for beginners, it seems quite difficult to have a structured intro based on the current state of the documentations.

For reference let’s take a look at the llvm equivalent in this link: Writing an LLVM Pass — LLVM 18.0.0git documentation

The biggest difference is the end-to-end nature of the introduction. It identifies the different components of the pass, writes down explanation along with the code blocks. Additionally, at the end, the entire pass and registration is summarized in a single file which shows the entirety. Then they move on to compile it, show the shared library that contains the pass and then they execute the pass using opt. The completeness of the pass gives a nice introduction to what passes are for and how they can be leveraged.

Again, MLIR’s current documentation for pass infrastructure is great. There is no doubt about that. But it lacks the end-to-end nature and completeness of the LLVM equivalent. For beginners, it would be more helpful if the intro follows the same format as the LLVM tutorial.

Again, this is just a basic suggestion from the perspective of a beginner. I have discussed this before with some of my labmates who suggested me to raise the issue with the MLIR developers (Which is why I am writing this post ).

Thanks in advance.

In this context, I’ve found the series of articles on the MLIR framework by @j2kun to be really good:
https://github.com/j2kun/mlir-tutorial, including examples of writing MLIR passes, like https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/, https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/, or https://jeremykun.com/2023/11/15/mlir-a-global-optimization-and-dataflow-analysis/

1 Like

The documentation isn’t intended to be a tutorial, however we do have tutorials as well! Have you gone through the Toy chapters for example? Toy Tutorial - MLIR

If someone wanted to propose a “how to write a basic pass” to be a small tutorial of its own here: Tutorials - MLIR ; it’d be welcome!

Thank you for the resources. I will go through all of them. I have another question.

In LLVM we can load passes against pre-built opt binaries. Is there any similar functionality in case of mlir-opt ? I see the following two options in mlir-opt:

In particular my question is: If I write a pass and compile it as MyPassLib.so with the pass name my-pass , can I load it against the mlir-opt in the following way:

mlir-opt --load-pass-plugin=/path/to/MyPassLib.so --my-pass some-input-mlir.mlir

Yes, we have an example in the repo for this: https://github.com/llvm/llvm-project/blob/02cbae4fe0683c90ccd544d0be7fa82732a502e8/mlir/examples/standalone/standalone-plugin/standalone-plugin.cpp#L35