Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

323 lines
15KB

  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>Expressions (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Expressions (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="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="Insn-Attributes.html#Insn-Attributes" rel="up" title="Insn Attributes">
  30. <link href="Tagging-Insns.html#Tagging-Insns" rel="next" title="Tagging Insns">
  31. <link href="Defining-Attributes.html#Defining-Attributes" rel="prev" title="Defining Attributes">
  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="Expressions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Tagging-Insns.html#Tagging-Insns" accesskey="n" rel="next">Tagging Insns</a>, Previous: <a href="Defining-Attributes.html#Defining-Attributes" accesskey="p" rel="prev">Defining Attributes</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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="Attribute-Expressions"></a>
  68. <h4 class="subsection">17.19.2 Attribute Expressions</h4>
  69. <a name="index-attribute-expressions"></a>
  70. <p>RTL expressions used to define attributes use the codes described above
  71. plus a few specific to attribute definitions, to be discussed below.
  72. Attribute value expressions must have one of the following forms:
  73. </p>
  74. <dl compact="compact">
  75. <dd><a name="index-const_005fint-and-attributes"></a>
  76. </dd>
  77. <dt><code>(const_int <var>i</var>)</code></dt>
  78. <dd><p>The integer <var>i</var> specifies the value of a numeric attribute. <var>i</var>
  79. must be non-negative.
  80. </p>
  81. <p>The value of a numeric attribute can be specified either with a
  82. <code>const_int</code>, or as an integer represented as a string in
  83. <code>const_string</code>, <code>eq_attr</code> (see below), <code>attr</code>,
  84. <code>symbol_ref</code>, simple arithmetic expressions, and <code>set_attr</code>
  85. overrides on specific instructions (see <a href="Tagging-Insns.html#Tagging-Insns">Tagging Insns</a>).
  86. </p>
  87. <a name="index-const_005fstring-and-attributes"></a>
  88. </dd>
  89. <dt><code>(const_string <var>value</var>)</code></dt>
  90. <dd><p>The string <var>value</var> specifies a constant attribute value.
  91. If <var>value</var> is specified as &lsquo;<samp>&quot;*&quot;</samp>&rsquo;, it means that the default value of
  92. the attribute is to be used for the insn containing this expression.
  93. &lsquo;<samp>&quot;*&quot;</samp>&rsquo; obviously cannot be used in the <var>default</var> expression
  94. of a <code>define_attr</code>.
  95. </p>
  96. <p>If the attribute whose value is being specified is numeric, <var>value</var>
  97. must be a string containing a non-negative integer (normally
  98. <code>const_int</code> would be used in this case). Otherwise, it must
  99. contain one of the valid values for the attribute.
  100. </p>
  101. <a name="index-if_005fthen_005felse-and-attributes"></a>
  102. </dd>
  103. <dt><code>(if_then_else <var>test</var> <var>true-value</var> <var>false-value</var>)</code></dt>
  104. <dd><p><var>test</var> specifies an attribute test, whose format is defined below.
  105. The value of this expression is <var>true-value</var> if <var>test</var> is true,
  106. otherwise it is <var>false-value</var>.
  107. </p>
  108. <a name="index-cond-and-attributes"></a>
  109. </dd>
  110. <dt><code>(cond [<var>test1</var> <var>value1</var> &hellip;] <var>default</var>)</code></dt>
  111. <dd><p>The first operand of this expression is a vector containing an even
  112. number of expressions and consisting of pairs of <var>test</var> and <var>value</var>
  113. expressions. The value of the <code>cond</code> expression is that of the
  114. <var>value</var> corresponding to the first true <var>test</var> expression. If
  115. none of the <var>test</var> expressions are true, the value of the <code>cond</code>
  116. expression is that of the <var>default</var> expression.
  117. </p></dd>
  118. </dl>
  119. <p><var>test</var> expressions can have one of the following forms:
  120. </p>
  121. <dl compact="compact">
  122. <dd><a name="index-const_005fint-and-attribute-tests"></a>
  123. </dd>
  124. <dt><code>(const_int <var>i</var>)</code></dt>
  125. <dd><p>This test is true if <var>i</var> is nonzero and false otherwise.
  126. </p>
  127. <a name="index-not-and-attributes"></a>
  128. <a name="index-ior-and-attributes"></a>
  129. <a name="index-and-and-attributes"></a>
  130. </dd>
  131. <dt><code>(not <var>test</var>)</code></dt>
  132. <dt><code>(ior <var>test1</var> <var>test2</var>)</code></dt>
  133. <dt><code>(and <var>test1</var> <var>test2</var>)</code></dt>
  134. <dd><p>These tests are true if the indicated logical function is true.
  135. </p>
  136. <a name="index-match_005foperand-and-attributes"></a>
  137. </dd>
  138. <dt><code>(match_operand:<var>m</var> <var>n</var> <var>pred</var> <var>constraints</var>)</code></dt>
  139. <dd><p>This test is true if operand <var>n</var> of the insn whose attribute value
  140. is being determined has mode <var>m</var> (this part of the test is ignored
  141. if <var>m</var> is <code>VOIDmode</code>) and the function specified by the string
  142. <var>pred</var> returns a nonzero value when passed operand <var>n</var> and mode
  143. <var>m</var> (this part of the test is ignored if <var>pred</var> is the null
  144. string).
  145. </p>
  146. <p>The <var>constraints</var> operand is ignored and should be the null string.
  147. </p>
  148. <a name="index-match_005ftest-and-attributes"></a>
  149. </dd>
  150. <dt><code>(match_test <var>c-expr</var>)</code></dt>
  151. <dd><p>The test is true if C expression <var>c-expr</var> is true. In non-constant
  152. attributes, <var>c-expr</var> has access to the following variables:
  153. </p>
  154. <dl compact="compact">
  155. <dt><var>insn</var></dt>
  156. <dd><p>The rtl instruction under test.
  157. </p></dd>
  158. <dt><var>which_alternative</var></dt>
  159. <dd><p>The <code>define_insn</code> alternative that <var>insn</var> matches.
  160. See <a href="Output-Statement.html#Output-Statement">Output Statement</a>.
  161. </p></dd>
  162. <dt><var>operands</var></dt>
  163. <dd><p>An array of <var>insn</var>&rsquo;s rtl operands.
  164. </p></dd>
  165. </dl>
  166. <p><var>c-expr</var> behaves like the condition in a C <code>if</code> statement,
  167. so there is no need to explicitly convert the expression into a boolean
  168. 0 or 1 value. For example, the following two tests are equivalent:
  169. </p>
  170. <div class="smallexample">
  171. <pre class="smallexample">(match_test &quot;x &amp; 2&quot;)
  172. (match_test &quot;(x &amp; 2) != 0&quot;)
  173. </pre></div>
  174. <a name="index-le-and-attributes"></a>
  175. <a name="index-leu-and-attributes"></a>
  176. <a name="index-lt-and-attributes"></a>
  177. <a name="index-gt-and-attributes"></a>
  178. <a name="index-gtu-and-attributes"></a>
  179. <a name="index-ge-and-attributes"></a>
  180. <a name="index-geu-and-attributes"></a>
  181. <a name="index-ne-and-attributes"></a>
  182. <a name="index-eq-and-attributes"></a>
  183. <a name="index-plus-and-attributes"></a>
  184. <a name="index-minus-and-attributes"></a>
  185. <a name="index-mult-and-attributes"></a>
  186. <a name="index-div-and-attributes"></a>
  187. <a name="index-mod-and-attributes"></a>
  188. <a name="index-abs-and-attributes"></a>
  189. <a name="index-neg-and-attributes"></a>
  190. <a name="index-ashift-and-attributes"></a>
  191. <a name="index-lshiftrt-and-attributes"></a>
  192. <a name="index-ashiftrt-and-attributes"></a>
  193. </dd>
  194. <dt><code>(le <var>arith1</var> <var>arith2</var>)</code></dt>
  195. <dt><code>(leu <var>arith1</var> <var>arith2</var>)</code></dt>
  196. <dt><code>(lt <var>arith1</var> <var>arith2</var>)</code></dt>
  197. <dt><code>(ltu <var>arith1</var> <var>arith2</var>)</code></dt>
  198. <dt><code>(gt <var>arith1</var> <var>arith2</var>)</code></dt>
  199. <dt><code>(gtu <var>arith1</var> <var>arith2</var>)</code></dt>
  200. <dt><code>(ge <var>arith1</var> <var>arith2</var>)</code></dt>
  201. <dt><code>(geu <var>arith1</var> <var>arith2</var>)</code></dt>
  202. <dt><code>(ne <var>arith1</var> <var>arith2</var>)</code></dt>
  203. <dt><code>(eq <var>arith1</var> <var>arith2</var>)</code></dt>
  204. <dd><p>These tests are true if the indicated comparison of the two arithmetic
  205. expressions is true. Arithmetic expressions are formed with
  206. <code>plus</code>, <code>minus</code>, <code>mult</code>, <code>div</code>, <code>mod</code>,
  207. <code>abs</code>, <code>neg</code>, <code>and</code>, <code>ior</code>, <code>xor</code>, <code>not</code>,
  208. <code>ashift</code>, <code>lshiftrt</code>, and <code>ashiftrt</code> expressions.
  209. </p>
  210. <a name="index-get_005fattr"></a>
  211. <p><code>const_int</code> and <code>symbol_ref</code> are always valid terms (see <a href="Insn-Lengths.html#Insn-Lengths">Insn Lengths</a>,for additional forms). <code>symbol_ref</code> is a string
  212. denoting a C expression that yields an <code>int</code> when evaluated by the
  213. &lsquo;<samp>get_attr_&hellip;</samp>&rsquo; routine. It should normally be a global
  214. variable.
  215. </p>
  216. <a name="index-eq_005fattr"></a>
  217. </dd>
  218. <dt><code>(eq_attr <var>name</var> <var>value</var>)</code></dt>
  219. <dd><p><var>name</var> is a string specifying the name of an attribute.
  220. </p>
  221. <p><var>value</var> is a string that is either a valid value for attribute
  222. <var>name</var>, a comma-separated list of values, or &lsquo;<samp>!</samp>&rsquo; followed by a
  223. value or list. If <var>value</var> does not begin with a &lsquo;<samp>!</samp>&rsquo;, this
  224. test is true if the value of the <var>name</var> attribute of the current
  225. insn is in the list specified by <var>value</var>. If <var>value</var> begins
  226. with a &lsquo;<samp>!</samp>&rsquo;, this test is true if the attribute&rsquo;s value is
  227. <em>not</em> in the specified list.
  228. </p>
  229. <p>For example,
  230. </p>
  231. <div class="smallexample">
  232. <pre class="smallexample">(eq_attr &quot;type&quot; &quot;load,store&quot;)
  233. </pre></div>
  234. <p>is equivalent to
  235. </p>
  236. <div class="smallexample">
  237. <pre class="smallexample">(ior (eq_attr &quot;type&quot; &quot;load&quot;) (eq_attr &quot;type&quot; &quot;store&quot;))
  238. </pre></div>
  239. <p>If <var>name</var> specifies an attribute of &lsquo;<samp>alternative</samp>&rsquo;, it refers to the
  240. value of the compiler variable <code>which_alternative</code>
  241. (see <a href="Output-Statement.html#Output-Statement">Output Statement</a>) and the values must be small integers. For
  242. example,
  243. </p>
  244. <div class="smallexample">
  245. <pre class="smallexample">(eq_attr &quot;alternative&quot; &quot;2,3&quot;)
  246. </pre></div>
  247. <p>is equivalent to
  248. </p>
  249. <div class="smallexample">
  250. <pre class="smallexample">(ior (eq (symbol_ref &quot;which_alternative&quot;) (const_int 2))
  251. (eq (symbol_ref &quot;which_alternative&quot;) (const_int 3)))
  252. </pre></div>
  253. <p>Note that, for most attributes, an <code>eq_attr</code> test is simplified in cases
  254. where the value of the attribute being tested is known for all insns matching
  255. a particular pattern. This is by far the most common case.
  256. </p>
  257. <a name="index-attr_005fflag"></a>
  258. </dd>
  259. <dt><code>(attr_flag <var>name</var>)</code></dt>
  260. <dd><p>The value of an <code>attr_flag</code> expression is true if the flag
  261. specified by <var>name</var> is true for the <code>insn</code> currently being
  262. scheduled.
  263. </p>
  264. <p><var>name</var> is a string specifying one of a fixed set of flags to test.
  265. Test the flags <code>forward</code> and <code>backward</code> to determine the
  266. direction of a conditional branch.
  267. </p>
  268. <p>This example describes a conditional branch delay slot which
  269. can be nullified for forward branches that are taken (annul-true) or
  270. for backward branches which are not taken (annul-false).
  271. </p>
  272. <div class="smallexample">
  273. <pre class="smallexample">(define_delay (eq_attr &quot;type&quot; &quot;cbranch&quot;)
  274. [(eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
  275. (and (eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
  276. (attr_flag &quot;forward&quot;))
  277. (and (eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
  278. (attr_flag &quot;backward&quot;))])
  279. </pre></div>
  280. <p>The <code>forward</code> and <code>backward</code> flags are false if the current
  281. <code>insn</code> being scheduled is not a conditional branch.
  282. </p>
  283. <p><code>attr_flag</code> is only used during delay slot scheduling and has no
  284. meaning to other passes of the compiler.
  285. </p>
  286. <a name="index-attr"></a>
  287. </dd>
  288. <dt><code>(attr <var>name</var>)</code></dt>
  289. <dd><p>The value of another attribute is returned. This is most useful
  290. for numeric attributes, as <code>eq_attr</code> and <code>attr_flag</code>
  291. produce more efficient code for non-numeric attributes.
  292. </p></dd>
  293. </dl>
  294. <hr>
  295. <div class="header">
  296. <p>
  297. Next: <a href="Tagging-Insns.html#Tagging-Insns" accesskey="n" rel="next">Tagging Insns</a>, Previous: <a href="Defining-Attributes.html#Defining-Attributes" accesskey="p" rel="prev">Defining Attributes</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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>
  298. </div>
  299. </body>
  300. </html>