How to read the source code of the LLVM pass and MLIR dialect

I have studies LLVM and MLIR for 10 days, and my advisor asked me to select some classic and common passes and dialects and read the source code. I’m totally confused, don’t know which pass or dialect to read. What should I read first? Could you give me some suggestions?

If you want to see a list of passes one way is to add --print-after-all to your llc invokation.

*** IR Dump After Expand large div/rem (expand-large-div-rem) ***
<...>

Take a look at the steps and pick one where something interesting happens. (there is --print-before-all as well, you can add both if you want)

A recommendation from me, Scalar Reduction of Aggregates (SROA) is one I came across often and seems quite commonly used. Search the codebase for that and see what you find.

You might want to work backwards by first reading the tests for the pass, so you understand the “why” before you get into the source which is more “how”.

And another tip is that https://godbolt.org/ does have a mode for IR input, and is sometimes a quicker way to experiment. You can even setup C and IR examples next to each other which is a great way to learn IMO.

Good luck :slight_smile:

1 Like

And if you really wanted something in MLIR land, I’ve no idea about that, but be assured that the same sort of options exist for MLIR too. Have a look at their llc equivalent.

1 Like

Thanks a lot for your adivce !!