[LLVMdev] How to get LoopInfo within Pass subclass?

Michael McCracken mmccrack at cs.ucsd.edu
Thu Aug 5 16:51:05 PDT 2004


Hi, I have a hopefully quick question. I'm writing a Pass that needs to 
see a whole module at a time and keep some state, so I subclassed Pass. 
However, I want to be able to see the Loops in each Function. Roughly, 
here's what I want:

virtual bool run(Module &M){
     // do stuff...
     for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I){
	    if(! I->isExternal()) visitFunction(*I);
     }
	// ...
       return false;
}

virtual void visitFunction(Function &F){
     LoopInfo *LI = &getAnalysis<LoopInfo>();
     std::vector<Loop*> SubLoops(LI->begin(), LI->end());
     for(unsigned i = 0, e = SubLoops.size(); i != e; ++i){
	   // visit SubLoops[i];
     }
}

So, I add LoopInfo as a required analysis:

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesAll();
       AU.addRequired<LoopInfo>();
};

However, when running I'm informed that:

PassManagerT.h:421: failed assertion `getAnalysisOrNullUp(P) && 
dynamic_cast<ImmutablePass*>(getAnalysisOrNullUp(P)) && "Pass available 
but not found! " "Perhaps this is a module pass requiring a function 
pass?"'

I couldn't find a clear explanation of which passes can require which 
other ones, and I'm a little confused as to whether what I want is even 
possible. How can I say that I want LoopInfo for each Function in my 
Module?

PS, if I'm not just missing it, and this is a gap in the docs, I'd be 
glad to try writing something to fill the gap. It'd probably be a good 
way to learn more about LLVM.

Thanks,
-mike
--
	Michael O. McCracken
	UCSD CSE Ph.D. Student
	mike at cs.ucsd.edu




More information about the llvm-dev mailing list