Now we are implementing a analysis pass for llvm, following this tutorial. and need to pass an additional argument to the plugin such as below:
opt -load /path/to/myplugin.so -mypass -mypass_option input.bc
However I did not find any manual telling me how to do. So I'm wondering whether it is possible in practice.
Thanks in advance.
The “Hello” pass is designed to simply print out the name of non-external functions that exist in the program being compiled. It does not modify the program at all, it just inspects it. The source code and files for this pass are available in the LLVM source tree in the lib/Transforms/Hello directory.
You can use Function::getArgumentList() method to get a list of function's arguments.
-mem2reg : Promote Memory to Register This file promotes memory references to be register references. It promotes alloca instructions which only have loads and stores as uses.
You should use the CommandLine library which comes built-in with LLVM. Basically, you just put at the top of the .cpp file of the pass:
#include "llvm/Support/CommandLine.h"
static cl::opt<string> InputFilename("mypass_option", cl::desc("Specify input filename for mypass"), cl::value_desc("filename"));
But I recommend you check the above link, it has full reference + convenient quickstart section.
For an example, take a look at the built-in loop unrolling pass - it defines two unsigned and two boolean options, right at the top of the source file, by using cl::opt<unsigned>
and cl::opt<bool>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With