Per_002dFunction-Data.html 7.0 KB

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