<html lang="en"> <head> <title>Alias analysis - GNU Compiler Collection (GCC) Internals</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Compiler Collection (GCC) Internals"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Tree-SSA.html#Tree-SSA" title="Tree SSA"> <link rel="prev" href="SSA.html#SSA" title="SSA"> <link rel="next" href="Memory-model.html#Memory-model" title="Memory model"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- Copyright (C) 1988-2015 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being ``Funding Free Software'', the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled ``GNU Free Documentation License''. (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.--> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Alias-analysis"></a> <p> Next: <a rel="next" accesskey="n" href="Memory-model.html#Memory-model">Memory model</a>, Previous: <a rel="previous" accesskey="p" href="SSA.html#SSA">SSA</a>, Up: <a rel="up" accesskey="u" href="Tree-SSA.html#Tree-SSA">Tree SSA</a> <hr> </div> <h3 class="section">12.4 Alias analysis</h3> <p><a name="index-alias-2530"></a><a name="index-flow_002dsensitive-alias-analysis-2531"></a><a name="index-flow_002dinsensitive-alias-analysis-2532"></a> Alias analysis in GIMPLE SSA form consists of two pieces. First the virtual SSA web ties conflicting memory accesses and provides a SSA use-def chain and SSA immediate-use chains for walking possibly dependent memory accesses. Second an alias-oracle can be queried to disambiguate explicit and implicit memory references. <ol type=1 start=1> <li>Memory SSA form. <p>All statements that may use memory have exactly one accompanied use of a virtual SSA name that represents the state of memory at the given point in the IL. <p>All statements that may define memory have exactly one accompanied definition of a virtual SSA name using the previous state of memory and defining the new state of memory after the given point in the IL. <pre class="smallexample"> int i; int foo (void) { # .MEM_3 = VDEF <.MEM_2(D)> i = 1; # VUSE <.MEM_3> return i; } </pre> <p>The virtual SSA names in this case are <code>.MEM_2(D)</code> and <code>.MEM_3</code>. The store to the global variable <code>i</code> defines <code>.MEM_3</code> invalidating <code>.MEM_2(D)</code>. The load from <code>i</code> uses that new state <code>.MEM_3</code>. <p>The virtual SSA web serves as constraints to SSA optimizers preventing illegitimate code-motion and optimization. It also provides a way to walk related memory statements. <li>Points-to and escape analysis. <p>Points-to analysis builds a set of constraints from the GIMPLE SSA IL representing all pointer operations and facts we do or do not know about pointers. Solving this set of constraints yields a conservatively correct solution for each pointer variable in the program (though we are only interested in SSA name pointers) as to what it may possibly point to. <p>This points-to solution for a given SSA name pointer is stored in the <code>pt_solution</code> sub-structure of the <code>SSA_NAME_PTR_INFO</code> record. The following accessor functions are available: <ul> <li><code>pt_solution_includes</code> <li><code>pt_solutions_intersect</code> </ul> <p>Points-to analysis also computes the solution for two special set of pointers, <code>ESCAPED</code> and <code>CALLUSED</code>. Those represent all memory that has escaped the scope of analysis or that is used by pure or nested const calls. <li>Type-based alias analysis <p>Type-based alias analysis is frontend dependent though generic support is provided by the middle-end in <code>alias.c</code>. TBAA code is used by both tree optimizers and RTL optimizers. <p>Every language that wishes to perform language-specific alias analysis should define a function that computes, given a <code>tree</code> node, an alias set for the node. Nodes in different alias sets are not allowed to alias. For an example, see the C front-end function <code>c_get_alias_set</code>. <li>Tree alias-oracle <p>The tree alias-oracle provides means to disambiguate two memory references and memory references against statements. The following queries are available: <ul> <li><code>refs_may_alias_p</code> <li><code>ref_maybe_used_by_stmt_p</code> <li><code>stmt_may_clobber_ref_p</code> </ul> <p>In addition to those two kind of statement walkers are available walking statements related to a reference ref. <code>walk_non_aliased_vuses</code> walks over dominating memory defining statements and calls back if the statement does not clobber ref providing the non-aliased VUSE. The walk stops at the first clobbering statement or if asked to. <code>walk_aliased_vdefs</code> walks over dominating memory defining statements and calls back on each statement clobbering ref providing its aliasing VDEF. The walk stops if asked to. </ol> </body></html>