Define-Subst-Example.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Subst Example</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Define Subst Example">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Define Subst Example">
  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="Define-Subst.html#Define-Subst" rel="up" title="Define Subst">
  30. <link href="Define-Subst-Pattern-Matching.html#Define-Subst-Pattern-Matching" rel="next" title="Define Subst Pattern Matching">
  31. <link href="Define-Subst.html#Define-Subst" rel="prev" title="Define Subst">
  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-Subst-Example"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Define-Subst-Pattern-Matching.html#Define-Subst-Pattern-Matching" accesskey="n" rel="next">Define Subst Pattern Matching</a>, Up: <a href="Define-Subst.html#Define-Subst" accesskey="u" rel="up">Define Subst</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="define_005fsubst-Example"></a>
  69. <h4 class="subsection">16.21.1 <code>define_subst</code> Example</h4>
  70. <a name="index-define_005fsubst-1"></a>
  71. <p>To illustrate how <code>define_subst</code> works, let us examine a simple
  72. template transformation.
  73. </p>
  74. <p>Suppose there are two kinds of instructions: one that touches flags and
  75. the other that does not. The instructions of the second type could be
  76. generated with the following <code>define_subst</code>:
  77. </p>
  78. <div class="smallexample">
  79. <pre class="smallexample">(define_subst &quot;add_clobber_subst&quot;
  80. [(set (match_operand:SI 0 &quot;&quot; &quot;&quot;)
  81. (match_operand:SI 1 &quot;&quot; &quot;&quot;))]
  82. &quot;&quot;
  83. [(set (match_dup 0)
  84. (match_dup 1))
  85. (clobber (reg:CC FLAGS_REG))]
  86. </pre></div>
  87. <p>This <code>define_subst</code> can be applied to any RTL pattern containing
  88. <code>set</code> of mode SI and generates a copy with clobber when it is
  89. applied.
  90. </p>
  91. <p>Assume there is an RTL template for a <code>max</code> instruction to be used
  92. in <code>define_subst</code> mentioned above:
  93. </p>
  94. <div class="smallexample">
  95. <pre class="smallexample">(define_insn &quot;maxsi&quot;
  96. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
  97. (max:SI
  98. (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  99. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  100. &quot;&quot;
  101. &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
  102. [&hellip;])
  103. </pre></div>
  104. <p>To mark the RTL template for <code>define_subst</code> application,
  105. subst-attributes are used. They should be declared in advance:
  106. </p>
  107. <div class="smallexample">
  108. <pre class="smallexample">(define_subst_attr &quot;add_clobber_name&quot; &quot;add_clobber_subst&quot; &quot;_noclobber&quot; &quot;_clobber&quot;)
  109. </pre></div>
  110. <p>Here &lsquo;<samp>add_clobber_name</samp>&rsquo; is the attribute name,
  111. &lsquo;<samp>add_clobber_subst</samp>&rsquo; is the name of the corresponding
  112. <code>define_subst</code>, the third argument (&lsquo;<samp>_noclobber</samp>&rsquo;) is the
  113. attribute value that would be substituted into the unchanged version of
  114. the source RTL template, and the last argument (&lsquo;<samp>_clobber</samp>&rsquo;) is the
  115. value that would be substituted into the second, transformed,
  116. version of the RTL template.
  117. </p>
  118. <p>Once the subst-attribute has been defined, it should be used in RTL
  119. templates which need to be processed by the <code>define_subst</code>. So,
  120. the original RTL template should be changed:
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">(define_insn &quot;maxsi&lt;add_clobber_name&gt;&quot;
  124. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
  125. (max:SI
  126. (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  127. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  128. &quot;&quot;
  129. &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
  130. [&hellip;])
  131. </pre></div>
  132. <p>The result of the <code>define_subst</code> usage would look like the following:
  133. </p>
  134. <div class="smallexample">
  135. <pre class="smallexample">(define_insn &quot;maxsi_noclobber&quot;
  136. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
  137. (max:SI
  138. (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  139. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  140. &quot;&quot;
  141. &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
  142. [&hellip;])
  143. (define_insn &quot;maxsi_clobber&quot;
  144. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
  145. (max:SI
  146. (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  147. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))
  148. (clobber (reg:CC FLAGS_REG))]
  149. &quot;&quot;
  150. &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
  151. [&hellip;])
  152. </pre></div>
  153. <hr>
  154. <div class="header">
  155. <p>
  156. Next: <a href="Define-Subst-Pattern-Matching.html#Define-Subst-Pattern-Matching" accesskey="n" rel="next">Define Subst Pattern Matching</a>, Up: <a href="Define-Subst.html#Define-Subst" accesskey="u" rel="up">Define Subst</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>
  157. </div>
  158. </body>
  159. </html>