You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
6.9KB

  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>Per-Function Data (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Per-Function Data (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Per-Function Data (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="Target-Macros.html#Target-Macros" rel="up" title="Target Macros">
  30. <link href="Storage-Layout.html#Storage-Layout" rel="next" title="Storage Layout">
  31. <link href="Run_002dtime-Target.html#Run_002dtime-Target" rel="prev" title="Run-time Target">
  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="Per_002dFunction-Data"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Storage-Layout.html#Storage-Layout" accesskey="n" rel="next">Storage Layout</a>, Previous: <a href="Run_002dtime-Target.html#Run_002dtime-Target" accesskey="p" rel="prev">Run-time Target</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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-data-structures-for-per_002dfunction-information_002e"></a>
  68. <h3 class="section">18.4 Defining data structures for per-function information.</h3>
  69. <a name="index-per_002dfunction-data"></a>
  70. <a name="index-data-structures"></a>
  71. <p>If the target needs to store information on a per-function basis, GCC
  72. provides a macro and a couple of variables to allow this. Note, just
  73. using statics to store the information is a bad idea, since GCC supports
  74. nested functions, so you can be halfway through encoding one function
  75. when another one comes along.
  76. </p>
  77. <p>GCC defines a data structure called <code>struct function</code> which
  78. contains all of the data specific to an individual function. This
  79. structure contains a field called <code>machine</code> whose type is
  80. <code>struct machine_function *</code>, which can be used by targets to point
  81. to their own specific data.
  82. </p>
  83. <p>If a target needs per-function specific data it should define the type
  84. <code>struct machine_function</code> and also the macro <code>INIT_EXPANDERS</code>.
  85. This macro should be used to initialize the function pointer
  86. <code>init_machine_status</code>. This pointer is explained below.
  87. </p>
  88. <p>One typical use of per-function, target specific data is to create an
  89. RTX to hold the register containing the function&rsquo;s return address. This
  90. RTX can then be used to implement the <code>__builtin_return_address</code>
  91. function, for level 0.
  92. </p>
  93. <p>Note&mdash;earlier implementations of GCC used a single data area to hold
  94. all of the per-function information. Thus when processing of a nested
  95. function began the old per-function data had to be pushed onto a
  96. stack, and when the processing was finished, it had to be popped off the
  97. stack. GCC used to provide function pointers called
  98. <code>save_machine_status</code> and <code>restore_machine_status</code> to handle
  99. the saving and restoring of the target specific information. Since the
  100. single data area approach is no longer used, these pointers are no
  101. longer supported.
  102. </p>
  103. <dl>
  104. <dt><a name="index-INIT_005fEXPANDERS"></a>Macro: <strong>INIT_EXPANDERS</strong></dt>
  105. <dd><p>Macro called to initialize any target specific information. This macro
  106. is called once per function, before generation of any RTL has begun.
  107. The intention of this macro is to allow the initialization of the
  108. function pointer <code>init_machine_status</code>.
  109. </p></dd></dl>
  110. <dl>
  111. <dt><a name="index-init_005fmachine_005fstatus"></a>Variable: <em>void (*)(struct function *)</em> <strong>init_machine_status</strong></dt>
  112. <dd><p>If this function pointer is non-<code>NULL</code> it will be called once per
  113. function, before function compilation starts, in order to allow the
  114. target to perform any target specific initialization of the
  115. <code>struct function</code> structure. It is intended that this would be
  116. used to initialize the <code>machine</code> of that structure.
  117. </p>
  118. <p><code>struct machine_function</code> structures are expected to be freed by GC.
  119. Generally, any memory that they reference must be allocated by using
  120. GC allocation, including the structure itself.
  121. </p></dd></dl>
  122. <hr>
  123. <div class="header">
  124. <p>
  125. Next: <a href="Storage-Layout.html#Storage-Layout" accesskey="n" rel="next">Storage Layout</a>, Previous: <a href="Run_002dtime-Target.html#Run_002dtime-Target" accesskey="p" rel="prev">Run-time Target</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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>
  126. </div>
  127. </body>
  128. </html>