Reputation: 453
I am working on a optimization pass and I need to remove a few dead basic blocks in a loop. I know that the pass unreachableblockelim
can do the job but how do I require it to execute in the middle of my pass? That is, without using opt command line interface:
opt -load myOptPass.dylib -unreachableblockelim ir.bc -o ir2.bc
Is that even possible? I couldn't find anything similar to what I am trying to achieve in the llvm source code.
Upvotes: 1
Views: 87
Reputation: 9675
LLVM contains two pass managers at the moment. The pass you want uses the new one (characterised by the pass inheriting PassInfoMixin), and using it in a new-PM pass requires including its header file in your pass' .cpp file:
#include "llvm/CodeGen/UnreachableBlockElim.h"
Your pass will contain a function named run(), which perhaps looks like this:
PreservedAnalyses MyPAss::run(Function &F, FunctionAnalysisManager &FAM) {
// some of your code goes here
UnreachableBlockElimPass ube;
ube.run(F, FAM);
// more of your code here
}
If your pass uses the old pass manager (characterised by inheriting FunctionPass, ModulePass etc) then it's a little more involved, because you need to provide that FunctionAnalysisManager yourself. In that case I'd start by migrating to the new way.
Upvotes: 3