[LLVMdev] Applying different Optimizations for different Functions - Questions?
Murat
murat at udel.edu
Sun Aug 10 21:50:09 PDT 2008
Hi!
I am trying to develop an LLVM tool which can apply different optimizations
for selected functions. For example, I want to apply an optimization onto one
function but not for another one.
I am using the standard optimizations available in LLVM.
That is the runOnModule function I have written:
bool ComplNewBBFuncs::runOnModule(Module &M)
{
Function *Main = M.getFunction("main");
if (Main == 0)
{
cerr << "!!! No Main Function" << std::endl;
return false;
}
//Determine each Function
LoopPass * UnrollLoops;
FunctionPass *DeadStoreElim;
LPPassManager *LPPM;
Function *CurFunc1 = M.getFunction("NewFunction1");
Function &Current1 = (*CurFunc1);
Function *CurFunc2 = M.getFunction("NewFunction2");
Function &Current2 = (*CurFunc2);
cerr << "Dead Store Eliminations" << std::endl;
DeadStoreElim = createDeadStoreEliminationPass();
DeadStoreElim->runOnFunction(Current1);
cerr << "Loop Unroll" << std::endl;
LPPM = new LPPassManager(1);
UnrollLoops = createLoopUnrollPass();
LPPM->add(UnrollLoops);
LPPM->runOnFunction(Current2);
LPPM->releaseMemory();
delete LPPM;
LPPM = NULL;
return true;
}
This tool compiles successfully, but I got errors when I apply it onto
a program.
DeadStoreElim = createDeadStoreEliminationPass();
DeadStoreElim->runOnFunction(Current1);
This part of the tool outputs following error message:
opt: /home/bolat/llvm-2.2/include/llvm/PassAnalysisSupport.h:178:
AnalysisType& llvm::Pass::getAnalysis() const [with AnalysisType =
llvm::MemoryDependenceAnalysis]: Assertion `Resolver &&"Pass has not
been inserted into a PassManager object!"' failed.
I would like to ask how I can include the resolvers?
I also get error when I try to apply the loop optimizations.
LPPM = new LPPassManager(1);
UnrollLoops = createLoopUnrollPass();
LPPM->add(UnrollLoops);
LPPM->runOnFunction(Current2);
LPPM->releaseMemory();
delete LPPM;
LPPM = NULL;
This part also terminates opt and outputs segmentation fault.
I am not sure if this is the correct way to apply loop optimizations
onto a specific function.
I appreciate for your help.
Thanks,
Murat
More information about the llvm-dev
mailing list