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.

188 lines
7.8KB

  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>Code Iterators (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Code Iterators (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Code Iterators (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="Iterators.html#Iterators" rel="up" title="Iterators">
  30. <link href="Int-Iterators.html#Int-Iterators" rel="next" title="Int Iterators">
  31. <link href="Examples.html#Examples" rel="prev" title="Examples">
  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="Code-Iterators"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Int-Iterators.html#Int-Iterators" accesskey="n" rel="next">Int Iterators</a>, Previous: <a href="Mode-Iterators.html#Mode-Iterators" accesskey="p" rel="prev">Mode Iterators</a>, Up: <a href="Iterators.html#Iterators" accesskey="u" rel="up">Iterators</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="Code-Iterators-1"></a>
  68. <h4 class="subsection">17.23.2 Code Iterators</h4>
  69. <a name="index-code-iterators-in-_002emd-files"></a>
  70. <a name="index-define_005fcode_005fiterator"></a>
  71. <a name="index-define_005fcode_005fattr"></a>
  72. <p>Code iterators operate in a similar way to mode iterators. See <a href="Mode-Iterators.html#Mode-Iterators">Mode Iterators</a>.
  73. </p>
  74. <p>The construct:
  75. </p>
  76. <div class="smallexample">
  77. <pre class="smallexample">(define_code_iterator <var>name</var> [(<var>code1</var> &quot;<var>cond1</var>&quot;) &hellip; (<var>coden</var> &quot;<var>condn</var>&quot;)])
  78. </pre></div>
  79. <p>defines a pseudo rtx code <var>name</var> that can be instantiated as
  80. <var>codei</var> if condition <var>condi</var> is true. Each <var>codei</var>
  81. must have the same rtx format. See <a href="RTL-Classes.html#RTL-Classes">RTL Classes</a>.
  82. </p>
  83. <p>As with mode iterators, each pattern that uses <var>name</var> will be
  84. expanded <var>n</var> times, once with all uses of <var>name</var> replaced by
  85. <var>code1</var>, once with all uses replaced by <var>code2</var>, and so on.
  86. See <a href="Defining-Mode-Iterators.html#Defining-Mode-Iterators">Defining Mode Iterators</a>.
  87. </p>
  88. <p>It is possible to define attributes for codes as well as for modes.
  89. There are two standard code attributes: <code>code</code>, the name of the
  90. code in lower case, and <code>CODE</code>, the name of the code in upper case.
  91. Other attributes are defined using:
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">(define_code_attr <var>name</var> [(<var>code1</var> &quot;<var>value1</var>&quot;) &hellip; (<var>coden</var> &quot;<var>valuen</var>&quot;)])
  95. </pre></div>
  96. <p>Instruction patterns can use code attributes as rtx codes, which can be
  97. useful if two sets of codes act in tandem. For example, the following
  98. <code>define_insn</code> defines two patterns, one calculating a signed absolute
  99. difference and another calculating an unsigned absolute difference:
  100. </p>
  101. <div class="smallexample">
  102. <pre class="smallexample">(define_code_iterator any_max [smax umax])
  103. (define_code_attr paired_min [(smax &quot;smin&quot;) (umax &quot;umin&quot;)])
  104. (define_insn &hellip;
  105. [(set (match_operand:SI 0 &hellip;)
  106. (minus:SI (any_max:SI (match_operand:SI 1 &hellip;)
  107. (match_operand:SI 2 &hellip;))
  108. (&lt;paired_min&gt;:SI (match_dup 1) (match_dup 2))))]
  109. &hellip;)
  110. </pre></div>
  111. <p>The signed version of the instruction uses <code>smax</code> and <code>smin</code>
  112. while the unsigned version uses <code>umax</code> and <code>umin</code>. There
  113. are no versions that pair <code>smax</code> with <code>umin</code> or <code>umax</code>
  114. with <code>smin</code>.
  115. </p>
  116. <p>Here&rsquo;s an example of code iterators in action, taken from the MIPS port:
  117. </p>
  118. <div class="smallexample">
  119. <pre class="smallexample">(define_code_iterator any_cond [unordered ordered unlt unge uneq ltgt unle ungt
  120. eq ne gt ge lt le gtu geu ltu leu])
  121. (define_expand &quot;b&lt;code&gt;&quot;
  122. [(set (pc)
  123. (if_then_else (any_cond:CC (cc0)
  124. (const_int 0))
  125. (label_ref (match_operand 0 &quot;&quot;))
  126. (pc)))]
  127. &quot;&quot;
  128. {
  129. gen_conditional_branch (operands, &lt;CODE&gt;);
  130. DONE;
  131. })
  132. </pre></div>
  133. <p>This is equivalent to:
  134. </p>
  135. <div class="smallexample">
  136. <pre class="smallexample">(define_expand &quot;bunordered&quot;
  137. [(set (pc)
  138. (if_then_else (unordered:CC (cc0)
  139. (const_int 0))
  140. (label_ref (match_operand 0 &quot;&quot;))
  141. (pc)))]
  142. &quot;&quot;
  143. {
  144. gen_conditional_branch (operands, UNORDERED);
  145. DONE;
  146. })
  147. (define_expand &quot;bordered&quot;
  148. [(set (pc)
  149. (if_then_else (ordered:CC (cc0)
  150. (const_int 0))
  151. (label_ref (match_operand 0 &quot;&quot;))
  152. (pc)))]
  153. &quot;&quot;
  154. {
  155. gen_conditional_branch (operands, ORDERED);
  156. DONE;
  157. })
  158. &hellip;
  159. </pre></div>
  160. <hr>
  161. <div class="header">
  162. <p>
  163. Next: <a href="Int-Iterators.html#Int-Iterators" accesskey="n" rel="next">Int Iterators</a>, Previous: <a href="Mode-Iterators.html#Mode-Iterators" accesskey="p" rel="prev">Mode Iterators</a>, Up: <a href="Iterators.html#Iterators" accesskey="u" rel="up">Iterators</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>
  164. </div>
  165. </body>
  166. </html>