link time optimization pass

Hi All,

How to write a link time optimization pass in llvm with LTO?

Is there a document, just like http://llvm.org/docs/WritingAnLLVMPass.html tells us how to write a llvm pass?

Thanks,

Hi All,

How to write a link time optimization pass in llvm with LTO?

LTO passes are just like any other LLVM pass. The only difference is that they are run by the link time optimizer plugin for the Gold linker.

Is there a document, just like http://llvm.org/docs/WritingAnLLVMPass.html tells us how to write a llvm pass?

You should read up on the LTO documentation at http://llvm.org/docs/LinkTimeOptimization.html and http://llvm.org/docs/GoldPlugin.html. You should then find the source code for the LLVM Gold plugin and modify it to run your pass. In essence, you'll build your own plugin for the Gold linker that runs your pass in addition to all of the other LLVM passes.

You can see an example of this in the SAFECode source code repository (http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/tools/LTO/). Just be forewarned that the LTO code in LLVM trunk has moved around a bit, so what you need to modify and where it is located has changed since LLVM 3.2.

If you could let me know what you modify to get it to work, please let me know. A student of mine is needing the same information for LLVM trunk. :slight_smile:

Regards,

John Criswell