Leaf-Functions.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: Leaf Functions</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Leaf Functions">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Leaf Functions">
  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="Registers.html#Registers" rel="up" title="Registers">
  30. <link href="Stack-Registers.html#Stack-Registers" rel="next" title="Stack Registers">
  31. <link href="Values-in-Registers.html#Values-in-Registers" rel="prev" title="Values in Registers">
  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="Leaf-Functions"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Stack-Registers.html#Stack-Registers" accesskey="n" rel="next">Stack Registers</a>, Previous: <a href="Values-in-Registers.html#Values-in-Registers" accesskey="p" rel="prev">Values in Registers</a>, Up: <a href="Registers.html#Registers" accesskey="u" rel="up">Registers</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="Handling-Leaf-Functions"></a>
  69. <h4 class="subsection">17.7.4 Handling Leaf Functions</h4>
  70. <a name="index-leaf-functions"></a>
  71. <a name="index-functions_002c-leaf"></a>
  72. <p>On some machines, a leaf function (i.e., one which makes no calls) can run
  73. more efficiently if it does not make its own register window. Often this
  74. means it is required to receive its arguments in the registers where they
  75. are passed by the caller, instead of the registers where they would
  76. normally arrive.
  77. </p>
  78. <p>The special treatment for leaf functions generally applies only when
  79. other conditions are met; for example, often they may use only those
  80. registers for its own variables and temporaries. We use the term &ldquo;leaf
  81. function&rdquo; to mean a function that is suitable for this special
  82. handling, so that functions with no calls are not necessarily &ldquo;leaf
  83. functions&rdquo;.
  84. </p>
  85. <p>GCC assigns register numbers before it knows whether the function is
  86. suitable for leaf function treatment. So it needs to renumber the
  87. registers in order to output a leaf function. The following macros
  88. accomplish this.
  89. </p>
  90. <dl>
  91. <dt><a name="index-LEAF_005fREGISTERS"></a>Macro: <strong>LEAF_REGISTERS</strong></dt>
  92. <dd><p>Name of a char vector, indexed by hard register number, which
  93. contains 1 for a register that is allowable in a candidate for leaf
  94. function treatment.
  95. </p>
  96. <p>If leaf function treatment involves renumbering the registers, then the
  97. registers marked here should be the ones before renumbering&mdash;those that
  98. GCC would ordinarily allocate. The registers which will actually be
  99. used in the assembler code, after renumbering, should not be marked with 1
  100. in this vector.
  101. </p>
  102. <p>Define this macro only if the target machine offers a way to optimize
  103. the treatment of leaf functions.
  104. </p></dd></dl>
  105. <dl>
  106. <dt><a name="index-LEAF_005fREG_005fREMAP"></a>Macro: <strong>LEAF_REG_REMAP</strong> <em>(<var>regno</var>)</em></dt>
  107. <dd><p>A C expression whose value is the register number to which <var>regno</var>
  108. should be renumbered, when a function is treated as a leaf function.
  109. </p>
  110. <p>If <var>regno</var> is a register number which should not appear in a leaf
  111. function before renumbering, then the expression should yield -1, which
  112. will cause the compiler to abort.
  113. </p>
  114. <p>Define this macro only if the target machine offers a way to optimize the
  115. treatment of leaf functions, and registers need to be renumbered to do
  116. this.
  117. </p></dd></dl>
  118. <a name="index-current_005ffunction_005fis_005fleaf"></a>
  119. <a name="index-current_005ffunction_005fuses_005fonly_005fleaf_005fregs"></a>
  120. <p><code>TARGET_ASM_FUNCTION_PROLOGUE</code> and
  121. <code>TARGET_ASM_FUNCTION_EPILOGUE</code> must usually treat leaf functions
  122. specially. They can test the C variable <code>current_function_is_leaf</code>
  123. which is nonzero for leaf functions. <code>current_function_is_leaf</code> is
  124. set prior to local register allocation and is valid for the remaining
  125. compiler passes. They can also test the C variable
  126. <code>current_function_uses_only_leaf_regs</code> which is nonzero for leaf
  127. functions which only use leaf registers.
  128. <code>current_function_uses_only_leaf_regs</code> is valid after all passes
  129. that modify the instructions have been run and is only useful if
  130. <code>LEAF_REGISTERS</code> is defined.
  131. </p>
  132. <hr>
  133. <div class="header">
  134. <p>
  135. Next: <a href="Stack-Registers.html#Stack-Registers" accesskey="n" rel="next">Stack Registers</a>, Previous: <a href="Values-in-Registers.html#Values-in-Registers" accesskey="p" rel="prev">Values in Registers</a>, Up: <a href="Registers.html#Registers" accesskey="u" rel="up">Registers</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>
  136. </div>
  137. </body>
  138. </html>