[Announce] llopt 1.0.0: Check you assumptions about LLVM optimizations

I’m please to announce the first release of llopt, a tool that takes a LLVM-IR file and gives you back the optimized LLVM-IR using the LLVM optimization passes.

The tool can be useful for quickly testing what optimizations are done by LLVM:

  • depending on the optimization level (the Clang equivalent of -O0, -O1, -O2 or -O3)
  • what does the LTO optimization pass

The tool also gives you a quick way see if your LLVM-IR module is syntactically correct or not by just disabling the optimizations (--opt=-1).

Of course the tool is written in OCaml using the official LLVM binding and is available via OPAM.
Its source code is really small and straightforward and can be easily modified to check specific optimizations:

Happy testing !


How do you deal with different optimization options/flags being different between versions?

Well, that’s easy: I don’t ^^"
As I said you can test the equivalent of -O0, -O1, -O2, -O3 and -flto with the tool. However if you need to check specific optimizations you can add them very easily by modifying the source code.
Here are the different options you can pass independently (look for the .mli files):

If you are also wondering about testing the differences across versions of LLVM what you can do is to just:

$ opam pin llvm <version>

and llopt will be recompiled using that version.