[LLVMdev] How to get LoopInfo within Pass subclass?

Michael McCracken mmccrack at cs.ucsd.edu
Thu Aug 5 18:09:02 PDT 2004


On Aug 5, 2004, at 5:30 PM, Chris Lattner wrote:

> 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

OK. Yeah, I stopped reading after I saw the first 'future extension'. 
Woops.

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

I'm not sure if I can do this. The pass I'm writing is writing info 
about the module and its parts to a file, so I need to see the module, 
if only to print its moduleIdentifier.

I'm not sure if there's a way to get the Module that a Function belongs 
to from within a FunctionPass. If I could do that, and cheat by keeping 
some state, I could do what I want as a FunctionPass. Am I missing 
something, or is that not possible?

Also, out of curiosity, why the stateless restriction - is it because 
passes may someday be run in parallel?

> However, if you want to work on the PassManager, please let us know! :)

This depends. If it's really in my way, I may have little choice. I 
would like to make a contribution, though, and it didn't actually sound 
too bad. Any guess what amount of work that'd be?
Assume I have a passing familiarity with the LLVM architecture, 
slightly rusty average C++ skills, and little shame in asking 
questions. :)

-mike

--
	Michael O. McCracken
	UCSD CSE Ph.D. Student
	mike at cs.ucsd.edu




More information about the llvm-dev mailing list