[LLVMdev] Passing parameters to LLVM optimisation passes

Wojciech Matyjewicz wmatyjewicz at fastmail.fm
Wed Feb 27 08:18:48 PST 2008


Hi,

> I'm fairly new to LLVM, and am writing an optimisation pass to be run by
> 'opt'.  However, i'd like this pass to be parameterisable; as such i'd like
> to be able to pass an option to it (preferably via the command line to
> 'opt').

You'll find it easy using the CommandLine library (a part of the LLVM
core). Please, include its header in your pass' implementation:

  #include <llvm/Support/CommandLine.h>

and define options you want. For example (taken from:
http://llvm.org/doxygen/LoopUnroll_8cpp-source.html):

  cl::opt<unsigned>
  UnrollThreshold
    ("unroll-threshold", cl::init(100), cl::Hidden,
     cl::desc("The cut-off point for automatic loop unrolling"));

or, because you'll probably need a string option (taken from:
http://llvm.org/doxygen/ProfileInfoLoaderPass_8cpp-source.html):

  cl::opt<std::string>
  ProfileInfoFilename("profile-info-file", cl::init("llvmprof.out"),
                      cl::value_desc("filename"),
                      cl::desc("Profile file loadedby-profile-loader"));

Then, in your code you can use these variables as they were of,
appropriately, unsigned or string type.

The full documentation of the CommandLine library is here:
http://llvm.org/docs/CommandLine.html

Wojtek




More information about the llvm-dev mailing list