From: Misha Brukman Date: Fri, 24 Oct 2003 18:06:11 +0000 (+0000) Subject: This is now valid HTML 4.01 Strict. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3896be2ecdcef019a10f3f4a43e5e2de3e3a2cf6;p=oota-llvm.git This is now valid HTML 4.01 Strict. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9475 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/AliasAnalysis.html b/docs/AliasAnalysis.html index e4bebca8aa6..64b7df80a62 100644 --- a/docs/AliasAnalysis.html +++ b/docs/AliasAnalysis.html @@ -1,8 +1,8 @@ - + - - + Alias Analysis Infrastructure in LLVM @@ -15,40 +15,41 @@
  1. Introduction
  2. -
  3. AliasAnalysis Overview
  4. +
  5. AliasAnalysis Overview +
  6. -
  7. Writing a new AliasAnalysis Implementation
  8. +
  9. Writing a new AliasAnalysis Implementation +
  10. -
  11. Using AliasAnalysis results
  12. +
  13. Using AliasAnalysis results -
  14. Helpful alias analysis related tools
  15. + + +
  16. Helpful alias analysis related tools - - -

    Written by Chris Lattner

    +
+
+

Written by Chris Lattner

+
@@ -113,17 +114,15 @@ mod/ref information for arbitrary instructions.
-

-Most importantly, the AliasAnalysis class provides several methods which are + +

Most importantly, the AliasAnalysis class provides several methods which are used to query whether or not pointers alias, whether function calls can modify -or read memory, etc. -

-

-Representing memory objects as a starting address and a size is critically +or read memory, etc.

+ +

Representing memory objects as a starting address and a size is critically important for precise Alias Analyses. For example, consider this (silly) C -code: -

-

+code:

+
   int i;
   char C[2];
@@ -134,15 +133,13 @@ code:
     C[1] = A[9-i];        /* One byte store */
   }
 
-

-

-In this case, the basicaa pass will disambiguate the stores to + +

In this case, the basicaa pass will disambiguate the stores to C[0] and C[1] because they are accesses to two distinct locations one byte apart, and the accesses are each one byte. In this case, the LICM pass can use store motion to remove the stores from the loop. In -constrast, the following code: -

-

+constrast, the following code:

+
   int i;
   char C[2];
@@ -153,13 +150,12 @@ constrast, the following code:
     C[1] = A[9-i];          /* One byte store */
   }
 
-

-

-In this case, the two stores to C do alias each other, because the access to the -&C[0] element is a two byte access. If size information wasn't + +

In this case, the two stores to C do alias each other, because the access to +the &C[0] element is a two byte access. If size information wasn't available in the query, even the first case would have to conservatively assume -that the accesses alias. -

+that the accesses alias.

+
@@ -168,18 +164,17 @@ that the accesses alias.
-

-An Alias Analysis implementation can return one of three responses: MustAlias, -MayAlias, and NoAlias. The No and May alias results are obvious: if the two -pointers may never equal each other, return NoAlias, if they might, return -MayAlias. -

-

-The Must Alias response is trickier though. In LLVM, the Must Alias response + +

An Alias Analysis implementation can return one of three responses: +MustAlias, MayAlias, and NoAlias. The No and May alias results are obvious: if +the two pointers may never equal each other, return NoAlias, if they might, +return MayAlias.

+ +

The Must Alias response is trickier though. In LLVM, the Must Alias response may only be returned if the two memory objects are guaranteed to always start at exactly the same location. If two memory objects overlap, but do not start at -the same location, MayAlias must be returned. -

+the same location, MayAlias must be returned.

+
@@ -188,12 +183,12 @@ the same location, MayAlias must be returned.
-

-The getModRefInfo methods return information about whether the + +

The getModRefInfo methods return information about whether the execution of an instruction can read or modify a memory location. Mod/Ref information is always conservative: if an action may read a location, Ref -is returned. -

+is returned.

+
@@ -203,13 +198,13 @@ is returned.
-

-Writing a new alias analysis implementation for LLVM is quite straight-forward. -There are already several implementations that you can use for examples, and the -following information should help fill in any details. For a minimal example, -take a look at the no-aa -implementation. -

+ +

Writing a new alias analysis implementation for LLVM is quite +straight-forward. There are already several implementations that you can use +for examples, and the following information should help fill in any details. +For a minimal example, take a look at the no-aa implementation.

+
@@ -218,13 +213,13 @@ implementation.
-

-The first step to determining what type of LLVM -pass you need to use for your Alias Analysis. As is the case with most -other analyses and transformations, the answer should be fairly obvious from -what type of problem you are trying to solve: -

-

+ +

The first step to determining what type of LLVM pass you need to use for your Alias +Analysis. As is the case with most other analyses and transformations, the +answer should be fairly obvious from what type of problem you are trying to +solve:

