Constant-Definitions.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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: Constant Definitions</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Constant Definitions">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Constant Definitions">
  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="Iterators.html#Iterators" rel="next" title="Iterators">
  31. <link href="Define-Subst-Output-Template.html#Define-Subst-Output-Template" rel="prev" title="Define Subst Output Template">
  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="Constant-Definitions"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Iterators.html#Iterators" accesskey="n" rel="next">Iterators</a>, Previous: <a href="Define-Subst.html#Define-Subst" accesskey="p" rel="prev">Define Subst</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="Constant-Definitions-1"></a>
  69. <h3 class="section">16.22 Constant Definitions</h3>
  70. <a name="index-constant-definitions"></a>
  71. <a name="index-define_005fconstants"></a>
  72. <p>Using literal constants inside instruction patterns reduces legibility and
  73. can be a maintenance problem.
  74. </p>
  75. <p>To overcome this problem, you may use the <code>define_constants</code>
  76. expression. It contains a vector of name-value pairs. From that
  77. point on, wherever any of the names appears in the MD file, it is as
  78. if the corresponding value had been written instead. You may use
  79. <code>define_constants</code> multiple times; each appearance adds more
  80. constants to the table. It is an error to redefine a constant with
  81. a different value.
  82. </p>
  83. <p>To come back to the a29k load multiple example, instead of
  84. </p>
  85. <div class="smallexample">
  86. <pre class="smallexample">(define_insn &quot;&quot;
  87. [(match_parallel 0 &quot;load_multiple_operation&quot;
  88. [(set (match_operand:SI 1 &quot;gpc_reg_operand&quot; &quot;=r&quot;)
  89. (match_operand:SI 2 &quot;memory_operand&quot; &quot;m&quot;))
  90. (use (reg:SI 179))
  91. (clobber (reg:SI 179))])]
  92. &quot;&quot;
  93. &quot;loadm 0,0,%1,%2&quot;)
  94. </pre></div>
  95. <p>You could write:
  96. </p>
  97. <div class="smallexample">
  98. <pre class="smallexample">(define_constants [
  99. (R_BP 177)
  100. (R_FC 178)
  101. (R_CR 179)
  102. (R_Q 180)
  103. ])
  104. (define_insn &quot;&quot;
  105. [(match_parallel 0 &quot;load_multiple_operation&quot;
  106. [(set (match_operand:SI 1 &quot;gpc_reg_operand&quot; &quot;=r&quot;)
  107. (match_operand:SI 2 &quot;memory_operand&quot; &quot;m&quot;))
  108. (use (reg:SI R_CR))
  109. (clobber (reg:SI R_CR))])]
  110. &quot;&quot;
  111. &quot;loadm 0,0,%1,%2&quot;)
  112. </pre></div>
  113. <p>The constants that are defined with a define_constant are also output
  114. in the insn-codes.h header file as #defines.
  115. </p>
  116. <a name="index-enumerations"></a>
  117. <a name="index-define_005fc_005fenum"></a>
  118. <p>You can also use the machine description file to define enumerations.
  119. Like the constants defined by <code>define_constant</code>, these enumerations
  120. are visible to both the machine description file and the main C code.
  121. </p>
  122. <p>The syntax is as follows:
  123. </p>
  124. <div class="smallexample">
  125. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [
  126. <var>value0</var>
  127. <var>value1</var>
  128. &hellip;
  129. <var>valuen</var>
  130. ])
  131. </pre></div>
  132. <p>This definition causes the equivalent of the following C code to appear
  133. in <samp>insn-constants.h</samp>:
  134. </p>
  135. <div class="smallexample">
  136. <pre class="smallexample">enum <var>name</var> {
  137. <var>value0</var> = 0,
  138. <var>value1</var> = 1,
  139. &hellip;
  140. <var>valuen</var> = <var>n</var>
  141. };
  142. #define NUM_<var>cname</var>_VALUES (<var>n</var> + 1)
  143. </pre></div>
  144. <p>where <var>cname</var> is the capitalized form of <var>name</var>.
  145. It also makes each <var>valuei</var> available in the machine description
  146. file, just as if it had been declared with:
  147. </p>
  148. <div class="smallexample">
  149. <pre class="smallexample">(define_constants [(<var>valuei</var> <var>i</var>)])
  150. </pre></div>
  151. <p>Each <var>valuei</var> is usually an upper-case identifier and usually
  152. begins with <var>cname</var>.
  153. </p>
  154. <p>You can split the enumeration definition into as many statements as
  155. you like. The above example is directly equivalent to:
  156. </p>
  157. <div class="smallexample">
  158. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [<var>value0</var>])
  159. (define_c_enum &quot;<var>name</var>&quot; [<var>value1</var>])
  160. &hellip;
  161. (define_c_enum &quot;<var>name</var>&quot; [<var>valuen</var>])
  162. </pre></div>
  163. <p>Splitting the enumeration helps to improve the modularity of each
  164. individual <code>.md</code> file. For example, if a port defines its
  165. synchronization instructions in a separate <samp>sync.md</samp> file,
  166. it is convenient to define all synchronization-specific enumeration
  167. values in <samp>sync.md</samp> rather than in the main <samp>.md</samp> file.
  168. </p>
  169. <p>Some enumeration names have special significance to GCC:
  170. </p>
  171. <dl compact="compact">
  172. <dt><code>unspecv</code></dt>
  173. <dd><a name="index-unspec_005fvolatile-1"></a>
  174. <p>If an enumeration called <code>unspecv</code> is defined, GCC will use it
  175. when printing out <code>unspec_volatile</code> expressions. For example:
  176. </p>
  177. <div class="smallexample">
  178. <pre class="smallexample">(define_c_enum &quot;unspecv&quot; [
  179. UNSPECV_BLOCKAGE
  180. ])
  181. </pre></div>
  182. <p>causes GCC to print &lsquo;<samp>(unspec_volatile &hellip; 0)</samp>&rsquo; as:
  183. </p>
  184. <div class="smallexample">
  185. <pre class="smallexample">(unspec_volatile ... UNSPECV_BLOCKAGE)
  186. </pre></div>
  187. </dd>
  188. <dt><code>unspec</code></dt>
  189. <dd><a name="index-unspec-1"></a>
  190. <p>If an enumeration called <code>unspec</code> is defined, GCC will use
  191. it when printing out <code>unspec</code> expressions. GCC will also use
  192. it when printing out <code>unspec_volatile</code> expressions unless an
  193. <code>unspecv</code> enumeration is also defined. You can therefore
  194. decide whether to keep separate enumerations for volatile and
  195. non-volatile expressions or whether to use the same enumeration
  196. for both.
  197. </p></dd>
  198. </dl>
  199. <a name="index-define_005fenum"></a>
  200. <a name="define_005fenum"></a><p>Another way of defining an enumeration is to use <code>define_enum</code>:
  201. </p>
  202. <div class="smallexample">
  203. <pre class="smallexample">(define_enum &quot;<var>name</var>&quot; [
  204. <var>value0</var>
  205. <var>value1</var>
  206. &hellip;
  207. <var>valuen</var>
  208. ])
  209. </pre></div>
  210. <p>This directive implies:
  211. </p>
  212. <div class="smallexample">
  213. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [
  214. <var>cname</var>_<var>cvalue0</var>
  215. <var>cname</var>_<var>cvalue1</var>
  216. &hellip;
  217. <var>cname</var>_<var>cvaluen</var>
  218. ])
  219. </pre></div>
  220. <a name="index-define_005fenum_005fattr-1"></a>
  221. <p>where <var>cvaluei</var> is the capitalized form of <var>valuei</var>.
  222. However, unlike <code>define_c_enum</code>, the enumerations defined
  223. by <code>define_enum</code> can be used in attribute specifications
  224. (see <a href="Defining-Attributes.html#define_005fenum_005fattr">define_enum_attr</a>).
  225. </p><hr>
  226. <div class="header">
  227. <p>
  228. Next: <a href="Iterators.html#Iterators" accesskey="n" rel="next">Iterators</a>, Previous: <a href="Define-Subst.html#Define-Subst" accesskey="p" rel="prev">Define Subst</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>
  229. </div>
  230. </body>
  231. </html>