Tutorial on writing Link Time Optimization Passes?

Hi,

Is there a tutorial on how to get started with writing link-time optimization passes? The documentation at http://www.llvm.org/docs/LinkTimeOptimization.html explains the design of the LTO interface, but does not explain where to start writing code. Would my pass go inside libLTO.a or is it separate from libLTO.a? What I would like to be able to do is traverse through the entire call graph of the program, which is only available at link-time.

Thank you,

Diego

Hi Diego,

There are no "lto specific" passes. We just write interprocedural passes and can choose to run them at either compile or link time. For some examples, please see lib/Transforms/IPO.

-Chris

The documentation you're looking for is:

   http://llvm.org/docs/WritingAnLLVMPass.html

If you're doing an optimization that runs at link-time, you'll probably be writing a ModulePass. You can run any pass at any time over any bitcode file with 'opt -mypass file.bc'. If you want to add it to the list of passes that run when linking via libLTO or llvm-ld, you can add it to the list in tools/llvm-ld/Optimize.cpp:Optimize and tools/lto/LTOCodeGenerator.cpp:generateAssemblyCode.

A couple other pointers to our doxygen:

   ModulePass: http://llvm.org/doxygen/classllvm_1_1ModulePass.html
   CallGraph: http://llvm.org/doxygen/classllvm_1_1CallGraph.html

You can take a look at lib/Transforms/IPO/Internalize.cpp to see an example of a link-time optimization pass that uses the CallGraph.

Nick

Diego Huang wrote:

Thanks Nick and Chris for your help! I've been able to install the Hello pass as a link-time pass in llvm-ld :slight_smile: Now onto the harder part of traversing the call graph and performing transformations...

Diego

Quoting Nick Lewycky <nicholas@mxc.ca>: