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.

342 lines
16KB

  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>RTL Template (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="RTL Template (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="RTL Template (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="Output-Template.html#Output-Template" rel="next" title="Output Template">
  31. <link href="Example.html#Example" rel="prev" title="Example">
  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="RTL-Template"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Output-Template.html#Output-Template" accesskey="n" rel="next">Output Template</a>, Previous: <a href="Example.html#Example" accesskey="p" rel="prev">Example</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="RTL-Template-1"></a>
  68. <h3 class="section">17.4 RTL Template</h3>
  69. <a name="index-RTL-insn-template"></a>
  70. <a name="index-generating-insns"></a>
  71. <a name="index-insns_002c-generating"></a>
  72. <a name="index-recognizing-insns"></a>
  73. <a name="index-insns_002c-recognizing"></a>
  74. <p>The RTL template is used to define which insns match the particular pattern
  75. and how to find their operands. For named patterns, the RTL template also
  76. says how to construct an insn from specified operands.
  77. </p>
  78. <p>Construction involves substituting specified operands into a copy of the
  79. template. Matching involves determining the values that serve as the
  80. operands in the insn being matched. Both of these activities are
  81. controlled by special expression types that direct matching and
  82. substitution of the operands.
  83. </p>
  84. <dl compact="compact">
  85. <dd><a name="index-match_005foperand"></a>
  86. </dd>
  87. <dt><code>(match_operand:<var>m</var> <var>n</var> <var>predicate</var> <var>constraint</var>)</code></dt>
  88. <dd><p>This expression is a placeholder for operand number <var>n</var> of
  89. the insn. When constructing an insn, operand number <var>n</var>
  90. will be substituted at this point. When matching an insn, whatever
  91. appears at this position in the insn will be taken as operand
  92. number <var>n</var>; but it must satisfy <var>predicate</var> or this instruction
  93. pattern will not match at all.
  94. </p>
  95. <p>Operand numbers must be chosen consecutively counting from zero in
  96. each instruction pattern. There may be only one <code>match_operand</code>
  97. expression in the pattern for each operand number. Usually operands
  98. are numbered in the order of appearance in <code>match_operand</code>
  99. expressions. In the case of a <code>define_expand</code>, any operand numbers
  100. used only in <code>match_dup</code> expressions have higher values than all
  101. other operand numbers.
  102. </p>
  103. <p><var>predicate</var> is a string that is the name of a function that
  104. accepts two arguments, an expression and a machine mode.
  105. See <a href="Predicates.html#Predicates">Predicates</a>. During matching, the function will be called with
  106. the putative operand as the expression and <var>m</var> as the mode
  107. argument (if <var>m</var> is not specified, <code>VOIDmode</code> will be used,
  108. which normally causes <var>predicate</var> to accept any mode). If it
  109. returns zero, this instruction pattern fails to match.
  110. <var>predicate</var> may be an empty string; then it means no test is to be
  111. done on the operand, so anything which occurs in this position is
  112. valid.
  113. </p>
  114. <p>Most of the time, <var>predicate</var> will reject modes other than <var>m</var>&mdash;but
  115. not always. For example, the predicate <code>address_operand</code> uses
  116. <var>m</var> as the mode of memory ref that the address should be valid for.
  117. Many predicates accept <code>const_int</code> nodes even though their mode is
  118. <code>VOIDmode</code>.
  119. </p>
  120. <p><var>constraint</var> controls reloading and the choice of the best register
  121. class to use for a value, as explained later (see <a href="Constraints.html#Constraints">Constraints</a>).
  122. If the constraint would be an empty string, it can be omitted.
  123. </p>
  124. <p>People are often unclear on the difference between the constraint and the
  125. predicate. The predicate helps decide whether a given insn matches the
  126. pattern. The constraint plays no role in this decision; instead, it
  127. controls various decisions in the case of an insn which does match.
  128. </p>
  129. <a name="index-match_005fscratch"></a>
  130. </dd>
  131. <dt><code>(match_scratch:<var>m</var> <var>n</var> <var>constraint</var>)</code></dt>
  132. <dd><p>This expression is also a placeholder for operand number <var>n</var>
  133. and indicates that operand must be a <code>scratch</code> or <code>reg</code>
  134. expression.
  135. </p>
  136. <p>When matching patterns, this is equivalent to
  137. </p>
  138. <div class="smallexample">
  139. <pre class="smallexample">(match_operand:<var>m</var> <var>n</var> &quot;scratch_operand&quot; <var>constraint</var>)
  140. </pre></div>
  141. <p>but, when generating RTL, it produces a (<code>scratch</code>:<var>m</var>)
  142. expression.
  143. </p>
  144. <p>If the last few expressions in a <code>parallel</code> are <code>clobber</code>
  145. expressions whose operands are either a hard register or
  146. <code>match_scratch</code>, the combiner can add or delete them when
  147. necessary. See <a href="Side-Effects.html#Side-Effects">Side Effects</a>.
  148. </p>
  149. <a name="index-match_005fdup"></a>
  150. </dd>
  151. <dt><code>(match_dup <var>n</var>)</code></dt>
  152. <dd><p>This expression is also a placeholder for operand number <var>n</var>.
  153. It is used when the operand needs to appear more than once in the
  154. insn.
  155. </p>
  156. <p>In construction, <code>match_dup</code> acts just like <code>match_operand</code>:
  157. the operand is substituted into the insn being constructed. But in
  158. matching, <code>match_dup</code> behaves differently. It assumes that operand
  159. number <var>n</var> has already been determined by a <code>match_operand</code>
  160. appearing earlier in the recognition template, and it matches only an
  161. identical-looking expression.
  162. </p>
  163. <p>Note that <code>match_dup</code> should not be used to tell the compiler that
  164. a particular register is being used for two operands (example:
  165. <code>add</code> that adds one register to another; the second register is
  166. both an input operand and the output operand). Use a matching
  167. constraint (see <a href="Simple-Constraints.html#Simple-Constraints">Simple Constraints</a>) for those. <code>match_dup</code> is for the cases where one
  168. operand is used in two places in the template, such as an instruction
  169. that computes both a quotient and a remainder, where the opcode takes
  170. two input operands but the RTL template has to refer to each of those
  171. twice; once for the quotient pattern and once for the remainder pattern.
  172. </p>
  173. <a name="index-match_005foperator"></a>
  174. </dd>
  175. <dt><code>(match_operator:<var>m</var> <var>n</var> <var>predicate</var> [<var>operands</var>&hellip;])</code></dt>
  176. <dd><p>This pattern is a kind of placeholder for a variable RTL expression
  177. code.
  178. </p>
  179. <p>When constructing an insn, it stands for an RTL expression whose
  180. expression code is taken from that of operand <var>n</var>, and whose
  181. operands are constructed from the patterns <var>operands</var>.
  182. </p>
  183. <p>When matching an expression, it matches an expression if the function
  184. <var>predicate</var> returns nonzero on that expression <em>and</em> the
  185. patterns <var>operands</var> match the operands of the expression.
  186. </p>
  187. <p>Suppose that the function <code>commutative_operator</code> is defined as
  188. follows, to match any expression whose operator is one of the
  189. commutative arithmetic operators of RTL and whose mode is <var>mode</var>:
  190. </p>
  191. <div class="smallexample">
  192. <pre class="smallexample">int
  193. commutative_integer_operator (x, mode)
  194. rtx x;
  195. machine_mode mode;
  196. {
  197. enum rtx_code code = GET_CODE (x);
  198. if (GET_MODE (x) != mode)
  199. return 0;
  200. return (GET_RTX_CLASS (code) == RTX_COMM_ARITH
  201. || code == EQ || code == NE);
  202. }
  203. </pre></div>
  204. <p>Then the following pattern will match any RTL expression consisting
  205. of a commutative operator applied to two general operands:
  206. </p>
  207. <div class="smallexample">
  208. <pre class="smallexample">(match_operator:SI 3 &quot;commutative_operator&quot;
  209. [(match_operand:SI 1 &quot;general_operand&quot; &quot;g&quot;)
  210. (match_operand:SI 2 &quot;general_operand&quot; &quot;g&quot;)])
  211. </pre></div>
  212. <p>Here the vector <code>[<var>operands</var>&hellip;]</code> contains two patterns
  213. because the expressions to be matched all contain two operands.
  214. </p>
  215. <p>When this pattern does match, the two operands of the commutative
  216. operator are recorded as operands 1 and 2 of the insn. (This is done
  217. by the two instances of <code>match_operand</code>.) Operand 3 of the insn
  218. will be the entire commutative expression: use <code>GET_CODE
  219. (operands[3])</code> to see which commutative operator was used.
  220. </p>
  221. <p>The machine mode <var>m</var> of <code>match_operator</code> works like that of
  222. <code>match_operand</code>: it is passed as the second argument to the
  223. predicate function, and that function is solely responsible for
  224. deciding whether the expression to be matched &ldquo;has&rdquo; that mode.
  225. </p>
  226. <p>When constructing an insn, argument 3 of the gen-function will specify
  227. the operation (i.e. the expression code) for the expression to be
  228. made. It should be an RTL expression, whose expression code is copied
  229. into a new expression whose operands are arguments 1 and 2 of the
  230. gen-function. The subexpressions of argument 3 are not used;
  231. only its expression code matters.
  232. </p>
  233. <p>When <code>match_operator</code> is used in a pattern for matching an insn,
  234. it usually best if the operand number of the <code>match_operator</code>
  235. is higher than that of the actual operands of the insn. This improves
  236. register allocation because the register allocator often looks at
  237. operands 1 and 2 of insns to see if it can do register tying.
  238. </p>
  239. <p>There is no way to specify constraints in <code>match_operator</code>. The
  240. operand of the insn which corresponds to the <code>match_operator</code>
  241. never has any constraints because it is never reloaded as a whole.
  242. However, if parts of its <var>operands</var> are matched by
  243. <code>match_operand</code> patterns, those parts may have constraints of
  244. their own.
  245. </p>
  246. <a name="index-match_005fop_005fdup"></a>
  247. </dd>
  248. <dt><code>(match_op_dup:<var>m</var> <var>n</var>[<var>operands</var>&hellip;])</code></dt>
  249. <dd><p>Like <code>match_dup</code>, except that it applies to operators instead of
  250. operands. When constructing an insn, operand number <var>n</var> will be
  251. substituted at this point. But in matching, <code>match_op_dup</code> behaves
  252. differently. It assumes that operand number <var>n</var> has already been
  253. determined by a <code>match_operator</code> appearing earlier in the
  254. recognition template, and it matches only an identical-looking
  255. expression.
  256. </p>
  257. <a name="index-match_005fparallel"></a>
  258. </dd>
  259. <dt><code>(match_parallel <var>n</var> <var>predicate</var> [<var>subpat</var>&hellip;])</code></dt>
  260. <dd><p>This pattern is a placeholder for an insn that consists of a
  261. <code>parallel</code> expression with a variable number of elements. This
  262. expression should only appear at the top level of an insn pattern.
  263. </p>
  264. <p>When constructing an insn, operand number <var>n</var> will be substituted at
  265. this point. When matching an insn, it matches if the body of the insn
  266. is a <code>parallel</code> expression with at least as many elements as the
  267. vector of <var>subpat</var> expressions in the <code>match_parallel</code>, if each
  268. <var>subpat</var> matches the corresponding element of the <code>parallel</code>,
  269. <em>and</em> the function <var>predicate</var> returns nonzero on the
  270. <code>parallel</code> that is the body of the insn. It is the responsibility
  271. of the predicate to validate elements of the <code>parallel</code> beyond
  272. those listed in the <code>match_parallel</code>.
  273. </p>
  274. <p>A typical use of <code>match_parallel</code> is to match load and store
  275. multiple expressions, which can contain a variable number of elements
  276. in a <code>parallel</code>. For example,
  277. </p>
  278. <div class="smallexample">
  279. <pre class="smallexample">(define_insn &quot;&quot;
  280. [(match_parallel 0 &quot;load_multiple_operation&quot;
  281. [(set (match_operand:SI 1 &quot;gpc_reg_operand&quot; &quot;=r&quot;)
  282. (match_operand:SI 2 &quot;memory_operand&quot; &quot;m&quot;))
  283. (use (reg:SI 179))
  284. (clobber (reg:SI 179))])]
  285. &quot;&quot;
  286. &quot;loadm 0,0,%1,%2&quot;)
  287. </pre></div>
  288. <p>This example comes from <samp>a29k.md</samp>. The function
  289. <code>load_multiple_operation</code> is defined in <samp>a29k.c</samp> and checks
  290. that subsequent elements in the <code>parallel</code> are the same as the
  291. <code>set</code> in the pattern, except that they are referencing subsequent
  292. registers and memory locations.
  293. </p>
  294. <p>An insn that matches this pattern might look like:
  295. </p>
  296. <div class="smallexample">
  297. <pre class="smallexample">(parallel
  298. [(set (reg:SI 20) (mem:SI (reg:SI 100)))
  299. (use (reg:SI 179))
  300. (clobber (reg:SI 179))
  301. (set (reg:SI 21)
  302. (mem:SI (plus:SI (reg:SI 100)
  303. (const_int 4))))
  304. (set (reg:SI 22)
  305. (mem:SI (plus:SI (reg:SI 100)
  306. (const_int 8))))])
  307. </pre></div>
  308. <a name="index-match_005fpar_005fdup"></a>
  309. </dd>
  310. <dt><code>(match_par_dup <var>n</var> [<var>subpat</var>&hellip;])</code></dt>
  311. <dd><p>Like <code>match_op_dup</code>, but for <code>match_parallel</code> instead of
  312. <code>match_operator</code>.
  313. </p>
  314. </dd>
  315. </dl>
  316. <hr>
  317. <div class="header">
  318. <p>
  319. Next: <a href="Output-Template.html#Output-Template" accesskey="n" rel="next">Output Template</a>, Previous: <a href="Example.html#Example" accesskey="p" rel="prev">Example</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>
  320. </div>
  321. </body>
  322. </html>