Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

219 lines
10KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Defining Attributes (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Defining Attributes (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Defining Attributes (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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="Insn-Attributes.html#Insn-Attributes" rel="up" title="Insn Attributes">
  30. <link href="Expressions.html#Expressions" rel="next" title="Expressions">
  31. <link href="Insn-Attributes.html#Insn-Attributes" rel="prev" title="Insn Attributes">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Defining-Attributes"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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>
  65. </div>
  66. <hr>
  67. <a name="Defining-Attributes-and-their-Values"></a>
  68. <h4 class="subsection">17.19.1 Defining Attributes and their Values</h4>
  69. <a name="index-defining-attributes-and-their-values"></a>
  70. <a name="index-attributes_002c-defining"></a>
  71. <a name="index-define_005fattr"></a>
  72. <p>The <code>define_attr</code> expression is used to define each attribute required
  73. by the target machine. It looks like:
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">(define_attr <var>name</var> <var>list-of-values</var> <var>default</var>)
  77. </pre></div>
  78. <p><var>name</var> is a string specifying the name of the attribute being
  79. defined. Some attributes are used in a special way by the rest of the
  80. compiler. The <code>enabled</code> attribute can be used to conditionally
  81. enable or disable insn alternatives (see <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives">Disable Insn Alternatives</a>). The <code>predicable</code> attribute, together with a
  82. suitable <code>define_cond_exec</code> (see <a href="Conditional-Execution.html#Conditional-Execution">Conditional Execution</a>), can
  83. be used to automatically generate conditional variants of instruction
  84. patterns. The <code>mnemonic</code> attribute can be used to check for the
  85. instruction mnemonic (see <a href="Mnemonic-Attribute.html#Mnemonic-Attribute">Mnemonic Attribute</a>). The compiler
  86. internally uses the names <code>ce_enabled</code> and <code>nonce_enabled</code>,
  87. so they should not be used elsewhere as alternative names.
  88. </p>
  89. <p><var>list-of-values</var> is either a string that specifies a comma-separated
  90. list of values that can be assigned to the attribute, or a null string to
  91. indicate that the attribute takes numeric values.
  92. </p>
  93. <p><var>default</var> is an attribute expression that gives the value of this
  94. attribute for insns that match patterns whose definition does not include
  95. an explicit value for this attribute. See <a href="Attr-Example.html#Attr-Example">Attr Example</a>, for more
  96. information on the handling of defaults. See <a href="Constant-Attributes.html#Constant-Attributes">Constant Attributes</a>,
  97. for information on attributes that do not depend on any particular insn.
  98. </p>
  99. <a name="index-insn_002dattr_002eh"></a>
  100. <p>For each defined attribute, a number of definitions are written to the
  101. <samp>insn-attr.h</samp> file. For cases where an explicit set of values is
  102. specified for an attribute, the following are defined:
  103. </p>
  104. <ul>
  105. <li> A &lsquo;<samp>#define</samp>&rsquo; is written for the symbol &lsquo;<samp>HAVE_ATTR_<var>name</var></samp>&rsquo;.
  106. </li><li> An enumerated class is defined for &lsquo;<samp>attr_<var>name</var></samp>&rsquo; with
  107. elements of the form &lsquo;<samp><var>upper-name</var>_<var>upper-value</var></samp>&rsquo; where
  108. the attribute name and value are first converted to uppercase.
  109. </li><li> A function &lsquo;<samp>get_attr_<var>name</var></samp>&rsquo; is defined that is passed an insn and
  110. returns the attribute value for that insn.
  111. </li></ul>
  112. <p>For example, if the following is present in the <samp>md</samp> file:
  113. </p>
  114. <div class="smallexample">
  115. <pre class="smallexample">(define_attr &quot;type&quot; &quot;branch,fp,load,store,arith&quot; &hellip;)
  116. </pre></div>
  117. <p>the following lines will be written to the file <samp>insn-attr.h</samp>.
  118. </p>
  119. <div class="smallexample">
  120. <pre class="smallexample">#define HAVE_ATTR_type 1
  121. enum attr_type {TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
  122. TYPE_STORE, TYPE_ARITH};
  123. extern enum attr_type get_attr_type ();
  124. </pre></div>
  125. <p>If the attribute takes numeric values, no <code>enum</code> type will be
  126. defined and the function to obtain the attribute&rsquo;s value will return
  127. <code>int</code>.
  128. </p>
  129. <p>There are attributes which are tied to a specific meaning. These
  130. attributes are not free to use for other purposes:
  131. </p>
  132. <dl compact="compact">
  133. <dt><code>length</code></dt>
  134. <dd><p>The <code>length</code> attribute is used to calculate the length of emitted
  135. code chunks. This is especially important when verifying branch
  136. distances. See <a href="Insn-Lengths.html#Insn-Lengths">Insn Lengths</a>.
  137. </p>
  138. </dd>
  139. <dt><code>enabled</code></dt>
  140. <dd><p>The <code>enabled</code> attribute can be defined to prevent certain
  141. alternatives of an insn definition from being used during code
  142. generation. See <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives">Disable Insn Alternatives</a>.
  143. </p>
  144. </dd>
  145. <dt><code>mnemonic</code></dt>
  146. <dd><p>The <code>mnemonic</code> attribute can be defined to implement instruction
  147. specific checks in e.g. the pipeline description.
  148. See <a href="Mnemonic-Attribute.html#Mnemonic-Attribute">Mnemonic Attribute</a>.
  149. </p></dd>
  150. </dl>
  151. <p>For each of these special attributes, the corresponding
  152. &lsquo;<samp>HAVE_ATTR_<var>name</var></samp>&rsquo; &lsquo;<samp>#define</samp>&rsquo; is also written when the
  153. attribute is not defined; in that case, it is defined as &lsquo;<samp>0</samp>&rsquo;.
  154. </p>
  155. <a name="index-define_005fenum_005fattr"></a>
  156. <a name="define_005fenum_005fattr"></a><p>Another way of defining an attribute is to use:
  157. </p>
  158. <div class="smallexample">
  159. <pre class="smallexample">(define_enum_attr &quot;<var>attr</var>&quot; &quot;<var>enum</var>&quot; <var>default</var>)
  160. </pre></div>
  161. <p>This works in just the same way as <code>define_attr</code>, except that
  162. the list of values is taken from a separate enumeration called
  163. <var>enum</var> (see <a href="Constant-Definitions.html#define_005fenum">define_enum</a>). This form allows you to use
  164. the same list of values for several attributes without having to
  165. repeat the list each time. For example:
  166. </p>
  167. <div class="smallexample">
  168. <pre class="smallexample">(define_enum &quot;processor&quot; [
  169. model_a
  170. model_b
  171. &hellip;
  172. ])
  173. (define_enum_attr &quot;arch&quot; &quot;processor&quot;
  174. (const (symbol_ref &quot;target_arch&quot;)))
  175. (define_enum_attr &quot;tune&quot; &quot;processor&quot;
  176. (const (symbol_ref &quot;target_tune&quot;)))
  177. </pre></div>
  178. <p>defines the same attributes as:
  179. </p>
  180. <div class="smallexample">
  181. <pre class="smallexample">(define_attr &quot;arch&quot; &quot;model_a,model_b,&hellip;&quot;
  182. (const (symbol_ref &quot;target_arch&quot;)))
  183. (define_attr &quot;tune&quot; &quot;model_a,model_b,&hellip;&quot;
  184. (const (symbol_ref &quot;target_tune&quot;)))
  185. </pre></div>
  186. <p>but without duplicating the processor list. The second example defines two
  187. separate C enums (<code>attr_arch</code> and <code>attr_tune</code>) whereas the first
  188. defines a single C enum (<code>processor</code>).
  189. </p><hr>
  190. <div class="header">
  191. <p>
  192. Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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>
  193. </div>
  194. </body>
  195. </html>