[LLVMdev] how can I have LoopInfo in a module pass?

John Criswell criswell at illinois.edu
Thu Mar 3 13:26:31 PST 2011


On 3/3/11 3:09 PM, Wenbin Zhang wrote:
> Hi all,
> I tried to have a LoopInfo object in a function pass, add
> addRequired<LoopInfo> in getAnalysisUsage, and then use
> getAnalysis<LoopInfo> 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<LoopInfo>(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<LoopInfo>(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.

> Best,
> --Wenbin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110303/00370104/attachment.html>


More information about the llvm-dev mailing list