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.

433 linhas
20KB

  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>Simple Constraints (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Simple Constraints (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Simple Constraints (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="Constraints.html#Constraints" rel="up" title="Constraints">
  30. <link href="Multi_002dAlternative.html#Multi_002dAlternative" rel="next" title="Multi-Alternative">
  31. <link href="Constraints.html#Constraints" rel="prev" title="Constraints">
  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="Simple-Constraints"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Multi_002dAlternative.html#Multi_002dAlternative" accesskey="n" rel="next">Multi-Alternative</a>, Up: <a href="Constraints.html#Constraints" accesskey="u" rel="up">Constraints</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="Simple-Constraints-1"></a>
  68. <h4 class="subsection">17.8.1 Simple Constraints</h4>
  69. <a name="index-simple-constraints"></a>
  70. <p>The simplest kind of constraint is a string full of letters, each of
  71. which describes one kind of operand that is permitted. Here are
  72. the letters that are allowed:
  73. </p>
  74. <dl compact="compact">
  75. <dt>whitespace</dt>
  76. <dd><p>Whitespace characters are ignored and can be inserted at any position
  77. except the first. This enables each alternative for different operands to
  78. be visually aligned in the machine description even if they have different
  79. number of constraints and modifiers.
  80. </p>
  81. <a name="index-m-in-constraint"></a>
  82. <a name="index-memory-references-in-constraints"></a>
  83. </dd>
  84. <dt>&lsquo;<samp>m</samp>&rsquo;</dt>
  85. <dd><p>A memory operand is allowed, with any kind of address that the machine
  86. supports in general.
  87. Note that the letter used for the general memory constraint can be
  88. re-defined by a back end using the <code>TARGET_MEM_CONSTRAINT</code> macro.
  89. </p>
  90. <a name="index-offsettable-address"></a>
  91. <a name="index-o-in-constraint"></a>
  92. </dd>
  93. <dt>&lsquo;<samp>o</samp>&rsquo;</dt>
  94. <dd><p>A memory operand is allowed, but only if the address is
  95. <em>offsettable</em>. This means that adding a small integer (actually,
  96. the width in bytes of the operand, as determined by its machine mode)
  97. may be added to the address and the result is also a valid memory
  98. address.
  99. </p>
  100. <a name="index-autoincrement_002fdecrement-addressing"></a>
  101. <p>For example, an address which is constant is offsettable; so is an
  102. address that is the sum of a register and a constant (as long as a
  103. slightly larger constant is also within the range of address-offsets
  104. supported by the machine); but an autoincrement or autodecrement
  105. address is not offsettable. More complicated indirect/indexed
  106. addresses may or may not be offsettable depending on the other
  107. addressing modes that the machine supports.
  108. </p>
  109. <p>Note that in an output operand which can be matched by another
  110. operand, the constraint letter &lsquo;<samp>o</samp>&rsquo; is valid only when accompanied
  111. by both &lsquo;<samp>&lt;</samp>&rsquo; (if the target machine has predecrement addressing)
  112. and &lsquo;<samp>&gt;</samp>&rsquo; (if the target machine has preincrement addressing).
  113. </p>
  114. <a name="index-V-in-constraint"></a>
  115. </dd>
  116. <dt>&lsquo;<samp>V</samp>&rsquo;</dt>
  117. <dd><p>A memory operand that is not offsettable. In other words, anything that
  118. would fit the &lsquo;<samp>m</samp>&rsquo; constraint but not the &lsquo;<samp>o</samp>&rsquo; constraint.
  119. </p>
  120. <a name="index-_003c-in-constraint"></a>
  121. </dd>
  122. <dt>&lsquo;<samp>&lt;</samp>&rsquo;</dt>
  123. <dd><p>A memory operand with autodecrement addressing (either predecrement or
  124. postdecrement) is allowed. In inline <code>asm</code> this constraint is only
  125. allowed if the operand is used exactly once in an instruction that can
  126. handle the side effects. Not using an operand with &lsquo;<samp>&lt;</samp>&rsquo; in constraint
  127. string in the inline <code>asm</code> pattern at all or using it in multiple
  128. instructions isn&rsquo;t valid, because the side effects wouldn&rsquo;t be performed
  129. or would be performed more than once. Furthermore, on some targets
  130. the operand with &lsquo;<samp>&lt;</samp>&rsquo; in constraint string must be accompanied by
  131. special instruction suffixes like <code>%U0</code> instruction suffix on PowerPC
  132. or <code>%P0</code> on IA-64.
  133. </p>
  134. <a name="index-_003e-in-constraint"></a>
  135. </dd>
  136. <dt>&lsquo;<samp>&gt;</samp>&rsquo;</dt>
  137. <dd><p>A memory operand with autoincrement addressing (either preincrement or
  138. postincrement) is allowed. In inline <code>asm</code> the same restrictions
  139. as for &lsquo;<samp>&lt;</samp>&rsquo; apply.
  140. </p>
  141. <a name="index-r-in-constraint"></a>
  142. <a name="index-registers-in-constraints"></a>
  143. </dd>
  144. <dt>&lsquo;<samp>r</samp>&rsquo;</dt>
  145. <dd><p>A register operand is allowed provided that it is in a general
  146. register.
  147. </p>
  148. <a name="index-constants-in-constraints"></a>
  149. <a name="index-i-in-constraint"></a>
  150. </dd>
  151. <dt>&lsquo;<samp>i</samp>&rsquo;</dt>
  152. <dd><p>An immediate integer operand (one with constant value) is allowed.
  153. This includes symbolic constants whose values will be known only at
  154. assembly time or later.
  155. </p>
  156. <a name="index-n-in-constraint"></a>
  157. </dd>
  158. <dt>&lsquo;<samp>n</samp>&rsquo;</dt>
  159. <dd><p>An immediate integer operand with a known numeric value is allowed.
  160. Many systems cannot support assembly-time constants for operands less
  161. than a word wide. Constraints for these operands should use &lsquo;<samp>n</samp>&rsquo;
  162. rather than &lsquo;<samp>i</samp>&rsquo;.
  163. </p>
  164. <a name="index-I-in-constraint"></a>
  165. </dd>
  166. <dt>&lsquo;<samp>I</samp>&rsquo;, &lsquo;<samp>J</samp>&rsquo;, &lsquo;<samp>K</samp>&rsquo;, &hellip; &lsquo;<samp>P</samp>&rsquo;</dt>
  167. <dd><p>Other letters in the range &lsquo;<samp>I</samp>&rsquo; through &lsquo;<samp>P</samp>&rsquo; may be defined in
  168. a machine-dependent fashion to permit immediate integer operands with
  169. explicit integer values in specified ranges. For example, on the
  170. 68000, &lsquo;<samp>I</samp>&rsquo; is defined to stand for the range of values 1 to 8.
  171. This is the range permitted as a shift count in the shift
  172. instructions.
  173. </p>
  174. <a name="index-E-in-constraint"></a>
  175. </dd>
  176. <dt>&lsquo;<samp>E</samp>&rsquo;</dt>
  177. <dd><p>An immediate floating operand (expression code <code>const_double</code>) is
  178. allowed, but only if the target floating point format is the same as
  179. that of the host machine (on which the compiler is running).
  180. </p>
  181. <a name="index-F-in-constraint"></a>
  182. </dd>
  183. <dt>&lsquo;<samp>F</samp>&rsquo;</dt>
  184. <dd><p>An immediate floating operand (expression code <code>const_double</code> or
  185. <code>const_vector</code>) is allowed.
  186. </p>
  187. <a name="index-G-in-constraint"></a>
  188. <a name="index-H-in-constraint"></a>
  189. </dd>
  190. <dt>&lsquo;<samp>G</samp>&rsquo;, &lsquo;<samp>H</samp>&rsquo;</dt>
  191. <dd><p>&lsquo;<samp>G</samp>&rsquo; and &lsquo;<samp>H</samp>&rsquo; may be defined in a machine-dependent fashion to
  192. permit immediate floating operands in particular ranges of values.
  193. </p>
  194. <a name="index-s-in-constraint"></a>
  195. </dd>
  196. <dt>&lsquo;<samp>s</samp>&rsquo;</dt>
  197. <dd><p>An immediate integer operand whose value is not an explicit integer is
  198. allowed.
  199. </p>
  200. <p>This might appear strange; if an insn allows a constant operand with a
  201. value not known at compile time, it certainly must allow any known
  202. value. So why use &lsquo;<samp>s</samp>&rsquo; instead of &lsquo;<samp>i</samp>&rsquo;? Sometimes it allows
  203. better code to be generated.
  204. </p>
  205. <p>For example, on the 68000 in a fullword instruction it is possible to
  206. use an immediate operand; but if the immediate value is between -128
  207. and 127, better code results from loading the value into a register and
  208. using the register. This is because the load into the register can be
  209. done with a &lsquo;<samp>moveq</samp>&rsquo; instruction. We arrange for this to happen
  210. by defining the letter &lsquo;<samp>K</samp>&rsquo; to mean &ldquo;any integer outside the
  211. range -128 to 127&rdquo;, and then specifying &lsquo;<samp>Ks</samp>&rsquo; in the operand
  212. constraints.
  213. </p>
  214. <a name="index-g-in-constraint"></a>
  215. </dd>
  216. <dt>&lsquo;<samp>g</samp>&rsquo;</dt>
  217. <dd><p>Any register, memory or immediate integer operand is allowed, except for
  218. registers that are not general registers.
  219. </p>
  220. <a name="index-X-in-constraint"></a>
  221. </dd>
  222. <dt>&lsquo;<samp>X</samp>&rsquo;</dt>
  223. <dd><p>Any operand whatsoever is allowed, even if it does not satisfy
  224. <code>general_operand</code>. This is normally used in the constraint of
  225. a <code>match_scratch</code> when certain alternatives will not actually
  226. require a scratch register.
  227. </p>
  228. <a name="index-0-in-constraint"></a>
  229. <a name="index-digits-in-constraint"></a>
  230. </dd>
  231. <dt>&lsquo;<samp>0</samp>&rsquo;, &lsquo;<samp>1</samp>&rsquo;, &lsquo;<samp>2</samp>&rsquo;, &hellip; &lsquo;<samp>9</samp>&rsquo;</dt>
  232. <dd><p>An operand that matches the specified operand number is allowed. If a
  233. digit is used together with letters within the same alternative, the
  234. digit should come last.
  235. </p>
  236. <p>This number is allowed to be more than a single digit. If multiple
  237. digits are encountered consecutively, they are interpreted as a single
  238. decimal integer. There is scant chance for ambiguity, since to-date
  239. it has never been desirable that &lsquo;<samp>10</samp>&rsquo; be interpreted as matching
  240. either operand 1 <em>or</em> operand 0. Should this be desired, one
  241. can use multiple alternatives instead.
  242. </p>
  243. <a name="index-matching-constraint"></a>
  244. <a name="index-constraint_002c-matching"></a>
  245. <p>This is called a <em>matching constraint</em> and what it really means is
  246. that the assembler has only a single operand that fills two roles
  247. considered separate in the RTL insn. For example, an add insn has two
  248. input operands and one output operand in the RTL, but on most CISC
  249. machines an add instruction really has only two operands, one of them an
  250. input-output operand:
  251. </p>
  252. <div class="smallexample">
  253. <pre class="smallexample">addl #35,r12
  254. </pre></div>
  255. <p>Matching constraints are used in these circumstances.
  256. More precisely, the two operands that match must include one input-only
  257. operand and one output-only operand. Moreover, the digit must be a
  258. smaller number than the number of the operand that uses it in the
  259. constraint.
  260. </p>
  261. <p>For operands to match in a particular case usually means that they
  262. are identical-looking RTL expressions. But in a few special cases
  263. specific kinds of dissimilarity are allowed. For example, <code>*x</code>
  264. as an input operand will match <code>*x++</code> as an output operand.
  265. For proper results in such cases, the output template should always
  266. use the output-operand&rsquo;s number when printing the operand.
  267. </p>
  268. <a name="index-load-address-instruction"></a>
  269. <a name="index-push-address-instruction"></a>
  270. <a name="index-address-constraints"></a>
  271. <a name="index-p-in-constraint"></a>
  272. </dd>
  273. <dt>&lsquo;<samp>p</samp>&rsquo;</dt>
  274. <dd><p>An operand that is a valid memory address is allowed. This is
  275. for &ldquo;load address&rdquo; and &ldquo;push address&rdquo; instructions.
  276. </p>
  277. <a name="index-address_005foperand-1"></a>
  278. <p>&lsquo;<samp>p</samp>&rsquo; in the constraint must be accompanied by <code>address_operand</code>
  279. as the predicate in the <code>match_operand</code>. This predicate interprets
  280. the mode specified in the <code>match_operand</code> as the mode of the memory
  281. reference for which the address would be valid.
  282. </p>
  283. <a name="index-other-register-constraints"></a>
  284. <a name="index-extensible-constraints"></a>
  285. </dd>
  286. <dt><var>other-letters</var></dt>
  287. <dd><p>Other letters can be defined in machine-dependent fashion to stand for
  288. particular classes of registers or other arbitrary operand types.
  289. &lsquo;<samp>d</samp>&rsquo;, &lsquo;<samp>a</samp>&rsquo; and &lsquo;<samp>f</samp>&rsquo; are defined on the 68000/68020 to stand
  290. for data, address and floating point registers.
  291. </p></dd>
  292. </dl>
  293. <p>In order to have valid assembler code, each operand must satisfy
  294. its constraint. But a failure to do so does not prevent the pattern
  295. from applying to an insn. Instead, it directs the compiler to modify
  296. the code so that the constraint will be satisfied. Usually this is
  297. done by copying an operand into a register.
  298. </p>
  299. <p>Contrast, therefore, the two instruction patterns that follow:
  300. </p>
  301. <div class="smallexample">
  302. <pre class="smallexample">(define_insn &quot;&quot;
  303. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r&quot;)
  304. (plus:SI (match_dup 0)
  305. (match_operand:SI 1 &quot;general_operand&quot; &quot;r&quot;)))]
  306. &quot;&quot;
  307. &quot;&hellip;&quot;)
  308. </pre></div>
  309. <p>which has two operands, one of which must appear in two places, and
  310. </p>
  311. <div class="smallexample">
  312. <pre class="smallexample">(define_insn &quot;&quot;
  313. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r&quot;)
  314. (plus:SI (match_operand:SI 1 &quot;general_operand&quot; &quot;0&quot;)
  315. (match_operand:SI 2 &quot;general_operand&quot; &quot;r&quot;)))]
  316. &quot;&quot;
  317. &quot;&hellip;&quot;)
  318. </pre></div>
  319. <p>which has three operands, two of which are required by a constraint to be
  320. identical. If we are considering an insn of the form
  321. </p>
  322. <div class="smallexample">
  323. <pre class="smallexample">(insn <var>n</var> <var>prev</var> <var>next</var>
  324. (set (reg:SI 3)
  325. (plus:SI (reg:SI 6) (reg:SI 109)))
  326. &hellip;)
  327. </pre></div>
  328. <p>the first pattern would not apply at all, because this insn does not
  329. contain two identical subexpressions in the right place. The pattern would
  330. say, &ldquo;That does not look like an add instruction; try other patterns&rdquo;.
  331. The second pattern would say, &ldquo;Yes, that&rsquo;s an add instruction, but there
  332. is something wrong with it&rdquo;. It would direct the reload pass of the
  333. compiler to generate additional insns to make the constraint true. The
  334. results might look like this:
  335. </p>
  336. <div class="smallexample">
  337. <pre class="smallexample">(insn <var>n2</var> <var>prev</var> <var>n</var>
  338. (set (reg:SI 3) (reg:SI 6))
  339. &hellip;)
  340. (insn <var>n</var> <var>n2</var> <var>next</var>
  341. (set (reg:SI 3)
  342. (plus:SI (reg:SI 3) (reg:SI 109)))
  343. &hellip;)
  344. </pre></div>
  345. <p>It is up to you to make sure that each operand, in each pattern, has
  346. constraints that can handle any RTL expression that could be present for
  347. that operand. (When multiple alternatives are in use, each pattern must,
  348. for each possible combination of operand expressions, have at least one
  349. alternative which can handle that combination of operands.) The
  350. constraints don&rsquo;t need to <em>allow</em> any possible operand&mdash;when this is
  351. the case, they do not constrain&mdash;but they must at least point the way to
  352. reloading any possible operand so that it will fit.
  353. </p>
  354. <ul>
  355. <li> If the constraint accepts whatever operands the predicate permits,
  356. there is no problem: reloading is never necessary for this operand.
  357. <p>For example, an operand whose constraints permit everything except
  358. registers is safe provided its predicate rejects registers.
  359. </p>
  360. <p>An operand whose predicate accepts only constant values is safe
  361. provided its constraints include the letter &lsquo;<samp>i</samp>&rsquo;. If any possible
  362. constant value is accepted, then nothing less than &lsquo;<samp>i</samp>&rsquo; will do;
  363. if the predicate is more selective, then the constraints may also be
  364. more selective.
  365. </p>
  366. </li><li> Any operand expression can be reloaded by copying it into a register.
  367. So if an operand&rsquo;s constraints allow some kind of register, it is
  368. certain to be safe. It need not permit all classes of registers; the
  369. compiler knows how to copy a register into another register of the
  370. proper class in order to make an instruction valid.
  371. </li><li> <a name="index-nonoffsettable-memory-reference"></a>
  372. <a name="index-memory-reference_002c-nonoffsettable"></a>
  373. A nonoffsettable memory reference can be reloaded by copying the
  374. address into a register. So if the constraint uses the letter
  375. &lsquo;<samp>o</samp>&rsquo;, all memory references are taken care of.
  376. </li><li> A constant operand can be reloaded by allocating space in memory to
  377. hold it as preinitialized data. Then the memory reference can be used
  378. in place of the constant. So if the constraint uses the letters
  379. &lsquo;<samp>o</samp>&rsquo; or &lsquo;<samp>m</samp>&rsquo;, constant operands are not a problem.
  380. </li><li> If the constraint permits a constant and a pseudo register used in an insn
  381. was not allocated to a hard register and is equivalent to a constant,
  382. the register will be replaced with the constant. If the predicate does
  383. not permit a constant and the insn is re-recognized for some reason, the
  384. compiler will crash. Thus the predicate must always recognize any
  385. objects allowed by the constraint.
  386. </li></ul>
  387. <p>If the operand&rsquo;s predicate can recognize registers, but the constraint does
  388. not permit them, it can make the compiler crash. When this operand happens
  389. to be a register, the reload pass will be stymied, because it does not know
  390. how to copy a register temporarily into memory.
  391. </p>
  392. <p>If the predicate accepts a unary operator, the constraint applies to the
  393. operand. For example, the MIPS processor at ISA level 3 supports an
  394. instruction which adds two registers in <code>SImode</code> to produce a
  395. <code>DImode</code> result, but only if the registers are correctly sign
  396. extended. This predicate for the input operands accepts a
  397. <code>sign_extend</code> of an <code>SImode</code> register. Write the constraint
  398. to indicate the type of register that is required for the operand of the
  399. <code>sign_extend</code>.
  400. </p>
  401. <hr>
  402. <div class="header">
  403. <p>
  404. Next: <a href="Multi_002dAlternative.html#Multi_002dAlternative" accesskey="n" rel="next">Multi-Alternative</a>, Up: <a href="Constraints.html#Constraints" accesskey="u" rel="up">Constraints</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>
  405. </div>
  406. </body>
  407. </html>