how can I have LoopInfo in a module pass?

Hi all,
I tried to have a LoopInfo object in a function pass, add addRequired in getAnalysisUsage, and then use getAnalysis in runOnFunction(). It worked OK.
Now I want to have a module pass to traverse the functions, and similarly I want to have to loop information of the functions. When I did the above in runOnModule, and run the pass, the following error popped out:

AnalysisType& llvm::Pass::getAnalysis() const [with AnalysisType = llvm::DominatorTree]: Assertion `Resolver && “Pass has not been inserted into a PassManager object!”’ failed.

Can anyone tell me the correct way to handle this in a module pass? Thanks a lot!

Best,
–Wenbin

Hi all,
I tried to have a LoopInfo object in a function pass, add addRequired in getAnalysisUsage, and then use getAnalysis in runOnFunction(). It worked OK.
Now I want to have a module pass to traverse the functions, and similarly I want to have to loop information of the functions. When I did the above in runOnModule, and run the pass, the following error popped out:

AnalysisType& llvm::Pass::getAnalysis() const [with AnalysisType = llvm::DominatorTree]: Assertion `Resolver && “Pass has not been inserted into a PassManager object!”’ failed.

Can anyone tell me the correct way to handle this in a module pass? Thanks a lot!

LoopInfo is a FunctionPass, so you have to use getAnalysis(F) where F is a pointer to the function that you want analyzed.

Note that LoopInfo, in this instance, will be re-run every time you call getAnalysis on it (this is a result of using a FunctionPass within a ModulePass). Be sure to structure you code to only call getAnalysis(F) on each function just once, if possible.

Also be sure that F is not a function declaration (i.e., a function with no body).

– John T.

Thanks John, I modify my code to like this:

bool XXX::ModulePass(Module &M){

LoopInfo &li = getAnalysis(fi);

}

Here fi is a Function* pointing to main().

Now when I run the pass, another error shows up:

AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*, llvm::Function&) [with AnalysisType = llvm::LoopInfo]: Assertion `ResultPass && “Unable to find requested analysis info”’ failed.

Did I miss something? Thanks!

Best,
–Wenbin

I think this assertion failure may be caused by the getAnalysisUsage(). Mine is like the following:

class myclass : public ModulePass{

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired();
}

}

Is it enough? Thanks!

Best,
–Wenbin

Sorry for the spaming. I solved that problem, which is caused by my typo…