blob: ebf638689824b25d14329364439194cbf497e15f [file] [log] [blame]
Misha Brukman084a3a072003-10-24 18:06:11 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman283ff692003-10-22 23:27:16 +00003<html>
4<head>
Misha Brukman3eef5d42004-07-01 15:33:24 +00005 <title>LLVM Alias Analysis Infrastructure</title>
Misha Brukmanc6ef5592004-01-15 19:04:12 +00006 <link rel="stylesheet" href="llvm.css" type="text/css">
Misha Brukman283ff692003-10-22 23:27:16 +00007</head>
Misha Brukman283ff692003-10-22 23:27:16 +00008<body>
Chris Lattnerb512e9f2003-03-04 19:37:49 +00009
Misha Brukman283ff692003-10-22 23:27:16 +000010<div class="doc_title">
Misha Brukman3eef5d42004-07-01 15:33:24 +000011 LLVM Alias Analysis Infrastructure
Misha Brukman283ff692003-10-22 23:27:16 +000012</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000013
14<ol>
Misha Brukman9782b032003-10-23 02:29:42 +000015 <li><a href="#introduction">Introduction</a></li>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000016
Chris Lattner2a19d832004-05-23 21:04:01 +000017 <li><a href="#overview"><tt>AliasAnalysis</tt> Class Overview</a>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000018 <ul>
Misha Brukman9782b032003-10-23 02:29:42 +000019 <li><a href="#pointers">Representation of Pointers</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000020 <li><a href="#alias">The <tt>alias</tt> method</a></li>
Misha Brukman9782b032003-10-23 02:29:42 +000021 <li><a href="#ModRefInfo">The <tt>getModRefInfo</tt> methods</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000022 <li><a href="#OtherItfs">Other useful <tt>AliasAnalysis</tt> methods</a></li>
23 </ul>
24 </li>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000025
Chris Lattner2a19d832004-05-23 21:04:01 +000026 <li><a href="#writingnew">Writing a new <tt>AliasAnalysis</tt> Implementation</a>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000027 <ul>
Misha Brukman9782b032003-10-23 02:29:42 +000028 <li><a href="#passsubclasses">Different Pass styles</a></li>
29 <li><a href="#requiredcalls">Required initialization calls</a></li>
30 <li><a href="#interfaces">Interfaces which may be specified</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000031 <li><a href="#chaining"><tt>AliasAnalysis</tt> chaining behavior</a></li>
32 <li><a href="#updating">Updating analysis results for transformations</a></li>
Misha Brukman9782b032003-10-23 02:29:42 +000033 <li><a href="#implefficiency">Efficiency Issues</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000034 </ul>
35 </li>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000036
Chris Lattner2a19d832004-05-23 21:04:01 +000037 <li><a href="#using">Using alias analysis results</a>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000038 <ul>
Chris Lattner6a6d3cc2009-04-25 21:11:37 +000039 <li><a href="#memdep">Using the <tt>MemoryDependenceAnalysis</tt> Pass</a></li>
Misha Brukman9782b032003-10-23 02:29:42 +000040 <li><a href="#ast">Using the <tt>AliasSetTracker</tt> class</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000041 <li><a href="#direct">Using the <tt>AliasAnalysis</tt> interface directly</a></li>
42 </ul>
43 </li>
Misha Brukman084a3a072003-10-24 18:06:11 +000044
Chris Lattner2a19d832004-05-23 21:04:01 +000045 <li><a href="#exist">Existing alias analysis implementations and clients</a>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000046 <ul>
Chris Lattner2a19d832004-05-23 21:04:01 +000047 <li><a href="#impls">Available <tt>AliasAnalysis</tt> implementations</a></li>
48 <li><a href="#aliasanalysis-xforms">Alias analysis driven transformations</a></li>
Misha Brukman3eef5d42004-07-01 15:33:24 +000049 <li><a href="#aliasanalysis-debug">Clients for debugging and evaluation of
50 implementations</a></li>
Chris Lattner2a19d832004-05-23 21:04:01 +000051 </ul>
52 </li>
Owen Anderson88847732007-10-02 00:44:20 +000053 <li><a href="#memdep">Memory Dependence Analysis</a></li>
Misha Brukman9782b032003-10-23 02:29:42 +000054</ol>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000055
Chris Lattner2a19d832004-05-23 21:04:01 +000056<div class="doc_author">
57 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p>
Misha Brukman084a3a072003-10-24 18:06:11 +000058</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000059
Chris Lattnerb512e9f2003-03-04 19:37:49 +000060<!-- *********************************************************************** -->
Misha Brukman283ff692003-10-22 23:27:16 +000061<div class="doc_section">
62 <a name="introduction">Introduction</a>
63</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000064<!-- *********************************************************************** -->
65
Misha Brukman283ff692003-10-22 23:27:16 +000066<div class="doc_text">
Misha Brukmanbc2d3302003-11-21 22:30:25 +000067
Chris Lattner2a19d832004-05-23 21:04:01 +000068<p>Alias Analysis (aka Pointer Analysis) is a class of techniques which attempt
69to determine whether or not two pointers ever can point to the same object in
70memory. There are many different algorithms for alias analysis and many
71different ways of classifying them: flow-sensitive vs flow-insensitive,
72context-sensitive vs context-insensitive, field-sensitive vs field-insensitive,
73unification-based vs subset-based, etc. Traditionally, alias analyses respond
Duncan Sands16f122e2007-03-30 12:22:09 +000074to a query with a <a href="#MustMayNo">Must, May, or No</a> alias response,
Chris Lattner2a19d832004-05-23 21:04:01 +000075indicating that two pointers always point to the same object, might point to the
76same object, or are known to never point to the same object.</p>
Misha Brukmanbc2d3302003-11-21 22:30:25 +000077
Chris Lattner2a19d832004-05-23 21:04:01 +000078<p>The LLVM <a
Reid Spencerca058542006-03-14 05:39:39 +000079href="http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
Chris Lattner2a19d832004-05-23 21:04:01 +000080class is the primary interface used by clients and implementations of alias
81analyses in the LLVM system. This class is the common interface between clients
82of alias analysis information and the implementations providing it, and is
83designed to support a wide range of implementations and clients (but currently
84all clients are assumed to be flow-insensitive). In addition to simple alias
85analysis information, this class exposes Mod/Ref information from those
86implementations which can provide it, allowing for powerful analyses and
87transformations to work well together.</p>
Misha Brukmanbc2d3302003-11-21 22:30:25 +000088
89<p>This document contains information necessary to successfully implement this
Chris Lattnerb512e9f2003-03-04 19:37:49 +000090interface, use it, and to test both sides. It also explains some of the finer
91points about what exactly results mean. If you feel that something is unclear
Misha Brukman283ff692003-10-22 23:27:16 +000092or should be added, please <a href="mailto:sabre@nondot.org">let me
Misha Brukmanbc2d3302003-11-21 22:30:25 +000093know</a>.</p>
94
Misha Brukman283ff692003-10-22 23:27:16 +000095</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +000096
97<!-- *********************************************************************** -->
Misha Brukman283ff692003-10-22 23:27:16 +000098<div class="doc_section">
Chris Lattner2a19d832004-05-23 21:04:01 +000099 <a name="overview"><tt>AliasAnalysis</tt> Class Overview</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000100</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000101<!-- *********************************************************************** -->
102
Misha Brukman283ff692003-10-22 23:27:16 +0000103<div class="doc_text">
Misha Brukmanbc2d3302003-11-21 22:30:25 +0000104
Chris Lattner2a19d832004-05-23 21:04:01 +0000105<p>The <a
Reid Spencerca058542006-03-14 05:39:39 +0000106href="http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
Chris Lattner2a19d832004-05-23 21:04:01 +0000107class defines the interface that the various alias analysis implementations
108should support. This class exports two important enums: <tt>AliasResult</tt>
109and <tt>ModRefResult</tt> which represent the result of an alias query or a
110mod/ref query, respectively.</p>
Misha Brukmanbc2d3302003-11-21 22:30:25 +0000111
Chris Lattner2a19d832004-05-23 21:04:01 +0000112<p>The <tt>AliasAnalysis</tt> interface exposes information about memory,
113represented in several different ways. In particular, memory objects are
114represented as a starting address and size, and function calls are represented
115as the actual <tt>call</tt> or <tt>invoke</tt> instructions that performs the
116call. The <tt>AliasAnalysis</tt> interface also exposes some helper methods
117which allow you to get mod/ref information for arbitrary instructions.</p>
Misha Brukmanbc2d3302003-11-21 22:30:25 +0000118
Misha Brukman283ff692003-10-22 23:27:16 +0000119</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000120
121<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000122<div class="doc_subsection">
123 <a name="pointers">Representation of Pointers</a>
124</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000125
Misha Brukman283ff692003-10-22 23:27:16 +0000126<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000127
Chris Lattner2a19d832004-05-23 21:04:01 +0000128<p>Most importantly, the <tt>AliasAnalysis</tt> class provides several methods
129which are used to query whether or not two memory objects alias, whether
130function calls can modify or read a memory object, etc. For all of these
131queries, memory objects are represented as a pair of their starting address (a
132symbolic LLVM <tt>Value*</tt>) and a static size.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000133
134<p>Representing memory objects as a starting address and a size is critically
Chris Lattner2a19d832004-05-23 21:04:01 +0000135important for correct Alias Analyses. For example, consider this (silly, but
136possible) C code:</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000137
Misha Brukman2361fcf2004-07-28 22:18:33 +0000138<div class="doc_code">
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000139<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000140int i;
141char C[2];
142char A[10];
143/* ... */
144for (i = 0; i != 10; ++i) {
145 C[0] = A[i]; /* One byte store */
146 C[1] = A[9-i]; /* One byte store */
147}
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000148</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000149</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000150
151<p>In this case, the <tt>basicaa</tt> pass will disambiguate the stores to
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000152<tt>C[0]</tt> and <tt>C[1]</tt> because they are accesses to two distinct
153locations one byte apart, and the accesses are each one byte. In this case, the
154LICM pass can use store motion to remove the stores from the loop. In
Misha Brukman084a3a072003-10-24 18:06:11 +0000155constrast, the following code:</p>
156
Misha Brukman2361fcf2004-07-28 22:18:33 +0000157<div class="doc_code">
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000158<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000159int i;
160char C[2];
161char A[10];
162/* ... */
163for (i = 0; i != 10; ++i) {
164 ((short*)C)[0] = A[i]; /* Two byte store! */
165 C[1] = A[9-i]; /* One byte store */
166}
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000167</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000168</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000169
170<p>In this case, the two stores to C do alias each other, because the access to
171the <tt>&amp;C[0]</tt> element is a two byte access. If size information wasn't
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000172available in the query, even the first case would have to conservatively assume
Misha Brukman084a3a072003-10-24 18:06:11 +0000173that the accesses alias.</p>
174
Misha Brukman283ff692003-10-22 23:27:16 +0000175</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000176
177<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000178<div class="doc_subsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000179 <a name="alias">The <tt>alias</tt> method</a>
180</div>
181
182<div class="doc_text">
183The <tt>alias</tt> method is the primary interface used to determine whether or
184not two memory objects alias each other. It takes two memory objects as input
185and returns MustAlias, MayAlias, or NoAlias as appropriate.
186</div>
187
188<!-- _______________________________________________________________________ -->
189<div class="doc_subsubsection">
Misha Brukman283ff692003-10-22 23:27:16 +0000190 <a name="MustMayNo">Must, May, and No Alias Responses</a>
191</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000192
Misha Brukman283ff692003-10-22 23:27:16 +0000193<div class="doc_text">
Nick Lewycky4048ca52008-12-14 21:08:48 +0000194<p>The NoAlias response is used when the two pointers refer to distinct objects,
Nick Lewycky9c7379d2008-12-18 02:15:05 +0000195regardless of whether the pointers compare equal. For example, freed pointers
196don't alias any pointers that were allocated afterwards. As a degenerate case,
197pointers returned by malloc(0) have no bytes for an object, and are considered
198NoAlias even when malloc returns the same pointer. The same rule applies to
199NULL pointers.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000200
Nick Lewycky4048ca52008-12-14 21:08:48 +0000201<p>The MayAlias response is used whenever the two pointers might refer to the
202same object. If the two memory objects overlap, but do not start at the same
203location, return MayAlias.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000204
Nick Lewycky4048ca52008-12-14 21:08:48 +0000205<p>The MustAlias response may only be returned if the two memory objects are
206guaranteed to always start at exactly the same location. A MustAlias response
207implies that the pointers compare equal.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000208
Misha Brukman283ff692003-10-22 23:27:16 +0000209</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000210
211<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000212<div class="doc_subsection">
213 <a name="ModRefInfo">The <tt>getModRefInfo</tt> methods</a>
214</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000215
Misha Brukman283ff692003-10-22 23:27:16 +0000216<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000217
218<p>The <tt>getModRefInfo</tt> methods return information about whether the
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000219execution of an instruction can read or modify a memory location. Mod/Ref
Chris Lattner2a19d832004-05-23 21:04:01 +0000220information is always conservative: if an instruction <b>might</b> read or write
221a location, ModRef is returned.</p>
222
223<p>The <tt>AliasAnalysis</tt> class also provides a <tt>getModRefInfo</tt>
224method for testing dependencies between function calls. This method takes two
225call sites (CS1 &amp; CS2), returns NoModRef if the two calls refer to disjoint
226memory locations, Ref if CS1 reads memory written by CS2, Mod if CS1 writes to
227memory read or written by CS2, or ModRef if CS1 might read or write memory
Chris Lattner88874ec2009-11-22 16:01:44 +0000228accessed by CS2. Note that this relation is not commutative.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000229
Misha Brukman283ff692003-10-22 23:27:16 +0000230</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000231
Chris Lattner2a19d832004-05-23 21:04:01 +0000232
233<!-- ======================================================================= -->
234<div class="doc_subsection">
235 <a name="OtherItfs">Other useful <tt>AliasAnalysis</tt> methods</a>
236</div>
237
238<div class="doc_text">
239
240<p>
241Several other tidbits of information are often collected by various alias
242analysis implementations and can be put to good use by various clients.
243</p>
244
245</div>
246
247<!-- _______________________________________________________________________ -->
248<div class="doc_subsubsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000249 The <tt>pointsToConstantMemory</tt> method
250</div>
251
252<div class="doc_text">
253
254<p>The <tt>pointsToConstantMemory</tt> method returns true if and only if the
255analysis can prove that the pointer only points to unchanging memory locations
256(functions, constant global variables, and the null pointer). This information
257can be used to refine mod/ref information: it is impossible for an unchanging
258memory location to be modified.</p>
259
260</div>
261
Chris Lattner2a19d832004-05-23 21:04:01 +0000262<!-- _______________________________________________________________________ -->
263<div class="doc_subsubsection">
264 <a name="simplemodref">The <tt>doesNotAccessMemory</tt> and
265 <tt>onlyReadsMemory</tt> methods</a>
266</div>
267
268<div class="doc_text">
269
270<p>These methods are used to provide very simple mod/ref information for
271function calls. The <tt>doesNotAccessMemory</tt> method returns true for a
272function if the analysis can prove that the function never reads or writes to
273memory, or if the function only reads from constant memory. Functions with this
274property are side-effect free and only depend on their input arguments, allowing
275them to be eliminated if they form common subexpressions or be hoisted out of
276loops. Many common functions behave this way (e.g., <tt>sin</tt> and
277<tt>cos</tt>) but many others do not (e.g., <tt>acos</tt>, which modifies the
278<tt>errno</tt> variable).</p>
279
280<p>The <tt>onlyReadsMemory</tt> method returns true for a function if analysis
281can prove that (at most) the function only reads from non-volatile memory.
282Functions with this property are side-effect free, only depending on their input
283arguments and the state of memory when they are called. This property allows
284calls to these functions to be eliminated and moved around, as long as there is
285no store instruction that changes the contents of memory. Note that all
286functions that satisfy the <tt>doesNotAccessMemory</tt> method also satisfies
287<tt>onlyReadsMemory</tt>.</p>
288
289</div>
290
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000291<!-- *********************************************************************** -->
Misha Brukman283ff692003-10-22 23:27:16 +0000292<div class="doc_section">
Chris Lattner2a19d832004-05-23 21:04:01 +0000293 <a name="writingnew">Writing a new <tt>AliasAnalysis</tt> Implementation</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000294</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000295<!-- *********************************************************************** -->
296
Misha Brukman283ff692003-10-22 23:27:16 +0000297<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000298
299<p>Writing a new alias analysis implementation for LLVM is quite
300straight-forward. There are already several implementations that you can use
301for examples, and the following information should help fill in any details.
Chris Lattner2a19d832004-05-23 21:04:01 +0000302For a examples, take a look at the <a href="#impls">various alias analysis
303implementations</a> included with LLVM.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000304
Misha Brukman283ff692003-10-22 23:27:16 +0000305</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000306
307<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000308<div class="doc_subsection">
309 <a name="passsubclasses">Different Pass styles</a>
310</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000311
Misha Brukman283ff692003-10-22 23:27:16 +0000312<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000313
314<p>The first step to determining what type of <a
315href="WritingAnLLVMPass.html">LLVM pass</a> you need to use for your Alias
316Analysis. As is the case with most other analyses and transformations, the
317answer should be fairly obvious from what type of problem you are trying to
318solve:</p>
319
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000320<ol>
Misha Brukman283ff692003-10-22 23:27:16 +0000321 <li>If you require interprocedural analysis, it should be a
322 <tt>Pass</tt>.</li>
Chris Lattner2a19d832004-05-23 21:04:01 +0000323 <li>If you are a function-local analysis, subclass <tt>FunctionPass</tt>.</li>
Misha Brukman283ff692003-10-22 23:27:16 +0000324 <li>If you don't need to look at the program at all, subclass
325 <tt>ImmutablePass</tt>.</li>
326</ol>
Misha Brukman084a3a072003-10-24 18:06:11 +0000327
328<p>In addition to the pass that you subclass, you should also inherit from the
Misha Brukmanb4dd5392003-05-07 21:47:16 +0000329<tt>AliasAnalysis</tt> interface, of course, and use the
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000330<tt>RegisterAnalysisGroup</tt> template to register as an implementation of
Misha Brukman084a3a072003-10-24 18:06:11 +0000331<tt>AliasAnalysis</tt>.</p>
332
Misha Brukman283ff692003-10-22 23:27:16 +0000333</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000334
335<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000336<div class="doc_subsection">
337 <a name="requiredcalls">Required initialization calls</a>
338</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000339
Misha Brukman283ff692003-10-22 23:27:16 +0000340<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000341
Chris Lattner2a19d832004-05-23 21:04:01 +0000342<p>Your subclass of <tt>AliasAnalysis</tt> is required to invoke two methods on
343the <tt>AliasAnalysis</tt> base class: <tt>getAnalysisUsage</tt> and
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000344<tt>InitializeAliasAnalysis</tt>. In particular, your implementation of
345<tt>getAnalysisUsage</tt> should explicitly call into the
346<tt>AliasAnalysis::getAnalysisUsage</tt> method in addition to doing any
347declaring any pass dependencies your pass has. Thus you should have something
Misha Brukman084a3a072003-10-24 18:06:11 +0000348like this:</p>
349
Misha Brukman2361fcf2004-07-28 22:18:33 +0000350<div class="doc_code">
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000351<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000352void getAnalysisUsage(AnalysisUsage &amp;AU) const {
353 AliasAnalysis::getAnalysisUsage(AU);
354 <i>// declare your dependencies here.</i>
355}
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000356</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000357</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000358
359<p>Additionally, your must invoke the <tt>InitializeAliasAnalysis</tt> method
360from your analysis run method (<tt>run</tt> for a <tt>Pass</tt>,
Chris Lattner2a19d832004-05-23 21:04:01 +0000361<tt>runOnFunction</tt> for a <tt>FunctionPass</tt>, or <tt>InitializePass</tt>
362for an <tt>ImmutablePass</tt>). For example (as part of a <tt>Pass</tt>):</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000363
Misha Brukman2361fcf2004-07-28 22:18:33 +0000364<div class="doc_code">
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000365<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000366bool run(Module &amp;M) {
367 InitializeAliasAnalysis(this);
368 <i>// Perform analysis here...</i>
369 return false;
370}
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000371</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000372</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000373
Misha Brukman283ff692003-10-22 23:27:16 +0000374</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000375
376<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000377<div class="doc_subsection">
378 <a name="interfaces">Interfaces which may be specified</a>
379</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000380
Misha Brukman283ff692003-10-22 23:27:16 +0000381<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000382
Chris Lattner2a19d832004-05-23 21:04:01 +0000383<p>All of the <a
384href="/doxygen/classllvm_1_1AliasAnalysis.html"><tt>AliasAnalysis</tt></a>
385virtual methods default to providing <a href="#chaining">chaining</a> to another
386alias analysis implementation, which ends up returning conservatively correct
387information (returning "May" Alias and "Mod/Ref" for alias and mod/ref queries
Misha Brukman084a3a072003-10-24 18:06:11 +0000388respectively). Depending on the capabilities of the analysis you are
389implementing, you just override the interfaces you can improve.</p>
390
Misha Brukman283ff692003-10-22 23:27:16 +0000391</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000392
Chris Lattner2a19d832004-05-23 21:04:01 +0000393
394
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000395<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000396<div class="doc_subsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000397 <a name="chaining"><tt>AliasAnalysis</tt> chaining behavior</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000398</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000399
Misha Brukman283ff692003-10-22 23:27:16 +0000400<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000401
Chris Lattner2a19d832004-05-23 21:04:01 +0000402<p>With only two special exceptions (the <tt><a
403href="#basic-aa">basicaa</a></tt> and <a href="#no-aa"><tt>no-aa</tt></a>
404passes) every alias analysis pass chains to another alias analysis
405implementation (for example, the user can specify "<tt>-basicaa -ds-aa
406-anders-aa -licm</tt>" to get the maximum benefit from the three alias
407analyses). The alias analysis class automatically takes care of most of this
408for methods that you don't override. For methods that you do override, in code
409paths that return a conservative MayAlias or Mod/Ref result, simply return
410whatever the superclass computes. For example:</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000411
Misha Brukman2361fcf2004-07-28 22:18:33 +0000412<div class="doc_code">
Chris Lattner2a19d832004-05-23 21:04:01 +0000413<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000414AliasAnalysis::AliasResult alias(const Value *V1, unsigned V1Size,
415 const Value *V2, unsigned V2Size) {
416 if (...)
417 return NoAlias;
418 ...
Chris Lattner2a19d832004-05-23 21:04:01 +0000419
Misha Brukman2361fcf2004-07-28 22:18:33 +0000420 <i>// Couldn't determine a must or no-alias result.</i>
421 return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
422}
Chris Lattner2a19d832004-05-23 21:04:01 +0000423</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000424</div>
Chris Lattner2a19d832004-05-23 21:04:01 +0000425
426<p>In addition to analysis queries, you must make sure to unconditionally pass
427LLVM <a href="#updating">update notification</a> methods to the superclass as
428well if you override them, which allows all alias analyses in a change to be
429updated.</p>
430
431</div>
432
433
434<!-- ======================================================================= -->
435<div class="doc_subsection">
436 <a name="updating">Updating analysis results for transformations</a>
437</div>
438
439<div class="doc_text">
440<p>
441Alias analysis information is initially computed for a static snapshot of the
442program, but clients will use this information to make transformations to the
443code. All but the most trivial forms of alias analysis will need to have their
444analysis results updated to reflect the changes made by these transformations.
445</p>
446
447<p>
448The <tt>AliasAnalysis</tt> interface exposes two methods which are used to
449communicate program changes from the clients to the analysis implementations.
450Various alias analysis implementations should use these methods to ensure that
451their internal data structures are kept up-to-date as the program changes (for
452example, when an instruction is deleted), and clients of alias analysis must be
453sure to call these interfaces appropriately.
454</p>
455</div>
456
457<!-- _______________________________________________________________________ -->
458<div class="doc_subsubsection">The <tt>deleteValue</tt> method</div>
459
460<div class="doc_text">
461The <tt>deleteValue</tt> method is called by transformations when they remove an
462instruction or any other value from the program (including values that do not
463use pointers). Typically alias analyses keep data structures that have entries
464for each value in the program. When this method is called, they should remove
465any entries for the specified value, if they exist.
466</div>
467
Chris Lattner2a19d832004-05-23 21:04:01 +0000468<!-- _______________________________________________________________________ -->
469<div class="doc_subsubsection">The <tt>copyValue</tt> method</div>
470
471<div class="doc_text">
472The <tt>copyValue</tt> method is used when a new value is introduced into the
473program. There is no way to introduce a value into the program that did not
474exist before (this doesn't make sense for a safe compiler transformation), so
475this is the only way to introduce a new value. This method indicates that the
476new value has exactly the same properties as the value being copied.
477</div>
478
Chris Lattner2a19d832004-05-23 21:04:01 +0000479<!-- _______________________________________________________________________ -->
480<div class="doc_subsubsection">The <tt>replaceWithNewValue</tt> method</div>
481
482<div class="doc_text">
483This method is a simple helper method that is provided to make clients easier to
484use. It is implemented by copying the old analysis information to the new
485value, then deleting the old value. This method cannot be overridden by alias
486analysis implementations.
Misha Brukman283ff692003-10-22 23:27:16 +0000487</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000488
489<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000490<div class="doc_subsection">
491 <a name="implefficiency">Efficiency Issues</a>
492</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000493
Misha Brukman283ff692003-10-22 23:27:16 +0000494<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000495
496<p>From the LLVM perspective, the only thing you need to do to provide an
497efficient alias analysis is to make sure that alias analysis <b>queries</b> are
498serviced quickly. The actual calculation of the alias analysis results (the
499"run" method) is only performed once, but many (perhaps duplicate) queries may
500be performed. Because of this, try to move as much computation to the run
501method as possible (within reason).</p>
502
Misha Brukman283ff692003-10-22 23:27:16 +0000503</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000504
505<!-- *********************************************************************** -->
Misha Brukman283ff692003-10-22 23:27:16 +0000506<div class="doc_section">
Chris Lattner2a19d832004-05-23 21:04:01 +0000507 <a name="using">Using alias analysis results</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000508</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000509<!-- *********************************************************************** -->
510
Misha Brukman283ff692003-10-22 23:27:16 +0000511<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000512
513<p>There are several different ways to use alias analysis results. In order of
514preference, these are...</p>
515
Misha Brukman283ff692003-10-22 23:27:16 +0000516</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000517
518<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000519<div class="doc_subsection">
Chris Lattner6a6d3cc2009-04-25 21:11:37 +0000520 <a name="memdep">Using the <tt>MemoryDependenceAnalysis</tt> Pass</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000521</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000522
Misha Brukman283ff692003-10-22 23:27:16 +0000523<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000524
Chris Lattner6a6d3cc2009-04-25 21:11:37 +0000525<p>The <tt>memdep</tt> pass uses alias analysis to provide high-level dependence
526information about memory-using instructions. This will tell you which store
527feeds into a load, for example. It uses caching and other techniques to be
528efficient, and is used by Dead Store Elimination, GVN, and memcpy optimizations.
529</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000530
Misha Brukman283ff692003-10-22 23:27:16 +0000531</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000532
533<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000534<div class="doc_subsection">
535 <a name="ast">Using the <tt>AliasSetTracker</tt> class</a>
536</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000537
Misha Brukman283ff692003-10-22 23:27:16 +0000538<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000539
540<p>Many transformations need information about alias <b>sets</b> that are active
541in some scope, rather than information about pairwise aliasing. The <tt><a
Misha Brukman2361fcf2004-07-28 22:18:33 +0000542href="/doxygen/classllvm_1_1AliasSetTracker.html">AliasSetTracker</a></tt> class
543is used to efficiently build these Alias Sets from the pairwise alias analysis
Chris Lattner2a19d832004-05-23 21:04:01 +0000544information provided by the <tt>AliasAnalysis</tt> interface.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000545
Chris Lattner2a19d832004-05-23 21:04:01 +0000546<p>First you initialize the AliasSetTracker by using the "<tt>add</tt>" methods
547to add information about various potentially aliasing instructions in the scope
548you are interested in. Once all of the alias sets are completed, your pass
549should simply iterate through the constructed alias sets, using the
550<tt>AliasSetTracker</tt> <tt>begin()</tt>/<tt>end()</tt> methods.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000551
552<p>The <tt>AliasSet</tt>s formed by the <tt>AliasSetTracker</tt> are guaranteed
Chris Lattnerb8b9163a2003-12-19 08:43:07 +0000553to be disjoint, calculate mod/ref information and volatility for the set, and
554keep track of whether or not all of the pointers in the set are Must aliases.
555The AliasSetTracker also makes sure that sets are properly folded due to call
Misha Brukman084a3a072003-10-24 18:06:11 +0000556instructions, and can provide a list of pointers in each set.</p>
557
558<p>As an example user of this, the <a href="/doxygen/structLICM.html">Loop
Chris Lattner2a19d832004-05-23 21:04:01 +0000559Invariant Code Motion</a> pass uses <tt>AliasSetTracker</tt>s to calculate alias
560sets for each loop nest. If an <tt>AliasSet</tt> in a loop is not modified,
561then all load instructions from that set may be hoisted out of the loop. If any
562alias sets are stored to <b>and</b> are must alias sets, then the stores may be
563sunk to outside of the loop, promoting the memory location to a register for the
564duration of the loop nest. Both of these transformations only apply if the
565pointer argument is loop-invariant.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000566
Misha Brukman283ff692003-10-22 23:27:16 +0000567</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000568
Chris Lattner2a19d832004-05-23 21:04:01 +0000569<!-- _______________________________________________________________________ -->
Chris Lattnerb8b9163a2003-12-19 08:43:07 +0000570<div class="doc_subsubsection">
571 The AliasSetTracker implementation
572</div>
573
574<div class="doc_text">
575
576<p>The AliasSetTracker class is implemented to be as efficient as possible. It
577uses the union-find algorithm to efficiently merge AliasSets when a pointer is
578inserted into the AliasSetTracker that aliases multiple sets. The primary data
579structure is a hash table mapping pointers to the AliasSet they are in.</p>
580
581<p>The AliasSetTracker class must maintain a list of all of the LLVM Value*'s
582that are in each AliasSet. Since the hash table already has entries for each
583LLVM Value* of interest, the AliasesSets thread the linked list through these
584hash-table nodes to avoid having to allocate memory unnecessarily, and to make
585merging alias sets extremely efficient (the linked list merge is constant time).
586</p>
587
588<p>You shouldn't need to understand these details if you are just a client of
589the AliasSetTracker, but if you look at the code, hopefully this brief
590description will help make sense of why things are designed the way they
591are.</p>
592
593</div>
594
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000595<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000596<div class="doc_subsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000597 <a name="direct">Using the <tt>AliasAnalysis</tt> interface directly</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000598</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000599
Misha Brukman283ff692003-10-22 23:27:16 +0000600<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000601
Chris Lattner2a19d832004-05-23 21:04:01 +0000602<p>If neither of these utility class are what your pass needs, you should use
603the interfaces exposed by the <tt>AliasAnalysis</tt> class directly. Try to use
604the higher-level methods when possible (e.g., use mod/ref information instead of
605the <a href="#alias"><tt>alias</tt></a> method directly if possible) to get the
606best precision and efficiency.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000607
Misha Brukman283ff692003-10-22 23:27:16 +0000608</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000609
610<!-- *********************************************************************** -->
Misha Brukman283ff692003-10-22 23:27:16 +0000611<div class="doc_section">
Chris Lattner2a19d832004-05-23 21:04:01 +0000612 <a name="exist">Existing alias analysis implementations and clients</a>
Misha Brukman283ff692003-10-22 23:27:16 +0000613</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000614<!-- *********************************************************************** -->
615
Misha Brukman283ff692003-10-22 23:27:16 +0000616<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000617
Chris Lattner2a19d832004-05-23 21:04:01 +0000618<p>If you're going to be working with the LLVM alias analysis infrastructure,
619you should know what clients and implementations of alias analysis are
620available. In particular, if you are implementing an alias analysis, you should
621be aware of the <a href="#aliasanalysis-debug">the clients</a> that are useful
622for monitoring and evaluating different implementations.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000623
Misha Brukman283ff692003-10-22 23:27:16 +0000624</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000625
626<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000627<div class="doc_subsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000628 <a name="impls">Available <tt>AliasAnalysis</tt> implementations</a>
629</div>
630
631<div class="doc_text">
632
633<p>This section lists the various implementations of the <tt>AliasAnalysis</tt>
634interface. With the exception of the <a href="#no-aa"><tt>-no-aa</tt></a> and
635<a href="#basic-aa"><tt>-basicaa</tt></a> implementations, all of these <a
Chris Lattner53e5e2a2004-06-21 22:52:48 +0000636href="#chaining">chain</a> to other alias analysis implementations.</p>
Chris Lattner2a19d832004-05-23 21:04:01 +0000637
638</div>
639
640<!-- _______________________________________________________________________ -->
641<div class="doc_subsubsection">
Misha Brukman283ff692003-10-22 23:27:16 +0000642 <a name="no-aa">The <tt>-no-aa</tt> pass</a>
643</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000644
Misha Brukman283ff692003-10-22 23:27:16 +0000645<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000646
Chris Lattner2a19d832004-05-23 21:04:01 +0000647<p>The <tt>-no-aa</tt> pass is just like what it sounds: an alias analysis that
648never returns any useful information. This pass can be useful if you think that
649alias analysis is doing something wrong and are trying to narrow down a
650problem.</p>
651
652</div>
653
Chris Lattner2a19d832004-05-23 21:04:01 +0000654<!-- _______________________________________________________________________ -->
655<div class="doc_subsubsection">
656 <a name="basic-aa">The <tt>-basicaa</tt> pass</a>
657</div>
658
659<div class="doc_text">
660
661<p>The <tt>-basicaa</tt> pass is the default LLVM alias analysis. It is an
662aggressive local analysis that "knows" many important facts:</p>
663
664<ul>
665<li>Distinct globals, stack allocations, and heap allocations can never
666 alias.</li>
667<li>Globals, stack allocations, and heap allocations never alias the null
668 pointer.</li>
669<li>Different fields of a structure do not alias.</li>
670<li>Indexes into arrays with statically differing subscripts cannot alias.</li>
671<li>Many common standard C library functions <a
672 href="#simplemodref">never access memory or only read memory</a>.</li>
673<li>Pointers that obviously point to constant globals
674 "<tt>pointToConstantMemory</tt>".</li>
675<li>Function calls can not modify or references stack allocations if they never
676 escape from the function that allocates them (a common case for automatic
677 arrays).</li>
678</ul>
679
680</div>
681
Chris Lattner9475b962004-06-28 19:19:47 +0000682<!-- _______________________________________________________________________ -->
683<div class="doc_subsubsection">
684 <a name="globalsmodref">The <tt>-globalsmodref-aa</tt> pass</a>
685</div>
686
687<div class="doc_text">
688
689<p>This pass implements a simple context-sensitive mod/ref and alias analysis
Chris Lattnerd1384372004-07-27 07:50:07 +0000690for internal global variables that don't "have their address taken". If a
691global does not have its address taken, the pass knows that no pointers alias
692the global. This pass also keeps track of functions that it knows never access
Chris Lattner6a6d3cc2009-04-25 21:11:37 +0000693memory or never read memory. This allows certain optimizations (e.g. GVN) to
Chris Lattnerd1384372004-07-27 07:50:07 +0000694eliminate call instructions entirely.
Chris Lattner9475b962004-06-28 19:19:47 +0000695</p>
696
697<p>The real power of this pass is that it provides context-sensitive mod/ref
698information for call instructions. This allows the optimizer to know that
699calls to a function do not clobber or read the value of the global, allowing
700loads and stores to be eliminated.</p>
701
702<p>Note that this pass is somewhat limited in its scope (only support
703non-address taken globals), but is very quick analysis.</p>
704</div>
Chris Lattner2a19d832004-05-23 21:04:01 +0000705
706<!-- _______________________________________________________________________ -->
707<div class="doc_subsubsection">
708 <a name="anders-aa">The <tt>-anders-aa</tt> pass</a>
709</div>
710
711<div class="doc_text">
712
713<p>The <tt>-anders-aa</tt> pass implements the well-known "Andersen's algorithm"
714for interprocedural alias analysis. This algorithm is a subset-based,
715flow-insensitive, context-insensitive, and field-insensitive alias analysis that
716is widely believed to be fairly precise. Unfortunately, this algorithm is also
717O(N<sup>3</sup>). The LLVM implementation currently does not implement any of
718the refinements (such as "online cycle elimination" or "offline variable
719substitution") to improve its efficiency, so it can be quite slow in common
720cases.
721</p>
722
723</div>
724
725<!-- _______________________________________________________________________ -->
726<div class="doc_subsubsection">
727 <a name="steens-aa">The <tt>-steens-aa</tt> pass</a>
728</div>
729
730<div class="doc_text">
731
732<p>The <tt>-steens-aa</tt> pass implements a variation on the well-known
733"Steensgaard's algorithm" for interprocedural alias analysis. Steensgaard's
734algorithm is a unification-based, flow-insensitive, context-insensitive, and
735field-insensitive alias analysis that is also very scalable (effectively linear
736time).</p>
737
738<p>The LLVM <tt>-steens-aa</tt> pass implements a "speculatively
739field-<b>sensitive</b>" version of Steensgaard's algorithm using the Data
740Structure Analysis framework. This gives it substantially more precision than
741the standard algorithm while maintaining excellent analysis scalability.</p>
742
Chris Lattner4b325282007-07-03 04:41:50 +0000743<p>Note that <tt>-steens-aa</tt> is available in the optional "poolalloc"
744module, it is not part of the LLVM core.</p>
745
Chris Lattner2a19d832004-05-23 21:04:01 +0000746</div>
747
748<!-- _______________________________________________________________________ -->
749<div class="doc_subsubsection">
750 <a name="ds-aa">The <tt>-ds-aa</tt> pass</a>
751</div>
752
753<div class="doc_text">
754
755<p>The <tt>-ds-aa</tt> pass implements the full Data Structure Analysis
756algorithm. Data Structure Analysis is a modular unification-based,
757flow-insensitive, context-<b>sensitive</b>, and speculatively
758field-<b>sensitive</b> alias analysis that is also quite scalable, usually at
759O(n*log(n)).</p>
760
761<p>This algorithm is capable of responding to a full variety of alias analysis
762queries, and can provide context-sensitive mod/ref information as well. The
763only major facility not implemented so far is support for must-alias
764information.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000765
Chris Lattner4b325282007-07-03 04:41:50 +0000766<p>Note that <tt>-ds-aa</tt> is available in the optional "poolalloc"
767module, it is not part of the LLVM core.</p>
768
Misha Brukman283ff692003-10-22 23:27:16 +0000769</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000770
771
772<!-- ======================================================================= -->
Misha Brukman283ff692003-10-22 23:27:16 +0000773<div class="doc_subsection">
Chris Lattner2a19d832004-05-23 21:04:01 +0000774 <a name="aliasanalysis-xforms">Alias analysis driven transformations</a>
775</div>
776
777<div class="doc_text">
778LLVM includes several alias-analysis driven transformations which can be used
779with any of the implementations above.
780</div>
781
782<!-- _______________________________________________________________________ -->
783<div class="doc_subsubsection">
784 <a name="adce">The <tt>-adce</tt> pass</a>
785</div>
786
787<div class="doc_text">
788
789<p>The <tt>-adce</tt> pass, which implements Aggressive Dead Code Elimination
790uses the <tt>AliasAnalysis</tt> interface to delete calls to functions that do
791not have side-effects and are not used.</p>
792
793</div>
794
795
796<!-- _______________________________________________________________________ -->
797<div class="doc_subsubsection">
798 <a name="licm">The <tt>-licm</tt> pass</a>
799</div>
800
801<div class="doc_text">
802
803<p>The <tt>-licm</tt> pass implements various Loop Invariant Code Motion related
804transformations. It uses the <tt>AliasAnalysis</tt> interface for several
805different transformations:</p>
806
807<ul>
808<li>It uses mod/ref information to hoist or sink load instructions out of loops
809if there are no instructions in the loop that modifies the memory loaded.</li>
810
811<li>It uses mod/ref information to hoist function calls out of loops that do not
812write to memory and are loop-invariant.</li>
813
814<li>If uses alias information to promote memory objects that are loaded and
815stored to in loops to live in a register instead. It can do this if there are
816no may aliases to the loaded/stored memory location.</li>
817</ul>
818
819</div>
820
821<!-- _______________________________________________________________________ -->
822<div class="doc_subsubsection">
823 <a name="argpromotion">The <tt>-argpromotion</tt> pass</a>
824</div>
825
826<div class="doc_text">
827<p>
828The <tt>-argpromotion</tt> pass promotes by-reference arguments to be passed in
829by-value instead. In particular, if pointer arguments are only loaded from it
830passes in the value loaded instead of the address to the function. This pass
831uses alias information to make sure that the value loaded from the argument
832pointer is not modified between the entry of the function and any load of the
833pointer.</p>
834</div>
835
836<!-- _______________________________________________________________________ -->
837<div class="doc_subsubsection">
Chris Lattner6a6d3cc2009-04-25 21:11:37 +0000838 <a name="gvn">The <tt>-gvn</tt>, <tt>-memcpyopt</tt>, and <tt>-dse</tt>
839 passes</a>
Chris Lattner2a19d832004-05-23 21:04:01 +0000840</div>
841
842<div class="doc_text">
Misha Brukman2361fcf2004-07-28 22:18:33 +0000843
Chris Lattner6a6d3cc2009-04-25 21:11:37 +0000844<p>These passes use AliasAnalysis information to reason about loads and stores.
845</p>
Chris Lattner2a19d832004-05-23 21:04:01 +0000846
847</div>
848
Chris Lattner2a19d832004-05-23 21:04:01 +0000849<!-- ======================================================================= -->
850<div class="doc_subsection">
Misha Brukman2361fcf2004-07-28 22:18:33 +0000851 <a name="aliasanalysis-debug">Clients for debugging and evaluation of
852 implementations</a>
Chris Lattner2a19d832004-05-23 21:04:01 +0000853</div>
854
Misha Brukman2361fcf2004-07-28 22:18:33 +0000855<div class="doc_text">
Chris Lattner2a19d832004-05-23 21:04:01 +0000856
Misha Brukman2361fcf2004-07-28 22:18:33 +0000857<p>These passes are useful for evaluating the various alias analysis
858implementations. You can use them with commands like '<tt>opt -anders-aa -ds-aa
859-aa-eval foo.bc -disable-output -stats</tt>'.</p>
860
861</div>
Chris Lattner2a19d832004-05-23 21:04:01 +0000862
863<!-- _______________________________________________________________________ -->
864<div class="doc_subsubsection">
Misha Brukman283ff692003-10-22 23:27:16 +0000865 <a name="print-alias-sets">The <tt>-print-alias-sets</tt> pass</a>
866</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000867
Misha Brukman283ff692003-10-22 23:27:16 +0000868<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000869
870<p>The <tt>-print-alias-sets</tt> pass is exposed as part of the
Chris Lattner2e6f4482006-01-03 06:04:48 +0000871<tt>opt</tt> tool to print out the Alias Sets formed by the <a
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000872href="#ast"><tt>AliasSetTracker</tt></a> class. This is useful if you're using
Chris Lattner2e6f4482006-01-03 06:04:48 +0000873the <tt>AliasSetTracker</tt> class. To use it, use something like:</p>
874
875<div class="doc_code">
876<pre>
877% opt -ds-aa -print-alias-sets -disable-output
878</pre>
879</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000880
Misha Brukman283ff692003-10-22 23:27:16 +0000881</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000882
Chris Lattner2a19d832004-05-23 21:04:01 +0000883
884<!-- _______________________________________________________________________ -->
885<div class="doc_subsubsection">
Misha Brukman283ff692003-10-22 23:27:16 +0000886 <a name="count-aa">The <tt>-count-aa</tt> pass</a>
887</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000888
Misha Brukman283ff692003-10-22 23:27:16 +0000889<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000890
891<p>The <tt>-count-aa</tt> pass is useful to see how many queries a particular
Misha Brukman2361fcf2004-07-28 22:18:33 +0000892pass is making and what responses are returned by the alias analysis. As an
893example,</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000894
Misha Brukman2361fcf2004-07-28 22:18:33 +0000895<div class="doc_code">
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000896<pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000897% opt -basicaa -count-aa -ds-aa -count-aa -licm
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000898</pre>
Misha Brukman2361fcf2004-07-28 22:18:33 +0000899</div>
Misha Brukman084a3a072003-10-24 18:06:11 +0000900
Misha Brukman2361fcf2004-07-28 22:18:33 +0000901<p>will print out how many queries (and what responses are returned) by the
902<tt>-licm</tt> pass (of the <tt>-ds-aa</tt> pass) and how many queries are made
903of the <tt>-basicaa</tt> pass by the <tt>-ds-aa</tt> pass. This can be useful
904when debugging a transformation or an alias analysis implementation.</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000905
Misha Brukman283ff692003-10-22 23:27:16 +0000906</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000907
Chris Lattner2a19d832004-05-23 21:04:01 +0000908<!-- _______________________________________________________________________ -->
909<div class="doc_subsubsection">
Misha Brukman283ff692003-10-22 23:27:16 +0000910 <a name="aa-eval">The <tt>-aa-eval</tt> pass</a>
911</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000912
Misha Brukman283ff692003-10-22 23:27:16 +0000913<div class="doc_text">
Misha Brukman084a3a072003-10-24 18:06:11 +0000914
915<p>The <tt>-aa-eval</tt> pass simply iterates through all pairs of pointers in a
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000916function and asks an alias analysis whether or not the pointers alias. This
917gives an indication of the precision of the alias analysis. Statistics are
Chris Lattner2a19d832004-05-23 21:04:01 +0000918printed indicating the percent of no/may/must aliases found (a more precise
919algorithm will have a lower number of may aliases).</p>
Misha Brukman084a3a072003-10-24 18:06:11 +0000920
Misha Brukman283ff692003-10-22 23:27:16 +0000921</div>
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000922
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000923<!-- *********************************************************************** -->
Owen Andersond263cfa2007-10-02 00:43:25 +0000924<div class="doc_section">
925 <a name="memdep">Memory Dependence Analysis</a>
926</div>
927<!-- *********************************************************************** -->
928
929<div class="doc_text">
930
931<p>If you're just looking to be a client of alias analysis information, consider
932using the Memory Dependence Analysis interface instead. MemDep is a lazy,
933caching layer on top of alias analysis that is able to answer the question of
934what preceding memory operations a given instruction depends on, either at an
935intra- or inter-block level. Because of its laziness and caching
936policy, using MemDep can be a significant performance win over accessing alias
937analysis directly.</p>
938
939</div>
940
941<!-- *********************************************************************** -->
Chris Lattnerb512e9f2003-03-04 19:37:49 +0000942
Misha Brukman084a3a072003-10-24 18:06:11 +0000943<hr>
Misha Brukmane8e932a2003-11-22 01:26:21 +0000944<address>
Misha Brukman8834af92003-12-21 22:53:21 +0000945 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +0000946 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmane8e932a2003-11-22 01:26:21 +0000947 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +0000948 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Misha Brukmane8e932a2003-11-22 01:26:21 +0000949
950 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +0000951 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
Misha Brukmane8e932a2003-11-22 01:26:21 +0000952 Last modified: $Date$
953</address>
Misha Brukman283ff692003-10-22 23:27:16 +0000954
955</body>
956</html>