Code-Iterators.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: Code Iterators</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Code Iterators">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Code Iterators">
  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="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.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="Code-Iterators"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="Code-Iterators-1"></a>
  69. <h4 class="subsection">16.23.2 Code Iterators</h4>
  70. <a name="index-code-iterators-in-_002emd-files"></a>
  71. <a name="index-define_005fcode_005fiterator"></a>
  72. <a name="index-define_005fcode_005fattr"></a>
  73. <p>Code iterators operate in a similar way to mode iterators. See <a href="Mode-Iterators.html#Mode-Iterators">Mode Iterators</a>.
  74. </p>
  75. <p>The construct:
  76. </p>
  77. <div class="smallexample">
  78. <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;)])
  79. </pre></div>
  80. <p>defines a pseudo rtx code <var>name</var> that can be instantiated as
  81. <var>codei</var> if condition <var>condi</var> is true. Each <var>codei</var>
  82. must have the same rtx format. See <a href="RTL-Classes.html#RTL-Classes">RTL Classes</a>.
  83. </p>
  84. <p>As with mode iterators, each pattern that uses <var>name</var> will be
  85. expanded <var>n</var> times, once with all uses of <var>name</var> replaced by
  86. <var>code1</var>, once with all uses replaced by <var>code2</var>, and so on.
  87. See <a href="Defining-Mode-Iterators.html#Defining-Mode-Iterators">Defining Mode Iterators</a>.
  88. </p>
  89. <p>It is possible to define attributes for codes as well as for modes.
  90. There are two standard code attributes: <code>code</code>, the name of the
  91. code in lower case, and <code>CODE</code>, the name of the code in upper case.
  92. Other attributes are defined using:
  93. </p>
  94. <div class="smallexample">
  95. <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;)])
  96. </pre></div>
  97. <p>Here&rsquo;s an example of code iterators in action, taken from the MIPS port:
  98. </p>
  99. <div class="smallexample">
  100. <pre class="smallexample">(define_code_iterator any_cond [unordered ordered unlt unge uneq ltgt unle ungt
  101. eq ne gt ge lt le gtu geu ltu leu])
  102. (define_expand &quot;b&lt;code&gt;&quot;
  103. [(set (pc)
  104. (if_then_else (any_cond:CC (cc0)
  105. (const_int 0))
  106. (label_ref (match_operand 0 &quot;&quot;))
  107. (pc)))]
  108. &quot;&quot;
  109. {
  110. gen_conditional_branch (operands, &lt;CODE&gt;);
  111. DONE;
  112. })
  113. </pre></div>
  114. <p>This is equivalent to:
  115. </p>
  116. <div class="smallexample">
  117. <pre class="smallexample">(define_expand &quot;bunordered&quot;
  118. [(set (pc)
  119. (if_then_else (unordered:CC (cc0)
  120. (const_int 0))
  121. (label_ref (match_operand 0 &quot;&quot;))
  122. (pc)))]
  123. &quot;&quot;
  124. {
  125. gen_conditional_branch (operands, UNORDERED);
  126. DONE;
  127. })
  128. (define_expand &quot;bordered&quot;
  129. [(set (pc)
  130. (if_then_else (ordered:CC (cc0)
  131. (const_int 0))
  132. (label_ref (match_operand 0 &quot;&quot;))
  133. (pc)))]
  134. &quot;&quot;
  135. {
  136. gen_conditional_branch (operands, ORDERED);
  137. DONE;
  138. })
  139. &hellip;
  140. </pre></div>
  141. <hr>
  142. <div class="header">
  143. <p>
  144. 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>
  145. </div>
  146. </body>
  147. </html>