Disable-Insn-Alternatives.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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: Disable Insn Alternatives</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Disable Insn Alternatives">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Disable Insn Alternatives">
  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="Define-Constraints.html#Define-Constraints" rel="next" title="Define Constraints">
  31. <link href="Machine-Constraints.html#Machine-Constraints" rel="prev" title="Machine 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="Disable-Insn-Alternatives"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Define-Constraints.html#Define-Constraints" accesskey="n" rel="next">Define Constraints</a>, Previous: <a href="Machine-Constraints.html#Machine-Constraints" accesskey="p" rel="prev">Machine 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="Disable-insn-alternatives-using-the-enabled-attribute"></a>
  69. <h4 class="subsection">16.8.6 Disable insn alternatives using the <code>enabled</code> attribute</h4>
  70. <a name="index-enabled"></a>
  71. <p>There are three insn attributes that may be used to selectively disable
  72. instruction alternatives:
  73. </p>
  74. <dl compact="compact">
  75. <dt><code>enabled</code></dt>
  76. <dd><p>Says whether an alternative is available on the current subtarget.
  77. </p>
  78. </dd>
  79. <dt><code>preferred_for_size</code></dt>
  80. <dd><p>Says whether an enabled alternative should be used in code that is
  81. optimized for size.
  82. </p>
  83. </dd>
  84. <dt><code>preferred_for_speed</code></dt>
  85. <dd><p>Says whether an enabled alternative should be used in code that is
  86. optimized for speed.
  87. </p></dd>
  88. </dl>
  89. <p>All these attributes should use <code>(const_int 1)</code> to allow an alternative
  90. or <code>(const_int 0)</code> to disallow it. The attributes must be a static
  91. property of the subtarget; they cannot for example depend on the
  92. current operands, on the current optimization level, on the location
  93. of the insn within the body of a loop, on whether register allocation
  94. has finished, or on the current compiler pass.
  95. </p>
  96. <p>The <code>enabled</code> attribute is a correctness property. It tells GCC to act
  97. as though the disabled alternatives were never defined in the first place.
  98. This is useful when adding new instructions to an existing pattern in
  99. cases where the new instructions are only available for certain cpu
  100. architecture levels (typically mapped to the <code>-march=</code> command-line
  101. option).
  102. </p>
  103. <p>In contrast, the <code>preferred_for_size</code> and <code>preferred_for_speed</code>
  104. attributes are strong optimization hints rather than correctness properties.
  105. <code>preferred_for_size</code> tells GCC which alternatives to consider when
  106. adding or modifying an instruction that GCC wants to optimize for size.
  107. <code>preferred_for_speed</code> does the same thing for speed. Note that things
  108. like code motion can lead to cases where code optimized for size uses
  109. alternatives that are not preferred for size, and similarly for speed.
  110. </p>
  111. <p>Although <code>define_insn</code>s can in principle specify the <code>enabled</code>
  112. attribute directly, it is often clearer to have subsiduary attributes
  113. for each architectural feature of interest. The <code>define_insn</code>s
  114. can then use these subsiduary attributes to say which alternatives
  115. require which features. The example below does this for <code>cpu_facility</code>.
  116. </p>
  117. <p>E.g. the following two patterns could easily be merged using the <code>enabled</code>
  118. attribute:
  119. </p>
  120. <div class="smallexample">
  121. <pre class="smallexample">
  122. (define_insn &quot;*movdi_old&quot;
  123. [(set (match_operand:DI 0 &quot;register_operand&quot; &quot;=d&quot;)
  124. (match_operand:DI 1 &quot;register_operand&quot; &quot; d&quot;))]
  125. &quot;!TARGET_NEW&quot;
  126. &quot;lgr %0,%1&quot;)
  127. (define_insn &quot;*movdi_new&quot;
  128. [(set (match_operand:DI 0 &quot;register_operand&quot; &quot;=d,f,d&quot;)
  129. (match_operand:DI 1 &quot;register_operand&quot; &quot; d,d,f&quot;))]
  130. &quot;TARGET_NEW&quot;
  131. &quot;@
  132. lgr %0,%1
  133. ldgr %0,%1
  134. lgdr %0,%1&quot;)
  135. </pre></div>
  136. <p>to:
  137. </p>
  138. <div class="smallexample">
  139. <pre class="smallexample">
  140. (define_insn &quot;*movdi_combined&quot;
  141. [(set (match_operand:DI 0 &quot;register_operand&quot; &quot;=d,f,d&quot;)
  142. (match_operand:DI 1 &quot;register_operand&quot; &quot; d,d,f&quot;))]
  143. &quot;&quot;
  144. &quot;@
  145. lgr %0,%1
  146. ldgr %0,%1
  147. lgdr %0,%1&quot;
  148. [(set_attr &quot;cpu_facility&quot; &quot;*,new,new&quot;)])
  149. </pre></div>
  150. <p>with the <code>enabled</code> attribute defined like this:
  151. </p>
  152. <div class="smallexample">
  153. <pre class="smallexample">
  154. (define_attr &quot;cpu_facility&quot; &quot;standard,new&quot; (const_string &quot;standard&quot;))
  155. (define_attr &quot;enabled&quot; &quot;&quot;
  156. (cond [(eq_attr &quot;cpu_facility&quot; &quot;standard&quot;) (const_int 1)
  157. (and (eq_attr &quot;cpu_facility&quot; &quot;new&quot;)
  158. (ne (symbol_ref &quot;TARGET_NEW&quot;) (const_int 0)))
  159. (const_int 1)]
  160. (const_int 0)))
  161. </pre></div>
  162. <hr>
  163. <div class="header">
  164. <p>
  165. Next: <a href="Define-Constraints.html#Define-Constraints" accesskey="n" rel="next">Define Constraints</a>, Previous: <a href="Machine-Constraints.html#Machine-Constraints" accesskey="p" rel="prev">Machine 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>
  166. </div>
  167. </body>
  168. </html>