677 lines · plain
1==================================2LLVM Alias Analysis Infrastructure3==================================4 5.. contents::6 :local:7 8Introduction9============10 11Alias Analysis (aka Pointer Analysis) is a class of techniques which attempt to12determine whether or not two pointers ever can point to the same object in13memory. There are many different algorithms for alias analysis and many14different ways of classifying them: flow-sensitive vs. flow-insensitive,15context-sensitive vs. context-insensitive, field-sensitive16vs. field-insensitive, unification-based vs. subset-based, etc. Traditionally,17alias analyses respond to a query with a `Must, May, or No`_ alias response,18indicating that two pointers always point to the same object, might point to the19same object, or are known to never point to the same object.20 21The LLVM `AliasAnalysis22<https://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__ class is the23primary interface used by clients and implementations of alias analyses in the24LLVM system. This class is the common interface between clients of alias25analysis information and the implementations providing it, and is designed to26support a wide range of implementations and clients (but currently all clients27are assumed to be flow-insensitive). In addition to simple alias analysis28information, this class exposes Mod/Ref information from those implementations29which can provide it, allowing for powerful analyses and transformations to work30well together.31 32This document contains information necessary to successfully implement this33interface, use it, and to test both sides. It also explains some of the finer34points about what exactly results mean.35 36``AliasAnalysis`` Class Overview37================================38 39The `AliasAnalysis <https://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__40class defines the interface that the various alias analysis implementations41should support. This class exports two important enums: ``AliasResult`` and42``ModRefResult`` which represent the result of an alias query or a mod/ref43query, respectively.44 45The ``AliasAnalysis`` interface exposes information about memory, represented in46several different ways. In particular, memory objects are represented as a47starting address and size, and function calls are represented as the actual48``call`` or ``invoke`` instructions that perform the call. The49``AliasAnalysis`` interface also exposes some helper methods which allow you to50get mod/ref information for arbitrary instructions.51 52All ``AliasAnalysis`` interfaces require that in queries involving multiple53values, values which are not :ref:`constants <constants>` are all54defined within the same function.55 56Representation of Pointers57--------------------------58 59Most importantly, the ``AliasAnalysis`` class provides several methods which are60used to query whether or not two memory objects alias, whether function calls61can modify or read a memory object, etc. For all of these queries, memory62objects are represented as a pair of their starting address (a symbolic LLVM63``Value*``) and a static size.64 65Representing memory objects as a starting address and a size is critically66important for correct Alias Analyses. For example, consider this (silly, but67possible) C code:68 69.. code-block:: c++70 71 int i;72 char C[2];73 char A[10];74 /* ... */75 for (i = 0; i != 10; ++i) {76 C[0] = A[i]; /* One byte store */77 C[1] = A[9-i]; /* One byte store */78 }79 80In this case, the ``basic-aa`` pass will disambiguate the stores to ``C[0]`` and81``C[1]`` because they are accesses to two distinct locations one byte apart, and82the accesses are each one byte. In this case, the Loop Invariant Code Motion83(LICM) pass can use store motion to remove the stores from the loop. In84contrast, the following code:85 86.. code-block:: c++87 88 int i;89 char C[2];90 char A[10];91 /* ... */92 for (i = 0; i != 10; ++i) {93 ((short*)C)[0] = A[i]; /* Two byte store! */94 C[1] = A[9-i]; /* One byte store */95 }96 97In this case, the two stores to C do alias each other, because the access to the98``&C[0]`` element is a two byte access. If size information wasn't available in99the query, even the first case would have to conservatively assume that the100accesses alias.101 102.. _alias:103 104The ``alias`` method105--------------------106 107The ``alias`` method is the primary interface used to determine whether or not108two memory objects alias each other. It takes two memory objects as input and109returns MustAlias, PartialAlias, MayAlias, or NoAlias as appropriate.110 111Like all ``AliasAnalysis`` interfaces, the ``alias`` method requires that either112the two pointer values be defined within the same function, or at least one of113the values is a :ref:`constant <constants>`.114 115.. _Must, May, or No:116 117Must, May, and No Alias Responses118^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^119 120The ``NoAlias`` response may be used when there is never an immediate dependence121between any memory reference *based* on one pointer and any memory reference122*based on* the other. The most obvious example is when the two pointers point to123non-overlapping memory ranges. Another is when the two pointers are only ever124used for reading memory. Another is when the memory is freed and reallocated125between accesses through one pointer and accesses through the other --- in this126case, there is a dependence, but it's mediated by the free and reallocation.127 128An exception to this is with the :ref:`noalias <noalias>` keyword;129the "irrelevant" dependencies are ignored.130 131The ``MayAlias`` response is used whenever the two pointers might refer to the132same object.133 134The ``PartialAlias`` response is used when the two memory objects are known to135be overlapping in some way, regardless of whether they start at the same address136or not.137 138The ``MustAlias`` response may only be returned if the two memory objects are139guaranteed to always start at exactly the same location. A ``MustAlias``140response does not imply that the pointers compare equal.141 142The ``getModRefInfo`` methods143-----------------------------144 145The ``getModRefInfo`` methods return information about whether the execution of146an instruction can read or modify a memory location. Mod/Ref information is147always conservative: if an instruction **might** read or write a location,148``ModRef`` is returned.149 150The ``AliasAnalysis`` class also provides a ``getModRefInfo`` method for testing151dependencies between function calls. This method takes two call sites (``CS1``152& ``CS2``), returns ``NoModRef`` if neither call writes to memory read or153written by the other, ``Ref`` if ``CS1`` reads memory written by ``CS2``,154``Mod`` if ``CS1`` writes to memory read or written by ``CS2``, or ``ModRef`` if155``CS1`` might read or write memory written to by ``CS2``. Note that this156relation is not commutative.157 158Other useful ``AliasAnalysis`` methods159--------------------------------------160 161Several other tidbits of information are often collected by various alias162analysis implementations and can be put to good use by various clients.163 164The ``getModRefInfoMask`` method165^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^166 167The ``getModRefInfoMask`` method returns a bound on Mod/Ref information for168the supplied pointer, based on knowledge about whether the pointer points to169globally-constant memory (for which it returns ``NoModRef``) or170locally-invariant memory (for which it returns ``Ref``). Globally-constant171memory includes functions, constant global variables, and the null pointer.172Locally-invariant memory is memory that we know is invariant for the lifetime173of its SSA value, but not necessarily for the life of the program: for example,174the memory pointed to by ``readonly`` ``noalias`` parameters is known-invariant175for the duration of the corresponding function call. Given Mod/Ref information176``MRI`` for a memory location ``Loc``, ``MRI`` can be refined with a statement177like ``MRI &= AA.getModRefInfoMask(Loc);``. Another useful idiom is178``isModSet(AA.getModRefInfoMask(Loc))``; this checks to see if the given179location can be modified at all. For convenience, there is also a method180``pointsToConstantMemory(Loc)``; this is synonymous with181``isNoModRef(AA.getModRefInfoMask(Loc))``.182 183.. _never access memory or only read memory:184 185The ``doesNotAccessMemory`` and ``onlyReadsMemory`` methods186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^187 188These methods are used to provide very simple mod/ref information for function189calls. The ``doesNotAccessMemory`` method returns true for a function if the190analysis can prove that the function never reads or writes to memory, or if the191function only reads from constant memory. Functions with this property are192side-effect free and only depend on their input arguments, allowing them to be193eliminated if they form common subexpressions or be hoisted out of loops. Many194common functions behave this way (e.g., ``sin`` and ``cos``) but many others do195not (e.g., ``acos``, which modifies the ``errno`` variable).196 197The ``onlyReadsMemory`` method returns true for a function if analysis can prove198that (at most) the function only reads from non-volatile memory. Functions with199this property are side-effect free, only depending on their input arguments and200the state of memory when they are called. This property allows calls to these201functions to be eliminated and moved around, as long as there is no store202instruction that changes the contents of memory. Note that all functions that203satisfy the ``doesNotAccessMemory`` method also satisfy ``onlyReadsMemory``.204 205Writing a new ``AliasAnalysis`` Implementation206==============================================207 208Writing a new alias analysis implementation for LLVM is quite straightforward.209There are already several implementations that you can use for examples, and the210following information should help fill in any details. For example, take a211look at the `various alias analysis implementations`_ included with LLVM.212 213Different Pass styles214---------------------215 216The first step is to determine what type of :doc:`LLVM pass <WritingAnLLVMPass>`217you need to use for your Alias Analysis. As is the case with most other218analyses and transformations, the answer should be fairly obvious from what type219of problem you are trying to solve:220 221#. If you require interprocedural analysis, it should be a ``Pass``.222#. If you are a function-local analysis, subclass ``FunctionPass``.223#. If you don't need to look at the program at all, subclass ``ImmutablePass``.224 225In addition to the pass that you subclass, you should also inherit from the226``AliasAnalysis`` interface, of course, and use the ``RegisterAnalysisGroup``227template to register as an implementation of ``AliasAnalysis``.228 229Required initialization calls230-----------------------------231 232Your subclass of ``AliasAnalysis`` is required to invoke two methods on the233``AliasAnalysis`` base class: ``getAnalysisUsage`` and234``InitializeAliasAnalysis``. In particular, your implementation of235``getAnalysisUsage`` should explicitly call into the236``AliasAnalysis::getAnalysisUsage`` method in addition to declaring237any pass dependencies your pass has. Thus you should have something like this:238 239.. code-block:: c++240 241 void getAnalysisUsage(AnalysisUsage &AU) const {242 AliasAnalysis::getAnalysisUsage(AU);243 // declare your dependencies here.244 }245 246Additionally, you must invoke the ``InitializeAliasAnalysis`` method from your247analysis run method (``run`` for a ``Pass``, ``runOnFunction`` for a248``FunctionPass``, or ``InitializePass`` for an ``ImmutablePass``). For example249(as part of a ``Pass``):250 251.. code-block:: c++252 253 bool run(Module &M) {254 InitializeAliasAnalysis(this);255 // Perform analysis here...256 return false;257 }258 259Interfaces which may be specified260---------------------------------261 262All of the `AliasAnalysis263<https://llvm.org/doxygen/classllvm_1_1AliasAnalysis.html>`__ virtual methods264default to providing :ref:`chaining <aliasanalysis-chaining>` to another alias265analysis implementation, which ends up returning conservatively correct266information (returning "May" Alias and "Mod/Ref" for alias and mod/ref queries267respectively). Depending on the capabilities of the analysis you are268implementing, you just override the interfaces you can improve.269 270.. _aliasanalysis-chaining:271 272``AliasAnalysis`` chaining behavior273-----------------------------------274 275Every alias analysis pass chains to another alias analysis implementation (for276example, the user can specify "``-basic-aa -ds-aa -licm``" to get the maximum277benefit from both alias analyses). The alias analysis class automatically278takes care of most of this for methods that you don't override. For methods279that you do override, in code paths that return a conservative MayAlias or280Mod/Ref result, simply return whatever the superclass computes. For example:281 282.. code-block:: c++283 284 AliasResult alias(const Value *V1, unsigned V1Size,285 const Value *V2, unsigned V2Size) {286 if (...)287 return NoAlias;288 ...289 290 // Couldn't determine a must or no-alias result.291 return AliasAnalysis::alias(V1, V1Size, V2, V2Size);292 }293 294In addition to analysis queries, you must make sure to unconditionally pass LLVM295`update notification`_ methods to the superclass as well if you override them,296which allows all alias analyses in a change to be updated.297 298.. _update notification:299 300Updating analysis results for transformations301---------------------------------------------302 303Alias analysis information is initially computed for a static snapshot of the304program, but clients will use this information to make transformations to the305code. All but the most trivial forms of alias analysis will need to have their306analysis results updated to reflect the changes made by these transformations.307 308The ``AliasAnalysis`` interface exposes four methods which are used to309communicate program changes from the clients to the analysis implementations.310Various alias analysis implementations should use these methods to ensure that311their internal data structures are kept up-to-date as the program changes (for312example, when an instruction is deleted), and clients of alias analysis must be313sure to call these interfaces appropriately.314 315The ``deleteValue`` method316^^^^^^^^^^^^^^^^^^^^^^^^^^317 318The ``deleteValue`` method is called by transformations when they remove an319instruction or any other value from the program (including values that do not320use pointers). Typically alias analyses keep data structures that have entries321for each value in the program. When this method is called, they should remove322any entries for the specified value, if they exist.323 324The ``copyValue`` method325^^^^^^^^^^^^^^^^^^^^^^^^326 327The ``copyValue`` method is used when a new value is introduced into the328program. There is no way to introduce a value into the program that did not329exist before (this doesn't make sense for a safe compiler transformation), so330this is the only way to introduce a new value. This method indicates that the331new value has exactly the same properties as the value being copied.332 333The ``replaceWithNewValue`` method334^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^335 336This method is a simple helper method that is provided to make clients easier to337use. It is implemented by copying the old analysis information to the new338value, then deleting the old value. This method cannot be overridden by alias339analysis implementations.340 341The ``addEscapingUse`` method342^^^^^^^^^^^^^^^^^^^^^^^^^^^^^343 344The ``addEscapingUse`` method is used when the uses of a pointer value have345changed in ways that may invalidate precomputed analysis information.346Implementations may either use this callback to provide conservative responses347for points whose uses have changed since analysis time, or may recompute some or348all of their internal state to continue providing accurate responses.349 350In general, any new use of a pointer value is considered an escaping use, and351must be reported through this callback, *except* for the uses below:352 353* A ``bitcast`` or ``getelementptr`` of the pointer354* A ``store`` through the pointer (but not a ``store`` *of* the pointer)355* A ``load`` through the pointer356 357Efficiency Issues358-----------------359 360From the LLVM perspective, the only thing you need to do to provide an efficient361alias analysis is to make sure that alias analysis **queries** are serviced362quickly. The actual calculation of the alias analysis results (the "run"363method) is only performed once, but many (perhaps duplicate) queries may be364performed. Because of this, try to move as much computation to the run method365as possible (within reason).366 367Limitations368-----------369 370The AliasAnalysis infrastructure has several limitations which make writing a371new ``AliasAnalysis`` implementation difficult.372 373There is no way to override the default alias analysis. It would be very useful374to be able to do something like "``opt -my-aa -O2``" and have it use ``-my-aa``375for all passes which need AliasAnalysis, but there is currently no support for376that, short of changing the source code and recompiling. Similarly, there is377also no way of setting a chain of analyses as the default.378 379There is no way for transform passes to declare that they preserve380``AliasAnalysis`` implementations. The ``AliasAnalysis`` interface includes381``deleteValue`` and ``copyValue`` methods which are intended to allow a pass to382keep an AliasAnalysis consistent; however, there's no way for a pass to declare383in its ``getAnalysisUsage`` that it does so. Some passes attempt to use384``AU.addPreserved<AliasAnalysis>``; however, this doesn't actually have any385effect.386 387Similarly, the ``opt -p`` option introduces ``ModulePass`` passes between each388pass, which prevents the use of ``FunctionPass`` alias analysis passes.389 390The ``AliasAnalysis`` API does have functions for notifying implementations when391values are deleted or copied; however, these aren't sufficient. There are many392other ways that LLVM IR can be modified which could be relevant to393``AliasAnalysis`` implementations which can not be expressed.394 395The ``AliasAnalysisDebugger`` utility seems to suggest that ``AliasAnalysis``396implementations can expect that they will be informed of any relevant ``Value``397before it appears in an alias query. However, popular clients such as ``GVN``398don't support this, and are known to trigger errors when run with the399``AliasAnalysisDebugger``.400 401The ``AliasSetTracker`` class (which is used by ``LICM``) makes a402non-deterministic number of alias queries. This can cause debugging techniques403involving pausing execution after a predetermined number of queries to be404unreliable.405 406Many alias queries can be reformulated in terms of other alias queries. When407multiple ``AliasAnalysis`` queries are chained together, it would make sense to408start those queries from the beginning of the chain, with care taken to avoid409infinite looping; however, currently an implementation which wants to do this can410only start such queries from itself.411 412Using alias analysis results413============================414 415There are several different ways to use alias analysis results. In order of416preference, these are:417 418Using the ``MemoryDependenceAnalysis`` Pass419-------------------------------------------420 421The ``memdep`` pass uses alias analysis to provide high-level dependence422information about memory-using instructions. This will tell you which store423feeds into a load, for example. It uses caching and other techniques to be424efficient, and is used by Dead Store Elimination, GVN, and memcpy optimizations.425 426.. _AliasSetTracker:427 428Using the ``AliasSetTracker`` class429-----------------------------------430 431Many transformations need information about alias **sets** that are active in432some scope, rather than information about pairwise aliasing. The433`AliasSetTracker <https://llvm.org/doxygen/classllvm_1_1AliasSetTracker.html>`__434class is used to efficiently build these Alias Sets from the pairwise alias435analysis information provided by the ``AliasAnalysis`` interface.436 437First you initialize the AliasSetTracker by using the "``add``" methods to add438information about various potentially aliasing instructions in the scope you are439interested in. Once all of the alias sets are completed, your pass should440simply iterate through the constructed alias sets, using the ``AliasSetTracker``441``begin()``/``end()`` methods.442 443The ``AliasSet``\s formed by the ``AliasSetTracker`` are guaranteed to be444disjoint, calculate mod/ref information and volatility for the set, and keep445track of whether or not all of the pointers in the set are Must aliases. The446AliasSetTracker also makes sure that sets are properly folded due to call447instructions, and can provide a list of pointers in each set.448 449As an example user of this, the `Loop Invariant Code Motion450<doxygen/structLICM.html>`_ pass uses ``AliasSetTracker``\s to calculate alias451sets for each loop nest. If an ``AliasSet`` in a loop is not modified, then all452load instructions from that set may be hoisted out of the loop. If any alias453sets are stored to **and** are must alias sets, then the stores may be sunk454to outside of the loop, promoting the memory location to a register for the455duration of the loop nest. Both of these transformations only apply if the456pointer argument is loop-invariant.457 458The AliasSetTracker implementation459^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^460 461The AliasSetTracker class is implemented to be as efficient as possible. It462uses the union-find algorithm to efficiently merge AliasSets when a pointer is463inserted into the AliasSetTracker that aliases multiple sets. The primary data464structure is a hash table mapping pointers to the AliasSet they are in.465 466The AliasSetTracker class must maintain a list of all of the LLVM ``Value*``\s467that are in each AliasSet. Since the hash table already has entries for each468LLVM ``Value*`` of interest, the AliasesSets thread the linked list through469these hash-table nodes to avoid having to allocate memory unnecessarily, and to470make merging alias sets extremely efficient (the linked list merge is constant471time).472 473You shouldn't need to understand these details if you are just a client of the474AliasSetTracker, but if you look at the code, hopefully this brief description475will help make sense of why things are designed the way they are.476 477Using the ``AliasAnalysis`` interface directly478----------------------------------------------479 480If neither of these utility classes are what your pass needs, you should use the481interfaces exposed by the ``AliasAnalysis`` class directly. Try to use the482higher-level methods when possible (e.g., use mod/ref information instead of the483`alias`_ method directly if possible) to get the best precision and efficiency.484 485Existing alias analysis implementations and clients486===================================================487 488If you're going to be working with the LLVM alias analysis infrastructure, you489should know what clients and implementations of alias analysis are available.490In particular, if you are implementing an alias analysis, you should be aware of491`the clients`_ that are useful for monitoring and evaluating different492implementations.493 494.. _various alias analysis implementations:495 496Available ``AliasAnalysis`` implementations497-------------------------------------------498 499This section lists the various implementations of the ``AliasAnalysis``500interface. All of these :ref:`chain <aliasanalysis-chaining>` to other501alias analysis implementations.502 503The ``-basic-aa`` pass504^^^^^^^^^^^^^^^^^^^^^^505 506The ``-basic-aa`` pass is an aggressive local analysis that *knows* many507important facts:508 509* Distinct globals, stack allocations, and heap allocations can never alias.510* Globals, stack allocations, and heap allocations never alias the null pointer.511* Different fields of a structure do not alias.512* Indexes into arrays with statically differing subscripts cannot alias.513* Many common standard C library functions `never access memory or only read514 memory`_.515* Pointers that obviously point to constant globals "``pointToConstantMemory``".516* Function calls cannot modify or reference stack allocations if they never517 escape from the function that allocates them (a common case for automatic518 arrays).519 520The ``-globalsmodref-aa`` pass521^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^522 523This pass implements a simple context-sensitive mod/ref and alias analysis for524internal global variables that don't "have their address taken". If a global525does not have its address taken, the pass knows that no pointers alias the526global. This pass also keeps track of functions that it knows never access527memory or never read memory. This allows certain optimizations (e.g. GVN) to528eliminate call instructions entirely.529 530The real power of this pass is that it provides context-sensitive mod/ref531information for call instructions. This allows the optimizer to know that calls532to a function do not clobber or read the value of the global, allowing loads and533stores to be eliminated.534 535.. note::536 537 This pass is somewhat limited in its scope (only support non-address taken538 globals), but is very quick analysis.539 540The ``-steens-aa`` pass541^^^^^^^^^^^^^^^^^^^^^^^542 543The ``-steens-aa`` pass implements a variation on the well-known "Steensgaard's544algorithm" for interprocedural alias analysis. Steensgaard's algorithm is a545unification-based, flow-insensitive, context-insensitive, and field-insensitive546alias analysis that is also very scalable (effectively linear time).547 548The LLVM ``-steens-aa`` pass implements a "speculatively field-**sensitive**"549version of Steensgaard's algorithm using the Data Structure Analysis framework.550This gives it substantially more precision than the standard algorithm while551maintaining excellent analysis scalability.552 553.. note::554 555 ``-steens-aa`` is available in the optional "poolalloc" module. It is not part556 of the LLVM core.557 558The ``-ds-aa`` pass559^^^^^^^^^^^^^^^^^^^560 561The ``-ds-aa`` pass implements the full Data Structure Analysis algorithm. Data562Structure Analysis is a modular unification-based, flow-insensitive,563context-**sensitive**, and speculatively field-**sensitive** alias564analysis that is also quite scalable, usually at ``O(n * log(n))``.565 566This algorithm is capable of responding to a full variety of alias analysis567queries, and can provide context-sensitive mod/ref information as well. The568only major facility not implemented so far is support for must-alias569information.570 571.. note::572 573 ``-ds-aa`` is available in the optional "poolalloc" module. It is not part of574 the LLVM core.575 576The ``-scev-aa`` pass577^^^^^^^^^^^^^^^^^^^^^578 579The ``-scev-aa`` pass implements AliasAnalysis queries by translating them into580ScalarEvolution queries. This gives it a more complete understanding of581``getelementptr`` instructions and loop induction variables than other alias582analyses have.583 584Alias analysis driven transformations585-------------------------------------586 587LLVM includes several alias-analysis driven transformations which can be used588with any of the implementations above.589 590The ``-adce`` pass591^^^^^^^^^^^^^^^^^^592 593The ``-adce`` pass, which implements Aggressive Dead Code Elimination, uses the594``AliasAnalysis`` interface to delete calls to functions that do not have595side-effects and are not used.596 597The ``-licm`` pass598^^^^^^^^^^^^^^^^^^599 600The ``-licm`` pass implements various Loop Invariant Code Motion related601transformations. It uses the ``AliasAnalysis`` interface for several different602transformations:603 604* It uses mod/ref information to hoist or sink load instructions out of loops if605 no instructions in the loop modify the memory loaded.606 607* It uses mod/ref information to hoist function calls out of loops that do not608 write to memory and are loop-invariant.609 610* It uses alias information to promote memory objects that are loaded and stored611 to in loops to live in a register instead. It can do this if there are no may612 aliases to the loaded/stored memory location.613 614The ``-argpromotion`` pass615^^^^^^^^^^^^^^^^^^^^^^^^^^616 617The ``-argpromotion`` pass promotes by-reference arguments to be passed in618by-value instead. In particular, if pointer arguments are only loaded from, it619passes in the value loaded instead of the address to the function. This pass620uses alias information to make sure that the value loaded from the argument621pointer is not modified between the entry of the function and any load of the622pointer.623 624The ``-gvn``, ``-memcpyopt``, and ``-dse`` passes625^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^626 627These passes use AliasAnalysis information to reason about loads and stores.628 629.. _the clients:630 631Clients for debugging and evaluation of implementations632-------------------------------------------------------633 634These passes are useful for evaluating the various alias analysis635implementations. You can use them with commands like:636 637.. code-block:: bash638 639 % opt -ds-aa -aa-eval foo.bc -disable-output -stats640 641The ``-print-alias-sets`` pass642^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^643 644The ``-print-alias-sets`` pass is exposed as part of the ``opt`` tool to print645out the Alias Sets formed by the `AliasSetTracker`_ class. This is useful if646you're using the ``AliasSetTracker`` class. To use it, use something like:647 648.. code-block:: bash649 650 % opt -ds-aa -print-alias-sets -disable-output651 652The ``-aa-eval`` pass653^^^^^^^^^^^^^^^^^^^^^654 655The ``-aa-eval`` pass simply iterates through all pairs of pointers in a656function and asks an alias analysis whether or not the pointers alias. This657gives an indication of the precision of the alias analysis. Statistics are658printed indicating the percent of no/may/must aliases found (a more precise659algorithm will have a lower number of may aliases).660 661Memory Dependence Analysis662==========================663 664.. note::665 666 We are currently in the process of migrating things from667 ``MemoryDependenceAnalysis`` to :doc:`MemorySSA`. Please try to use668 that instead.669 670If you're just looking to be a client of alias analysis information, consider671using the Memory Dependence Analysis interface instead. MemDep is a lazy,672caching layer on top of alias analysis that is able to answer the question of673what preceding memory operations a given instruction depends on, either at an674intra- or inter-block level. Because of its laziness and caching policy, using675MemDep can be a significant performance win over accessing alias analysis676directly.677