+
  1. If you require interprocedural analysis, it should be a Pass.
  2. @@ -233,13 +228,12 @@ what type of problem you are trying to solve:
  3. If you don't need to look at the program at all, subclass ImmutablePass.
-

-

-In addition to the pass that you subclass, you should also inherit from the + +

In addition to the pass that you subclass, you should also inherit from the AliasAnalysis interface, of course, and use the RegisterAnalysisGroup template to register as an implementation of -AliasAnalysis. -

+AliasAnalysis.

+
@@ -248,31 +242,28 @@ In addition to the pass that you subclass, you should also inherit from the
-

-Your subclass of AliasAnalysis is required to invoke two methods on the + +

Your subclass of AliasAnalysis is required to invoke two methods on the AliasAnalysis base class: getAnalysisUsage and InitializeAliasAnalysis. In particular, your implementation of getAnalysisUsage should explicitly call into the AliasAnalysis::getAnalysisUsage method in addition to doing any declaring any pass dependencies your pass has. Thus you should have something -like this: -

-

+like this:

+
     void getAnalysisUsage(AnalysisUsage &AU) const {
       AliasAnalysis::getAnalysisUsage(AU);
       // declare your dependencies here.
     }
 
-

-

-Additionally, your must invoke the InitializeAliasAnalysis method from -your analysis run method (run for a Pass, + +

Additionally, your must invoke the InitializeAliasAnalysis method +from your analysis run method (run for a Pass, runOnFunction for a FunctionPass, runOnBasicBlock for a BasicBlockPass, or InitializeAliasAnalysis for an -ImmutablePass). For example (as part of a Pass): -

-

+ImmutablePass). For example (as part of a Pass):

+
     bool run(Module &M) {
       InitializeAliasAnalysis(this);
@@ -280,7 +271,7 @@ a BasicBlockPass, or InitializeAliasAnalysis for an
       return false;
     }
 
-

+
@@ -289,13 +280,13 @@ a BasicBlockPass, or InitializeAliasAnalysis for an
-

-All of the AliasAnalysis virtual -methods default to providing conservatively correct information (returning "May" -Alias and "Mod/Ref" for alias and mod/ref queries respectively). Depending on -the capabilities of the analysis you are implementing, you just override the -interfaces you can improve. -

+ +

All of the AliasAnalysis +virtual methods default to providing conservatively correct information +(returning "May" Alias and "Mod/Ref" for alias and mod/ref queries +respectively). Depending on the capabilities of the analysis you are +implementing, you just override the interfaces you can improve.

+
@@ -304,15 +295,15 @@ interfaces you can improve.
-

