[llvm-commits] [llvm] r107109 - in /llvm/trunk: include/llvm/Analysis/AliasAnalysis.h include/llvm/Analysis/Passes.h lib/Analysis/AliasAnalysis.cpp lib/Analysis/BasicAliasAnalysis.cpp test/Analysis/BasicAA/interprocedural.ll

Chris Lattner clattner at apple.com
Wed Jun 30 21:31:50 PDT 2010


On Jun 30, 2010, at 9:21 PM, Chris Lattner wrote:

>> 
>> Then there's "arguments can't alias allocas" logic. From a non-interprocedural
>> perspective, this works. From an interprocedural perspective, consider
>> function r0 in the included testcase.
> 
> Again, this is only true if AA were a context or path sensitive interface, but it isn't.  GlobalModRef is an example of a context sensitive analysis which is queried with a context insensitive interface.  DSA (in the poolalloc module) is another.  To be able to do context sensitive queries, you have to be able to pass information into the clients.  I am pretty sure that I covered this in my phd thesis if you care.

Let me put this a different way.  The AliasAnalysis interface is *really only intended* for context insensitive clients.  DSA provides a series of passes (bottom-up, top-down etc) which context sensitive clients can use to get specific information.  The DSA algorithm captures a bunch of information into various data structures, which aren't directly useful for implementing AA.

When it comes to actually implementing the AA interface with the DSA information (section 4.2 of http://llvm.org/pubs/2005-05-04-LattnerPHDThesis.pdf), the problem comes down to using the information captured by the previous passes to respond to the various queries.

For example, the alias query (when both pointers are global or within the same function) find the function the pointer is in and devolves to looking in that one graph.  Amusingly, the implementation currently asserts if the pointers are in two different functions:

http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructureAA.cpp?revision=HEAD&view=markup
...

AliasAnalysis::AliasResult DSAA::alias(const Value *V1, unsigned V1Size,
                                       const Value *V2, unsigned V2Size) {
  assert(valid && "DSAA invalidated but then queried?!");
  if (V1 == V2) return MustAlias;

  DSGraph *G1 = getGraphForValue(V1);
  DSGraph *G2 = getGraphForValue(V2);
  assert((!G1 || !G2 || G1 == G2) && "Alias query for 2 different functions?");

  // Get the graph to use...
  DSGraph* G = G1 ? G1 : (G2 ? G2 : TD->getGlobalsGraph());

This is basically saying "get the one functions graph if either pointer is local to a function, otherwise get the globals graph if they are both global".  The assertion will trigger if you have pointers within different functions.  Asserting in this case is lame of course (DSA should just return MayAlias), but we don't have any clients that make that query.
The DSA information is used in more interesting ways for mod/ref queries.  To answer whether a call to a function modifies an alloca in the caller, for example, it does some heavy graph mapping/manipulation which *is* context sensitive.  However, this is still within the context-sensitive query API.
I don't think we need the "IP BasicAA" pass: if you agree, please remove it.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100630/b8cf775c/attachment.html>


More information about the llvm-commits mailing list