Define-Constraints.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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: Define Constraints</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Define Constraints">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Define Constraints">
  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="Constraints.html#Constraints" rel="up" title="Constraints">
  30. <link href="C-Constraint-Interface.html#C-Constraint-Interface" rel="next" title="C Constraint Interface">
  31. <link href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives" rel="prev" title="Disable Insn Alternatives">
  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="Define-Constraints"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="C-Constraint-Interface.html#C-Constraint-Interface" accesskey="n" rel="next">C Constraint Interface</a>, Previous: <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives" accesskey="p" rel="prev">Disable Insn Alternatives</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>
  66. </div>
  67. <hr>
  68. <a name="Defining-Machine_002dSpecific-Constraints"></a>
  69. <h4 class="subsection">16.8.7 Defining Machine-Specific Constraints</h4>
  70. <a name="index-defining-constraints"></a>
  71. <a name="index-constraints_002c-defining"></a>
  72. <p>Machine-specific constraints fall into two categories: register and
  73. non-register constraints. Within the latter category, constraints
  74. which allow subsets of all possible memory or address operands should
  75. be specially marked, to give <code>reload</code> more information.
  76. </p>
  77. <p>Machine-specific constraints can be given names of arbitrary length,
  78. but they must be entirely composed of letters, digits, underscores
  79. (&lsquo;<samp>_</samp>&rsquo;), and angle brackets (&lsquo;<samp>&lt; &gt;</samp>&rsquo;). Like C identifiers, they
  80. must begin with a letter or underscore.
  81. </p>
  82. <p>In order to avoid ambiguity in operand constraint strings, no
  83. constraint can have a name that begins with any other constraint&rsquo;s
  84. name. For example, if <code>x</code> is defined as a constraint name,
  85. <code>xy</code> may not be, and vice versa. As a consequence of this rule,
  86. no constraint may begin with one of the generic constraint letters:
  87. &lsquo;<samp>E F V X g i m n o p r s</samp>&rsquo;.
  88. </p>
  89. <p>Register constraints correspond directly to register classes.
  90. See <a href="Register-Classes.html#Register-Classes">Register Classes</a>. There is thus not much flexibility in their
  91. definitions.
  92. </p>
  93. <dl>
  94. <dt><a name="index-define_005fregister_005fconstraint"></a>MD Expression: <strong>define_register_constraint</strong> <em>name regclass docstring</em></dt>
  95. <dd><p>All three arguments are string constants.
  96. <var>name</var> is the name of the constraint, as it will appear in
  97. <code>match_operand</code> expressions. If <var>name</var> is a multi-letter
  98. constraint its length shall be the same for all constraints starting
  99. with the same letter. <var>regclass</var> can be either the
  100. name of the corresponding register class (see <a href="Register-Classes.html#Register-Classes">Register Classes</a>),
  101. or a C expression which evaluates to the appropriate register class.
  102. If it is an expression, it must have no side effects, and it cannot
  103. look at the operand. The usual use of expressions is to map some
  104. register constraints to <code>NO_REGS</code> when the register class
  105. is not available on a given subarchitecture.
  106. </p>
  107. <p><var>docstring</var> is a sentence documenting the meaning of the
  108. constraint. Docstrings are explained further below.
  109. </p></dd></dl>
  110. <p>Non-register constraints are more like predicates: the constraint
  111. definition gives a boolean expression which indicates whether the
  112. constraint matches.
  113. </p>
  114. <dl>
  115. <dt><a name="index-define_005fconstraint"></a>MD Expression: <strong>define_constraint</strong> <em>name docstring exp</em></dt>
  116. <dd><p>The <var>name</var> and <var>docstring</var> arguments are the same as for
  117. <code>define_register_constraint</code>, but note that the docstring comes
  118. immediately after the name for these expressions. <var>exp</var> is an RTL
  119. expression, obeying the same rules as the RTL expressions in predicate
  120. definitions. See <a href="Defining-Predicates.html#Defining-Predicates">Defining Predicates</a>, for details. If it
  121. evaluates true, the constraint matches; if it evaluates false, it
  122. doesn&rsquo;t. Constraint expressions should indicate which RTL codes they
  123. might match, just like predicate expressions.
  124. </p>
  125. <p><code>match_test</code> C expressions have access to the
  126. following variables:
  127. </p>
  128. <dl compact="compact">
  129. <dt><var>op</var></dt>
  130. <dd><p>The RTL object defining the operand.
  131. </p></dd>
  132. <dt><var>mode</var></dt>
  133. <dd><p>The machine mode of <var>op</var>.
  134. </p></dd>
  135. <dt><var>ival</var></dt>
  136. <dd><p>&lsquo;<samp>INTVAL (<var>op</var>)</samp>&rsquo;, if <var>op</var> is a <code>const_int</code>.
  137. </p></dd>
  138. <dt><var>hval</var></dt>
  139. <dd><p>&lsquo;<samp>CONST_DOUBLE_HIGH (<var>op</var>)</samp>&rsquo;, if <var>op</var> is an integer
  140. <code>const_double</code>.
  141. </p></dd>
  142. <dt><var>lval</var></dt>
  143. <dd><p>&lsquo;<samp>CONST_DOUBLE_LOW (<var>op</var>)</samp>&rsquo;, if <var>op</var> is an integer
  144. <code>const_double</code>.
  145. </p></dd>
  146. <dt><var>rval</var></dt>
  147. <dd><p>&lsquo;<samp>CONST_DOUBLE_REAL_VALUE (<var>op</var>)</samp>&rsquo;, if <var>op</var> is a floating-point
  148. <code>const_double</code>.
  149. </p></dd>
  150. </dl>
  151. <p>The <var>*val</var> variables should only be used once another piece of the
  152. expression has verified that <var>op</var> is the appropriate kind of RTL
  153. object.
  154. </p></dd></dl>
  155. <p>Most non-register constraints should be defined with
  156. <code>define_constraint</code>. The remaining two definition expressions
  157. are only appropriate for constraints that should be handled specially
  158. by <code>reload</code> if they fail to match.
  159. </p>
  160. <dl>
  161. <dt><a name="index-define_005fmemory_005fconstraint"></a>MD Expression: <strong>define_memory_constraint</strong> <em>name docstring exp</em></dt>
  162. <dd><p>Use this expression for constraints that match a subset of all memory
  163. operands: that is, <code>reload</code> can make them match by converting the
  164. operand to the form &lsquo;<samp>(mem&nbsp;(reg&nbsp;<var>X</var>))<!-- /@w --></samp>&rsquo;, where <var>X</var> is a
  165. base register (from the register class specified by
  166. <code>BASE_REG_CLASS</code>, see <a href="Register-Classes.html#Register-Classes">Register Classes</a>).
  167. </p>
  168. <p>For example, on the S/390, some instructions do not accept arbitrary
  169. memory references, but only those that do not make use of an index
  170. register. The constraint letter &lsquo;<samp>Q</samp>&rsquo; is defined to represent a
  171. memory address of this type. If &lsquo;<samp>Q</samp>&rsquo; is defined with
  172. <code>define_memory_constraint</code>, a &lsquo;<samp>Q</samp>&rsquo; constraint can handle any
  173. memory operand, because <code>reload</code> knows it can simply copy the
  174. memory address into a base register if required. This is analogous to
  175. the way an &lsquo;<samp>o</samp>&rsquo; constraint can handle any memory operand.
  176. </p>
  177. <p>The syntax and semantics are otherwise identical to
  178. <code>define_constraint</code>.
  179. </p></dd></dl>
  180. <dl>
  181. <dt><a name="index-define_005fspecial_005fmemory_005fconstraint"></a>MD Expression: <strong>define_special_memory_constraint</strong> <em>name docstring exp</em></dt>
  182. <dd><p>Use this expression for constraints that match a subset of all memory
  183. operands: that is, <code>reload</code> can not make them match by reloading
  184. the address as it is described for <code>define_memory_constraint</code> or
  185. such address reload is undesirable with the performance point of view.
  186. </p>
  187. <p>For example, <code>define_special_memory_constraint</code> can be useful if
  188. specifically aligned memory is necessary or desirable for some insn
  189. operand.
  190. </p>
  191. <p>The syntax and semantics are otherwise identical to
  192. <code>define_constraint</code>.
  193. </p></dd></dl>
  194. <dl>
  195. <dt><a name="index-define_005faddress_005fconstraint"></a>MD Expression: <strong>define_address_constraint</strong> <em>name docstring exp</em></dt>
  196. <dd><p>Use this expression for constraints that match a subset of all address
  197. operands: that is, <code>reload</code> can make the constraint match by
  198. converting the operand to the form &lsquo;<samp>(reg&nbsp;<var>X</var>)<!-- /@w --></samp>&rsquo;, again
  199. with <var>X</var> a base register.
  200. </p>
  201. <p>Constraints defined with <code>define_address_constraint</code> can only be
  202. used with the <code>address_operand</code> predicate, or machine-specific
  203. predicates that work the same way. They are treated analogously to
  204. the generic &lsquo;<samp>p</samp>&rsquo; constraint.
  205. </p>
  206. <p>The syntax and semantics are otherwise identical to
  207. <code>define_constraint</code>.
  208. </p></dd></dl>
  209. <p>For historical reasons, names beginning with the letters &lsquo;<samp>G H</samp>&rsquo;
  210. are reserved for constraints that match only <code>const_double</code>s, and
  211. names beginning with the letters &lsquo;<samp>I J K L M N O P</samp>&rsquo; are reserved
  212. for constraints that match only <code>const_int</code>s. This may change in
  213. the future. For the time being, constraints with these names must be
  214. written in a stylized form, so that <code>genpreds</code> can tell you did
  215. it correctly:
  216. </p>
  217. <div class="smallexample">
  218. <pre class="smallexample">(define_constraint &quot;[<var>GHIJKLMNOP</var>]&hellip;&quot;
  219. &quot;<var>doc</var>&hellip;&quot;
  220. (and (match_code &quot;const_int&quot;) ; <span class="roman"><code>const_double</code> for G/H</span>
  221. <var>condition</var>&hellip;)) ; <span class="roman">usually a <code>match_test</code></span>
  222. </pre></div>
  223. <p>It is fine to use names beginning with other letters for constraints
  224. that match <code>const_double</code>s or <code>const_int</code>s.
  225. </p>
  226. <p>Each docstring in a constraint definition should be one or more complete
  227. sentences, marked up in Texinfo format. <em>They are currently unused.</em>
  228. In the future they will be copied into the GCC manual, in <a href="Machine-Constraints.html#Machine-Constraints">Machine Constraints</a>, replacing the hand-maintained tables currently found in
  229. that section. Also, in the future the compiler may use this to give
  230. more helpful diagnostics when poor choice of <code>asm</code> constraints
  231. causes a reload failure.
  232. </p>
  233. <p>If you put the pseudo-Texinfo directive &lsquo;<samp>@internal</samp>&rsquo; at the
  234. beginning of a docstring, then (in the future) it will appear only in
  235. the internals manual&rsquo;s version of the machine-specific constraint tables.
  236. Use this for constraints that should not appear in <code>asm</code> statements.
  237. </p>
  238. <hr>
  239. <div class="header">
  240. <p>
  241. Next: <a href="C-Constraint-Interface.html#C-Constraint-Interface" accesskey="n" rel="next">C Constraint Interface</a>, Previous: <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives" accesskey="p" rel="prev">Disable Insn Alternatives</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>
  242. </div>
  243. </body>
  244. </html>