Update how to release document.
[oota-llvm.git] / docs / AliasAnalysis.html
index df85d74371b36c58c647d9ba0be60cd79d7ab843..748b3cb30eb9c958fb426ffeefe6276849153cef 100644 (file)
@@ -2,13 +2,13 @@
                       "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
-  <title>The LLVM Alias Analysis Infrastructure</title>
+  <title>LLVM Alias Analysis Infrastructure</title>
   <link rel="stylesheet" href="llvm.css" type="text/css">
 </head>
 <body>
 
 <div class="doc_title">
-  The LLVM Alias Analysis Infrastructure
+  LLVM Alias Analysis Infrastructure
 </div>
 
 <ol>
@@ -46,7 +46,8 @@
     <ul>
     <li><a href="#impls">Available <tt>AliasAnalysis</tt> implementations</a></li>
     <li><a href="#aliasanalysis-xforms">Alias analysis driven transformations</a></li>
-    <li><a href="#aliasanalysis-debug">Clients for debugging and evaluation of implementations</a></li>
+    <li><a href="#aliasanalysis-debug">Clients for debugging and evaluation of
+    implementations</a></li>
     </ul>
   </li>
 </ol>
@@ -69,12 +70,12 @@ memory.  There are many different algorithms for alias analysis and many
 different ways of classifying them: flow-sensitive vs flow-insensitive,
 context-sensitive vs context-insensitive, field-sensitive vs field-insensitive,
 unification-based vs subset-based, etc.  Traditionally, alias analyses respond
-to a query with a <a href="#MustNoMay">Must, May, or No</a> alias response,
+to a query with a <a href="#MustMayNo">Must, May, or No</a> alias response,
 indicating that two pointers always point to the same object, might point to the
 same object, or are known to never point to the same object.</p>
 
 <p>The LLVM <a
-href="http://llvm.cs.uiuc.edu/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
+href="http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
 class is the primary interface used by clients and implementations of alias
 analyses in the LLVM system.  This class is the common interface between clients
 of alias analysis information and the implementations providing it, and is
@@ -101,7 +102,7 @@ know</a>.</p>
 <div class="doc_text">
 
 <p>The <a
-href="http://llvm.cs.uiuc.edu/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
+href="http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
 class defines the interface that the various alias analysis implementations
 should support.  This class exports two important enums: <tt>AliasResult</tt>
 and <tt>ModRefResult</tt> which represent the result of an alias query or a
@@ -133,16 +134,18 @@ symbolic LLVM <tt>Value*</tt>) and a static size.</p>
 important for correct Alias Analyses.  For example, consider this (silly, but
 possible) C code:</p>
 
+<div class="doc_code">
 <pre>
-  int i;
-  char C[2];
-  char A[10]; 
-  /* ... */
-  for (i = 0; i != 10; ++i) {
-    C[0] = A[i];          /* One byte store */
-    C[1] = A[9-i];        /* One byte store */
-  }
+int i;
+char C[2];
+char A[10]; 
+/* ... */
+for (i = 0; i != 10; ++i) {
+  C[0] = A[i];          /* One byte store */
+  C[1] = A[9-i];        /* One byte store */
+}
 </pre>
+</div>
 
 <p>In this case, the <tt>basicaa</tt> pass will disambiguate the stores to
 <tt>C[0]</tt> and <tt>C[1]</tt> because they are accesses to two distinct
@@ -150,16 +153,18 @@ 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:</p>
 
+<div class="doc_code">
 <pre>
-  int i;
-  char C[2];
-  char A[10]; 
-  /* ... */
-  for (i = 0; i != 10; ++i) {
-    ((short*)C)[0] = A[i];  /* Two byte store! */
-    C[1] = A[9-i];          /* One byte store */
-  }
+int i;
+char C[2];
+char A[10]; 
+/* ... */
+for (i = 0; i != 10; ++i) {
+  ((short*)C)[0] = A[i];  /* Two byte store! */
+  C[1] = A[9-i];          /* One byte store */
+}
 </pre>
+</div>
 
 <p>In this case, the two stores to C do alias each other, because the access to
 the <tt>&amp;C[0]</tt> element is a two byte access.  If size information wasn't
@@ -269,7 +274,6 @@ memory location to be modified.</p>
 
 </div>
 
-
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
   <a name="simplemodref">The <tt>doesNotAccessMemory</tt> and
@@ -299,8 +303,6 @@ functions that satisfy the <tt>doesNotAccessMemory</tt> method also satisfies
 
 </div>
 
-
-
 <!-- *********************************************************************** -->
 <div class="doc_section">
   <a name="writingnew">Writing a new <tt>AliasAnalysis</tt> Implementation</a>
@@ -360,25 +362,29 @@ the <tt>AliasAnalysis</tt> base class: <tt>getAnalysisUsage</tt> and
 declaring any pass dependencies your pass has.  Thus you should have something
 like this:</p>
 
