Is it possible to output the optimizations performed by thinlto

My purpose is to understand in more detail what optimizations thinlto has done.
Currently, there are only two articles I have found

I feel that the main length of the first is to introduce the design motivation of thinlto, and the clang document documents only introduce how to use it.
Is there an option or tool that can count the additional optimizations performed by thinlto?
Are there any other switches that thinlto can turn on to perform some more radical optimizations?
If you have any documentation on this, please share it.

The thin link (the -flto=thin a.o b.o step in in-process ThinLTO, or -flto=thin -Wl,--thinlto-index-only=a.rsp,--thinlto-emit-imports-files a.o b.o step in distributed ThinLTO) computes export and import lists, whether functions/global variables should be internalized, and some function attributes.

You can use -Wl,--save-temps to dump the symbol resolution file (*.resolution.txt) and some intermediate bitcode files for the regular LTO part. -Wl,-mllvm=-debug gives you some information about function importing.

The main optimizations are performed in backend compiles (-fthinlto-index= in distributed ThinLTO). You can use clang -c -fuse-ld=lld -O2 -fthinlto-index=lto/a.o.thinlto.bc a.o -o lto/a.o -mllvm=-print-changed to observe how the LLVM IR changes. Use -mllvm=-print-imports to dump the import list for in-process ThinLTO in the absence of --thinlto-emit-imports-files.

1 Like