Expressions.html 15 KB

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