AliasAnalysis tutorial

Hi !
I'm writting an AliasAnalysis using the online tutorial (http://www.llvm.org/docs/AliasAnalysis.html).
My problem is to chain this pass (function Pass in my case) with the basicAA ...
I know that my pass is running (runOnFunction) but the virtual methods derived from AliasAnalysis
(alias, getModRefInfo, etc ... ) are never called (even in the case wherer the basicAA reaches the end of 'getModRefInfo(CallSite CS, Value *P, unsigned Size)' virtual function)

Either, i misunderstood the process of AA (I expect that each virtual method of each AA are called if they are defined until
one of them gives a result (and that's why we need the last 'return') ( = the chain) , but maybe it's not true )
or i have forgotten a special instruction (something like 'registration of a new AA' ) , or maybe both :slight_smile:
Could anybody give me an advice, please ?

Thank you !

Julien

Hi !
In my quest of implementing my own AA, i understood that it doesn't work
because i don't use the 'opt' tool but i create my own PassManager (this for other reasons).
The problem is the same with other existing AA (AndersensPass or globalModRefPass) :
these AApasses are not chained with the basicAA when they are created in PassManager ...

So my question is now : how to call an AAPass using a local PassManager (without opt) ?

Thank you !

Julien

Julien Schmitt wrote:

Hi !
In my quest of implementing my own AA, i understood that it doesn't work
because i don't use the 'opt' tool but i create my own PassManager (this for other reasons).
The problem is the same with other existing AA (AndersensPass or globalModRefPass) :
these AApasses are not chained with the basicAA when they are created in PassManager ...

So my question is now : how to call an AAPass using a local PassManager (without opt) ?
  

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.

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 :

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

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' )

to be continued ...

Julien

Julien Schmitt a écrit :

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.