Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

261 lines
12KB

  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>Constant expressions (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Constant expressions (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Constant expressions (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="Expression-trees.html#Expression-trees" rel="up" title="Expression trees">
  30. <link href="Storage-References.html#Storage-References" rel="next" title="Storage References">
  31. <link href="Expression-trees.html#Expression-trees" rel="prev" title="Expression trees">
  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="Constant-expressions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Storage-References.html#Storage-References" accesskey="n" rel="next">Storage References</a>, Up: <a href="Expression-trees.html#Expression-trees" accesskey="u" rel="up">Expression trees</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="Constant-expressions-1"></a>
  68. <h4 class="subsection">11.6.1 Constant expressions</h4>
  69. <a name="index-INTEGER_005fCST"></a>
  70. <a name="index-tree_005fint_005fcst_005flt"></a>
  71. <a name="index-tree_005fint_005fcst_005fequal"></a>
  72. <a name="index-tree_005ffits_005fuhwi_005fp"></a>
  73. <a name="index-tree_005ffits_005fshwi_005fp"></a>
  74. <a name="index-tree_005fto_005fuhwi"></a>
  75. <a name="index-tree_005fto_005fshwi"></a>
  76. <a name="index-TREE_005fINT_005fCST_005fNUNITS"></a>
  77. <a name="index-TREE_005fINT_005fCST_005fELT"></a>
  78. <a name="index-TREE_005fINT_005fCST_005fLOW"></a>
  79. <a name="index-REAL_005fCST"></a>
  80. <a name="index-FIXED_005fCST"></a>
  81. <a name="index-COMPLEX_005fCST"></a>
  82. <a name="index-VECTOR_005fCST"></a>
  83. <a name="index-STRING_005fCST"></a>
  84. <a name="index-POLY_005fINT_005fCST"></a>
  85. <a name="index-TREE_005fSTRING_005fLENGTH"></a>
  86. <a name="index-TREE_005fSTRING_005fPOINTER"></a>
  87. <p>The table below begins with constants, moves on to unary expressions,
  88. then proceeds to binary expressions, and concludes with various other
  89. kinds of expressions:
  90. </p>
  91. <dl compact="compact">
  92. <dt><code>INTEGER_CST</code></dt>
  93. <dd><p>These nodes represent integer constants. Note that the type of these
  94. constants is obtained with <code>TREE_TYPE</code>; they are not always of type
  95. <code>int</code>. In particular, <code>char</code> constants are represented with
  96. <code>INTEGER_CST</code> nodes. The value of the integer constant <code>e</code> is
  97. represented in an array of HOST_WIDE_INT. There are enough elements
  98. in the array to represent the value without taking extra elements for
  99. redundant 0s or -1. The number of elements used to represent <code>e</code>
  100. is available via <code>TREE_INT_CST_NUNITS</code>. Element <code>i</code> can be
  101. extracted by using <code>TREE_INT_CST_ELT (e, i)</code>.
  102. <code>TREE_INT_CST_LOW</code> is a shorthand for <code>TREE_INT_CST_ELT (e, 0)</code>.
  103. </p>
  104. <p>The functions <code>tree_fits_shwi_p</code> and <code>tree_fits_uhwi_p</code>
  105. can be used to tell if the value is small enough to fit in a
  106. signed HOST_WIDE_INT or an unsigned HOST_WIDE_INT respectively.
  107. The value can then be extracted using <code>tree_to_shwi</code> and
  108. <code>tree_to_uhwi</code>.
  109. </p>
  110. </dd>
  111. <dt><code>REAL_CST</code></dt>
  112. <dd>
  113. <p>FIXME: Talk about how to obtain representations of this constant, do
  114. comparisons, and so forth.
  115. </p>
  116. </dd>
  117. <dt><code>FIXED_CST</code></dt>
  118. <dd>
  119. <p>These nodes represent fixed-point constants. The type of these constants
  120. is obtained with <code>TREE_TYPE</code>. <code>TREE_FIXED_CST_PTR</code> points to
  121. a <code>struct fixed_value</code>; <code>TREE_FIXED_CST</code> returns the structure
  122. itself. <code>struct fixed_value</code> contains <code>data</code> with the size of two
  123. <code>HOST_BITS_PER_WIDE_INT</code> and <code>mode</code> as the associated fixed-point
  124. machine mode for <code>data</code>.
  125. </p>
  126. </dd>
  127. <dt><code>COMPLEX_CST</code></dt>
  128. <dd><p>These nodes are used to represent complex number constants, that is a
  129. <code>__complex__</code> whose parts are constant nodes. The
  130. <code>TREE_REALPART</code> and <code>TREE_IMAGPART</code> return the real and the
  131. imaginary parts respectively.
  132. </p>
  133. </dd>
  134. <dt><code>VECTOR_CST</code></dt>
  135. <dd><p>These nodes are used to represent vector constants. Each vector
  136. constant <var>v</var> is treated as a specific instance of an arbitrary-length
  137. sequence that itself contains &lsquo;<samp>VECTOR_CST_NPATTERNS (<var>v</var>)</samp>&rsquo;
  138. interleaved patterns. Each pattern has the form:
  139. </p>
  140. <div class="smallexample">
  141. <pre class="smallexample">{ <var>base0</var>, <var>base1</var>, <var>base1</var> + <var>step</var>, <var>base1</var> + <var>step</var> * 2, &hellip; }
  142. </pre></div>
  143. <p>The first three elements in each pattern are enough to determine the
  144. values of the other elements. However, if all <var>step</var>s are zero,
  145. only the first two elements are needed. If in addition each <var>base1</var>
  146. is equal to the corresponding <var>base0</var>, only the first element in
  147. each pattern is needed. The number of encoded elements per pattern
  148. is given by &lsquo;<samp>VECTOR_CST_NELTS_PER_PATTERN (<var>v</var>)</samp>&rsquo;.
  149. </p>
  150. <p>For example, the constant:
  151. </p>
  152. <div class="smallexample">
  153. <pre class="smallexample">{ 0, 1, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18 }
  154. </pre></div>
  155. <p>is interpreted as an interleaving of the sequences:
  156. </p>
  157. <div class="smallexample">
  158. <pre class="smallexample">{ 0, 2, 3, 4, 5, 6, 7, 8 }
  159. { 1, 6, 8, 10, 12, 14, 16, 18 }
  160. </pre></div>
  161. <p>where the sequences are represented by the following patterns:
  162. </p>
  163. <div class="smallexample">
  164. <pre class="smallexample"><var>base0</var> == 0, <var>base1</var> == 2, <var>step</var> == 1
  165. <var>base0</var> == 1, <var>base1</var> == 6, <var>step</var> == 2
  166. </pre></div>
  167. <p>In this case:
  168. </p>
  169. <div class="smallexample">
  170. <pre class="smallexample">VECTOR_CST_NPATTERNS (<var>v</var>) == 2
  171. VECTOR_CST_NELTS_PER_PATTERN (<var>v</var>) == 3
  172. </pre></div>
  173. <p>The vector is therefore encoded using the first 6 elements
  174. (&lsquo;<samp>{ 0, 1, 2, 6, 3, 8 }</samp>&rsquo;), with the remaining 10 elements
  175. being implicit extensions of them.
  176. </p>
  177. <p>Sometimes this scheme can create two possible encodings of the same
  178. vector. For example { 0, 1 } could be seen as two patterns with
  179. one element each or one pattern with two elements (<var>base0</var> and
  180. <var>base1</var>). The canonical encoding is always the one with the
  181. fewest patterns or (if both encodings have the same number of
  182. petterns) the one with the fewest encoded elements.
  183. </p>
  184. <p>&lsquo;<samp>vector_cst_encoding_nelts (<var>v</var>)</samp>&rsquo; gives the total number of
  185. encoded elements in <var>v</var>, which is 6 in the example above.
  186. <code>VECTOR_CST_ENCODED_ELTS (<var>v</var>)</code> gives a pointer to the elements
  187. encoded in <var>v</var> and <code>VECTOR_CST_ENCODED_ELT (<var>v</var>, <var>i</var>)</code>
  188. accesses the value of encoded element <var>i</var>.
  189. </p>
  190. <p>&lsquo;<samp>VECTOR_CST_DUPLICATE_P (<var>v</var>)</samp>&rsquo; is true if <var>v</var> simply contains
  191. repeated instances of &lsquo;<samp>VECTOR_CST_NPATTERNS (<var>v</var>)</samp>&rsquo; values. This is
  192. a shorthand for testing &lsquo;<samp>VECTOR_CST_NELTS_PER_PATTERN (<var>v</var>) == 1</samp>&rsquo;.
  193. </p>
  194. <p>&lsquo;<samp>VECTOR_CST_STEPPED_P (<var>v</var>)</samp>&rsquo; is true if at least one
  195. pattern in <var>v</var> has a nonzero step. This is a shorthand for
  196. testing &lsquo;<samp>VECTOR_CST_NELTS_PER_PATTERN (<var>v</var>) == 3</samp>&rsquo;.
  197. </p>
  198. <p>The utility function <code>vector_cst_elt</code> gives the value of an
  199. arbitrary index as a <code>tree</code>. <code>vector_cst_int_elt</code> gives
  200. the same value as a <code>wide_int</code>.
  201. </p>
  202. </dd>
  203. <dt><code>STRING_CST</code></dt>
  204. <dd><p>These nodes represent string-constants. The <code>TREE_STRING_LENGTH</code>
  205. returns the length of the string, as an <code>int</code>. The
  206. <code>TREE_STRING_POINTER</code> is a <code>char*</code> containing the string
  207. itself. The string may not be <code>NUL</code>-terminated, and it may contain
  208. embedded <code>NUL</code> characters. Therefore, the
  209. <code>TREE_STRING_LENGTH</code> includes the trailing <code>NUL</code> if it is
  210. present.
  211. </p>
  212. <p>For wide string constants, the <code>TREE_STRING_LENGTH</code> is the number
  213. of bytes in the string, and the <code>TREE_STRING_POINTER</code>
  214. points to an array of the bytes of the string, as represented on the
  215. target system (that is, as integers in the target endianness). Wide and
  216. non-wide string constants are distinguished only by the <code>TREE_TYPE</code>
  217. of the <code>STRING_CST</code>.
  218. </p>
  219. <p>FIXME: The formats of string constants are not well-defined when the
  220. target system bytes are not the same width as host system bytes.
  221. </p>
  222. </dd>
  223. <dt><code>POLY_INT_CST</code></dt>
  224. <dd><p>These nodes represent invariants that depend on some target-specific
  225. runtime parameters. They consist of <code>NUM_POLY_INT_COEFFS</code>
  226. coefficients, with the first coefficient being the constant term and
  227. the others being multipliers that are applied to the runtime parameters.
  228. </p>
  229. <p><code>POLY_INT_CST_ELT (<var>x</var>, <var>i</var>)</code> references coefficient number
  230. <var>i</var> of <code>POLY_INT_CST</code> node <var>x</var>. Each coefficient is an
  231. <code>INTEGER_CST</code>.
  232. </p>
  233. </dd>
  234. </dl>
  235. <hr>
  236. <div class="header">
  237. <p>
  238. Next: <a href="Storage-References.html#Storage-References" accesskey="n" rel="next">Storage References</a>, Up: <a href="Expression-trees.html#Expression-trees" accesskey="u" rel="up">Expression trees</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>
  239. </div>
  240. </body>
  241. </html>