Passing parameters to LLVM optimisation passes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing parameters to LLVM optimisation passes

Ian Jason
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').

e.g. so i can do something like this "opt -load mypass.so -MyPass=MyPassOption < inputfile.bc ..."

(for example one thing I would like to do is pass a list of function names to optimise, the pass would then optimise these (and their children) and ignore everything else)

I've had a trawl through the documentation but can't seem to see a way of doing this within the pass framework.  I may be missing something.  Is it possible?  If so, could someone point me in the right direction?

Thanks,
Ian
Reply | Threaded
Open this post in threaded view
|

Re: Passing parameters to LLVM optimisation passes

John Criswell-2
Ian Jason wrote:
> 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').
>
> e.g. so i can do something like this "opt -load mypass.so
> -MyPass=MyPassOption < inputfile.bc ..."
>  
Yes, this is possible.  In your source code, you simply need to add a
new command line option using LLVM's command line library.  This library
allows you to create a global variable for each command line option that
you want.  When you load your pass into opt, the global variables'
constructors automatically register your command line options with the
opt tool.

For example, you might do something like this in your code:

namespace {
  cl::opt<bool> OnlyPrintMain("only-print-main-ds", cl::ReallyHidden);
}

This defines a command line option "-only-print-main-ds" that toggles a
boolean flag.  The OnlyPrintMain variable than acts like a C++ boolean:

if (OnlyPrintMain)
    do something
else
    do something else

More information on the command line library can be found in its
documentation: http://llvm.org/docs/CommandLine.html

-- John T.

> (for example one thing I would like to do is pass a list of function names
> to optimise, the pass would then optimise these (and their children) and
> ignore everything else)
>
> I've had a trawl through the documentation but can't seem to see a way of
> doing this within the pass framework.  I may be missing something.  Is it
> possible?  If so, could someone point me in the right direction?
>
> Thanks,
> Ian
> --
> View this message in context: http://www.nabble.com/Passing-parameters-to-LLVM-optimisation-passes-tp15711960p15711960.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>  

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Passing parameters to LLVM optimisation passes

Wojciech Matyjewicz
In reply to this post by Ian Jason
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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev