Substitutions.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: Substitutions</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Substitutions">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Substitutions">
  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="Mode-Iterators.html#Mode-Iterators" rel="up" title="Mode Iterators">
  30. <link href="Examples.html#Examples" rel="next" title="Examples">
  31. <link href="Defining-Mode-Iterators.html#Defining-Mode-Iterators" rel="prev" title="Defining Mode Iterators">
  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="Substitutions"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Examples.html#Examples" accesskey="n" rel="next">Examples</a>, Previous: <a href="Defining-Mode-Iterators.html#Defining-Mode-Iterators" accesskey="p" rel="prev">Defining Mode Iterators</a>, Up: <a href="Mode-Iterators.html#Mode-Iterators" accesskey="u" rel="up">Mode Iterators</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="Substitution-in-Mode-Iterators"></a>
  69. <h4 class="subsubsection">16.23.1.2 Substitution in Mode Iterators</h4>
  70. <a name="index-define_005fmode_005fattr"></a>
  71. <p>If an <samp>.md</samp> file construct uses mode iterators, each version of the
  72. construct will often need slightly different strings or modes. For
  73. example:
  74. </p>
  75. <ul>
  76. <li> When a <code>define_expand</code> defines several <code>add<var>m</var>3</code> patterns
  77. (see <a href="Standard-Names.html#Standard-Names">Standard Names</a>), each expander will need to use the
  78. appropriate mode name for <var>m</var>.
  79. </li><li> When a <code>define_insn</code> defines several instruction patterns,
  80. each instruction will often use a different assembler mnemonic.
  81. </li><li> When a <code>define_insn</code> requires operands with different modes,
  82. using an iterator for one of the operand modes usually requires a specific
  83. mode for the other operand(s).
  84. </li></ul>
  85. <p>GCC supports such variations through a system of &ldquo;mode attributes&rdquo;.
  86. There are two standard attributes: <code>mode</code>, which is the name of
  87. the mode in lower case, and <code>MODE</code>, which is the same thing in
  88. upper case. You can define other attributes using:
  89. </p>
  90. <div class="smallexample">
  91. <pre class="smallexample">(define_mode_attr <var>name</var> [(<var>mode1</var> &quot;<var>value1</var>&quot;) &hellip; (<var>moden</var> &quot;<var>valuen</var>&quot;)])
  92. </pre></div>
  93. <p>where <var>name</var> is the name of the attribute and <var>valuei</var>
  94. is the value associated with <var>modei</var>.
  95. </p>
  96. <p>When GCC replaces some <var>:iterator</var> with <var>:mode</var>, it will scan
  97. each string and mode in the pattern for sequences of the form
  98. <code>&lt;<var>iterator</var>:<var>attr</var>&gt;</code>, where <var>attr</var> is the name of a
  99. mode attribute. If the attribute is defined for <var>mode</var>, the whole
  100. <code>&lt;&hellip;&gt;</code> sequence will be replaced by the appropriate attribute
  101. value.
  102. </p>
  103. <p>For example, suppose an <samp>.md</samp> file has:
  104. </p>
  105. <div class="smallexample">
  106. <pre class="smallexample">(define_mode_iterator P [(SI &quot;Pmode == SImode&quot;) (DI &quot;Pmode == DImode&quot;)])
  107. (define_mode_attr load [(SI &quot;lw&quot;) (DI &quot;ld&quot;)])
  108. </pre></div>
  109. <p>If one of the patterns that uses <code>:P</code> contains the string
  110. <code>&quot;&lt;P:load&gt;\t%0,%1&quot;</code>, the <code>SI</code> version of that pattern
  111. will use <code>&quot;lw\t%0,%1&quot;</code> and the <code>DI</code> version will use
  112. <code>&quot;ld\t%0,%1&quot;</code>.
  113. </p>
  114. <p>Here is an example of using an attribute for a mode:
  115. </p>
  116. <div class="smallexample">
  117. <pre class="smallexample">(define_mode_iterator LONG [SI DI])
  118. (define_mode_attr SHORT [(SI &quot;HI&quot;) (DI &quot;SI&quot;)])
  119. (define_insn &hellip;
  120. (sign_extend:LONG (match_operand:&lt;LONG:SHORT&gt; &hellip;)) &hellip;)
  121. </pre></div>
  122. <p>The <code><var>iterator</var>:</code> prefix may be omitted, in which case the
  123. substitution will be attempted for every iterator expansion.
  124. </p>
  125. <hr>
  126. <div class="header">
  127. <p>
  128. Next: <a href="Examples.html#Examples" accesskey="n" rel="next">Examples</a>, Previous: <a href="Defining-Mode-Iterators.html#Defining-Mode-Iterators" accesskey="p" rel="prev">Defining Mode Iterators</a>, Up: <a href="Mode-Iterators.html#Mode-Iterators" accesskey="u" rel="up">Mode Iterators</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>
  129. </div>
  130. </body>
  131. </html>