2003-10-24 20:06:11 +02:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
2003-10-23 01:27:16 +02:00
|
|
|
<html>
|
|
|
|
<head>
|
2003-10-24 20:06:11 +02:00
|
|
|
<link rel="stylesheet" href="llvm.css" type="text/css">
|
2003-10-23 01:27:16 +02:00
|
|
|
<title>Alias Analysis Infrastructure in LLVM</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_title">
|
|
|
|
Alias Analysis Infrastructure in LLVM
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<ol>
|
2003-10-23 04:29:42 +02:00
|
|
|
<li><a href="#introduction">Introduction</a></li>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-24 20:06:11 +02:00
|
|
|
<li><a href="#overview">AliasAnalysis Overview</a>
|
2003-03-04 20:37:49 +01:00
|
|
|
<ul>
|
2003-10-23 04:29:42 +02:00
|
|
|
<li><a href="#pointers">Representation of Pointers</a></li>
|
|
|
|
<li><a href="#MustMayNo">Must, May, and No Alias Responses</a></li>
|
|
|
|
<li><a href="#ModRefInfo">The <tt>getModRefInfo</tt> methods</a></li>
|
2003-10-24 20:06:11 +02:00
|
|
|
</ul></li>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-24 20:06:11 +02:00
|
|
|
<li><a href="#writingnew">Writing a new AliasAnalysis Implementation</a>
|
2003-03-04 20:37:49 +01:00
|
|
|
<ul>
|
2003-10-23 04:29:42 +02:00
|
|
|
<li><a href="#passsubclasses">Different Pass styles</a></li>
|
|
|
|
<li><a href="#requiredcalls">Required initialization calls</a></li>
|
|
|
|
<li><a href="#interfaces">Interfaces which may be specified</a></li>
|
|
|
|
<li><a href="#chaining">The AliasAnalysis chaining behavior</a></li>
|
|
|
|
<li><a href="#implefficiency">Efficiency Issues</a></li>
|
2003-10-24 20:06:11 +02:00
|
|
|
</ul></li>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-24 20:06:11 +02:00
|
|
|
<li><a href="#using">Using AliasAnalysis results</a>
|
2003-03-04 20:37:49 +01:00
|
|
|
<ul>
|
2003-10-23 04:29:42 +02:00
|
|
|
<li><a href="#loadvn">Using the <tt>-load-vn</tt> Pass</a></li>
|
|
|
|
<li><a href="#ast">Using the <tt>AliasSetTracker</tt> class</a></li>
|
|
|
|
<li><a href="#direct">Using the AliasAnalysis interface directly</a></li>
|
2003-10-24 20:06:11 +02:00
|
|
|
</ul></li>
|
|
|
|
|
|
|
|
<li><a href="#tools">Helpful alias analysis related tools</a>
|
2003-03-04 20:37:49 +01:00
|
|
|
<ul>
|
2003-10-23 04:29:42 +02:00
|
|
|
<li><a href="#no-aa">The <tt>-no-aa</tt> pass</a></li>
|
|
|
|
<li><a href="#print-alias-sets">The <tt>-print-alias-sets</tt> pass</a></li>
|
|
|
|
<li><a href="#count-aa">The <tt>-count-aa</tt> pass</a></li>
|
|
|
|
<li><a href="#aa-eval">The <tt>-aa-eval</tt> pass</a></li>
|
2003-10-24 20:06:11 +02:00
|
|
|
</ul></li>
|
2003-10-23 04:29:42 +02:00
|
|
|
</ol>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-24 20:06:11 +02:00
|
|
|
<div class="doc_text">
|
|
|
|
<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></b></p>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_section">
|
|
|
|
<a name="introduction">Introduction</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-11-21 23:30:25 +01:00
|
|
|
|
|
|
|
<p>Alias Analysis (or Pointer Analysis) is a technique which attempts to
|
|
|
|
determine whether or not two pointers ever can point to the same object in
|
|
|
|
memory. Traditionally, Alias Analyses respond to a query with either a <a
|
2003-03-04 20:37:49 +01:00
|
|
|
href="#MustNoMay">Must, May, or No</a> alias response, indicating that two
|
|
|
|
pointers do point to the same object, might point to the same object, or are
|
2003-11-21 23:30:25 +01:00
|
|
|
known not to point to the same object.</p>
|
|
|
|
|
2003-12-18 00:10:49 +01:00
|
|
|
<p>The <a href="/doxygen/classllvm_1_1AliasAnalysis.html">AliasAnalysis</a> class is the
|
2003-03-04 20:37:49 +01:00
|
|
|
centerpiece of the LLVM Alias Analysis related infrastructure. This class is
|
|
|
|
the common interface between clients of alias analysis information and the
|
|
|
|
implementations providing it. In addition to simple alias analysis information,
|
|
|
|
this class exposes Mod/Ref information from those implementations which can
|
|
|
|
provide it, allowing for powerful analyses and transformations to work well
|
2003-11-21 23:30:25 +01:00
|
|
|
together.</p>
|
|
|
|
|
|
|
|
<p>This document contains information necessary to successfully implement this
|
2003-03-04 20:37:49 +01:00
|
|
|
interface, use it, and to test both sides. It also explains some of the finer
|
|
|
|
points about what exactly results mean. If you feel that something is unclear
|
2003-10-23 01:27:16 +02:00
|
|
|
or should be added, please <a href="mailto:sabre@nondot.org">let me
|
2003-11-21 23:30:25 +01:00
|
|
|
know</a>.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_section">
|
|
|
|
<a name="overview">AliasAnalysis Overview</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-11-21 23:30:25 +01:00
|
|
|
|
2003-12-18 00:10:49 +01:00
|
|
|
<p>The <a href="/doxygen/classllvm_1_1AliasAnalysis.html">AliasAnalysis</a> class
|
2003-11-21 23:30:25 +01:00
|
|
|
defines the interface that 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 mod/ref
|
|
|
|
query, respectively.</p>
|
|
|
|
|
|
|
|
<p>The AliasAnalysis interface exposes information about memory, represented in
|
2003-03-04 20:37:49 +01:00
|
|
|
several different ways. In particular, memory objects are represented as a
|
|
|
|
starting address and size, and function calls are represented as the actual
|
|
|
|
<tt>call</tt> or <tt>invoke</tt> instructions that performs the call. The
|
|
|
|
AliasAnalysis interface also exposes some helper methods which allow you to get
|
2003-11-21 23:30:25 +01:00
|
|
|
mod/ref information for arbitrary instructions.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="pointers">Representation of Pointers</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>Most importantly, the AliasAnalysis class provides several methods which are
|
2003-03-04 20:37:49 +01:00
|
|
|
used to query whether or not pointers alias, whether function calls can modify
|
2003-10-24 20:06:11 +02:00
|
|
|
or read memory, etc.</p>
|
|
|
|
|
|
|
|
<p>Representing memory objects as a starting address and a size is critically
|
2003-03-04 20:37:49 +01:00
|
|
|
important for precise Alias Analyses. For example, consider this (silly) C
|
2003-10-24 20:06:11 +02:00
|
|
|
code:</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<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 */
|
|
|
|
}
|
|
|
|
</pre>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>In this case, the <tt>basicaa</tt> pass will disambiguate the stores to
|
2003-03-04 20:37:49 +01:00
|
|
|
<tt>C[0]</tt> and <tt>C[1]</tt> 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
|
2003-10-24 20:06:11 +02:00
|
|
|
constrast, the following code:</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<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 */
|
|
|
|
}
|
|
|
|
</pre>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>In this case, the two stores to C do alias each other, because the access to
|
|
|
|
the <tt>&C[0]</tt> element is a two byte access. If size information wasn't
|
2003-03-04 20:37:49 +01:00
|
|
|
available in the query, even the first case would have to conservatively assume
|
2003-10-24 20:06:11 +02:00
|
|
|
that the accesses alias.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="MustMayNo">Must, May, and No Alias Responses</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>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.</p>
|
|
|
|
|
|
|
|
<p>The Must Alias response is trickier though. In LLVM, the Must Alias response
|
2003-03-04 20:37:49 +01:00
|
|
|
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
|
2003-10-24 20:06:11 +02:00
|
|
|
the same location, MayAlias must be returned.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="ModRefInfo">The <tt>getModRefInfo</tt> methods</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The <tt>getModRefInfo</tt> methods return information about whether the
|
2003-03-04 20:37:49 +01:00
|
|
|
execution of an instruction can read or modify a memory location. Mod/Ref
|
|
|
|
information is always conservative: if an action <b>may</b> read a location, Ref
|
2003-10-24 20:06:11 +02:00
|
|
|
is returned.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_section">
|
|
|
|
<a name="writingnew">Writing a new AliasAnalysis Implementation</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>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 <a
|
2003-12-17 19:46:49 +01:00
|
|
|
href="/doxygen/structllvm_1_1NoAA.html"><tt>no-aa</tt></a> implementation.</p>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="passsubclasses">Different Pass styles</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The first step to determining what type of <a
|
|
|
|
href="WritingAnLLVMPass.html">LLVM pass</a> 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:</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<ol>
|
2003-10-23 01:27:16 +02:00
|
|
|
<li>If you require interprocedural analysis, it should be a
|
|
|
|
<tt>Pass</tt>.</li>
|
|
|
|
<li>If you are a global analysis, subclass <tt>FunctionPass</tt>.</li>
|
|
|
|
<li>If you are a local pass, subclass <tt>BasicBlockPass</tt>.</li>
|
|
|
|
<li>If you don't need to look at the program at all, subclass
|
|
|
|
<tt>ImmutablePass</tt>.</li>
|
|
|
|
</ol>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>In addition to the pass that you subclass, you should also inherit from the
|
2003-05-07 23:47:16 +02:00
|
|
|
<tt>AliasAnalysis</tt> interface, of course, and use the
|
2003-03-04 20:37:49 +01:00
|
|
|
<tt>RegisterAnalysisGroup</tt> template to register as an implementation of
|
2003-10-24 20:06:11 +02:00
|
|
|
<tt>AliasAnalysis</tt>.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="requiredcalls">Required initialization calls</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>Your subclass of AliasAnalysis is required to invoke two methods on the
|
2003-03-04 20:37:49 +01:00
|
|
|
AliasAnalysis base class: <tt>getAnalysisUsage</tt> and
|
|
|
|
<tt>InitializeAliasAnalysis</tt>. In particular, your implementation of
|
|
|
|
<tt>getAnalysisUsage</tt> should explicitly call into the
|
|
|
|
<tt>AliasAnalysis::getAnalysisUsage</tt> method in addition to doing any
|
|
|
|
declaring any pass dependencies your pass has. Thus you should have something
|
2003-10-24 20:06:11 +02:00
|
|
|
like this:</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<pre>
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AliasAnalysis::getAnalysisUsage(AU);
|
|
|
|
<i>// declare your dependencies here.</i>
|
|
|
|
}
|
|
|
|
</pre>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>Additionally, your must invoke the <tt>InitializeAliasAnalysis</tt> method
|
|
|
|
from your analysis run method (<tt>run</tt> for a <tt>Pass</tt>,
|
2003-03-04 20:37:49 +01:00
|
|
|
<tt>runOnFunction</tt> for a <tt>FunctionPass</tt>, <tt>runOnBasicBlock</tt> for
|
|
|
|
a <tt>BasicBlockPass</tt>, or <tt>InitializeAliasAnalysis</tt> for an
|
2003-10-24 20:06:11 +02:00
|
|
|
<tt>ImmutablePass</tt>). For example (as part of a <tt>Pass</tt>):</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<pre>
|
|
|
|
bool run(Module &M) {
|
|
|
|
InitializeAliasAnalysis(this);
|
|
|
|
<i>// Perform analysis here...</i>
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
</pre>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="interfaces">Interfaces which may be specified</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
2003-12-18 00:10:49 +01:00
|
|
|
<p>All of the <a href="/doxygen/classllvm_1_1AliasAnalysis.html">AliasAnalysis</a>
|
2003-10-24 20:06:11 +02:00
|
|
|
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.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="chaining">The AliasAnalysis chaining behavior</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>With only two special exceptions (the <tt>basicaa</tt> and <a
|
2003-03-04 20:37:49 +01:00
|
|
|
href="#no-aa"><tt>no-aa</tt></a> passes) every alias analysis pass should chain
|
|
|
|
to another alias analysis implementation (for example, you could specify
|
|
|
|
"<tt>-basic-aa -ds-aa -andersens-aa -licm</tt>" to get the maximum benefit from
|
|
|
|
the three alias analyses). To do this, simply "Require" AliasAnalysis in your
|
|
|
|
<tt>getAnalysisUsage</tt> method, and if you need to return a conservative
|
2003-10-24 20:06:11 +02:00
|
|
|
MayAlias or Mod/Ref result, simply chain to a lower analysis.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="implefficiency">Efficiency Issues</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>From the LLVM perspective, the only thing you need to do to provide an
|
|
|
|
efficient alias analysis is to make sure that alias analysis <b>queries</b> 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).</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_section">
|
|
|
|
<a name="using">Using AliasAnalysis results</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>There are several different ways to use alias analysis results. In order of
|
|
|
|
preference, these are...</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="loadvn">Using the <tt>-load-vn</tt> Pass</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The <tt>load-vn</tt> pass uses alias analysis to provide value numbering
|
2003-03-04 20:37:49 +01:00
|
|
|
information for <tt>load</tt> 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
|
2003-10-24 20:06:11 +02:00
|
|
|
<tt>load-vn</tt> pass, which uses alias analysis.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="ast">Using the <tt>AliasSetTracker</tt> class</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<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
|
2003-12-18 00:10:49 +01:00
|
|
|
href="/doxygen/classllvm_1_1AliasSetTracker.html">AliasSetTracker</a></tt> class is used
|
2003-03-04 20:37:49 +01:00
|
|
|
to efficiently build these Alias Sets from the pairwise alias analysis
|
2003-10-24 20:06:11 +02:00
|
|
|
information provided by the AliasAnalysis interface.</p>
|
|
|
|
|
|
|
|
<p>First you initialize the AliasSetTracker by use the "<tt>add</tt>" methods to
|
2003-03-04 20:37:49 +01:00
|
|
|
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
|
2003-10-24 20:06:11 +02:00
|
|
|
<tt>begin()</tt>/<tt>end()</tt> methods.</p>
|
|
|
|
|
|
|
|
<p>The <tt>AliasSet</tt>s formed by the <tt>AliasSetTracker</tt> are guaranteed
|
|
|
|
to be disjoint, calculate mod/ref information for the set, and keep track of
|
2003-03-04 20:37:49 +01:00
|
|
|
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
|
2003-10-24 20:06:11 +02:00
|
|
|
instructions, and can provide a list of pointers in each set.</p>
|
|
|
|
|
|
|
|
<p>As an example user of this, the <a href="/doxygen/structLICM.html">Loop
|
2003-03-04 20:37:49 +01:00
|
|
|
Invariant Code Motion</a> 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 <b>and</b> are must alias sets, then the stores may be sunk to
|
|
|
|
outside of the loop. Both of these transformations obviously only apply if the
|
2003-10-24 20:06:11 +02:00
|
|
|
pointer argument is loop-invariant.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="direct">Using the AliasAnalysis interface directly</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>As a last resort, your pass could use the AliasAnalysis interface directly to
|
2003-03-04 20:37:49 +01:00
|
|
|
service your pass. If you find the need to do this, please <a
|
|
|
|
href="mailto:sabre@nondot.org">let me know</a> so I can see if something new
|
2003-10-24 20:06:11 +02:00
|
|
|
needs to be added to LLVM.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_section">
|
|
|
|
<a name="tools">Helpful alias-analysis-related tools</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>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...</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="no-aa">The <tt>-no-aa</tt> pass</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The <tt>-no-aa</tt> 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
|
|
|
|
<tt>basicaa</tt> pass which does quite a bit of disambiguation on its own.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="print-alias-sets">The <tt>-print-alias-sets</tt> pass</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<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
|
2003-03-04 20:37:49 +01:00
|
|
|
href="#ast"><tt>AliasSetTracker</tt></a> class. This is useful if you're using
|
2003-10-24 20:06:11 +02:00
|
|
|
the <tt>AliasSetTracker</tt>.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="count-aa">The <tt>-count-aa</tt> pass</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The <tt>-count-aa</tt> 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:</p>
|
|
|
|
|
2003-03-04 20:37:49 +01:00
|
|
|
<pre>
|
|
|
|
$ opt -basicaa -count-aa -ds-aa -count-aa -licm
|
|
|
|
</pre>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<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 evaluating an alias analysis for precision.</p>
|
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- ======================================================================= -->
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_subsection">
|
|
|
|
<a name="aa-eval">The <tt>-aa-eval</tt> pass</a>
|
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
<div class="doc_text">
|
2003-10-24 20:06:11 +02:00
|
|
|
|
|
|
|
<p>The <tt>-aa-eval</tt> pass simply iterates through all pairs of pointers in a
|
2003-03-04 20:37:49 +01:00
|
|
|
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
|
2003-11-22 02:07:30 +01:00
|
|
|
printed.</p>
|
2003-10-24 20:06:11 +02:00
|
|
|
|
2003-10-23 01:27:16 +02:00
|
|
|
</div>
|
2003-03-04 20:37:49 +01:00
|
|
|
|
|
|
|
<!-- *********************************************************************** -->
|
|
|
|
|
2003-10-24 20:06:11 +02:00
|
|
|
<hr>
|
2003-11-22 02:26:21 +01:00
|
|
|
<address>
|
|
|
|
<a href="http://jigsaw.w3.org/css-validator/"><img
|
2003-11-22 02:07:30 +01:00
|
|
|
src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
|
2003-11-22 02:26:21 +01:00
|
|
|
<a href="http://validator.w3.org/check/referer"><img
|
|
|
|
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">The LLVM Compiler Infrastructure</a><br>
|
|
|
|
Last modified: $Date$
|
|
|
|
</address>
|
2003-10-23 01:27:16 +02:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|