[LLVMdev] reusing FunctionPassManager with different Modules

Nick Lewycky nicholas at mxc.ca
Sun Sep 25 09:09:21 PDT 2011


On 09/25/2011 08:29 AM, Redmond, Paul wrote:
> Thanks.
>
> The reason I ask is because I'm looking at some code that does just that. A single FunctionPassManager is constructed with a dummy Module and createStandardFunctionPasses is called on it. The FunctionPassManager cached and run on Functions in other Modules. So far I haven't noticed any problems but I guess that is because the passes added by createStandardFunctionPasses don't touch the Module.

Right, don't do that. There aren't many passes that do anything at all 
with doInitialization/doFinalization, but:
  - the inliner uses it to initialize the set of noinline functions from 
llvm.noinline
  - the inliner uses it to clean up dead functions after inlining
  - SimplifyLibCalls adds missing function attributes to "well-known" 
(ie. standardized) functions
  - LowerInvoke uses it to create a linked list of jmpbuf and ensure 
that the Module has an abort() function to call

So you might not notice the problem, but it may harm you in subtle ways. 
(And even if it doesn't now, LLVM is patient and may try again tomorrow.)

If the time to construct the FPM is a problem, please quantify it and 
file a bug for that.

Nick

> paul
>
> -----Original Message-----
> From: Nick Lewycky [mailto:nicholas at mxc.ca]
> Sent: Saturday, September 24, 2011 12:21 PM
> To: Redmond, Paul
> Cc: llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] reusing FunctionPassManager with different Modules
>
> On 09/23/2011 11:28 AM, Redmond, Paul wrote:
>> Hi,
>>
>> Is it generally safe to cache a FunctionPassManager and reuse it on
>> modules other than the one it was constructed with (assuming they have
>> the same target triple)?
>
> No. FunctionPass has a pair of methods, doInitialization and doFinalization, which take Module&  and are allowed to read or modify it outside runOnFunction.
>
> Nick
>




More information about the llvm-dev mailing list