[LLVMdev] Error when using getAnalysis

John Criswell criswell at cs.uiuc.edu
Mon Dec 1 07:38:26 PST 2008


nitisha warkari wrote:
> Hi,
>
> I'm trying to use the function getAnalysis. This is the code I'm using :
>
>  void getAnalysisUsage(AnalysisUsage &AU) const {
>       AU.addRequired<LoopInfo>();
>       AU.setPreservesAll();
>     }
>
>  virtual bool runOnModule(Module &M) {
>      LoopInfo &LI = getAnalysis<LoopInfo>();
>
>
>    }
>   
The LoopInfo pass is a FunctionPass, whereas your pass is a ModulePass.  
This means that your pass needs to determine which function it wants 
LoopInfo information for and run it for each of those functions.

For example, you might do something like this:

virtual bool runOnModule (Module &M) {
    Function * F = M.getFunction ("functionname");
    LoopInfo &LI = getAnalysis<LoopInfo>(*F);
}

If you need to process all functions within a Module, then look at the 
Module::iterator on the LLVM doxygen web pages: 
http://llvm.org/doxygen/hierarchy.html

-- John T.

>
>
> I get following error when I try to run my pass :
>
> opt: /net/hc295/nwarkari/llvm/llvm-2.3/include/llvm/PassAnalysisSupport.h:193: AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*) const [with AnalysisType = llvm::LoopInfo]: Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.
> opt[0x83cfa9d]
> /lib/tls/libc.so.6(abort+0xe9)[0x15d289]
> /lib/tls/libc.so.6(__assert_fail+0x101)[0x154da1]
> opt(_ZNK4llvm4Pass13getAnalysisIDINS_8LoopInfoEEERT_PKNS_8PassInfoE+0x54)[0x81294a0]
>
> Could someone please help me out with this?
>
> Thanks!
> Nitisha
>
>
>   




More information about the llvm-dev mailing list