Murat
2008-Aug-11 04:50 UTC
[LLVMdev] Applying different Optimizations for different Functions - Questions?
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
David Greene
2008-Aug-11 21:04 UTC
[LLVMdev] Applying different Optimizations for different Functions - Questions?
On Sunday 10 August 2008 23:50, Murat wrote:> 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 did some work on this kind of thing locally and found it to be much harder than I'd anticipated. I've got several patches in my queue to fix various problems with global data that should resolve most of the issues. No time frame on when those will go in, unfortunately. -Dave
Devang Patel
2008-Aug-11 21:25 UTC
[LLVMdev] Applying different Optimizations for different Functions - Questions?
On Aug 10, 2008, at 9:50 PM, Murat wrote:> 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.You are required to "add" passes, before running them, so that the pass manager can schedule required analysis information properly. In your case, you could try... bool ComplNewBBFuncs::runOnModule(Module &M) { Function *Main = M.getFunction("main"); if (Main == 0) { cerr << "!!! No Main Function" << std::endl; return false; } //Determine each Function Function *CurFunc1 = M.getFunction("NewFunction1"); Function &Current1 = (*CurFunc1); Function *CurFunc2 = M.getFunction("NewFunction2"); Function &Current2 = (*CurFunc2); FunctionPassManager FPM1; FPM1.add(createDeadStoreEliminationPass()); FunctionPassManager FPM2; FPM2.add(createLoopUnrollPass()); /* This will setup loop pass manager appropriately */ FPM1.run(Current1); FPM2.run(Current2); }