Reputation: 21
By using opt, we can run a custom pass, or run a -O1 -O2 -O3 pass pipeline on a foo.ll file, but it all happens on the command line, and the IR is a file form.This is not conducive to some optimization of IR in the form of memory (each IR file is a module in memory form)in your own project. By the way of opt just like this:
opt -O2 foo.ll -o foo2.ll
Then we can get an optimized IR file foo2.ll.
Now, I want do the optimization in the program. I have compiled some custom passes into libraries outside the source tree. How to organize passes into pipelines by using the API interface of the new pass manager, and apply thepipline in an IR module?
My goal is :
①load the local pass's libraries in the program with a certain LLVM data structure(I am not sure which data structure it is)
②Register the passes which loaded into the program as sequential piplines
③Finally, apply Pass Pipline to an IR Module and return a new IR Module optimized by this Pipline
If doing this outside the source tree, by linking the static library to call the API, which API should I start with? Are there some examples to refer to? For example, how to use the new pass manager outside the source tree, and how to load the natively compiled pass library into memory
Upvotes: 0
Views: 1224
Reputation: 9675
Passes are run by a pass manager; opt is basically a small program that loads a module from a file, configures and runs a pass manager and writes the module at the end.
The pipeline you mention is much of what the pass manager is/does. I'm not quite clear on what exactly you're trying to do, but the general direction is clear enough. All the tasks in that direction involve using the pass manager. You configure the pass manager to use your custom passes and probably some/many that are included in LLVM, then you tell the pass manager to do its work on a module, and it calls your passes as necessary. The module is the in-memory data structure you want, it can be read or written as a .bc or .ll file.
Upvotes: 1