Hi all,
I was wondering if there’s any way to pass command line arguments to LLVM optimization passes when run through the opt tool.
For example, suppose I register called MyPass, then I want to run
opt -load libMyPass.so -MyPass 3 < input.bc
and have “3” be available to MyPass as a kind of argv argumnet through some method.
Or does it take a major rewrite of the opt tool command line parsing?
Thanks!
Harel Cain
Hi Harel,
Several existing passes can take command line arguments. Have a look at lib/Transforms/Scalar/LoopUnrollPass.cpp for example. Its command line arguments are defined using the cl::opt objects.
Best regards,
A follow-up question:
Is there a way to make different passes accept one command line option that
will affect all of them?
For example, I'd like to have a -optStrength parameter, that can be given to
all of my passes simultaneously.
Thanks a lot,
Guy
Arnaud Allard de Grandmaison wrote:
You could make the cl:opt object visible outside one of your passes, and use it in your other passes : in other words, it is a global variable shared between several files.
Best regards,
Yep. The ARM, X86 and PPC backends do this, for example. To find some examples, in <llvm>/lib/Target, run: grep -R "extern cl::opt" *
-Jim