Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

292 linhas
13KB

  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>Expander Definitions (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Expander Definitions (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Expander Definitions (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="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
  30. <link href="Insn-Splitting.html#Insn-Splitting" rel="next" title="Insn Splitting">
  31. <link href="Insn-Canonicalizations.html#Insn-Canonicalizations" rel="prev" title="Insn Canonicalizations">
  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="Expander-Definitions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Insn-Splitting.html#Insn-Splitting" accesskey="n" rel="next">Insn Splitting</a>, Previous: <a href="Insn-Canonicalizations.html#Insn-Canonicalizations" accesskey="p" rel="prev">Insn Canonicalizations</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</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="Defining-RTL-Sequences-for-Code-Generation"></a>
  68. <h3 class="section">17.15 Defining RTL Sequences for Code Generation</h3>
  69. <a name="index-expander-definitions"></a>
  70. <a name="index-code-generation-RTL-sequences"></a>
  71. <a name="index-defining-RTL-sequences-for-code-generation"></a>
  72. <p>On some target machines, some standard pattern names for RTL generation
  73. cannot be handled with single insn, but a sequence of RTL insns can
  74. represent them. For these target machines, you can write a
  75. <code>define_expand</code> to specify how to generate the sequence of RTL.
  76. </p>
  77. <a name="index-define_005fexpand"></a>
  78. <p>A <code>define_expand</code> is an RTL expression that looks almost like a
  79. <code>define_insn</code>; but, unlike the latter, a <code>define_expand</code> is used
  80. only for RTL generation and it can produce more than one RTL insn.
  81. </p>
  82. <p>A <code>define_expand</code> RTX has four operands:
  83. </p>
  84. <ul>
  85. <li> The name. Each <code>define_expand</code> must have a name, since the only
  86. use for it is to refer to it by name.
  87. </li><li> The RTL template. This is a vector of RTL expressions representing
  88. a sequence of separate instructions. Unlike <code>define_insn</code>, there
  89. is no implicit surrounding <code>PARALLEL</code>.
  90. </li><li> The condition, a string containing a C expression. This expression is
  91. used to express how the availability of this pattern depends on
  92. subclasses of target machine, selected by command-line options when GCC
  93. is run. This is just like the condition of a <code>define_insn</code> that
  94. has a standard name. Therefore, the condition (if present) may not
  95. depend on the data in the insn being matched, but only the
  96. target-machine-type flags. The compiler needs to test these conditions
  97. during initialization in order to learn exactly which named instructions
  98. are available in a particular run.
  99. </li><li> The preparation statements, a string containing zero or more C
  100. statements which are to be executed before RTL code is generated from
  101. the RTL template.
  102. <p>Usually these statements prepare temporary registers for use as
  103. internal operands in the RTL template, but they can also generate RTL
  104. insns directly by calling routines such as <code>emit_insn</code>, etc.
  105. Any such insns precede the ones that come from the RTL template.
  106. </p>
  107. </li><li> Optionally, a vector containing the values of attributes. See <a href="Insn-Attributes.html#Insn-Attributes">Insn Attributes</a>.
  108. </li></ul>
  109. <p>Every RTL insn emitted by a <code>define_expand</code> must match some
  110. <code>define_insn</code> in the machine description. Otherwise, the compiler
  111. will crash when trying to generate code for the insn or trying to optimize
  112. it.
  113. </p>
  114. <p>The RTL template, in addition to controlling generation of RTL insns,
  115. also describes the operands that need to be specified when this pattern
  116. is used. In particular, it gives a predicate for each operand.
  117. </p>
  118. <p>A true operand, which needs to be specified in order to generate RTL from
  119. the pattern, should be described with a <code>match_operand</code> in its first
  120. occurrence in the RTL template. This enters information on the operand&rsquo;s
  121. predicate into the tables that record such things. GCC uses the
  122. information to preload the operand into a register if that is required for
  123. valid RTL code. If the operand is referred to more than once, subsequent
  124. references should use <code>match_dup</code>.
  125. </p>
  126. <p>The RTL template may also refer to internal &ldquo;operands&rdquo; which are
  127. temporary registers or labels used only within the sequence made by the
  128. <code>define_expand</code>. Internal operands are substituted into the RTL
  129. template with <code>match_dup</code>, never with <code>match_operand</code>. The
  130. values of the internal operands are not passed in as arguments by the
  131. compiler when it requests use of this pattern. Instead, they are computed
  132. within the pattern, in the preparation statements. These statements
  133. compute the values and store them into the appropriate elements of
  134. <code>operands</code> so that <code>match_dup</code> can find them.
  135. </p>
  136. <p>There are two special macros defined for use in the preparation statements:
  137. <code>DONE</code> and <code>FAIL</code>. Use them with a following semicolon,
  138. as a statement.
  139. </p>
  140. <dl compact="compact">
  141. <dd>
  142. <a name="index-DONE"></a>
  143. </dd>
  144. <dt><code>DONE</code></dt>
  145. <dd><p>Use the <code>DONE</code> macro to end RTL generation for the pattern. The
  146. only RTL insns resulting from the pattern on this occasion will be
  147. those already emitted by explicit calls to <code>emit_insn</code> within the
  148. preparation statements; the RTL template will not be generated.
  149. </p>
  150. <a name="index-FAIL"></a>
  151. </dd>
  152. <dt><code>FAIL</code></dt>
  153. <dd><p>Make the pattern fail on this occasion. When a pattern fails, it means
  154. that the pattern was not truly available. The calling routines in the
  155. compiler will try other strategies for code generation using other patterns.
  156. </p>
  157. <p>Failure is currently supported only for binary (addition, multiplication,
  158. shifting, etc.) and bit-field (<code>extv</code>, <code>extzv</code>, and <code>insv</code>)
  159. operations.
  160. </p></dd>
  161. </dl>
  162. <p>If the preparation falls through (invokes neither <code>DONE</code> nor
  163. <code>FAIL</code>), then the <code>define_expand</code> acts like a
  164. <code>define_insn</code> in that the RTL template is used to generate the
  165. insn.
  166. </p>
  167. <p>The RTL template is not used for matching, only for generating the
  168. initial insn list. If the preparation statement always invokes
  169. <code>DONE</code> or <code>FAIL</code>, the RTL template may be reduced to a simple
  170. list of operands, such as this example:
  171. </p>
  172. <div class="smallexample">
  173. <pre class="smallexample">(define_expand &quot;addsi3&quot;
  174. [(match_operand:SI 0 &quot;register_operand&quot; &quot;&quot;)
  175. (match_operand:SI 1 &quot;register_operand&quot; &quot;&quot;)
  176. (match_operand:SI 2 &quot;register_operand&quot; &quot;&quot;)]
  177. </pre><pre class="smallexample"> &quot;&quot;
  178. &quot;
  179. {
  180. handle_add (operands[0], operands[1], operands[2]);
  181. DONE;
  182. }&quot;)
  183. </pre></div>
  184. <p>Here is an example, the definition of left-shift for the SPUR chip:
  185. </p>
  186. <div class="smallexample">
  187. <pre class="smallexample">(define_expand &quot;ashlsi3&quot;
  188. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;&quot;)
  189. (ashift:SI
  190. </pre><pre class="smallexample"> (match_operand:SI 1 &quot;register_operand&quot; &quot;&quot;)
  191. (match_operand:SI 2 &quot;nonmemory_operand&quot; &quot;&quot;)))]
  192. &quot;&quot;
  193. &quot;
  194. </pre></div>
  195. <div class="smallexample">
  196. <pre class="smallexample">{
  197. if (GET_CODE (operands[2]) != CONST_INT
  198. || (unsigned) INTVAL (operands[2]) &gt; 3)
  199. FAIL;
  200. }&quot;)
  201. </pre></div>
  202. <p>This example uses <code>define_expand</code> so that it can generate an RTL insn
  203. for shifting when the shift-count is in the supported range of 0 to 3 but
  204. fail in other cases where machine insns aren&rsquo;t available. When it fails,
  205. the compiler tries another strategy using different patterns (such as, a
  206. library call).
  207. </p>
  208. <p>If the compiler were able to handle nontrivial condition-strings in
  209. patterns with names, then it would be possible to use a
  210. <code>define_insn</code> in that case. Here is another case (zero-extension
  211. on the 68000) which makes more use of the power of <code>define_expand</code>:
  212. </p>
  213. <div class="smallexample">
  214. <pre class="smallexample">(define_expand &quot;zero_extendhisi2&quot;
  215. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;&quot;)
  216. (const_int 0))
  217. (set (strict_low_part
  218. (subreg:HI
  219. (match_dup 0)
  220. 0))
  221. (match_operand:HI 1 &quot;general_operand&quot; &quot;&quot;))]
  222. &quot;&quot;
  223. &quot;operands[1] = make_safe_from (operands[1], operands[0]);&quot;)
  224. </pre></div>
  225. <p><a name="index-make_005fsafe_005ffrom"></a>
  226. Here two RTL insns are generated, one to clear the entire output operand
  227. and the other to copy the input operand into its low half. This sequence
  228. is incorrect if the input operand refers to [the old value of] the output
  229. operand, so the preparation statement makes sure this isn&rsquo;t so. The
  230. function <code>make_safe_from</code> copies the <code>operands[1]</code> into a
  231. temporary register if it refers to <code>operands[0]</code>. It does this
  232. by emitting another RTL insn.
  233. </p>
  234. <p>Finally, a third example shows the use of an internal operand.
  235. Zero-extension on the SPUR chip is done by <code>and</code>-ing the result
  236. against a halfword mask. But this mask cannot be represented by a
  237. <code>const_int</code> because the constant value is too large to be legitimate
  238. on this machine. So it must be copied into a register with
  239. <code>force_reg</code> and then the register used in the <code>and</code>.
  240. </p>
  241. <div class="smallexample">
  242. <pre class="smallexample">(define_expand &quot;zero_extendhisi2&quot;
  243. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;&quot;)
  244. (and:SI (subreg:SI
  245. (match_operand:HI 1 &quot;register_operand&quot; &quot;&quot;)
  246. 0)
  247. (match_dup 2)))]
  248. &quot;&quot;
  249. &quot;operands[2]
  250. = force_reg (SImode, GEN_INT (65535)); &quot;)
  251. </pre></div>
  252. <p><em>Note:</em> If the <code>define_expand</code> is used to serve a
  253. standard binary or unary arithmetic operation or a bit-field operation,
  254. then the last insn it generates must not be a <code>code_label</code>,
  255. <code>barrier</code> or <code>note</code>. It must be an <code>insn</code>,
  256. <code>jump_insn</code> or <code>call_insn</code>. If you don&rsquo;t need a real insn
  257. at the end, emit an insn to copy the result of the operation into
  258. itself. Such an insn will generate no code, but it can avoid problems
  259. in the compiler.
  260. </p>
  261. <hr>
  262. <div class="header">
  263. <p>
  264. Next: <a href="Insn-Splitting.html#Insn-Splitting" accesskey="n" rel="next">Insn Splitting</a>, Previous: <a href="Insn-Canonicalizations.html#Insn-Canonicalizations" accesskey="p" rel="prev">Insn Canonicalizations</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</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>
  265. </div>
  266. </body>
  267. </html>