AliasAnalysis calling failed in Pass interaction

Dear LLVM developers,

I am Shen, a PhD student at Lehigh Univ. PA. Now I am implementing a Program Dependence Graph(PDG) on LLVM. I have 4 passes here:

  1. ProgramDependenceGraph (a ModulePass on the highest level)
  2. DataDependenceGraph (a Intermediate FunctionPass).
  3. FlowDependenceAnalysis Pass (a intermediate FunctionPass) which uses llvm built-in AliasAnalysis (-basicaa)
  4. AliasAnalysis Pass (LLVM built-in Pass)

When my call chain is

DatadependenceGraph ← FlowDependenceAnalysis ← AliasAnalysis

everything is fine and basicaa is executed successfully.

My problem is, when I use a Module Pass to call a Function Pass, the low level AliasAnalysis does not work anymore, all return values for location comparisons are “May Alias”. In other words, the call chain

ProgramDependenceGraph(Module Pass) ← DatadependenceGraph(Function Pass) ← FlowDependenceAnalysis ← AliasAnalysis if failed.

However, if I change ProgramDependenceGraph into a Function Pass, this call chain works and AliasAnalysis can be executed successfully.

So, i guess there may be an error in my interaction between Module Pass and Function Pass. Could you give me some hints to help me solve it? Thank you very much!

Here are some key code for Pass interaction in my implementation:

bool ProgramDependencyGraph::runOnModule(Module &M)
{

for(Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
{
DataDependencyGraph &ddgGraph = getAnalysis(*F);


}

}

void ProgramDependencyGraph::getAnalysisUsage(AnalysisUsage &AU) const
{

AU.addRequired();

AU.setPreservesAll();

}

Best Regards,

Shen

Dear LLVM developers,

I am Shen, a PhD student at Lehigh Univ. PA. Now I am implementing a
Program Dependence Graph(PDG) on LLVM. I have 4 passes here:

1. ProgramDependenceGraph (a ModulePass on the highest level)
2. DataDependenceGraph (a Intermediate FunctionPass).
3. FlowDependenceAnalysis Pass (a intermediate FunctionPass) which uses llvm
built-in AliasAnalysis (-basicaa)

Does this implement AliasAnalysis?

4. AliasAnalysis Pass (LLVM built-in Pass)

When my call chain is

DatadependenceGraph <-- FlowDependenceAnalysis <-- AliasAnalysis

everything is fine and basicaa is executed successfully.

BasicAA is not AliasAnalysis. BasicAA is *an* AliasAnalysis.

If you have not added BasicAliasAnalysis to the pass list, it will not
be called when you call AliasAnalysis API.

My problem is, when I use a Module Pass to call a Function Pass, the low
level AliasAnalysis does not work anymore, all return values for location
comparisons are "May Alias". In other words, the call chain

ProgramDependenceGraph(Module Pass) <-- DatadependenceGraph(Function Pass)
<-- FlowDependenceAnalysis <-- AliasAnalysis if failed.

However, if I change ProgramDependenceGraph into a Function Pass, this call
chain works and AliasAnalysis can be executed successfully.

So, i guess there may be an error in my interaction between Module Pass and
Function Pass. Could you give me some hints to help me solve it? Thank you
very much!

Here are some key code for Pass interaction in my implementation:

bool ProgramDependencyGraph::runOnModule(Module &M)
{
...
  for(Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
    {
       DataDependencyGraph &ddgGraph = getAnalysis<DataDependencyGraph>(*F);
       ....
    }
}

...
void ProgramDependencyGraph::getAnalysisUsage(AnalysisUsage &AU) const
{
   ...
  AU.addRequired<DataDependencyGraph>();
  AU.setPreservesAll();
}

This does not require alias analysis or it's analysis group, which is
wrong if you want those to work?

Hi Daniel, thanks for your reply! Yes I didn’t implement AA by myself but called builtin -basicaa interface for temporary use. Just add the -basicaa option in my opt command.

I hope -basicaa can be called to process to check some simple aliases. And when I do

DataDependencyGraph &ddgGraph = getAnalysis(*F);

inside a Function Pass, it works.What make me confused is when my Pass is a Module Pass, --basicaa cannot be called anymore. It seems the -basicaa option cannot be seen by getAnalysis() if I call it in a Module Pass.

Do you have any suggestions?

Best Regards,

Shen

Hi Daniel, thanks for your reply! Yes I didn't implement AA by myself but
called builtin -basicaa interface for temporary use. Just add the -basicaa
option in my opt command.

I hope -basicaa can be called to process to check some simple aliases. And
when I do

DataDependencyGraph &ddgGraph = getAnalysis<DataDependencyGraph>(*F);

inside a Function Pass, it works.What make me confused is when my Pass is a
Module Pass, --basicaa cannot be called anymore. It seems the -basicaa
option cannot be seen by getAnalysis() if I call it in a Module Pass.

Using it as a command line option makes it run a pass. It does not
make it available to your pass.
Essentially, you are getting lucky.
The point at which basicaa gets runs when added as a command line
option happens to make it hang around at the point you are using a
function pass.

If you want this to work properly, always, the right thing to do is to
tell it you want alias analysis in your AnalysisUsage.

IE
  AU.addRequiredTransitive<AliasAnalysis>();