RTL-passes.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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: RTL passes</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: RTL passes">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: RTL passes">
  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="Passes.html#Passes" rel="up" title="Passes">
  30. <link href="Optimization-info.html#Optimization-info" rel="next" title="Optimization info">
  31. <link href="Tree-SSA-passes.html#Tree-SSA-passes" rel="prev" title="Tree SSA passes">
  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="RTL-passes"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Optimization-info.html#Optimization-info" accesskey="n" rel="next">Optimization info</a>, Previous: <a href="Tree-SSA-passes.html#Tree-SSA-passes" accesskey="p" rel="prev">Tree SSA passes</a>, Up: <a href="Passes.html#Passes" accesskey="u" rel="up">Passes</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="RTL-passes-1"></a>
  69. <h3 class="section">9.6 RTL passes</h3>
  70. <p>The following briefly describes the RTL generation and optimization
  71. passes that are run after the Tree optimization passes.
  72. </p>
  73. <ul>
  74. <li> RTL generation
  75. <p>The source files for RTL generation include
  76. <samp>stmt.c</samp>,
  77. <samp>calls.c</samp>,
  78. <samp>expr.c</samp>,
  79. <samp>explow.c</samp>,
  80. <samp>expmed.c</samp>,
  81. <samp>function.c</samp>,
  82. <samp>optabs.c</samp>
  83. and <samp>emit-rtl.c</samp>.
  84. Also, the file
  85. <samp>insn-emit.c</samp>, generated from the machine description by the
  86. program <code>genemit</code>, is used in this pass. The header file
  87. <samp>expr.h</samp> is used for communication within this pass.
  88. </p>
  89. <a name="index-genflags"></a>
  90. <a name="index-gencodes"></a>
  91. <p>The header files <samp>insn-flags.h</samp> and <samp>insn-codes.h</samp>,
  92. generated from the machine description by the programs <code>genflags</code>
  93. and <code>gencodes</code>, tell this pass which standard names are available
  94. for use and which patterns correspond to them.
  95. </p>
  96. </li><li> Generation of exception landing pads
  97. <p>This pass generates the glue that handles communication between the
  98. exception handling library routines and the exception handlers within
  99. the function. Entry points in the function that are invoked by the
  100. exception handling library are called <em>landing pads</em>. The code
  101. for this pass is located in <samp>except.c</samp>.
  102. </p>
  103. </li><li> Control flow graph cleanup
  104. <p>This pass removes unreachable code, simplifies jumps to next, jumps to
  105. jump, jumps across jumps, etc. The pass is run multiple times.
  106. For historical reasons, it is occasionally referred to as the &ldquo;jump
  107. optimization pass&rdquo;. The bulk of the code for this pass is in
  108. <samp>cfgcleanup.c</samp>, and there are support routines in <samp>cfgrtl.c</samp>
  109. and <samp>jump.c</samp>.
  110. </p>
  111. </li><li> Forward propagation of single-def values
  112. <p>This pass attempts to remove redundant computation by substituting
  113. variables that come from a single definition, and
  114. seeing if the result can be simplified. It performs copy propagation
  115. and addressing mode selection. The pass is run twice, with values
  116. being propagated into loops only on the second run. The code is
  117. located in <samp>fwprop.c</samp>.
  118. </p>
  119. </li><li> Common subexpression elimination
  120. <p>This pass removes redundant computation within basic blocks, and
  121. optimizes addressing modes based on cost. The pass is run twice.
  122. The code for this pass is located in <samp>cse.c</samp>.
  123. </p>
  124. </li><li> Global common subexpression elimination
  125. <p>This pass performs two
  126. different types of GCSE depending on whether you are optimizing for
  127. size or not (LCM based GCSE tends to increase code size for a gain in
  128. speed, while Morel-Renvoise based GCSE does not).
  129. When optimizing for size, GCSE is done using Morel-Renvoise Partial
  130. Redundancy Elimination, with the exception that it does not try to move
  131. invariants out of loops&mdash;that is left to the loop optimization pass.
  132. If MR PRE GCSE is done, code hoisting (aka unification) is also done, as
  133. well as load motion.
  134. If you are optimizing for speed, LCM (lazy code motion) based GCSE is
  135. done. LCM is based on the work of Knoop, Ruthing, and Steffen. LCM
  136. based GCSE also does loop invariant code motion. We also perform load
  137. and store motion when optimizing for speed.
  138. Regardless of which type of GCSE is used, the GCSE pass also performs
  139. global constant and copy propagation.
  140. The source file for this pass is <samp>gcse.c</samp>, and the LCM routines
  141. are in <samp>lcm.c</samp>.
  142. </p>
  143. </li><li> Loop optimization
  144. <p>This pass performs several loop related optimizations.
  145. The source files <samp>cfgloopanal.c</samp> and <samp>cfgloopmanip.c</samp> contain
  146. generic loop analysis and manipulation code. Initialization and finalization
  147. of loop structures is handled by <samp>loop-init.c</samp>.
  148. A loop invariant motion pass is implemented in <samp>loop-invariant.c</samp>.
  149. Basic block level optimizations&mdash;unrolling, and peeling loops&mdash;
  150. are implemented in <samp>loop-unroll.c</samp>.
  151. Replacing of the exit condition of loops by special machine-dependent
  152. instructions is handled by <samp>loop-doloop.c</samp>.
  153. </p>
  154. </li><li> Jump bypassing
  155. <p>This pass is an aggressive form of GCSE that transforms the control
  156. flow graph of a function by propagating constants into conditional
  157. branch instructions. The source file for this pass is <samp>gcse.c</samp>.
  158. </p>
  159. </li><li> If conversion
  160. <p>This pass attempts to replace conditional branches and surrounding
  161. assignments with arithmetic, boolean value producing comparison
  162. instructions, and conditional move instructions. In the very last
  163. invocation after reload/LRA, it will generate predicated instructions
  164. when supported by the target. The code is located in <samp>ifcvt.c</samp>.
  165. </p>
  166. </li><li> Web construction
  167. <p>This pass splits independent uses of each pseudo-register. This can
  168. improve effect of the other transformation, such as CSE or register
  169. allocation. The code for this pass is located in <samp>web.c</samp>.
  170. </p>
  171. </li><li> Instruction combination
  172. <p>This pass attempts to combine groups of two or three instructions that
  173. are related by data flow into single instructions. It combines the
  174. RTL expressions for the instructions by substitution, simplifies the
  175. result using algebra, and then attempts to match the result against
  176. the machine description. The code is located in <samp>combine.c</samp>.
  177. </p>
  178. </li><li> Mode switching optimization
  179. <p>This pass looks for instructions that require the processor to be in a
  180. specific &ldquo;mode&rdquo; and minimizes the number of mode changes required to
  181. satisfy all users. What these modes are, and what they apply to are
  182. completely target-specific. The code for this pass is located in
  183. <samp>mode-switching.c</samp>.
  184. </p>
  185. </li><li> <a name="index-modulo-scheduling"></a>
  186. <a name="index-sms_002c-swing_002c-software-pipelining"></a>
  187. Modulo scheduling
  188. <p>This pass looks at innermost loops and reorders their instructions
  189. by overlapping different iterations. Modulo scheduling is performed
  190. immediately before instruction scheduling. The code for this pass is
  191. located in <samp>modulo-sched.c</samp>.
  192. </p>
  193. </li><li> Instruction scheduling
  194. <p>This pass looks for instructions whose output will not be available by
  195. the time that it is used in subsequent instructions. Memory loads and
  196. floating point instructions often have this behavior on RISC machines.
  197. It re-orders instructions within a basic block to try to separate the
  198. definition and use of items that otherwise would cause pipeline
  199. stalls. This pass is performed twice, before and after register
  200. allocation. The code for this pass is located in <samp>haifa-sched.c</samp>,
  201. <samp>sched-deps.c</samp>, <samp>sched-ebb.c</samp>, <samp>sched-rgn.c</samp> and
  202. <samp>sched-vis.c</samp>.
  203. </p>
  204. </li><li> Register allocation
  205. <p>These passes make sure that all occurrences of pseudo registers are
  206. eliminated, either by allocating them to a hard register, replacing
  207. them by an equivalent expression (e.g. a constant) or by placing
  208. them on the stack. This is done in several subpasses:
  209. </p>
  210. <ul>
  211. <li> The integrated register allocator (<acronym>IRA</acronym>). It is called
  212. integrated because coalescing, register live range splitting, and hard
  213. register preferencing are done on-the-fly during coloring. It also
  214. has better integration with the reload/LRA pass. Pseudo-registers spilled
  215. by the allocator or the reload/LRA have still a chance to get
  216. hard-registers if the reload/LRA evicts some pseudo-registers from
  217. hard-registers. The allocator helps to choose better pseudos for
  218. spilling based on their live ranges and to coalesce stack slots
  219. allocated for the spilled pseudo-registers. IRA is a regional
  220. register allocator which is transformed into Chaitin-Briggs allocator
  221. if there is one region. By default, IRA chooses regions using
  222. register pressure but the user can force it to use one region or
  223. regions corresponding to all loops.
  224. <p>Source files of the allocator are <samp>ira.c</samp>, <samp>ira-build.c</samp>,
  225. <samp>ira-costs.c</samp>, <samp>ira-conflicts.c</samp>, <samp>ira-color.c</samp>,
  226. <samp>ira-emit.c</samp>, <samp>ira-lives</samp>, plus header files <samp>ira.h</samp>
  227. and <samp>ira-int.h</samp> used for the communication between the allocator
  228. and the rest of the compiler and between the IRA files.
  229. </p>
  230. </li><li> <a name="index-reloading"></a>
  231. Reloading. This pass renumbers pseudo registers with the hardware
  232. registers numbers they were allocated. Pseudo registers that did not
  233. get hard registers are replaced with stack slots. Then it finds
  234. instructions that are invalid because a value has failed to end up in
  235. a register, or has ended up in a register of the wrong kind. It fixes
  236. up these instructions by reloading the problematical values
  237. temporarily into registers. Additional instructions are generated to
  238. do the copying.
  239. <p>The reload pass also optionally eliminates the frame pointer and inserts
  240. instructions to save and restore call-clobbered registers around calls.
  241. </p>
  242. <p>Source files are <samp>reload.c</samp> and <samp>reload1.c</samp>, plus the header
  243. <samp>reload.h</samp> used for communication between them.
  244. </p>
  245. </li><li> <a name="index-Local-Register-Allocator-_0028LRA_0029"></a>
  246. This pass is a modern replacement of the reload pass. Source files
  247. are <samp>lra.c</samp>, <samp>lra-assign.c</samp>, <samp>lra-coalesce.c</samp>,
  248. <samp>lra-constraints.c</samp>, <samp>lra-eliminations.c</samp>,
  249. <samp>lra-lives.c</samp>, <samp>lra-remat.c</samp>, <samp>lra-spills.c</samp>, the
  250. header <samp>lra-int.h</samp> used for communication between them, and the
  251. header <samp>lra.h</samp> used for communication between LRA and the rest of
  252. compiler.
  253. <p>Unlike the reload pass, intermediate LRA decisions are reflected in
  254. RTL as much as possible. This reduces the number of target-dependent
  255. macros and hooks, leaving instruction constraints as the primary
  256. source of control.
  257. </p>
  258. <p>LRA is run on targets for which TARGET_LRA_P returns true.
  259. </p></li></ul>
  260. </li><li> Basic block reordering
  261. <p>This pass implements profile guided code positioning. If profile
  262. information is not available, various types of static analysis are
  263. performed to make the predictions normally coming from the profile
  264. feedback (IE execution frequency, branch probability, etc). It is
  265. implemented in the file <samp>bb-reorder.c</samp>, and the various
  266. prediction routines are in <samp>predict.c</samp>.
  267. </p>
  268. </li><li> Variable tracking
  269. <p>This pass computes where the variables are stored at each
  270. position in code and generates notes describing the variable locations
  271. to RTL code. The location lists are then generated according to these
  272. notes to debug information if the debugging information format supports
  273. location lists. The code is located in <samp>var-tracking.c</samp>.
  274. </p>
  275. </li><li> Delayed branch scheduling
  276. <p>This optional pass attempts to find instructions that can go into the
  277. delay slots of other instructions, usually jumps and calls. The code
  278. for this pass is located in <samp>reorg.c</samp>.
  279. </p>
  280. </li><li> Branch shortening
  281. <p>On many RISC machines, branch instructions have a limited range.
  282. Thus, longer sequences of instructions must be used for long branches.
  283. In this pass, the compiler figures out what how far each instruction
  284. will be from each other instruction, and therefore whether the usual
  285. instructions, or the longer sequences, must be used for each branch.
  286. The code for this pass is located in <samp>final.c</samp>.
  287. </p>
  288. </li><li> Register-to-stack conversion
  289. <p>Conversion from usage of some hard registers to usage of a register
  290. stack may be done at this point. Currently, this is supported only
  291. for the floating-point registers of the Intel 80387 coprocessor. The
  292. code for this pass is located in <samp>reg-stack.c</samp>.
  293. </p>
  294. </li><li> Final
  295. <p>This pass outputs the assembler code for the function. The source files
  296. are <samp>final.c</samp> plus <samp>insn-output.c</samp>; the latter is generated
  297. automatically from the machine description by the tool <samp>genoutput</samp>.
  298. The header file <samp>conditions.h</samp> is used for communication between
  299. these files.
  300. </p>
  301. </li><li> Debugging information output
  302. <p>This is run after final because it must output the stack slot offsets
  303. for pseudo registers that did not get hard registers. Source files
  304. are <samp>dbxout.c</samp> for DBX symbol table format, <samp>sdbout.c</samp> for
  305. SDB symbol table format, <samp>dwarfout.c</samp> for DWARF symbol table
  306. format, files <samp>dwarf2out.c</samp> and <samp>dwarf2asm.c</samp> for DWARF2
  307. symbol table format, and <samp>vmsdbgout.c</samp> for VMS debug symbol table
  308. format.
  309. </p>
  310. </li></ul>
  311. <hr>
  312. <div class="header">
  313. <p>
  314. Next: <a href="Optimization-info.html#Optimization-info" accesskey="n" rel="next">Optimization info</a>, Previous: <a href="Tree-SSA-passes.html#Tree-SSA-passes" accesskey="p" rel="prev">Tree SSA passes</a>, Up: <a href="Passes.html#Passes" accesskey="u" rel="up">Passes</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>
  315. </div>
  316. </body>
  317. </html>