You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 line
11KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Dependency analysis (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Dependency analysis (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Dependency analysis (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" rel="up" title="Loop Analysis and Representation">
  30. <link href="Machine-Desc.html#Machine-Desc" rel="next" title="Machine Desc">
  31. <link href="Number-of-iterations.html#Number-of-iterations" rel="prev" title="Number of iterations">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Dependency-analysis"></a>
  62. <div class="header">
  63. <p>
  64. Previous: <a href="Number-of-iterations.html#Number-of-iterations" accesskey="p" rel="prev">Number of iterations</a>, Up: <a href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Data-Dependency-Analysis"></a>
  68. <h3 class="section">16.8 Data Dependency Analysis</h3>
  69. <a name="index-Data-Dependency-Analysis"></a>
  70. <p>The code for the data dependence analysis can be found in
  71. <samp>tree-data-ref.c</samp> and its interface and data structures are
  72. described in <samp>tree-data-ref.h</samp>. The function that computes the
  73. data dependences for all the array and pointer references for a given
  74. loop is <code>compute_data_dependences_for_loop</code>. This function is
  75. currently used by the linear loop transform and the vectorization
  76. passes. Before calling this function, one has to allocate two vectors:
  77. a first vector will contain the set of data references that are
  78. contained in the analyzed loop body, and the second vector will contain
  79. the dependence relations between the data references. Thus if the
  80. vector of data references is of size <code>n</code>, the vector containing the
  81. dependence relations will contain <code>n*n</code> elements. However if the
  82. analyzed loop contains side effects, such as calls that potentially can
  83. interfere with the data references in the current analyzed loop, the
  84. analysis stops while scanning the loop body for data references, and
  85. inserts a single <code>chrec_dont_know</code> in the dependence relation
  86. array.
  87. </p>
  88. <p>The data references are discovered in a particular order during the
  89. scanning of the loop body: the loop body is analyzed in execution order,
  90. and the data references of each statement are pushed at the end of the
  91. data reference array. Two data references syntactically occur in the
  92. program in the same order as in the array of data references. This
  93. syntactic order is important in some classical data dependence tests,
  94. and mapping this order to the elements of this array avoids costly
  95. queries to the loop body representation.
  96. </p>
  97. <p>Three types of data references are currently handled: ARRAY_REF,
  98. INDIRECT_REF and COMPONENT_REF. The data structure for the data reference
  99. is <code>data_reference</code>, where <code>data_reference_p</code> is a name of a
  100. pointer to the data reference structure. The structure contains the
  101. following elements:
  102. </p>
  103. <ul>
  104. <li> <code>base_object_info</code>: Provides information about the base object
  105. of the data reference and its access functions. These access functions
  106. represent the evolution of the data reference in the loop relative to
  107. its base, in keeping with the classical meaning of the data reference
  108. access function for the support of arrays. For example, for a reference
  109. <code>a.b[i][j]</code>, the base object is <code>a.b</code> and the access functions,
  110. one for each array subscript, are:
  111. <code>{i_init, + i_step}_1, {j_init, +, j_step}_2</code>.
  112. </li><li> <code>first_location_in_loop</code>: Provides information about the first
  113. location accessed by the data reference in the loop and about the access
  114. function used to represent evolution relative to this location. This data
  115. is used to support pointers, and is not used for arrays (for which we
  116. have base objects). Pointer accesses are represented as a one-dimensional
  117. access that starts from the first location accessed in the loop. For
  118. example:
  119. <div class="smallexample">
  120. <pre class="smallexample"> for1 i
  121. for2 j
  122. *((int *)p + i + j) = a[i][j];
  123. </pre></div>
  124. <p>The access function of the pointer access is <code>{0, + 4B}_for2</code>
  125. relative to <code>p + i</code>. The access functions of the array are
  126. <code>{i_init, + i_step}_for1</code> and <code>{j_init, +, j_step}_for2</code>
  127. relative to <code>a</code>.
  128. </p>
  129. <p>Usually, the object the pointer refers to is either unknown, or we cannot
  130. prove that the access is confined to the boundaries of a certain object.
  131. </p>
  132. <p>Two data references can be compared only if at least one of these two
  133. representations has all its fields filled for both data references.
  134. </p>
  135. <p>The current strategy for data dependence tests is as follows:
  136. If both <code>a</code> and <code>b</code> are represented as arrays, compare
  137. <code>a.base_object</code> and <code>b.base_object</code>;
  138. if they are equal, apply dependence tests (use access functions based on
  139. base_objects).
  140. Else if both <code>a</code> and <code>b</code> are represented as pointers, compare
  141. <code>a.first_location</code> and <code>b.first_location</code>;
  142. if they are equal, apply dependence tests (use access functions based on
  143. first location).
  144. However, if <code>a</code> and <code>b</code> are represented differently, only try
  145. to prove that the bases are definitely different.
  146. </p>
  147. </li><li> Aliasing information.
  148. </li><li> Alignment information.
  149. </li></ul>
  150. <p>The structure describing the relation between two data references is
  151. <code>data_dependence_relation</code> and the shorter name for a pointer to
  152. such a structure is <code>ddr_p</code>. This structure contains:
  153. </p>
  154. <ul>
  155. <li> a pointer to each data reference,
  156. </li><li> a tree node <code>are_dependent</code> that is set to <code>chrec_known</code>
  157. if the analysis has proved that there is no dependence between these two
  158. data references, <code>chrec_dont_know</code> if the analysis was not able to
  159. determine any useful result and potentially there could exist a
  160. dependence between these data references, and <code>are_dependent</code> is
  161. set to <code>NULL_TREE</code> if there exist a dependence relation between the
  162. data references, and the description of this dependence relation is
  163. given in the <code>subscripts</code>, <code>dir_vects</code>, and <code>dist_vects</code>
  164. arrays,
  165. </li><li> a boolean that determines whether the dependence relation can be
  166. represented by a classical distance vector,
  167. </li><li> an array <code>subscripts</code> that contains a description of each
  168. subscript of the data references. Given two array accesses a
  169. subscript is the tuple composed of the access functions for a given
  170. dimension. For example, given <code>A[f1][f2][f3]</code> and
  171. <code>B[g1][g2][g3]</code>, there are three subscripts: <code>(f1, g1), (f2,
  172. g2), (f3, g3)</code>.
  173. </li><li> two arrays <code>dir_vects</code> and <code>dist_vects</code> that contain
  174. classical representations of the data dependences under the form of
  175. direction and distance dependence vectors,
  176. </li><li> an array of loops <code>loop_nest</code> that contains the loops to
  177. which the distance and direction vectors refer to.
  178. </li></ul>
  179. <p>Several functions for pretty printing the information extracted by the
  180. data dependence analysis are available: <code>dump_ddrs</code> prints with a
  181. maximum verbosity the details of a data dependence relations array,
  182. <code>dump_dist_dir_vectors</code> prints only the classical distance and
  183. direction vectors for a data dependence relations array, and
  184. <code>dump_data_references</code> prints the details of the data references
  185. contained in a data reference array.
  186. </p>
  187. <hr>
  188. <div class="header">
  189. <p>
  190. Previous: <a href="Number-of-iterations.html#Number-of-iterations" accesskey="p" rel="prev">Number of iterations</a>, Up: <a href="Loop-Analysis-and-Representation.html#Loop-Analysis-and-Representation" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  191. </div>
  192. </body>
  193. </html>