[LLVMdev] How to get LoopInfo within Pass subclass?

Chris Lattner sabre at nondot.org
Thu Aug 5 17:30:29 PDT 2004


On Thu, 5 Aug 2004, Michael McCracken wrote:

> 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,

ok.

> 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?

Unfortunately this is a big missing feature in the pass management system.
In particular, as the assertion says, a "Pass" cannot yet require a
"FunctionPass".  The reason this is tricky is that each (e.g.) LoopInfo
instance contains loop information for one function.  When we allow Pass
objects to require FunctionPass objects, the PassManager will have to
instantiate one FunctionPass for each function in the module.

This is clearly something that we want to do, but unfortunately we can't
do it yet.  This is actually mentioned here, though I'm not suprised you
missed it: :)
http://llvm.org/docs/WritingAnLLVMPass.html#PassFunctionPass

As a work-around you can make your "Pass" object work as a FunctionPass.
I don't know what this will do to the logic in the pass, but if this is an
option, it would be the best way to go.

You're right that FunctionPass's are not supposed to have state (something
that many people overlook :) ), however, for now, nothing will break if it
does have state, and this is really the only way around this.  However, if
you want to work on the PassManager, please let us know! :)

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://nondot.org/sabre/




More information about the llvm-dev mailing list