Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

346 lines
14KB

  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>Edges (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Edges (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Edges (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="Profile-information.html#Profile-information" rel="next" title="Profile information">
  31. <link href="Basic-Blocks.html#Basic-Blocks" rel="prev" title="Basic Blocks">
  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="Edges"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Profile-information.html#Profile-information" accesskey="n" rel="next">Profile information</a>, Previous: <a href="Basic-Blocks.html#Basic-Blocks" accesskey="p" rel="prev">Basic Blocks</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="Edges-1"></a>
  68. <h3 class="section">15.2 Edges</h3>
  69. <a name="index-edge-in-the-flow-graph"></a>
  70. <a name="index-edge"></a>
  71. <p>Edges represent possible control flow transfers from the end of some
  72. basic block A to the head of another basic block B. We say that A is
  73. a predecessor of B, and B is a successor of A. Edges are represented
  74. in GCC with the <code>edge</code> data type. Each <code>edge</code> acts as a
  75. link between two basic blocks: The <code>src</code> member of an edge
  76. points to the predecessor basic block of the <code>dest</code> basic block.
  77. The members <code>preds</code> and <code>succs</code> of the <code>basic_block</code> data
  78. type point to type-safe vectors of edges to the predecessors and
  79. successors of the block.
  80. </p>
  81. <a name="index-edge-iterators"></a>
  82. <p>When walking the edges in an edge vector, <em>edge iterators</em> should
  83. be used. Edge iterators are constructed using the
  84. <code>edge_iterator</code> data structure and several methods are available
  85. to operate on them:
  86. </p>
  87. <dl compact="compact">
  88. <dt><code>ei_start</code>
  89. <a name="index-ei_005fstart"></a>
  90. </dt>
  91. <dd><p>This function initializes an <code>edge_iterator</code> that points to the
  92. first edge in a vector of edges.
  93. </p>
  94. </dd>
  95. <dt><code>ei_last</code>
  96. <a name="index-ei_005flast"></a>
  97. </dt>
  98. <dd><p>This function initializes an <code>edge_iterator</code> that points to the
  99. last edge in a vector of edges.
  100. </p>
  101. </dd>
  102. <dt><code>ei_end_p</code>
  103. <a name="index-ei_005fend_005fp"></a>
  104. </dt>
  105. <dd><p>This predicate is <code>true</code> if an <code>edge_iterator</code> represents
  106. the last edge in an edge vector.
  107. </p>
  108. </dd>
  109. <dt><code>ei_one_before_end_p</code>
  110. <a name="index-ei_005fone_005fbefore_005fend_005fp"></a>
  111. </dt>
  112. <dd><p>This predicate is <code>true</code> if an <code>edge_iterator</code> represents
  113. the second last edge in an edge vector.
  114. </p>
  115. </dd>
  116. <dt><code>ei_next</code>
  117. <a name="index-ei_005fnext"></a>
  118. </dt>
  119. <dd><p>This function takes a pointer to an <code>edge_iterator</code> and makes it
  120. point to the next edge in the sequence.
  121. </p>
  122. </dd>
  123. <dt><code>ei_prev</code>
  124. <a name="index-ei_005fprev"></a>
  125. </dt>
  126. <dd><p>This function takes a pointer to an <code>edge_iterator</code> and makes it
  127. point to the previous edge in the sequence.
  128. </p>
  129. </dd>
  130. <dt><code>ei_edge</code>
  131. <a name="index-ei_005fedge"></a>
  132. </dt>
  133. <dd><p>This function returns the <code>edge</code> currently pointed to by an
  134. <code>edge_iterator</code>.
  135. </p>
  136. </dd>
  137. <dt><code>ei_safe_safe</code>
  138. <a name="index-ei_005fsafe_005fsafe"></a>
  139. </dt>
  140. <dd><p>This function returns the <code>edge</code> currently pointed to by an
  141. <code>edge_iterator</code>, but returns <code>NULL</code> if the iterator is
  142. pointing at the end of the sequence. This function has been provided
  143. for existing code makes the assumption that a <code>NULL</code> edge
  144. indicates the end of the sequence.
  145. </p>
  146. </dd>
  147. </dl>
  148. <p>The convenience macro <code>FOR_EACH_EDGE</code> can be used to visit all of
  149. the edges in a sequence of predecessor or successor edges. It must
  150. not be used when an element might be removed during the traversal,
  151. otherwise elements will be missed. Here is an example of how to use
  152. the macro:
  153. </p>
  154. <div class="smallexample">
  155. <pre class="smallexample">edge e;
  156. edge_iterator ei;
  157. FOR_EACH_EDGE (e, ei, bb-&gt;succs)
  158. {
  159. if (e-&gt;flags &amp; EDGE_FALLTHRU)
  160. break;
  161. }
  162. </pre></div>
  163. <a name="index-fall_002dthru"></a>
  164. <p>There are various reasons why control flow may transfer from one block
  165. to another. One possibility is that some instruction, for example a
  166. <code>CODE_LABEL</code>, in a linearized instruction stream just always
  167. starts a new basic block. In this case a <em>fall-thru</em> edge links
  168. the basic block to the first following basic block. But there are
  169. several other reasons why edges may be created. The <code>flags</code>
  170. field of the <code>edge</code> data type is used to store information
  171. about the type of edge we are dealing with. Each edge is of one of
  172. the following types:
  173. </p>
  174. <dl compact="compact">
  175. <dt><em>jump</em></dt>
  176. <dd><p>No type flags are set for edges corresponding to jump instructions.
  177. These edges are used for unconditional or conditional jumps and in
  178. RTL also for table jumps. They are the easiest to manipulate as they
  179. may be freely redirected when the flow graph is not in SSA form.
  180. </p>
  181. </dd>
  182. <dt><em>fall-thru</em></dt>
  183. <dd><a name="index-EDGE_005fFALLTHRU_002c-force_005fnonfallthru"></a>
  184. <p>Fall-thru edges are present in case where the basic block may continue
  185. execution to the following one without branching. These edges have
  186. the <code>EDGE_FALLTHRU</code> flag set. Unlike other types of edges, these
  187. edges must come into the basic block immediately following in the
  188. instruction stream. The function <code>force_nonfallthru</code> is
  189. available to insert an unconditional jump in the case that redirection
  190. is needed. Note that this may require creation of a new basic block.
  191. </p>
  192. </dd>
  193. <dt><em>exception handling</em></dt>
  194. <dd><a name="index-exception-handling"></a>
  195. <a name="index-EDGE_005fABNORMAL_002c-EDGE_005fEH"></a>
  196. <p>Exception handling edges represent possible control transfers from a
  197. trapping instruction to an exception handler. The definition of
  198. &ldquo;trapping&rdquo; varies. In C++, only function calls can throw, but for
  199. Ada exceptions like division by zero or segmentation fault are
  200. defined and thus each instruction possibly throwing this kind of
  201. exception needs to be handled as control flow instruction. Exception
  202. edges have the <code>EDGE_ABNORMAL</code> and <code>EDGE_EH</code> flags set.
  203. </p>
  204. <a name="index-purge_005fdead_005fedges"></a>
  205. <p>When updating the instruction stream it is easy to change possibly
  206. trapping instruction to non-trapping, by simply removing the exception
  207. edge. The opposite conversion is difficult, but should not happen
  208. anyway. The edges can be eliminated via <code>purge_dead_edges</code> call.
  209. </p>
  210. <a name="index-REG_005fEH_005fREGION_002c-EDGE_005fABNORMAL_005fCALL"></a>
  211. <p>In the RTL representation, the destination of an exception edge is
  212. specified by <code>REG_EH_REGION</code> note attached to the insn.
  213. In case of a trapping call the <code>EDGE_ABNORMAL_CALL</code> flag is set
  214. too. In the <code>GIMPLE</code> representation, this extra flag is not set.
  215. </p>
  216. <a name="index-may_005ftrap_005fp_002c-tree_005fcould_005ftrap_005fp"></a>
  217. <p>In the RTL representation, the predicate <code>may_trap_p</code> may be used
  218. to check whether instruction still may trap or not. For the tree
  219. representation, the <code>tree_could_trap_p</code> predicate is available,
  220. but this predicate only checks for possible memory traps, as in
  221. dereferencing an invalid pointer location.
  222. </p>
  223. </dd>
  224. <dt><em>sibling calls</em></dt>
  225. <dd><a name="index-sibling-call"></a>
  226. <a name="index-EDGE_005fABNORMAL_002c-EDGE_005fSIBCALL"></a>
  227. <p>Sibling calls or tail calls terminate the function in a non-standard
  228. way and thus an edge to the exit must be present.
  229. <code>EDGE_SIBCALL</code> and <code>EDGE_ABNORMAL</code> are set in such case.
  230. These edges only exist in the RTL representation.
  231. </p>
  232. </dd>
  233. <dt><em>computed jumps</em></dt>
  234. <dd><a name="index-computed-jump"></a>
  235. <a name="index-EDGE_005fABNORMAL"></a>
  236. <p>Computed jumps contain edges to all labels in the function referenced
  237. from the code. All those edges have <code>EDGE_ABNORMAL</code> flag set.
  238. The edges used to represent computed jumps often cause compile time
  239. performance problems, since functions consisting of many taken labels
  240. and many computed jumps may have <em>very</em> dense flow graphs, so
  241. these edges need to be handled with special care. During the earlier
  242. stages of the compilation process, GCC tries to avoid such dense flow
  243. graphs by factoring computed jumps. For example, given the following
  244. series of jumps,
  245. </p>
  246. <div class="smallexample">
  247. <pre class="smallexample"> goto *x;
  248. [ &hellip; ]
  249. goto *x;
  250. [ &hellip; ]
  251. goto *x;
  252. [ &hellip; ]
  253. </pre></div>
  254. <p>factoring the computed jumps results in the following code sequence
  255. which has a much simpler flow graph:
  256. </p>
  257. <div class="smallexample">
  258. <pre class="smallexample"> goto y;
  259. [ &hellip; ]
  260. goto y;
  261. [ &hellip; ]
  262. goto y;
  263. [ &hellip; ]
  264. y:
  265. goto *x;
  266. </pre></div>
  267. <a name="index-pass_005fduplicate_005fcomputed_005fgotos"></a>
  268. <p>However, the classic problem with this transformation is that it has a
  269. runtime cost in there resulting code: An extra jump. Therefore, the
  270. computed jumps are un-factored in the later passes of the compiler
  271. (in the pass called <code>pass_duplicate_computed_gotos</code>).
  272. Be aware of that when you work on passes in that area. There have
  273. been numerous examples already where the compile time for code with
  274. unfactored computed jumps caused some serious headaches.
  275. </p>
  276. </dd>
  277. <dt><em>nonlocal goto handlers</em></dt>
  278. <dd><a name="index-nonlocal-goto-handler"></a>
  279. <a name="index-EDGE_005fABNORMAL_002c-EDGE_005fABNORMAL_005fCALL"></a>
  280. <p>GCC allows nested functions to return into caller using a <code>goto</code>
  281. to a label passed to as an argument to the callee. The labels passed
  282. to nested functions contain special code to cleanup after function
  283. call. Such sections of code are referred to as &ldquo;nonlocal goto
  284. receivers&rdquo;. If a function contains such nonlocal goto receivers, an
  285. edge from the call to the label is created with the
  286. <code>EDGE_ABNORMAL</code> and <code>EDGE_ABNORMAL_CALL</code> flags set.
  287. </p>
  288. </dd>
  289. <dt><em>function entry points</em></dt>
  290. <dd><a name="index-function-entry-point_002c-alternate-function-entry-point"></a>
  291. <a name="index-LABEL_005fALTERNATE_005fNAME"></a>
  292. <p>By definition, execution of function starts at basic block 0, so there
  293. is always an edge from the <code>ENTRY_BLOCK_PTR</code> to basic block 0.
  294. There is no <code>GIMPLE</code> representation for alternate entry points at
  295. this moment. In RTL, alternate entry points are specified by
  296. <code>CODE_LABEL</code> with <code>LABEL_ALTERNATE_NAME</code> defined. This
  297. feature is currently used for multiple entry point prologues and is
  298. limited to post-reload passes only. This can be used by back-ends to
  299. emit alternate prologues for functions called from different contexts.
  300. In future full support for multiple entry functions defined by Fortran
  301. 90 needs to be implemented.
  302. </p>
  303. </dd>
  304. <dt><em>function exits</em></dt>
  305. <dd><p>In the pre-reload representation a function terminates after the last
  306. instruction in the insn chain and no explicit return instructions are
  307. used. This corresponds to the fall-thru edge into exit block. After
  308. reload, optimal RTL epilogues are used that use explicit (conditional)
  309. return instructions that are represented by edges with no flags set.
  310. </p>
  311. </dd>
  312. </dl>
  313. <hr>
  314. <div class="header">
  315. <p>
  316. Next: <a href="Profile-information.html#Profile-information" accesskey="n" rel="next">Profile information</a>, Previous: <a href="Basic-Blocks.html#Basic-Blocks" accesskey="p" rel="prev">Basic Blocks</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>
  317. </div>
  318. </body>
  319. </html>