No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

186 líneas
9.2KB

  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>Profile information (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Profile information (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Profile information (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="Control-Flow.html#Control-Flow" rel="up" title="Control Flow">
  30. <link href="Maintaining-the-CFG.html#Maintaining-the-CFG" rel="next" title="Maintaining the CFG">
  31. <link href="Edges.html#Edges" rel="prev" title="Edges">
  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="Profile-information"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Maintaining-the-CFG.html#Maintaining-the-CFG" accesskey="n" rel="next">Maintaining the CFG</a>, Previous: <a href="Edges.html#Edges" accesskey="p" rel="prev">Edges</a>, Up: <a href="Control-Flow.html#Control-Flow" accesskey="u" rel="up">Control Flow</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="Profile-information-1"></a>
  68. <h3 class="section">15.3 Profile information</h3>
  69. <a name="index-profile-representation"></a>
  70. <p>In many cases a compiler must make a choice whether to trade speed in
  71. one part of code for speed in another, or to trade code size for code
  72. speed. In such cases it is useful to know information about how often
  73. some given block will be executed. That is the purpose for
  74. maintaining profile within the flow graph.
  75. GCC can handle profile information obtained through <em>profile
  76. feedback</em>, but it can also estimate branch probabilities based on
  77. statics and heuristics.
  78. </p>
  79. <a name="index-profile-feedback"></a>
  80. <p>The feedback based profile is produced by compiling the program with
  81. instrumentation, executing it on a train run and reading the numbers
  82. of executions of basic blocks and edges back to the compiler while
  83. re-compiling the program to produce the final executable. This method
  84. provides very accurate information about where a program spends most
  85. of its time on the train run. Whether it matches the average run of
  86. course depends on the choice of train data set, but several studies
  87. have shown that the behavior of a program usually changes just
  88. marginally over different data sets.
  89. </p>
  90. <a name="index-Static-profile-estimation"></a>
  91. <a name="index-branch-prediction"></a>
  92. <a name="index-predict_002edef"></a>
  93. <p>When profile feedback is not available, the compiler may be asked to
  94. attempt to predict the behavior of each branch in the program using a
  95. set of heuristics (see <samp>predict.def</samp> for details) and compute
  96. estimated frequencies of each basic block by propagating the
  97. probabilities over the graph.
  98. </p>
  99. <a name="index-frequency_002c-count_002c-BB_005fFREQ_005fBASE"></a>
  100. <p>Each <code>basic_block</code> contains two integer fields to represent
  101. profile information: <code>frequency</code> and <code>count</code>. The
  102. <code>frequency</code> is an estimation how often is basic block executed
  103. within a function. It is represented as an integer scaled in the
  104. range from 0 to <code>BB_FREQ_BASE</code>. The most frequently executed
  105. basic block in function is initially set to <code>BB_FREQ_BASE</code> and
  106. the rest of frequencies are scaled accordingly. During optimization,
  107. the frequency of the most frequent basic block can both decrease (for
  108. instance by loop unrolling) or grow (for instance by cross-jumping
  109. optimization), so scaling sometimes has to be performed multiple
  110. times.
  111. </p>
  112. <a name="index-gcov_005ftype"></a>
  113. <p>The <code>count</code> contains hard-counted numbers of execution measured
  114. during training runs and is nonzero only when profile feedback is
  115. available. This value is represented as the host&rsquo;s widest integer
  116. (typically a 64 bit integer) of the special type <code>gcov_type</code>.
  117. </p>
  118. <p>Most optimization passes can use only the frequency information of a
  119. basic block, but a few passes may want to know hard execution counts.
  120. The frequencies should always match the counts after scaling, however
  121. during updating of the profile information numerical error may
  122. accumulate into quite large errors.
  123. </p>
  124. <a name="index-REG_005fBR_005fPROB_005fBASE_002c-EDGE_005fFREQUENCY"></a>
  125. <p>Each edge also contains a branch probability field: an integer in the
  126. range from 0 to <code>REG_BR_PROB_BASE</code>. It represents probability of
  127. passing control from the end of the <code>src</code> basic block to the
  128. <code>dest</code> basic block, i.e. the probability that control will flow
  129. along this edge. The <code>EDGE_FREQUENCY</code> macro is available to
  130. compute how frequently a given edge is taken. There is a <code>count</code>
  131. field for each edge as well, representing same information as for a
  132. basic block.
  133. </p>
  134. <p>The basic block frequencies are not represented in the instruction
  135. stream, but in the RTL representation the edge frequencies are
  136. represented for conditional jumps (via the <code>REG_BR_PROB</code>
  137. macro) since they are used when instructions are output to the
  138. assembly file and the flow graph is no longer maintained.
  139. </p>
  140. <a name="index-reverse-probability"></a>
  141. <p>The probability that control flow arrives via a given edge to its
  142. destination basic block is called <em>reverse probability</em> and is not
  143. directly represented, but it may be easily computed from frequencies
  144. of basic blocks.
  145. </p>
  146. <a name="index-redirect_005fedge_005fand_005fbranch"></a>
  147. <p>Updating profile information is a delicate task that can unfortunately
  148. not be easily integrated with the CFG manipulation API. Many of the
  149. functions and hooks to modify the CFG, such as
  150. <code>redirect_edge_and_branch</code>, do not have enough information to
  151. easily update the profile, so updating it is in the majority of cases
  152. left up to the caller. It is difficult to uncover bugs in the profile
  153. updating code, because they manifest themselves only by producing
  154. worse code, and checking profile consistency is not possible because
  155. of numeric error accumulation. Hence special attention needs to be
  156. given to this issue in each pass that modifies the CFG.
  157. </p>
  158. <a name="index-REG_005fBR_005fPROB_005fBASE_002c-BB_005fFREQ_005fBASE_002c-count"></a>
  159. <p>It is important to point out that <code>REG_BR_PROB_BASE</code> and
  160. <code>BB_FREQ_BASE</code> are both set low enough to be possible to compute
  161. second power of any frequency or probability in the flow graph, it is
  162. not possible to even square the <code>count</code> field, as modern CPUs are
  163. fast enough to execute $2^32$ operations quickly.
  164. </p>
  165. <hr>
  166. <div class="header">
  167. <p>
  168. Next: <a href="Maintaining-the-CFG.html#Maintaining-the-CFG" accesskey="n" rel="next">Maintaining the CFG</a>, Previous: <a href="Edges.html#Edges" accesskey="p" rel="prev">Edges</a>, Up: <a href="Control-Flow.html#Control-Flow" accesskey="u" rel="up">Control Flow</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>
  169. </div>
  170. </body>
  171. </html>