Tuple-representation.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Tuple representation</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Tuple representation">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Tuple representation">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="GIMPLE.html#GIMPLE" rel="up" title="GIMPLE">
  30. <link href="Class-hierarchy-of-GIMPLE-statements.html#Class-hierarchy-of-GIMPLE-statements" rel="next" title="Class hierarchy of GIMPLE statements">
  31. <link href="GIMPLE.html#GIMPLE" rel="prev" title="GIMPLE">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Tuple-representation"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Class-hierarchy-of-GIMPLE-statements.html#Class-hierarchy-of-GIMPLE-statements" accesskey="n" rel="next">Class hierarchy of GIMPLE statements</a>, Up: <a href="GIMPLE.html#GIMPLE" accesskey="u" rel="up">GIMPLE</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>
  66. </div>
  67. <hr>
  68. <a name="Tuple-representation-1"></a>
  69. <h3 class="section">11.1 Tuple representation</h3>
  70. <a name="index-tuples"></a>
  71. <p>GIMPLE instructions are tuples of variable size divided in two
  72. groups: a header describing the instruction and its locations,
  73. and a variable length body with all the operands. Tuples are
  74. organized into a hierarchy with 3 main classes of tuples.
  75. </p>
  76. <a name="gimple-_0028gsbase_0029"></a>
  77. <h4 class="subsection">11.1.1 <code>gimple</code> (gsbase)</h4>
  78. <a name="index-gimple"></a>
  79. <p>This is the root of the hierarchy, it holds basic information
  80. needed by most GIMPLE statements. There are some fields that
  81. may not be relevant to every GIMPLE statement, but those were
  82. moved into the base structure to take advantage of holes left by
  83. other fields (thus making the structure more compact). The
  84. structure takes 4 words (32 bytes) on 64 bit hosts:
  85. </p>
  86. <table>
  87. <tr><td>Field</td><td>Size (bits)</td></tr>
  88. <tr><td><code>code</code></td><td>8</td></tr>
  89. <tr><td><code>subcode</code></td><td>16</td></tr>
  90. <tr><td><code>no_warning</code></td><td>1</td></tr>
  91. <tr><td><code>visited</code></td><td>1</td></tr>
  92. <tr><td><code>nontemporal_move</code></td><td>1</td></tr>
  93. <tr><td><code>plf</code></td><td>2</td></tr>
  94. <tr><td><code>modified</code></td><td>1</td></tr>
  95. <tr><td><code>has_volatile_ops</code></td><td>1</td></tr>
  96. <tr><td><code>references_memory_p</code></td><td>1</td></tr>
  97. <tr><td><code>uid</code></td><td>32</td></tr>
  98. <tr><td><code>location</code></td><td>32</td></tr>
  99. <tr><td><code>num_ops</code></td><td>32</td></tr>
  100. <tr><td><code>bb</code></td><td>64</td></tr>
  101. <tr><td><code>block</code></td><td>63</td></tr>
  102. <tr><td>Total size</td><td>32 bytes</td></tr>
  103. </table>
  104. <ul>
  105. <li> <code>code</code>
  106. Main identifier for a GIMPLE instruction.
  107. </li><li> <code>subcode</code>
  108. Used to distinguish different variants of the same basic
  109. instruction or provide flags applicable to a given code. The
  110. <code>subcode</code> flags field has different uses depending on the code of
  111. the instruction, but mostly it distinguishes instructions of the
  112. same family. The most prominent use of this field is in
  113. assignments, where subcode indicates the operation done on the
  114. RHS of the assignment. For example, a = b + c is encoded as
  115. <code>GIMPLE_ASSIGN &lt;PLUS_EXPR, a, b, c&gt;</code>.
  116. </li><li> <code>no_warning</code>
  117. Bitflag to indicate whether a warning has already been issued on
  118. this statement.
  119. </li><li> <code>visited</code>
  120. General purpose &ldquo;visited&rdquo; marker. Set and cleared by each pass
  121. when needed.
  122. </li><li> <code>nontemporal_move</code>
  123. Bitflag used in assignments that represent non-temporal moves.
  124. Although this bitflag is only used in assignments, it was moved
  125. into the base to take advantage of the bit holes left by the
  126. previous fields.
  127. </li><li> <code>plf</code>
  128. Pass Local Flags. This 2-bit mask can be used as general purpose
  129. markers by any pass. Passes are responsible for clearing and
  130. setting these two flags accordingly.
  131. </li><li> <code>modified</code>
  132. Bitflag to indicate whether the statement has been modified.
  133. Used mainly by the operand scanner to determine when to re-scan a
  134. statement for operands.
  135. </li><li> <code>has_volatile_ops</code>
  136. Bitflag to indicate whether this statement contains operands that
  137. have been marked volatile.
  138. </li><li> <code>references_memory_p</code>
  139. Bitflag to indicate whether this statement contains memory
  140. references (i.e., its operands are either global variables, or
  141. pointer dereferences or anything that must reside in memory).
  142. </li><li> <code>uid</code>
  143. This is an unsigned integer used by passes that want to assign
  144. IDs to every statement. These IDs must be assigned and used by
  145. each pass.
  146. </li><li> <code>location</code>
  147. This is a <code>location_t</code> identifier to specify source code
  148. location for this statement. It is inherited from the front
  149. end.
  150. </li><li> <code>num_ops</code>
  151. Number of operands that this statement has. This specifies the
  152. size of the operand vector embedded in the tuple. Only used in
  153. some tuples, but it is declared in the base tuple to take
  154. advantage of the 32-bit hole left by the previous fields.
  155. </li><li> <code>bb</code>
  156. Basic block holding the instruction.
  157. </li><li> <code>block</code>
  158. Lexical block holding this statement. Also used for debug
  159. information generation.
  160. </li></ul>
  161. <a name="gimple_005fstatement_005fwith_005fops"></a>
  162. <h4 class="subsection">11.1.2 <code>gimple_statement_with_ops</code></h4>
  163. <a name="index-gimple_005fstatement_005fwith_005fops"></a>
  164. <p>This tuple is actually split in two:
  165. <code>gimple_statement_with_ops_base</code> and
  166. <code>gimple_statement_with_ops</code>. This is needed to accommodate the
  167. way the operand vector is allocated. The operand vector is
  168. defined to be an array of 1 element. So, to allocate a dynamic
  169. number of operands, the memory allocator (<code>gimple_alloc</code>) simply
  170. allocates enough memory to hold the structure itself plus <code>N
  171. - 1</code> operands which run &ldquo;off the end&rdquo; of the structure. For
  172. example, to allocate space for a tuple with 3 operands,
  173. <code>gimple_alloc</code> reserves <code>sizeof (struct
  174. gimple_statement_with_ops) + 2 * sizeof (tree)</code> bytes.
  175. </p>
  176. <p>On the other hand, several fields in this tuple need to be shared
  177. with the <code>gimple_statement_with_memory_ops</code> tuple. So, these
  178. common fields are placed in <code>gimple_statement_with_ops_base</code> which
  179. is then inherited from the other two tuples.
  180. </p>
  181. <table>
  182. <tr><td><code>gsbase</code></td><td>256</td></tr>
  183. <tr><td><code>def_ops</code></td><td>64</td></tr>
  184. <tr><td><code>use_ops</code></td><td>64</td></tr>
  185. <tr><td><code>op</code></td><td><code>num_ops</code> * 64</td></tr>
  186. <tr><td>Total size</td><td>48 + 8 * <code>num_ops</code> bytes</td></tr>
  187. </table>
  188. <ul>
  189. <li> <code>gsbase</code>
  190. Inherited from <code>struct gimple</code>.
  191. </li><li> <code>def_ops</code>
  192. Array of pointers into the operand array indicating all the slots that
  193. contain a variable written-to by the statement. This array is
  194. also used for immediate use chaining. Note that it would be
  195. possible to not rely on this array, but the changes required to
  196. implement this are pretty invasive.
  197. </li><li> <code>use_ops</code>
  198. Similar to <code>def_ops</code> but for variables read by the statement.
  199. </li><li> <code>op</code>
  200. Array of trees with <code>num_ops</code> slots.
  201. </li></ul>
  202. <a name="gimple_005fstatement_005fwith_005fmemory_005fops"></a>
  203. <h4 class="subsection">11.1.3 <code>gimple_statement_with_memory_ops</code></h4>
  204. <p>This tuple is essentially identical to <code>gimple_statement_with_ops</code>,
  205. except that it contains 4 additional fields to hold vectors
  206. related memory stores and loads. Similar to the previous case,
  207. the structure is split in two to accommodate for the operand
  208. vector (<code>gimple_statement_with_memory_ops_base</code> and
  209. <code>gimple_statement_with_memory_ops</code>).
  210. </p>
  211. <table>
  212. <tr><td>Field</td><td>Size (bits)</td></tr>
  213. <tr><td><code>gsbase</code></td><td>256</td></tr>
  214. <tr><td><code>def_ops</code></td><td>64</td></tr>
  215. <tr><td><code>use_ops</code></td><td>64</td></tr>
  216. <tr><td><code>vdef_ops</code></td><td>64</td></tr>
  217. <tr><td><code>vuse_ops</code></td><td>64</td></tr>
  218. <tr><td><code>stores</code></td><td>64</td></tr>
  219. <tr><td><code>loads</code></td><td>64</td></tr>
  220. <tr><td><code>op</code></td><td><code>num_ops</code> * 64</td></tr>
  221. <tr><td>Total size</td><td>80 + 8 * <code>num_ops</code> bytes</td></tr>
  222. </table>
  223. <ul>
  224. <li> <code>vdef_ops</code>
  225. Similar to <code>def_ops</code> but for <code>VDEF</code> operators. There is
  226. one entry per memory symbol written by this statement. This is
  227. used to maintain the memory SSA use-def and def-def chains.
  228. </li><li> <code>vuse_ops</code>
  229. Similar to <code>use_ops</code> but for <code>VUSE</code> operators. There is
  230. one entry per memory symbol loaded by this statement. This is
  231. used to maintain the memory SSA use-def chains.
  232. </li><li> <code>stores</code>
  233. Bitset with all the UIDs for the symbols written-to by the
  234. statement. This is different than <code>vdef_ops</code> in that all the
  235. affected symbols are mentioned in this set. If memory
  236. partitioning is enabled, the <code>vdef_ops</code> vector will refer to memory
  237. partitions. Furthermore, no SSA information is stored in this
  238. set.
  239. </li><li> <code>loads</code>
  240. Similar to <code>stores</code>, but for memory loads. (Note that there
  241. is some amount of redundancy here, it should be possible to
  242. reduce memory utilization further by removing these sets).
  243. </li></ul>
  244. <p>All the other tuples are defined in terms of these three basic
  245. ones. Each tuple will add some fields.
  246. </p>
  247. <hr>
  248. <div class="header">
  249. <p>
  250. Next: <a href="Class-hierarchy-of-GIMPLE-statements.html#Class-hierarchy-of-GIMPLE-statements" accesskey="n" rel="next">Class hierarchy of GIMPLE statements</a>, Up: <a href="GIMPLE.html#GIMPLE" accesskey="u" rel="up">GIMPLE</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>
  251. </div>
  252. </body>
  253. </html>