+<div class="doc_code">
 <pre>
-    void getAnalysisUsage(AnalysisUsage &amp;AU) const {
-      AliasAnalysis::getAnalysisUsage(AU);
-      <i>// declare your dependencies here.</i>
-    }
+void getAnalysisUsage(AnalysisUsage &amp;AU) const {
+  AliasAnalysis::getAnalysisUsage(AU);
+  <i>// declare your dependencies here.</i>
+}
 </pre>
+</div>
 
 <p>Additionally, your must invoke the <tt>InitializeAliasAnalysis</tt> method
 from your analysis run method (<tt>run</tt> for a <tt>Pass</tt>,
 <tt>runOnFunction</tt> for a <tt>FunctionPass</tt>, or <tt>InitializePass</tt>
 for an <tt>ImmutablePass</tt>).  For example (as part of a <tt>Pass</tt>):</p>
 
+<div class="doc_code">
 <pre>
-    bool run(Module &amp;M) {
-      InitializeAliasAnalysis(this);
-      <i>// Perform analysis here...</i>
-      return false;
-    }
+bool run(Module &amp;M) {
+  InitializeAliasAnalysis(this);
+  <i>// Perform analysis here...</i>
+  return false;
+}
 </pre>
+</div>
 
 </div>
 
@@ -418,17 +424,19 @@ for methods that you don't override.  For methods that you do override, in code
 paths that return a conservative MayAlias or Mod/Ref result, simply return
 whatever the superclass computes.  For example:</p>
 
+<div class="doc_code">
 <pre>
-  AliasAnalysis::AliasResult alias(const Value *V1, unsigned V1Size,
-                                   const Value *V2, unsigned V2Size) {
-    if (...)
-      return NoAlias;
-    ...
-
-    <i>// Couldn't determine a must or no-alias result.</i>
-    return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
-  }
+AliasAnalysis::AliasResult alias(const Value *V1, unsigned V1Size,
+                                 const Value *V2, unsigned V2Size) {
+  if (...)
+    return NoAlias;
+  ...
+
+  <i>// Couldn't determine a must or no-alias result.</i>
+  return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
+}
 </pre>
+</div>
 
 <p>In addition to analysis queries, you must make sure to unconditionally pass
 LLVM <a href="#updating">update notification</a> methods to the superclass as
@@ -472,7 +480,6 @@ for each value in the program.  When this method is called, they should remove
 any entries for the specified value, if they exist.
 </div>
 
-
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">The <tt>copyValue</tt> method</div>
 
@@ -484,7 +491,6 @@ this is the only way to introduce a new value.  This method indicates that the
 new value has exactly the same properties as the value being copied.
 </div>
 
-
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">The <tt>replaceWithNewValue</tt> method</div>
 
@@ -548,8 +554,8 @@ just use the <tt>load-vn</tt> pass, which uses alias analysis.</p>
 
 <p>Many transformations need information about alias <b>sets</b> that are active
 in some scope, rather than information about pairwise aliasing.  The <tt><a
-href="/doxygen/classllvm_1_1AliasSetTracker.html">AliasSetTracker</a></tt> class is used
-to efficiently build these Alias Sets from the pairwise alias analysis
+href="/doxygen/classllvm_1_1AliasSetTracker.html">AliasSetTracker</a></tt> class
+is used to efficiently build these Alias Sets from the pairwise alias analysis
 information provided by the <tt>AliasAnalysis</tt> interface.</p>
 
 <p>First you initialize the AliasSetTracker by using the "<tt>add</tt>" methods
@@ -601,7 +607,6 @@ are.</p>
 
 </div>
 
-
 <!-- ======================================================================= -->
 <div class="doc_subsection">
   <a name="direct">Using the <tt>AliasAnalysis</tt> interface directly</a>
@@ -643,7 +648,7 @@ for monitoring and evaluating different implementations.</p>
 <p>This section lists the various implementations of the <tt>AliasAnalysis</tt>
 interface.  With the exception of the <a href="#no-aa"><tt>-no-aa</tt></a> and
 <a href="#basic-aa"><tt>-basicaa</tt></a> implementations, all of these <a
-href="chaining">chain</a> to other alias analysis implementations.</p>
+href="#chaining">chain</a> to other alias analysis implementations.</p>
 
 </div>
 
@@ -661,7 +666,6 @@ problem.</p>
 
 </div>
 
-
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
   <a name="basic-aa">The <tt>-basicaa</tt> pass</a>
