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.

227 lines
11KB

  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>Defining Predicates (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Defining Predicates (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Defining Predicates (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="Predicates.html#Predicates" rel="up" title="Predicates">
  30. <link href="Constraints.html#Constraints" rel="next" title="Constraints">
  31. <link href="Machine_002dIndependent-Predicates.html#Machine_002dIndependent-Predicates" rel="prev" title="Machine-Independent Predicates">
  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="Defining-Predicates"></a>
  62. <div class="header">
  63. <p>
  64. Previous: <a href="Machine_002dIndependent-Predicates.html#Machine_002dIndependent-Predicates" accesskey="p" rel="prev">Machine-Independent Predicates</a>, Up: <a href="Predicates.html#Predicates" accesskey="u" rel="up">Predicates</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-Machine_002dSpecific-Predicates"></a>
  68. <h4 class="subsection">17.7.2 Defining Machine-Specific Predicates</h4>
  69. <a name="index-defining-predicates"></a>
  70. <a name="index-define_005fpredicate"></a>
  71. <a name="index-define_005fspecial_005fpredicate"></a>
  72. <p>Many machines have requirements for their operands that cannot be
  73. expressed precisely using the generic predicates. You can define
  74. additional predicates using <code>define_predicate</code> and
  75. <code>define_special_predicate</code> expressions. These expressions have
  76. three operands:
  77. </p>
  78. <ul>
  79. <li> The name of the predicate, as it will be referred to in
  80. <code>match_operand</code> or <code>match_operator</code> expressions.
  81. </li><li> An RTL expression which evaluates to true if the predicate allows the
  82. operand <var>op</var>, false if it does not. This expression can only use
  83. the following RTL codes:
  84. <dl compact="compact">
  85. <dt><code>MATCH_OPERAND</code></dt>
  86. <dd><p>When written inside a predicate expression, a <code>MATCH_OPERAND</code>
  87. expression evaluates to true if the predicate it names would allow
  88. <var>op</var>. The operand number and constraint are ignored. Due to
  89. limitations in <code>genrecog</code>, you can only refer to generic
  90. predicates and predicates that have already been defined.
  91. </p>
  92. </dd>
  93. <dt><code>MATCH_CODE</code></dt>
  94. <dd><p>This expression evaluates to true if <var>op</var> or a specified
  95. subexpression of <var>op</var> has one of a given list of RTX codes.
  96. </p>
  97. <p>The first operand of this expression is a string constant containing a
  98. comma-separated list of RTX code names (in lower case). These are the
  99. codes for which the <code>MATCH_CODE</code> will be true.
  100. </p>
  101. <p>The second operand is a string constant which indicates what
  102. subexpression of <var>op</var> to examine. If it is absent or the empty
  103. string, <var>op</var> itself is examined. Otherwise, the string constant
  104. must be a sequence of digits and/or lowercase letters. Each character
  105. indicates a subexpression to extract from the current expression; for
  106. the first character this is <var>op</var>, for the second and subsequent
  107. characters it is the result of the previous character. A digit
  108. <var>n</var> extracts &lsquo;<samp>XEXP&nbsp;(<var>e</var>,&nbsp;<var>n</var>)<!-- /@w --></samp>&rsquo;; a letter <var>l</var>
  109. extracts &lsquo;<samp>XVECEXP&nbsp;(<var>e</var>,&nbsp;0,&nbsp;<var>n</var>)<!-- /@w --></samp>&rsquo; where <var>n</var> is the
  110. alphabetic ordinal of <var>l</var> (0 for &lsquo;a&rsquo;, 1 for &rsquo;b&rsquo;, and so on). The
  111. <code>MATCH_CODE</code> then examines the RTX code of the subexpression
  112. extracted by the complete string. It is not possible to extract
  113. components of an <code>rtvec</code> that is not at position 0 within its RTX
  114. object.
  115. </p>
  116. </dd>
  117. <dt><code>MATCH_TEST</code></dt>
  118. <dd><p>This expression has one operand, a string constant containing a C
  119. expression. The predicate&rsquo;s arguments, <var>op</var> and <var>mode</var>, are
  120. available with those names in the C expression. The <code>MATCH_TEST</code>
  121. evaluates to true if the C expression evaluates to a nonzero value.
  122. <code>MATCH_TEST</code> expressions must not have side effects.
  123. </p>
  124. </dd>
  125. <dt><code>AND</code></dt>
  126. <dt><code>IOR</code></dt>
  127. <dt><code>NOT</code></dt>
  128. <dt><code>IF_THEN_ELSE</code></dt>
  129. <dd><p>The basic &lsquo;<samp>MATCH_</samp>&rsquo; expressions can be combined using these
  130. logical operators, which have the semantics of the C operators
  131. &lsquo;<samp>&amp;&amp;</samp>&rsquo;, &lsquo;<samp>||</samp>&rsquo;, &lsquo;<samp>!</samp>&rsquo;, and &lsquo;<samp>?&nbsp;:<!-- /@w --></samp>&rsquo; respectively. As
  132. in Common Lisp, you may give an <code>AND</code> or <code>IOR</code> expression an
  133. arbitrary number of arguments; this has exactly the same effect as
  134. writing a chain of two-argument <code>AND</code> or <code>IOR</code> expressions.
  135. </p></dd>
  136. </dl>
  137. </li><li> An optional block of C code, which should execute
  138. &lsquo;<samp>return&nbsp;true<!-- /@w --></samp>&rsquo; if the predicate is found to match and
  139. &lsquo;<samp>return&nbsp;false<!-- /@w --></samp>&rsquo; if it does not. It must not have any side
  140. effects. The predicate arguments, <var>op</var> and <var>mode</var>, are
  141. available with those names.
  142. <p>If a code block is present in a predicate definition, then the RTL
  143. expression must evaluate to true <em>and</em> the code block must
  144. execute &lsquo;<samp>return&nbsp;true<!-- /@w --></samp>&rsquo; for the predicate to allow the operand.
  145. The RTL expression is evaluated first; do not re-check anything in the
  146. code block that was checked in the RTL expression.
  147. </p></li></ul>
  148. <p>The program <code>genrecog</code> scans <code>define_predicate</code> and
  149. <code>define_special_predicate</code> expressions to determine which RTX
  150. codes are possibly allowed. You should always make this explicit in
  151. the RTL predicate expression, using <code>MATCH_OPERAND</code> and
  152. <code>MATCH_CODE</code>.
  153. </p>
  154. <p>Here is an example of a simple predicate definition, from the IA64
  155. machine description:
  156. </p>
  157. <div class="smallexample">
  158. <pre class="smallexample">;; <span class="roman">True if <var>op</var> is a <code>SYMBOL_REF</code> which refers to the sdata section.</span>
  159. (define_predicate &quot;small_addr_symbolic_operand&quot;
  160. (and (match_code &quot;symbol_ref&quot;)
  161. (match_test &quot;SYMBOL_REF_SMALL_ADDR_P (op)&quot;)))
  162. </pre></div>
  163. <p>And here is another, showing the use of the C block.
  164. </p>
  165. <div class="smallexample">
  166. <pre class="smallexample">;; <span class="roman">True if <var>op</var> is a register operand that is (or could be) a GR reg.</span>
  167. (define_predicate &quot;gr_register_operand&quot;
  168. (match_operand 0 &quot;register_operand&quot;)
  169. {
  170. unsigned int regno;
  171. if (GET_CODE (op) == SUBREG)
  172. op = SUBREG_REG (op);
  173. regno = REGNO (op);
  174. return (regno &gt;= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
  175. })
  176. </pre></div>
  177. <p>Predicates written with <code>define_predicate</code> automatically include
  178. a test that <var>mode</var> is <code>VOIDmode</code>, or <var>op</var> has the same
  179. mode as <var>mode</var>, or <var>op</var> is a <code>CONST_INT</code> or
  180. <code>CONST_DOUBLE</code>. They do <em>not</em> check specifically for
  181. integer <code>CONST_DOUBLE</code>, nor do they test that the value of either
  182. kind of constant fits in the requested mode. This is because
  183. target-specific predicates that take constants usually have to do more
  184. stringent value checks anyway. If you need the exact same treatment
  185. of <code>CONST_INT</code> or <code>CONST_DOUBLE</code> that the generic predicates
  186. provide, use a <code>MATCH_OPERAND</code> subexpression to call
  187. <code>const_int_operand</code>, <code>const_double_operand</code>, or
  188. <code>immediate_operand</code>.
  189. </p>
  190. <p>Predicates written with <code>define_special_predicate</code> do not get any
  191. automatic mode checks, and are treated as having special mode handling
  192. by <code>genrecog</code>.
  193. </p>
  194. <p>The program <code>genpreds</code> is responsible for generating code to
  195. test predicates. It also writes a header file containing function
  196. declarations for all machine-specific predicates. It is not necessary
  197. to declare these predicates in <samp><var>cpu</var>-protos.h</samp>.
  198. </p>
  199. <hr>
  200. <div class="header">
  201. <p>
  202. Previous: <a href="Machine_002dIndependent-Predicates.html#Machine_002dIndependent-Predicates" accesskey="p" rel="prev">Machine-Independent Predicates</a>, Up: <a href="Predicates.html#Predicates" accesskey="u" rel="up">Predicates</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>
  203. </div>
  204. </body>
  205. </html>