[LLVMdev] Error when using getAnalysis

730 views
Skip to first unread message

nitisha warkari

unread,
Nov 29, 2008, 11:53:23 PM11/29/08
to llv...@cs.uiuc.edu
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>();


   }



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
 

Bill Wendling

unread,
Nov 30, 2008, 12:06:20 AM11/30/08
to LLVM Developers Mailing List

You might need to have your pass inherit from the LoopPass instead of
ModulePass. See some examples in lib/Transforms/Scalar.

-bw

_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

John Criswell

unread,
Dec 1, 2008, 10:38:26 AM12/1/08
to LLVM Developers Mailing List
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
>
>
>

_______________________________________________

Jeff Yeong-Peng Hao

unread,
Dec 2, 2008, 1:40:29 PM12/2/08
to LLVM Developers Mailing List

Hi,

I had a question about this as well. The documentation about writing a
pass shows an example like what John wrote, calling a function pass within
a module pass on a per function basis. However, if I code it that way, I
still get the same error:

opt: /x/jeffhao/llvm/llvm/include/llvm/PassAnalysisSupport.h:232:
AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*,
llvm::Function&) [with AnalysisType = llvm::LoopInfo]: Assertion


`ResultPass && "getAnalysis*() called on an analysis that was not "
"'required' by pass!"' failed.

If I remove the addRequired from getAnalysisUsage, I get this error:

opt: /x/jeffhao/llvm/llvm-2.4/lib/VMCore/PassManager.cpp:1440: virtual
llvm::Pass* llvm::MPPassManager::getOnTheFlyPass(llvm::Pass*, const
llvm::PassInfo*, llvm::Function&): Assertion `FPP && "Unable to find on the
fly pass"' failed.

What else needs to be added to make the code run?

Jeff

On Mon, 1 Dec 2008 09:38:26 -0600, John Criswell <cris...@cs.uiuc.edu>
wrote:

Devang Patel

unread,
Dec 2, 2008, 2:06:44 PM12/2/08
to LLVM Developers Mailing List

On Dec 2, 2008, at 10:40 AM, Jeff Yeong-Peng Hao wrote:

>
> Hi,
>
> I had a question about this as well. The documentation about
> writing a
> pass shows an example like what John wrote, calling a function pass
> within
> a module pass on a per function basis. However, if I code it that
> way, I
> still get the same error:
>
> opt: /x/jeffhao/llvm/llvm/include/llvm/PassAnalysisSupport.h:232:
> AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*,
> llvm::Function&) [with AnalysisType = llvm::LoopInfo]: Assertion
> `ResultPass && "getAnalysis*() called on an analysis that was not "
> "'required' by pass!"' failed.
>
> If I remove the addRequired from getAnalysisUsage, I get this error:
>
> opt: /x/jeffhao/llvm/llvm-2.4/lib/VMCore/PassManager.cpp:1440: virtual
> llvm::Pass* llvm::MPPassManager::getOnTheFlyPass(llvm::Pass*, const
> llvm::PassInfo*, llvm::Function&): Assertion `FPP && "Unable to find
> on the
> fly pass"' failed.
>
> What else needs to be added to make the code run?

Is it possible for you to provide a reproducible test case to help us
understand what is going on ?
Thanks,
-
Devang

Jeff Yeong-Peng Hao

unread,
Dec 2, 2008, 2:35:24 PM12/2/08
to LLVM Developers Mailing List
Sure. I've attached the code for the test pass I wrote, as well as the
code and bitcode for the testcase I'm running. All the functionality has
been stripped out of the pass, and the pass compiles without a problem, but
the error appears when the pass is run.

Jeff

ModuleLoop.cpp
ModuleLoop.h
simple.c
simple.bc

Devang Patel

unread,
Dec 2, 2008, 3:12:09 PM12/2/08
to LLVM Developers Mailing List
Jeff,

Just add !isDeclaration() check before requesting loop info. In your
example, there is not any way to get loopinfo for printf whose
definition is not available.

if (!F.isDeclaration())
LoopInfo &LI = getAnalysis<LoopInfo>(F);

-
Devang

> ModuleLoop
> .cpp
> >
> <
> ModuleLoop
> .h
> ><simple.c><simple.bc>_______________________________________________

Reply all
Reply to author
Forward
0 new messages