Predicates.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: Predicates</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Predicates">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Predicates">
  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="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
  30. <link href="Machine_002dIndependent-Predicates.html#Machine_002dIndependent-Predicates" rel="next" title="Machine-Independent Predicates">
  31. <link href="Output-Statement.html#Output-Statement" rel="prev" title="Output Statement">
  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="Predicates"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Constraints.html#Constraints" accesskey="n" rel="next">Constraints</a>, Previous: <a href="Output-Statement.html#Output-Statement" accesskey="p" rel="prev">Output Statement</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>
  66. </div>
  67. <hr>
  68. <a name="Predicates-1"></a>
  69. <h3 class="section">16.7 Predicates</h3>
  70. <a name="index-predicates"></a>
  71. <a name="index-operand-predicates"></a>
  72. <a name="index-operator-predicates"></a>
  73. <p>A predicate determines whether a <code>match_operand</code> or
  74. <code>match_operator</code> expression matches, and therefore whether the
  75. surrounding instruction pattern will be used for that combination of
  76. operands. GCC has a number of machine-independent predicates, and you
  77. can define machine-specific predicates as needed. By convention,
  78. predicates used with <code>match_operand</code> have names that end in
  79. &lsquo;<samp>_operand</samp>&rsquo;, and those used with <code>match_operator</code> have names
  80. that end in &lsquo;<samp>_operator</samp>&rsquo;.
  81. </p>
  82. <p>All predicates are boolean functions (in the mathematical sense) of
  83. two arguments: the RTL expression that is being considered at that
  84. position in the instruction pattern, and the machine mode that the
  85. <code>match_operand</code> or <code>match_operator</code> specifies. In this
  86. section, the first argument is called <var>op</var> and the second argument
  87. <var>mode</var>. Predicates can be called from C as ordinary two-argument
  88. functions; this can be useful in output templates or other
  89. machine-specific code.
  90. </p>
  91. <p>Operand predicates can allow operands that are not actually acceptable
  92. to the hardware, as long as the constraints give reload the ability to
  93. fix them up (see <a href="Constraints.html#Constraints">Constraints</a>). However, GCC will usually generate
  94. better code if the predicates specify the requirements of the machine
  95. instructions as closely as possible. Reload cannot fix up operands
  96. that must be constants (&ldquo;immediate operands&rdquo;); you must use a
  97. predicate that allows only constants, or else enforce the requirement
  98. in the extra condition.
  99. </p>
  100. <a name="index-predicates-and-machine-modes"></a>
  101. <a name="index-normal-predicates"></a>
  102. <a name="index-special-predicates"></a>
  103. <p>Most predicates handle their <var>mode</var> argument in a uniform manner.
  104. If <var>mode</var> is <code>VOIDmode</code> (unspecified), then <var>op</var> can have
  105. any mode. If <var>mode</var> is anything else, then <var>op</var> must have the
  106. same mode, unless <var>op</var> is a <code>CONST_INT</code> or integer
  107. <code>CONST_DOUBLE</code>. These RTL expressions always have
  108. <code>VOIDmode</code>, so it would be counterproductive to check that their
  109. mode matches. Instead, predicates that accept <code>CONST_INT</code> and/or
  110. integer <code>CONST_DOUBLE</code> check that the value stored in the
  111. constant will fit in the requested mode.
  112. </p>
  113. <p>Predicates with this behavior are called <em>normal</em>.
  114. <code>genrecog</code> can optimize the instruction recognizer based on
  115. knowledge of how normal predicates treat modes. It can also diagnose
  116. certain kinds of common errors in the use of normal predicates; for
  117. instance, it is almost always an error to use a normal predicate
  118. without specifying a mode.
  119. </p>
  120. <p>Predicates that do something different with their <var>mode</var> argument
  121. are called <em>special</em>. The generic predicates
  122. <code>address_operand</code> and <code>pmode_register_operand</code> are special
  123. predicates. <code>genrecog</code> does not do any optimizations or
  124. diagnosis when special predicates are used.
  125. </p>
  126. <table class="menu" border="0" cellspacing="0">
  127. <tr><td align="left" valign="top">&bull; <a href="Machine_002dIndependent-Predicates.html#Machine_002dIndependent-Predicates" accesskey="1">Machine-Independent Predicates</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Predicates available to all back ends.
  128. </td></tr>
  129. <tr><td align="left" valign="top">&bull; <a href="Defining-Predicates.html#Defining-Predicates" accesskey="2">Defining Predicates</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How to write machine-specific predicate
  130. functions.
  131. </td></tr>
  132. </table>
  133. <hr>
  134. <div class="header">
  135. <p>
  136. Next: <a href="Constraints.html#Constraints" accesskey="n" rel="next">Constraints</a>, Previous: <a href="Output-Statement.html#Output-Statement" accesskey="p" rel="prev">Output Statement</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>
  137. </div>
  138. </body>
  139. </html>