3 ==================================
4 LLVM Alias Analysis Infrastructure
5 ==================================
13 Alias Analysis (aka Pointer Analysis) is a class of techniques which attempt to
14 determine whether or not two pointers ever can point to the same object in
15 memory. There are many different algorithms for alias analysis and many
16 different ways of classifying them: flow-sensitive vs. flow-insensitive,
17 context-sensitive vs. context-insensitive, field-sensitive
18 vs. field-insensitive, unification-based vs. subset-based, etc. Traditionally,
19 alias analyses respond to a query with a `Must, May, or No`_ alias response,
20 indicating that two pointers always point to the same object, might point to the
21 same object, or are known to never point to the same object.
23 The LLVM `AliasAnalysis
24 <http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__ class is the
25 primary interface used by clients and implementations of alias analyses in the
26 LLVM system. This class is the common interface between clients of alias
27 analysis information and the implementations providing it, and is designed to
28 support a wide range of implementations and clients (but currently all clients
29 are assumed to be flow-insensitive). In addition to simple alias analysis
30 information, this class exposes Mod/Ref information from those implementations
31 which can provide it, allowing for powerful analyses and transformations to work
34 This document contains information necessary to successfully implement this
35 interface, use it, and to test both sides. It also explains some of the finer
36 points about what exactly results mean. If you feel that something is unclear
37 or should be added, please `let me know <mailto:sabre@nondot.org>`_.
39 ``AliasAnalysis`` Class Overview
40 ================================
42 The `AliasAnalysis <http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__
43 class defines the interface that the various alias analysis implementations
44 should support. This class exports two important enums: ``AliasResult`` and
45 ``ModRefResult`` which represent the result of an alias query or a mod/ref
48 The ``AliasAnalysis`` interface exposes information about memory, represented in
49 several different ways. In particular, memory objects are represented as a
50 starting address and size, and function calls are represented as the actual
51 ``call`` or ``invoke`` instructions that performs the call. The
52 ``AliasAnalysis`` interface also exposes some helper methods which allow you to
53 get mod/ref information for arbitrary instructions.
55 All ``AliasAnalysis`` interfaces require that in queries involving multiple
56 values, values which are not `constants <LangRef.html#constants>`_ are all
57 defined within the same function.
59 Representation of Pointers
60 --------------------------
62 Most importantly, the ``AliasAnalysis`` class provides several methods which are
63 used to query whether or not two memory objects alias, whether function calls
64 can modify or read a memory object, etc. For all of these queries, memory
65 objects are represented as a pair of their starting address (a symbolic LLVM
66 ``Value*``) and a static size.
68 Representing memory objects as a starting address and a size is critically
69 important for correct Alias Analyses. For example, consider this (silly, but
78 for (i = 0; i != 10; ++i) {
79 C[0] = A[i]; /* One byte store */
80 C[1] = A[9-i]; /* One byte store */
83 In this case, the ``basicaa`` pass will disambiguate the stores to ``C[0]`` and
84 ``C[1]`` because they are accesses to two distinct locations one byte apart, and
85 the accesses are each one byte. In this case, the Loop Invariant Code Motion
86 (LICM) pass can use store motion to remove the stores from the loop. In
87 constrast, the following code:
95 for (i = 0; i != 10; ++i) {
96 ((short*)C)[0] = A[i]; /* Two byte store! */
97 C[1] = A[9-i]; /* One byte store */
100 In this case, the two stores to C do alias each other, because the access to the
101 ``&C[0]`` element is a two byte access. If size information wasn't available in
102 the query, even the first case would have to conservatively assume that the
110 The ``alias`` method is the primary interface used to determine whether or not
111 two memory objects alias each other. It takes two memory objects as input and
112 returns MustAlias, PartialAlias, MayAlias, or NoAlias as appropriate.
114 Like all ``AliasAnalysis`` interfaces, the ``alias`` method requires that either
115 the two pointer values be defined within the same function, or at least one of
116 the values is a `constant <LangRef.html#constants>`_.
118 .. _Must, May, or No:
120 Must, May, and No Alias Responses
121 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123 The ``NoAlias`` response may be used when there is never an immediate dependence
124 between any memory reference *based* on one pointer and any memory reference
125 *based* the other. The most obvious example is when the two pointers point to
126 non-overlapping memory ranges. Another is when the two pointers are only ever
127 used for reading memory. Another is when the memory is freed and reallocated
128 between accesses through one pointer and accesses through the other --- in this
129 case, there is a dependence, but it's mediated by the free and reallocation.
131 As an exception to this is with the `noalias <LangRef.html#noalias>`_ keyword;
132 the "irrelevant" dependencies are ignored.
134 The ``MayAlias`` response is used whenever the two pointers might refer to the
137 The ``PartialAlias`` response is used when the two memory objects are known to
138 be overlapping in some way, but do not start at the same address.
140 The ``MustAlias`` response may only be returned if the two memory objects are
141 guaranteed to always start at exactly the same location. A ``MustAlias``
142 response implies that the pointers compare equal.
144 The ``getModRefInfo`` methods
145 -----------------------------
147 The ``getModRefInfo`` methods return information about whether the execution of
148 an instruction can read or modify a memory location. Mod/Ref information is
149 always conservative: if an instruction **might** read or write a location,
150 ``ModRef`` is returned.
152 The ``AliasAnalysis`` class also provides a ``getModRefInfo`` method for testing
153 dependencies between function calls. This method takes two call sites (``CS1``
154 & ``CS2``), returns ``NoModRef`` if neither call writes to memory read or
155 written by the other, ``Ref`` if ``CS1`` reads memory written by ``CS2``,
156 ``Mod`` if ``CS1`` writes to memory read or written by ``CS2``, or ``ModRef`` if
157 ``CS1`` might read or write memory written to by ``CS2``. Note that this
158 relation is not commutative.
160 Other useful ``AliasAnalysis`` methods
161 --------------------------------------
163 Several other tidbits of information are often collected by various alias
164 analysis implementations and can be put to good use by various clients.
166 The ``pointsToConstantMemory`` method
167 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169 The ``pointsToConstantMemory`` method returns true if and only if the analysis
170 can prove that the pointer only points to unchanging memory locations
171 (functions, constant global variables, and the null pointer). This information
172 can be used to refine mod/ref information: it is impossible for an unchanging
173 memory location to be modified.
175 .. _never access memory or only read memory:
177 The ``doesNotAccessMemory`` and ``onlyReadsMemory`` methods
178 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180 These methods are used to provide very simple mod/ref information for function
181 calls. The ``doesNotAccessMemory`` method returns true for a function if the
182 analysis can prove that the function never reads or writes to memory, or if the
183 function only reads from constant memory. Functions with this property are
184 side-effect free and only depend on their input arguments, allowing them to be
185 eliminated if they form common subexpressions or be hoisted out of loops. Many
186 common functions behave this way (e.g., ``sin`` and ``cos``) but many others do
187 not (e.g., ``acos``, which modifies the ``errno`` variable).
189 The ``onlyReadsMemory`` method returns true for a function if analysis can prove
190 that (at most) the function only reads from non-volatile memory. Functions with
191 this property are side-effect free, only depending on their input arguments and
192 the state of memory when they are called. This property allows calls to these
193 functions to be eliminated and moved around, as long as there is no store
194 instruction that changes the contents of memory. Note that all functions that
195 satisfy the ``doesNotAccessMemory`` method also satisfies ``onlyReadsMemory``.
197 Writing a new ``AliasAnalysis`` Implementation
198 ==============================================
200 Writing a new alias analysis implementation for LLVM is quite straight-forward.
201 There are already several implementations that you can use for examples, and the
202 following information should help fill in any details. For a examples, take a
203 look at the `various alias analysis implementations`_ included with LLVM.
205 Different Pass styles
206 ---------------------
208 The first step to determining what type of `LLVM pass <WritingAnLLVMPass.html>`_
209 you need to use for your Alias Analysis. As is the case with most other
210 analyses and transformations, the answer should be fairly obvious from what type
211 of problem you are trying to solve:
213 #. If you require interprocedural analysis, it should be a ``Pass``.
214 #. If you are a function-local analysis, subclass ``FunctionPass``.
215 #. If you don't need to look at the program at all, subclass ``ImmutablePass``.
217 In addition to the pass that you subclass, you should also inherit from the
218 ``AliasAnalysis`` interface, of course, and use the ``RegisterAnalysisGroup``
219 template to register as an implementation of ``AliasAnalysis``.
221 Required initialization calls
222 -----------------------------
224 Your subclass of ``AliasAnalysis`` is required to invoke two methods on the
225 ``AliasAnalysis`` base class: ``getAnalysisUsage`` and
226 ``InitializeAliasAnalysis``. In particular, your implementation of
227 ``getAnalysisUsage`` should explicitly call into the
228 ``AliasAnalysis::getAnalysisUsage`` method in addition to doing any declaring
229 any pass dependencies your pass has. Thus you should have something like this:
233 void getAnalysisUsage(AnalysisUsage &AU) const {
234 AliasAnalysis::getAnalysisUsage(AU);
235 // declare your dependencies here.
238 Additionally, your must invoke the ``InitializeAliasAnalysis`` method from your
239 analysis run method (``run`` for a ``Pass``, ``runOnFunction`` for a
240 ``FunctionPass``, or ``InitializePass`` for an ``ImmutablePass``). For example
241 (as part of a ``Pass``):
245 bool run(Module &M) {
246 InitializeAliasAnalysis(this);
247 // Perform analysis here...
251 Interfaces which may be specified
252 ---------------------------------
254 All of the `AliasAnalysis
255 <http://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__ virtual methods
256 default to providing `chaining`_ to another alias analysis implementation, which
257 ends up returning conservatively correct information (returning "May" Alias and
258 "Mod/Ref" for alias and mod/ref queries respectively). Depending on the
259 capabilities of the analysis you are implementing, you just override the
260 interfaces you can improve.
265 ``AliasAnalysis`` chaining behavior
266 -----------------------------------
268 With only one special exception (the `no-aa`_ pass) every alias analysis pass
269 chains to another alias analysis implementation (for example, the user can
270 specify "``-basicaa -ds-aa -licm``" to get the maximum benefit from both alias
271 analyses). The alias analysis class automatically takes care of most of this
272 for methods that you don't override. For methods that you do override, in code
273 paths that return a conservative MayAlias or Mod/Ref result, simply return
274 whatever the superclass computes. For example:
278 AliasAnalysis::AliasResult alias(const Value *V1, unsigned V1Size,
279 const Value *V2, unsigned V2Size) {
284 // Couldn't determine a must or no-alias result.
285 return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
288 In addition to analysis queries, you must make sure to unconditionally pass LLVM
289 `update notification`_ methods to the superclass as well if you override them,
290 which allows all alias analyses in a change to be updated.
292 .. _update notification:
294 Updating analysis results for transformations
295 ---------------------------------------------
297 Alias analysis information is initially computed for a static snapshot of the
298 program, but clients will use this information to make transformations to the
299 code. All but the most trivial forms of alias analysis will need to have their
300 analysis results updated to reflect the changes made by these transformations.
302 The ``AliasAnalysis`` interface exposes four methods which are used to
303 communicate program changes from the clients to the analysis implementations.
304 Various alias analysis implementations should use these methods to ensure that
305 their internal data structures are kept up-to-date as the program changes (for
306 example, when an instruction is deleted), and clients of alias analysis must be
307 sure to call these interfaces appropriately.
309 The ``deleteValue`` method
310 ^^^^^^^^^^^^^^^^^^^^^^^^^^
312 The ``deleteValue`` method is called by transformations when they remove an
313 instruction or any other value from the program (including values that do not
314 use pointers). Typically alias analyses keep data structures that have entries
315 for each value in the program. When this method is called, they should remove
316 any entries for the specified value, if they exist.
318 The ``copyValue`` method
319 ^^^^^^^^^^^^^^^^^^^^^^^^
321 The ``copyValue`` method is used when a new value is introduced into the
322 program. There is no way to introduce a value into the program that did not
323 exist before (this doesn't make sense for a safe compiler transformation), so
324 this is the only way to introduce a new value. This method indicates that the
325 new value has exactly the same properties as the value being copied.
327 The ``replaceWithNewValue`` method
328 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
330 This method is a simple helper method that is provided to make clients easier to
331 use. It is implemented by copying the old analysis information to the new
332 value, then deleting the old value. This method cannot be overridden by alias
333 analysis implementations.
335 The ``addEscapingUse`` method
336 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
338 The ``addEscapingUse`` method is used when the uses of a pointer value have
339 changed in ways that may invalidate precomputed analysis information.
340 Implementations may either use this callback to provide conservative responses
341 for points whose uses have change since analysis time, or may recompute some or
342 all of their internal state to continue providing accurate responses.
344 In general, any new use of a pointer value is considered an escaping use, and
345 must be reported through this callback, *except* for the uses below:
347 * A ``bitcast`` or ``getelementptr`` of the pointer
348 * A ``store`` through the pointer (but not a ``store`` *of* the pointer)
349 * A ``load`` through the pointer
354 From the LLVM perspective, the only thing you need to do to provide an efficient
355 alias analysis is to make sure that alias analysis **queries** are serviced
356 quickly. The actual calculation of the alias analysis results (the "run"
357 method) is only performed once, but many (perhaps duplicate) queries may be
358 performed. Because of this, try to move as much computation to the run method
359 as possible (within reason).
364 The AliasAnalysis infrastructure has several limitations which make writing a
365 new ``AliasAnalysis`` implementation difficult.
367 There is no way to override the default alias analysis. It would be very useful
368 to be able to do something like "``opt -my-aa -O2``" and have it use ``-my-aa``
369 for all passes which need AliasAnalysis, but there is currently no support for
370 that, short of changing the source code and recompiling. Similarly, there is
371 also no way of setting a chain of analyses as the default.
373 There is no way for transform passes to declare that they preserve
374 ``AliasAnalysis`` implementations. The ``AliasAnalysis`` interface includes
375 ``deleteValue`` and ``copyValue`` methods which are intended to allow a pass to
376 keep an AliasAnalysis consistent, however there's no way for a pass to declare
377 in its ``getAnalysisUsage`` that it does so. Some passes attempt to use
378 ``AU.addPreserved<AliasAnalysis>``, however this doesn't actually have any
381 ``AliasAnalysisCounter`` (``-count-aa``) and ``AliasDebugger`` (``-debug-aa``)
382 are implemented as ``ModulePass`` classes, so if your alias analysis uses
383 ``FunctionPass``, it won't be able to use these utilities. If you try to use
384 them, the pass manager will silently route alias analysis queries directly to
385 ``BasicAliasAnalysis`` instead.
387 Similarly, the ``opt -p`` option introduces ``ModulePass`` passes between each
388 pass, which prevents the use of ``FunctionPass`` alias analysis passes.
390 The ``AliasAnalysis`` API does have functions for notifying implementations when
391 values are deleted or copied, however these aren't sufficient. There are many
392 other ways that LLVM IR can be modified which could be relevant to
393 ``AliasAnalysis`` implementations which can not be expressed.
395 The ``AliasAnalysisDebugger`` utility seems to suggest that ``AliasAnalysis``
396 implementations can expect that they will be informed of any relevant ``Value``
397 before it appears in an alias query. However, popular clients such as ``GVN``
398 don't support this, and are known to trigger errors when run with the
399 ``AliasAnalysisDebugger``.
401 Due to several of the above limitations, the most obvious use for the
402 ``AliasAnalysisCounter`` utility, collecting stats on all alias queries in a
403 compilation, doesn't work, even if the ``AliasAnalysis`` implementations don't
404 use ``FunctionPass``. There's no way to set a default, much less a default
405 sequence, and there's no way to preserve it.
407 The ``AliasSetTracker`` class (which is used by ``LICM``) makes a
408 non-deterministic number of alias queries. This can cause stats collected by
409 ``AliasAnalysisCounter`` to have fluctuations among identical runs, for
410 example. Another consequence is that debugging techniques involving pausing
411 execution after a predetermined number of queries can be unreliable.
413 Many alias queries can be reformulated in terms of other alias queries. When
414 multiple ``AliasAnalysis`` queries are chained together, it would make sense to
415 start those queries from the beginning of the chain, with care taken to avoid
416 infinite looping, however currently an implementation which wants to do this can
417 only start such queries from itself.
419 Using alias analysis results
420 ============================
422 There are several different ways to use alias analysis results. In order of
423 preference, these are:
425 Using the ``MemoryDependenceAnalysis`` Pass
426 -------------------------------------------
428 The ``memdep`` pass uses alias analysis to provide high-level dependence
429 information about memory-using instructions. This will tell you which store
430 feeds into a load, for example. It uses caching and other techniques to be
431 efficient, and is used by Dead Store Elimination, GVN, and memcpy optimizations.
435 Using the ``AliasSetTracker`` class
436 -----------------------------------
438 Many transformations need information about alias **sets** that are active in
439 some scope, rather than information about pairwise aliasing. The
440 `AliasSetTracker <http://llvm.org/doxygen/classllvm_1_1AliasSetTracker.html>`__
441 class is used to efficiently build these Alias Sets from the pairwise alias
442 analysis information provided by the ``AliasAnalysis`` interface.
444 First you initialize the AliasSetTracker by using the "``add``" methods to add
445 information about various potentially aliasing instructions in the scope you are
446 interested in. Once all of the alias sets are completed, your pass should
447 simply iterate through the constructed alias sets, using the ``AliasSetTracker``
448 ``begin()``/``end()`` methods.
450 The ``AliasSet``\s formed by the ``AliasSetTracker`` are guaranteed to be
451 disjoint, calculate mod/ref information and volatility for the set, and keep
452 track of whether or not all of the pointers in the set are Must aliases. The
453 AliasSetTracker also makes sure that sets are properly folded due to call
454 instructions, and can provide a list of pointers in each set.
456 As an example user of this, the `Loop Invariant Code Motion
457 <doxygen/structLICM.html>`_ pass uses ``AliasSetTracker``\s to calculate alias
458 sets for each loop nest. If an ``AliasSet`` in a loop is not modified, then all
459 load instructions from that set may be hoisted out of the loop. If any alias
460 sets are stored to **and** are must alias sets, then the stores may be sunk
461 to outside of the loop, promoting the memory location to a register for the
462 duration of the loop nest. Both of these transformations only apply if the
463 pointer argument is loop-invariant.
465 The AliasSetTracker implementation
466 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
468 The AliasSetTracker class is implemented to be as efficient as possible. It
469 uses the union-find algorithm to efficiently merge AliasSets when a pointer is
470 inserted into the AliasSetTracker that aliases multiple sets. The primary data
471 structure is a hash table mapping pointers to the AliasSet they are in.
473 The AliasSetTracker class must maintain a list of all of the LLVM ``Value*``\s
474 that are in each AliasSet. Since the hash table already has entries for each
475 LLVM ``Value*`` of interest, the AliasesSets thread the linked list through
476 these hash-table nodes to avoid having to allocate memory unnecessarily, and to
477 make merging alias sets extremely efficient (the linked list merge is constant
480 You shouldn't need to understand these details if you are just a client of the
481 AliasSetTracker, but if you look at the code, hopefully this brief description
482 will help make sense of why things are designed the way they are.
484 Using the ``AliasAnalysis`` interface directly
485 ----------------------------------------------
487 If neither of these utility class are what your pass needs, you should use the
488 interfaces exposed by the ``AliasAnalysis`` class directly. Try to use the
489 higher-level methods when possible (e.g., use mod/ref information instead of the
490 `alias`_ method directly if possible) to get the best precision and efficiency.
492 Existing alias analysis implementations and clients
493 ===================================================
495 If you're going to be working with the LLVM alias analysis infrastructure, you
496 should know what clients and implementations of alias analysis are available.
497 In particular, if you are implementing an alias analysis, you should be aware of
498 the `the clients`_ that are useful for monitoring and evaluating different
501 .. _various alias analysis implementations:
503 Available ``AliasAnalysis`` implementations
504 -------------------------------------------
506 This section lists the various implementations of the ``AliasAnalysis``
507 interface. With the exception of the `-no-aa`_ implementation, all of these
508 `chain`_ to other alias analysis implementations.
516 The ``-no-aa`` pass is just like what it sounds: an alias analysis that never
517 returns any useful information. This pass can be useful if you think that alias
518 analysis is doing something wrong and are trying to narrow down a problem.
520 The ``-basicaa`` pass
521 ^^^^^^^^^^^^^^^^^^^^^
523 The ``-basicaa`` pass is an aggressive local analysis that *knows* many
526 * Distinct globals, stack allocations, and heap allocations can never alias.
527 * Globals, stack allocations, and heap allocations never alias the null pointer.
528 * Different fields of a structure do not alias.
529 * Indexes into arrays with statically differing subscripts cannot alias.
530 * Many common standard C library functions `never access memory or only read
532 * Pointers that obviously point to constant globals "``pointToConstantMemory``".
533 * Function calls can not modify or references stack allocations if they never
534 escape from the function that allocates them (a common case for automatic
537 The ``-globalsmodref-aa`` pass
538 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
540 This pass implements a simple context-sensitive mod/ref and alias analysis for
541 internal global variables that don't "have their address taken". If a global
542 does not have its address taken, the pass knows that no pointers alias the
543 global. This pass also keeps track of functions that it knows never access
544 memory or never read memory. This allows certain optimizations (e.g. GVN) to
545 eliminate call instructions entirely.
547 The real power of this pass is that it provides context-sensitive mod/ref
548 information for call instructions. This allows the optimizer to know that calls
549 to a function do not clobber or read the value of the global, allowing loads and
550 stores to be eliminated.
554 This pass is somewhat limited in its scope (only support non-address taken
555 globals), but is very quick analysis.
557 The ``-steens-aa`` pass
558 ^^^^^^^^^^^^^^^^^^^^^^^
560 The ``-steens-aa`` pass implements a variation on the well-known "Steensgaard's
561 algorithm" for interprocedural alias analysis. Steensgaard's algorithm is a
562 unification-based, flow-insensitive, context-insensitive, and field-insensitive
563 alias analysis that is also very scalable (effectively linear time).
565 The LLVM ``-steens-aa`` pass implements a "speculatively field-**sensitive**"
566 version of Steensgaard's algorithm using the Data Structure Analysis framework.
567 This gives it substantially more precision than the standard algorithm while
568 maintaining excellent analysis scalability.
572 ``-steens-aa`` is available in the optional "poolalloc" module. It is not part
578 The ``-ds-aa`` pass implements the full Data Structure Analysis algorithm. Data
579 Structure Analysis is a modular unification-based, flow-insensitive,
580 context-**sensitive**, and speculatively field-**sensitive** alias
581 analysis that is also quite scalable, usually at ``O(n * log(n))``.
583 This algorithm is capable of responding to a full variety of alias analysis
584 queries, and can provide context-sensitive mod/ref information as well. The
585 only major facility not implemented so far is support for must-alias
590 ``-ds-aa`` is available in the optional "poolalloc" module. It is not part of
593 The ``-scev-aa`` pass
594 ^^^^^^^^^^^^^^^^^^^^^
596 The ``-scev-aa`` pass implements AliasAnalysis queries by translating them into
597 ScalarEvolution queries. This gives it a more complete understanding of
598 ``getelementptr`` instructions and loop induction variables than other alias
601 Alias analysis driven transformations
602 -------------------------------------
604 LLVM includes several alias-analysis driven transformations which can be used
605 with any of the implementations above.
610 The ``-adce`` pass, which implements Aggressive Dead Code Elimination uses the
611 ``AliasAnalysis`` interface to delete calls to functions that do not have
612 side-effects and are not used.
617 The ``-licm`` pass implements various Loop Invariant Code Motion related
618 transformations. It uses the ``AliasAnalysis`` interface for several different
621 * It uses mod/ref information to hoist or sink load instructions out of loops if
622 there are no instructions in the loop that modifies the memory loaded.
624 * It uses mod/ref information to hoist function calls out of loops that do not
625 write to memory and are loop-invariant.
627 * If uses alias information to promote memory objects that are loaded and stored
628 to in loops to live in a register instead. It can do this if there are no may
629 aliases to the loaded/stored memory location.
631 The ``-argpromotion`` pass
632 ^^^^^^^^^^^^^^^^^^^^^^^^^^
634 The ``-argpromotion`` pass promotes by-reference arguments to be passed in
635 by-value instead. In particular, if pointer arguments are only loaded from it
636 passes in the value loaded instead of the address to the function. This pass
637 uses alias information to make sure that the value loaded from the argument
638 pointer is not modified between the entry of the function and any load of the
641 The ``-gvn``, ``-memcpyopt``, and ``-dse`` passes
642 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
644 These passes use AliasAnalysis information to reason about loads and stores.
648 Clients for debugging and evaluation of implementations
649 -------------------------------------------------------
651 These passes are useful for evaluating the various alias analysis
652 implementations. You can use them with commands like:
656 % opt -ds-aa -aa-eval foo.bc -disable-output -stats
658 The ``-print-alias-sets`` pass
659 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
661 The ``-print-alias-sets`` pass is exposed as part of the ``opt`` tool to print
662 out the Alias Sets formed by the `AliasSetTracker`_ class. This is useful if
663 you're using the ``AliasSetTracker`` class. To use it, use something like:
667 % opt -ds-aa -print-alias-sets -disable-output
669 The ``-count-aa`` pass
670 ^^^^^^^^^^^^^^^^^^^^^^
672 The ``-count-aa`` pass is useful to see how many queries a particular pass is
673 making and what responses are returned by the alias analysis. As an example:
677 % opt -basicaa -count-aa -ds-aa -count-aa -licm
679 will print out how many queries (and what responses are returned) by the
680 ``-licm`` pass (of the ``-ds-aa`` pass) and how many queries are made of the
681 ``-basicaa`` pass by the ``-ds-aa`` pass. This can be useful when debugging a
682 transformation or an alias analysis implementation.
684 The ``-aa-eval`` pass
685 ^^^^^^^^^^^^^^^^^^^^^
687 The ``-aa-eval`` pass simply iterates through all pairs of pointers in a
688 function and asks an alias analysis whether or not the pointers alias. This
689 gives an indication of the precision of the alias analysis. Statistics are
690 printed indicating the percent of no/may/must aliases found (a more precise
691 algorithm will have a lower number of may aliases).
693 Memory Dependence Analysis
694 ==========================
696 If you're just looking to be a client of alias analysis information, consider
697 using the Memory Dependence Analysis interface instead. MemDep is a lazy,
698 caching layer on top of alias analysis that is able to answer the question of
699 what preceding memory operations a given instruction depends on, either at an
700 intra- or inter-block level. Because of its laziness and caching policy, using
701 MemDep can be a significant performance win over accessing alias analysis