LLVM pass creation related - llvm

I want to create a pass that will insert a function (that is in some c file) after every load instruction.I know how to insert a function with no arguments.But a function that also have argument. I am not able to insert that.How should i do that?
Thanks in advance.

Use the CallInst::Create static method. It takes an ArrayRef of arguments. By grepping for this method call in the source of LLVM & Clang you can find many examples for using it.

Related

llvm - Pass arguments to a pass

I need to tell the pass to look out for a specific function in the file. And I want to specify which function to look out for 'on the go' i.e when I run the pass. Any idea how I can do that? It's sort of like passing arguments to a function in theory.
Add a command line option using cl::opt<string> and set it when running your pass.
Alternatively, if you are producing an IR from C or C++ using clang, you can utilize __attribute((__annotate__(("foo")))) to mark functions you are interested in.

how can i modify the RWX attribute of function in LLVM IR?

Due to project requirements, i need to modify the RXW attribute of some functions. Such as modify a function attribute to WX. I tried to separate the functions in different sections, but what problem is that i don't know how to modify those attribute in LLVM IR. Is there any good way?
From my understanding here. You don't modify a function as RWX, you mark the memory page containing that function to be RWX.
You choices would be:
- Post process after the file has been linked
- Use LLVM IR to add external function calls to system API which will mark the memory page as RWX

How do I add Reg2Mem pass to addRequired() in LLVM?

I want to remove phi nodes from my llvm IR files, so I've read that Reg2Mem pass is a solution (why?).
I can easily use this pass from the opt tool by specifying -reg2mem as argument.
However, I want this functionality be built into my own pass called FlattenO. Therefore, I try to add the Reg2Mem pass as a required dependency of my pass (it should be called automatically then?).
void FlattenO::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<Reg2Mem>();
}
The code above doesn't work, because it cannot find any Reg2Mem pass. What files should I include to use the Reg2Mem pass? Also, please correct my code, so everything should work as intended.

Is there a way to make a pass over two llvm-ir?

I want to compare two llvm-ir programs function by function. I thought it will be help full if I do it as an LLVM pass where I can have access to CFG of the program. It seems all the passes(Module, Function, ..) were working on single program, How can I do a pass over two programs simultaneously?
I would just run llvm-link (a command-line tool bundled with LLVM) to merge the IR files together first, then use a regular module pass.
I think the function renaming rule in llvm-link is something like renaming f to f.llvm.X where X is the module ID, so your pass could identify pairs by them having the same name prefix before the module ID.

Available Analysis and Transform passes for LLVM

Is there any document on the list of Analysis and Transform passes available for use in the AnalysisUsage::addRequired<> and Pass::geAnalysis<> functions?
I can get a list of passes in http://llvm.org/docs/Passes.html, but it only shows the command line names for the passes. How can I know the underlying pass classes?
Not really, no. Just look at the source. The header files in include/llvm/Analysis/ and include/llvm/Transforms/ will tell you everything you need to know.
Moreover, grepping over the source for getAnalysis< will tell you which passes are used as analyses inside the LLVM source code.