-With only two special exceptions (the basicaa and With only two special exceptions (the basicaa and no-aa passes) every alias analysis pass should chain to another alias analysis implementation (for example, you could specify "-basic-aa -ds-aa -andersens-aa -licm" to get the maximum benefit from the three alias analyses). To do this, simply "Require" AliasAnalysis in your getAnalysisUsage method, and if you need to return a conservative -MayAlias or Mod/Ref result, simply chain to a lower analysis. -

+MayAlias or Mod/Ref result, simply chain to a lower analysis.

+
@@ -321,14 +312,14 @@ MayAlias or Mod/Ref result, simply chain to a lower analysis.
-

-From the LLVM perspective, the only thing you need to do to provide an efficient -alias analysis is to make sure that alias analysis queries are serviced -quickly. The actual calculation of the alias analysis results (the "run" -method) is only performed once, but many (perhaps duplicate) queries may be -performed. Because of this, try to move as much computation to the run method -as possible (within reason). -

+ +

From the LLVM perspective, the only thing you need to do to provide an +efficient alias analysis is to make sure that alias analysis queries are +serviced quickly. The actual calculation of the alias analysis results (the +"run" method) is only performed once, but many (perhaps duplicate) queries may +be performed. Because of this, try to move as much computation to the run +method as possible (within reason).

+
@@ -338,10 +329,10 @@ as possible (within reason).
-

-There are several different ways to use alias analysis results. In order of -preference, these are... -

+ +

There are several different ways to use alias analysis results. In order of +preference, these are...

+
@@ -350,13 +341,13 @@ preference, these are...
-

-The load-vn pass uses alias analysis to provide value numbering + +

The load-vn pass uses alias analysis to provide value numbering information for load instructions. If your analysis or transformation can be modelled in a form that uses value numbering information, you don't have to do anything special to handle load instructions: just use the -load-vn pass, which uses alias analysis. -

+load-vn pass, which uses alias analysis.

+
@@ -365,36 +356,33 @@ to do anything special to handle load instructions: just use the
-

-Many transformations need information about alias sets that are active in -some scope, rather than information about pairwise aliasing. The Many transformations need information about alias sets that are active +in some scope, rather than information about pairwise aliasing. The AliasSetTracker class is used to efficiently build these Alias Sets from the pairwise alias analysis -information provided by the AliasAnalysis interface. -

-

-First you initialize the AliasSetTracker by use the "add" methods to +information provided by the AliasAnalysis interface.

+ +

First you initialize the AliasSetTracker by use the "add" methods to add information about various potentially aliasing instructions in the scope you are interested in. Once all of the alias sets are completed, your pass should simply iterate through the constructed alias sets, using the AliasSetTracker -begin()/end() methods. -

-

-The AliasSets formed by the AliasSetTracker are guaranteed to -be disjoint, calculate mod/ref information for the set, and keep track of +begin()/end() methods.

+ +

The AliasSets formed by the AliasSetTracker are guaranteed +to be disjoint, calculate mod/ref information for the set, and keep track of whether or not all of the pointers in the set are Must aliases. The AliasSetTracker also makes sure that sets are properly folded due to call -instructions, and can provide a list of pointers in each set. -

-

-As an example user of this, the Loop +instructions, and can provide a list of pointers in each set.

+ +

As an example user of this, the Loop Invariant Code Motion pass uses AliasSetTrackers to build alias information about each loop nest. If an AliasSet in a loop is not modified, then all load instructions from that set may be hoisted out of the loop. If any alias sets are stored and are must alias sets, then the stores may be sunk to outside of the loop. Both of these transformations obviously only apply if the -pointer argument is loop-invariant. -

+pointer argument is loop-invariant.

+
@@ -403,12 +391,12 @@ pointer argument is loop-invariant.
-

-As a last resort, your pass could use the AliasAnalysis interface directly to + +

As a last resort, your pass could use the AliasAnalysis interface directly to service your pass. If you find the need to do this, please let me know so I can see if something new -needs to be added to LLVM. -

+needs to be added to LLVM.

+
@@ -418,10 +406,11 @@ needs to be added to LLVM.
-

-If you're going to be working with the AliasAnalysis infrastructure, there are -several nice tools that may be useful for you and are worth knowing about... -

+ +

If you're going to be working with the AliasAnalysis infrastructure, there +are several nice tools that may be useful for you and are worth knowing +about...

+
@@ -430,13 +419,13 @@ several nice tools that may be useful for you and are worth knowing about...
-

-The -no-aa analysis is just like what it sounds: an alias analysis that -never returns any useful information. This pass can be useful if you think that -alias analysis is doing something wrong and are trying to narrow down a problem. -If you don't specify an alias analysis, the default will be to use the -basicaa pass which does quite a bit of disambiguation on its own. -

+ +

The -no-aa analysis is just like what it sounds: an alias analysis +that never returns any useful information. This pass can be useful if you think +that alias analysis is doing something wrong and are trying to narrow down a +problem. If you don't specify an alias analysis, the default will be to use the +basicaa pass which does quite a bit of disambiguation on its own.

+
@@ -446,12 +435,12 @@ If you don't specify an alias analysis, the default will be to use the
-

-The -print-alias-sets pass is exposed as part of the analyze -tool to print out the Alias Sets formed by the The -print-alias-sets pass is exposed as part of the +analyze tool to print out the Alias Sets formed by the AliasSetTracker class. This is useful if you're using -the AliasSetTracker. -

+the AliasSetTracker.

+
@@ -460,22 +449,20 @@ the AliasSetTracker.
-

-The -count-aa pass is useful to see how many queries a particular pass -is making and what kinds of responses are returned by the alias analysis. An -example usage is: -

-

+ +

The -count-aa pass is useful to see how many queries a particular +pass is making and what kinds of responses are returned by the alias analysis. +An example usage is:

+
   $ opt -basicaa -count-aa -ds-aa -count-aa -licm
 
-

-

-Which will print out how many queries (and what responses are returned) by the --licm pass (of the -ds-aa pass) and how many queries are made -of the -basicaa pass by the -ds-aa pass. This can be useful -when evaluating an alias analysis for precision. -

+ +

Which will print out how many queries (and what responses are returned) by +the -licm pass (of the -ds-aa pass) and how many queries are +made of the -basicaa pass by the -ds-aa pass. This can be +useful when evaluating an alias analysis for precision.

+
@@ -484,20 +471,22 @@ when evaluating an alias analysis for precision.
-

-The -aa-eval pass simply iterates through all pairs of pointers in a + +

The -aa-eval pass simply iterates through all pairs of pointers in a function and asks an alias analysis whether or not the pointers alias. This gives an indication of the precision of the alias analysis. Statistics are printed.

+
-
-
Chris Lattner
-Last modified: $Date$ -
+
+