@@ -690,6 +694,29 @@ aggressive local analysis that "knows" many important facts:</p>
 
 </div>
 
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="globalsmodref">The <tt>-globalsmodref-aa</tt> pass</a>
+</div>
+
+<div class="doc_text">
+
+<p>This pass implements a simple context-sensitive mod/ref and alias analysis
+for internal global variables that don't "have their address taken".  If a
+global does not have its address taken, the pass knows that no pointers alias
+the global.  This pass also keeps track of functions that it knows never access
+memory or never read memory.  This allows certain optimizations (e.g. GCSE) to
+eliminate call instructions entirely.
+</p>
+
+<p>The real power of this pass is that it provides context-sensitive mod/ref 
+information for call instructions.  This allows the optimizer to know that 
+calls to a function do not clobber or read the value of the global, allowing 
+loads and stores to be eliminated.</p>
+
+<p>Note that this pass is somewhat limited in its scope (only support 
+non-address taken globals), but is very quick analysis.</p>
+</div>
 
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
@@ -728,6 +755,9 @@ field-<b>sensitive</b>" version of Steensgaard's algorithm using the Data
 Structure Analysis framework.  This gives it substantially more precision than
 the standard algorithm while maintaining excellent analysis scalability.</p>
 
+<p>Note that <tt>-steens-aa</tt> is available in the optional "poolalloc"
+module, it is not part of the LLVM core.</p>
+
 </div>
 
 <!-- _______________________________________________________________________ -->
@@ -748,6 +778,9 @@ queries, and can provide context-sensitive mod/ref information as well.  The
 only major facility not implemented so far is support for must-alias
 information.</p>
 
+<p>Note that <tt>-ds-aa</tt> is available in the optional "poolalloc"
+module, it is not part of the LLVM core.</p>
+
 </div>
 
 
@@ -821,8 +854,8 @@ pointer.</p>
 </div>
 
 <div class="doc_text">
-<p>
-The <tt>-load-vn</tt> pass uses alias analysis to "<a href="#loadvn">value
+
+<p>The <tt>-load-vn</tt> pass uses alias analysis to "<a href="#loadvn">value
 number</a>" loads and pointers values, which is used by the GCSE pass to
 eliminate instructions.  The <tt>-load-vn</tt> pass relies on alias information
 and must-alias information.  This combination of passes can make the following
@@ -840,18 +873,19 @@ calls into direct calls.</li>
 
 </div>
 
-
-
-
 <!-- ======================================================================= -->
 <div class="doc_subsection">
-  <a name="aliasanalysis-debug">Clients for debugging and evaluation of implementations</a>
+  <a name="aliasanalysis-debug">Clients for debugging and evaluation of
+  implementations</a>
 </div>
 
-These passes are useful for evaluating the various alias analysis
+<div class="doc_text">
+
+<p>These passes are useful for evaluating the various alias analysis
 implementations.  You can use them with commands like '<tt>opt -anders-aa -ds-aa
--aa-eval foo.bc -disable-output -stats</tt>'.
+-aa-eval foo.bc -disable-output -stats</tt>'.</p>
 
+</div>
 
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
@@ -861,9 +895,15 @@ implementations.  You can use them with commands like '<tt>opt -anders-aa -ds-aa
 <div class="doc_text">
 
 <p>The <tt>-print-alias-sets</tt> pass is exposed as part of the
-<tt>analyze</tt> tool to print out the Alias Sets formed by the <a
+<tt>opt</tt> tool to print out the Alias Sets formed by the <a
 href="#ast"><tt>AliasSetTracker</tt></a> class.  This is useful if you're using
-the <tt>AliasSetTracker</tt> class.</p>
+the <tt>AliasSetTracker</tt> class.  To use it, use something like:</p>
+
+<div class="doc_code">
+<pre>
+% opt -ds-aa -print-alias-sets -disable-output
+</pre>
+</div>
 
 </div>
 
@@ -876,17 +916,19 @@ the <tt>AliasSetTracker</tt> class.</p>
 <div class="doc_text">
 
 <p>The <tt>-count-aa</tt> pass is useful to see how many queries a particular
-pass is making and what responses are returned by the alias analysis.  An
-example usage is:</p>
+pass is making and what responses are returned by the alias analysis.  As an
+example,</p>
 
+<div class="doc_code">
 <pre>
-  $ opt -basicaa -count-aa -ds-aa -count-aa -licm
+% opt -basicaa -count-aa -ds-aa -count-aa -licm
 </pre>
+</div>
 
-<p>Which will print out how many queries (and what responses are returned) by
-the <tt>-licm</tt> pass (of the <tt>-ds-aa</tt> pass) and how many queries are
-made of the <tt>-basicaa</tt> pass by the <tt>-ds-aa</tt> pass.  This can be
-useful when debugging a transformation or an alias analysis implementation.</p>
+<p>will print out how many queries (and what responses are returned) by the
+<tt>-licm</tt> pass (of the <tt>-ds-aa</tt> pass) and how many queries are made
+of the <tt>-basicaa</tt> pass by the <tt>-ds-aa</tt> pass.  This can be useful
+when debugging a transformation or an alias analysis implementation.</p>
 
 </div>
 
@@ -915,7 +957,7 @@ algorithm will have a lower number of may aliases).</p>
   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
 
   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
-  <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
+  <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
   Last modified: $Date$
 </address>