[LLVMdev] AliasAnalysis tutorial 2

John Criswell criswell at uiuc.edu
Wed Dec 10 05:13:32 PST 2008


Julien Schmitt wrote:
> Well, now i added the creation of my AA just before the
> creation of DSE, (in the former case it was done at top of all passes list)
> and it's working (alias and getModRefInfo are called)...
> Maybe a particular pass destroyed the AliasAnalysGroup ??
>   
Yes, this is a known limitation of the PassManager.  The PassManager 
will try to automatically schedule analysis passes for registered 
transform passes as needed.  However, when scheduling an analysis group, 
it will always pick the default implementation (in the case of 
AliasAnalysis, it's BasicAA) if there is not another implementation that 
has been explicitly added *and* not invalidated by a subsequent transform.

As an example, let us say that your AliasAnalysis pass is called A, a 
pass B uses the AliasAnalysis group, and a pass C invalidates all 
analysis passes.  If you explicitly tell PassManager to run, in the 
following order:

A->B->C->B

... then your pass A will be run, followed by B which will use it as 
expected.  Pass C will invalidate A, and then PassManager will need to 
schedule another AliasAnalysis group pass between C and the second 
execution of B since B needs AliasAnalysis results.  Currently, 
PassManager will run BasicAA because it selects the default.  So, what 
you get in the end is:

A->B->C->BasicAA->B

The solution for now is to simply know which passes will require an 
AliasAnalysis group and to ensure that your pass is always available 
when such passes are run.  This requires you to explicitly schedule your 
alias analysis pass before any transform that needs alias analysis.

Note that you'll get this behavior whether you use opt or you build your 
own command-line tool that uses PassManager.  Both use PassManager to 
schedule passes.
> However he solution is not very clean, since i don't know which
> pass need an AA (i guess this should be automatic whith the
> method 'getAnalysisUsage' )
>   
Agreed.  It would be better if you could tell PassManager something to 
the effect of:

"when a pass requests an analysis of this group, run this subset of 
passes from that group and let them be queried in this order."

However, to the best of my knowledge, no one has implemented such a 
feature (or one like it) yet.

-- John T.

> to be continued ...
>
> Julien
>
>
>
> Julien Schmitt a écrit :
>   
>> Thank you very much John for your answer , you understood well my problem
>> (and the signification of my "own" PassManager).
>>
>> I already tried your solution but it is not enough. The problem is the
>> same with
>> existing AA (andersen for example) : when calling with opt, this works
>> well, but
>> when adding in local PassManager ( with add() ), it is not working (I
>> test this with
>> the DeadStoreEliminationPass which performs an AA).
>> In particular,  the pass is run (runOnFunction) but the derived method from
>> AliasAnalysis (like 'alias' or 'getModRefInfo') are not chained with
>> those from
>> basicAA when needed.
>>
>> Now, i'm trying to understand how opt, RegisterPass, RegisterAnalysisGroup
>> etc, are working, but it is quite difficult (very high level C++!)
>>
>> Thank you.
>>
>> Julien
>>
>>
>>
>> John Criswell a écrit :
>>   
>>     
>>> I'm assuming that by "creating your own PassManager" you mean that
>>> you're writing your own C++ tool that creates a PassManager object and
>>> then explicitly adds passes using the add() method of PassManager.  Is
>>> this correct?
>>>
>>> In that case, I think all you need to do is to explicitly specify your
>>> alias analysis as one of the passes to run:
>>>
>>> PassManager Passes;
>>>
>>> Passes.add (new YourAliasAnalysisPass());
>>> Passes.add (new WhateverPassUsesTheAliasAnalysisInterface());
>>>
>>> Creating a pass in the AliasAnalysis group doesn't mean that it will
>>> automatically be run when an alias analysis is needed.  Rather, what it
>>> means is that *if* a pass requests an AliasAnalysis group pass *and*
>>> your pass has already been executed, the pass requesting an
>>> AliasAnalysis group pass will find your pass and use it. That is why you
>>> need to add it explicitly.  If you don't add it explicitly, the
>>> PassManager will simply use the default AliasAnalisys group pass, which
>>> I believe is BasicAA.
>>>
>>> Does this help answer your question, or am I misunderstanding something?
>>>
>>> -- John T.
>>>
>>>
>>>     
>>>       
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>> CONFIDENTIAL NOTICE: The contents of this message, including any attachments, are confidential and are intended solely for the use of the person or entity to whom the message was addressed. If you are not the intended recipient of this message, please be advised that any dissemination, distribution, or use of the contents of this message is strictly prohibited. If you received this message in error, please notify the sender. Please also permanently delete all copies of the original message and any attached documentation. Thank you.
>>   
>>     
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list