C-Constraint-Interface.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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: C Constraint Interface</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: C Constraint Interface">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: C Constraint Interface">
  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="Standard-Names.html#Standard-Names" rel="next" title="Standard Names">
  31. <link href="Define-Constraints.html#Define-Constraints" rel="prev" title="Define Constraints">
  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="C-Constraint-Interface"></a>
  63. <div class="header">
  64. <p>
  65. Previous: <a href="Define-Constraints.html#Define-Constraints" accesskey="p" rel="prev">Define Constraints</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="Testing-constraints-from-C"></a>
  69. <h4 class="subsection">16.8.8 Testing constraints from C</h4>
  70. <a name="index-testing-constraints"></a>
  71. <a name="index-constraints_002c-testing"></a>
  72. <p>It is occasionally useful to test a constraint from C code rather than
  73. implicitly via the constraint string in a <code>match_operand</code>. The
  74. generated file <samp>tm_p.h</samp> declares a few interfaces for working
  75. with constraints. At present these are defined for all constraints
  76. except <code>g</code> (which is equivalent to <code>general_operand</code>).
  77. </p>
  78. <p>Some valid constraint names are not valid C identifiers, so there is a
  79. mangling scheme for referring to them from C. Constraint names that
  80. do not contain angle brackets or underscores are left unchanged.
  81. Underscores are doubled, each &lsquo;<samp>&lt;</samp>&rsquo; is replaced with &lsquo;<samp>_l</samp>&rsquo;, and
  82. each &lsquo;<samp>&gt;</samp>&rsquo; with &lsquo;<samp>_g</samp>&rsquo;. Here are some examples:
  83. </p>
  84. <div class="example">
  85. <table>
  86. <tr><td><pre class="example"><strong>Original</strong></pre></td><td><pre class="example"><strong>Mangled</strong></pre></td></tr>
  87. <tr><td><pre class="example"><code>x</code></pre></td><td><pre class="example"><code>x</code></pre></td></tr>
  88. <tr><td><pre class="example"><code>P42x</code></pre></td><td><pre class="example"><code>P42x</code></pre></td></tr>
  89. <tr><td><pre class="example"><code>P4_x</code></pre></td><td><pre class="example"><code>P4__x</code></pre></td></tr>
  90. <tr><td><pre class="example"><code>P4&gt;x</code></pre></td><td><pre class="example"><code>P4_gx</code></pre></td></tr>
  91. <tr><td><pre class="example"><code>P4&gt;&gt;</code></pre></td><td><pre class="example"><code>P4_g_g</code></pre></td></tr>
  92. <tr><td><pre class="example"><code>P4_g&gt;</code></pre></td><td><pre class="example"><code>P4__g_g</code></pre></td></tr>
  93. </table>
  94. </div>
  95. <p>Throughout this section, the variable <var>c</var> is either a constraint
  96. in the abstract sense, or a constant from <code>enum constraint_num</code>;
  97. the variable <var>m</var> is a mangled constraint name (usually as part of
  98. a larger identifier).
  99. </p>
  100. <dl>
  101. <dt><a name="index-constraint_005fnum"></a>Enum: <strong>constraint_num</strong></dt>
  102. <dd><p>For each constraint except <code>g</code>, there is a corresponding
  103. enumeration constant: &lsquo;<samp>CONSTRAINT_</samp>&rsquo; plus the mangled name of the
  104. constraint. Functions that take an <code>enum constraint_num</code> as an
  105. argument expect one of these constants.
  106. </p></dd></dl>
  107. <dl>
  108. <dt><a name="index-satisfies_005fconstraint_005f"></a>Function: <em>inline bool</em> <strong>satisfies_constraint_</strong> <em><var>m</var> (rtx <var>exp</var>)</em></dt>
  109. <dd><p>For each non-register constraint <var>m</var> except <code>g</code>, there is
  110. one of these functions; it returns <code>true</code> if <var>exp</var> satisfies the
  111. constraint. These functions are only visible if <samp>rtl.h</samp> was included
  112. before <samp>tm_p.h</samp>.
  113. </p></dd></dl>
  114. <dl>
  115. <dt><a name="index-constraint_005fsatisfied_005fp"></a>Function: <em>bool</em> <strong>constraint_satisfied_p</strong> <em>(rtx <var>exp</var>, enum constraint_num <var>c</var>)</em></dt>
  116. <dd><p>Like the <code>satisfies_constraint_<var>m</var></code> functions, but the
  117. constraint to test is given as an argument, <var>c</var>. If <var>c</var>
  118. specifies a register constraint, this function will always return
  119. <code>false</code>.
  120. </p></dd></dl>
  121. <dl>
  122. <dt><a name="index-reg_005fclass_005ffor_005fconstraint"></a>Function: <em>enum reg_class</em> <strong>reg_class_for_constraint</strong> <em>(enum constraint_num <var>c</var>)</em></dt>
  123. <dd><p>Returns the register class associated with <var>c</var>. If <var>c</var> is not
  124. a register constraint, or those registers are not available for the
  125. currently selected subtarget, returns <code>NO_REGS</code>.
  126. </p></dd></dl>
  127. <p>Here is an example use of <code>satisfies_constraint_<var>m</var></code>. In
  128. peephole optimizations (see <a href="Peephole-Definitions.html#Peephole-Definitions">Peephole Definitions</a>), operand
  129. constraint strings are ignored, so if there are relevant constraints,
  130. they must be tested in the C condition. In the example, the
  131. optimization is applied if operand 2 does <em>not</em> satisfy the
  132. &lsquo;<samp>K</samp>&rsquo; constraint. (This is a simplified version of a peephole
  133. definition from the i386 machine description.)
  134. </p>
  135. <div class="smallexample">
  136. <pre class="smallexample">(define_peephole2
  137. [(match_scratch:SI 3 &quot;r&quot;)
  138. (set (match_operand:SI 0 &quot;register_operand&quot; &quot;&quot;)
  139. (mult:SI (match_operand:SI 1 &quot;memory_operand&quot; &quot;&quot;)
  140. (match_operand:SI 2 &quot;immediate_operand&quot; &quot;&quot;)))]
  141. &quot;!satisfies_constraint_K (operands[2])&quot;
  142. [(set (match_dup 3) (match_dup 1))
  143. (set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))]
  144. &quot;&quot;)
  145. </pre></div>
  146. <hr>
  147. <div class="header">
  148. <p>
  149. Previous: <a href="Define-Constraints.html#Define-Constraints" accesskey="p" rel="prev">Define Constraints</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>
  150. </div>
  151. </body>
  152. </html>