📄 passes.texi
字号:
It does so by storing the values of these computations to a bankof temporary variables that are rotated at the end of loop. To avoidthe need for this rotation, the loop is then unrolled and the copiesof the loop body are rewritten to use the appropriate version ofthe temporary variable. This pass is located in @file{tree-predcom.c}and described by @code{pass_predcom}.@item Array prefetchingThis pass issues prefetch instructions for array references insideloops. The pass is located in @file{tree-ssa-loop-prefetch.c} anddescribed by @code{pass_loop_prefetch}.@item ReassociationThis pass rewrites arithmetic expressions to enable optimizations thatoperate on them, like redundancy elimination and vectorization. Thepass is located in @file{tree-ssa-reassoc.c} and described by@code{pass_reassoc}.@item Optimization of @code{stdarg} functionsThis pass tries to avoid the saving of register arguments into thestack on entry to @code{stdarg} functions. If the function doesn'tuse any @code{va_start} macros, no registers need to be saved. If@code{va_start} macros are used, the @code{va_list} variables don'tescape the function, it is only necessary to save registers that willbe used in @code{va_arg} macros. For instance, if @code{va_arg} isonly used with integral types in the function, floating pointregisters don't need to be saved. This pass is located in@code{tree-stdarg.c} and described by @code{pass_stdarg}.@end itemize@node RTL passes@section RTL passesThe following briefly describes the rtl generation and optimizationpasses that are run after tree optimization.@itemize @bullet@item RTL generation@c Avoiding overfull is tricky here.The source files for RTL generation include@file{stmt.c},@file{calls.c},@file{expr.c},@file{explow.c},@file{expmed.c},@file{function.c},@file{optabs.c}and @file{emit-rtl.c}.Also, the file@file{insn-emit.c}, generated from the machine description by theprogram @code{genemit}, is used in this pass. The header file@file{expr.h} is used for communication within this pass.@findex genflags@findex gencodesThe header files @file{insn-flags.h} and @file{insn-codes.h},generated from the machine description by the programs @code{genflags}and @code{gencodes}, tell this pass which standard names are availablefor use and which patterns correspond to them.@item Generate exception handling landing padsThis pass generates the glue that handles communication between theexception handling library routines and the exception handlers withinthe function. Entry points in the function that are invoked by theexception handling library are called @dfn{landing pads}. The codefor this pass is located within @file{except.c}.@item Cleanup control flow graphThis pass removes unreachable code, simplifies jumps to next, jumps tojump, jumps across jumps, etc. The pass is run multiple times.For historical reasons, it is occasionally referred to as the ``jumpoptimization pass''. The bulk of the code for this pass is in@file{cfgcleanup.c}, and there are support routines in @file{cfgrtl.c}and @file{jump.c}.@item Forward propagation of single-def valuesThis pass attempts to remove redundant computation by substitutingvariables that come from a single definition, andseeing if the result can be simplified. It performs copy propagationand addressing mode selection. The pass is run twice, with valuesbeing propagated into loops only on the second run. It is located in@file{fwprop.c}.@item Common subexpression eliminationThis pass removes redundant computation within basic blocks, andoptimizes addressing modes based on cost. The pass is run twice.The source is located in @file{cse.c}.@item Global common subexpression elimination.This pass performs twodifferent types of GCSE depending on whether you are optimizing forsize or not (LCM based GCSE tends to increase code size for a gain inspeed, while Morel-Renvoise based GCSE does not).When optimizing for size, GCSE is done using Morel-Renvoise PartialRedundancy Elimination, with the exception that it does not try to moveinvariants out of loops---that is left to the loop optimization pass.If MR PRE GCSE is done, code hoisting (aka unification) is also done, aswell as load motion.If you are optimizing for speed, LCM (lazy code motion) based GCSE isdone. LCM is based on the work of Knoop, Ruthing, and Steffen. LCMbased GCSE also does loop invariant code motion. We also perform loadand store motion when optimizing for speed.Regardless of which type of GCSE is used, the GCSE pass also performsglobal constant and copy propagation.The source file for this pass is @file{gcse.c}, and the LCM routinesare in @file{lcm.c}.@item Loop optimizationThis pass performs several loop related optimizations.The source files @file{cfgloopanal.c} and @file{cfgloopmanip.c} containgeneric loop analysis and manipulation code. Initialization and finalizationof loop structures is handled by @file{loop-init.c}.A loop invariant motion pass is implemented in @file{loop-invariant.c}.Basic block level optimizations---unrolling, peeling and unswitching loops---are implemented in @file{loop-unswitch.c} and @file{loop-unroll.c}.Replacing of the exit condition of loops by special machine-dependentinstructions is handled by @file{loop-doloop.c}.@item Jump bypassingThis pass is an aggressive form of GCSE that transforms the controlflow graph of a function by propagating constants into conditionalbranch instructions. The source file for this pass is @file{gcse.c}.@item If conversionThis pass attempts to replace conditional branches and surroundingassignments with arithmetic, boolean value producing comparisoninstructions, and conditional move instructions. In the very lastinvocation after reload, it will generate predicated instructionswhen supported by the target. The pass is located in @file{ifcvt.c}.@item Web constructionThis pass splits independent uses of each pseudo-register. This canimprove effect of the other transformation, such as CSE or registerallocation. Its source files are @file{web.c}.@item Life analysisThis pass computes which pseudo-registers are live at each point inthe program, and makes the first instruction that uses a value pointat the instruction that computed the value. It then deletescomputations whose results are never used, and combines memoryreferences with add or subtract instructions to make autoincrement orautodecrement addressing. The pass is located in @file{flow.c}.@item Instruction combinationThis pass attempts to combine groups of two or three instructions thatare related by data flow into single instructions. It combines theRTL expressions for the instructions by substitution, simplifies theresult using algebra, and then attempts to match the result againstthe machine description. The pass is located in @file{combine.c}.@item Register movementThis pass looks for cases where matching constraints would force aninstruction to need a reload, and this reload would be aregister-to-register move. It then attempts to change the registersused by the instruction to avoid the move instruction.The pass is located in @file{regmove.c}.@item Optimize mode switchingThis pass looks for instructions that require the processor to be in aspecific ``mode'' and minimizes the number of mode changes required tosatisfy all users. What these modes are, and what they apply to arecompletely target-specific.The source is located in @file{mode-switching.c}.@cindex modulo scheduling@cindex sms, swing, software pipelining@item Modulo schedulingThis pass looks at innermost loops and reorders their instructionsby overlapping different iterations. Modulo scheduling is performedimmediately before instruction scheduling.The pass is located in (@file{modulo-sched.c}).@item Instruction schedulingThis pass looks for instructions whose output will not be available bythe time that it is used in subsequent instructions. Memory loads andfloating point instructions often have this behavior on RISC machines.It re-orders instructions within a basic block to try to separate thedefinition and use of items that otherwise would cause pipelinestalls. This pass is performed twice, before and after registerallocation. The pass is located in @file{haifa-sched.c},@file{sched-deps.c}, @file{sched-ebb.c}, @file{sched-rgn.c} and@file{sched-vis.c}.@item Register allocationThese passes make sure that all occurrences of pseudo registers areeliminated, either by allocating them to a hard register, replacingthem by an equivalent expression (e.g.@: a constant) or by placingthem on the stack. This is done in several subpasses:@itemize @bullet@itemRegister class preferencing. The RTL code is scanned to find outwhich register class is best for each pseudo register. The sourcefile is @file{regclass.c}.@itemLocal register allocation. This pass allocates hard registers topseudo registers that are used only within one basic block. Becausethe basic block is linear, it can use fast and powerful techniques todo a decent job. The source is located in @file{local-alloc.c}.@itemGlobal register allocation. This pass allocates hard registers forthe remaining pseudo registers (those whose life spans are notcontained in one basic block). The pass is located in @file{global.c}.@cindex reloading@itemReloading. This pass renumbers pseudo registers with the hardwareregisters numbers they were allocated. Pseudo registers that did notget hard registers are replaced with stack slots. Then it findsinstructions that are invalid because a value has failed to end up ina register, or has ended up in a register of the wrong kind. It fixesup these instructions by reloading the problematical valuestemporarily into registers. Additional instructions are generated todo the copying.The reload pass also optionally eliminates the frame pointer and insertsinstructions to save and restore call-clobbered registers around calls.Source files are @file{reload.c} and @file{reload1.c}, plus the header@file{reload.h} used for communication between them.@end itemize@item Basic block reorderingThis pass implements profile guided code positioning. If profileinformation is not available, various types of static analysis areperformed to make the predictions normally coming from the profilefeedback (IE execution frequency, branch probability, etc). It isimplemented in the file @file{bb-reorder.c}, and the variousprediction routines are in @file{predict.c}.@item Variable trackingThis pass computes where the variables are stored at eachposition in code and generates notes describing the variable locationsto RTL code. The location lists are then generated according to thesenotes to debug information if the debugging information format supportslocation lists.@item Delayed branch schedulingThis optional pass attempts to find instructions that can go into thedelay slots of other instructions, usually jumps and calls. Thesource file name is @file{reorg.c}.@item Branch shorteningOn many RISC machines, branch instructions have a limited range.Thus, longer sequences of instructions must be used for long branches.In this pass, the compiler figures out what how far each instructionwill be from each other instruction, and therefore whether the usualinstructions, or the longer sequences, must be used for each branch.@item Register-to-stack conversionConversion from usage of some hard registers to usage of a registerstack may be done at this point. Currently, this is supported onlyfor the floating-point registers of the Intel 80387 coprocessor. Thesource file name is @file{reg-stack.c}.@item FinalThis pass outputs the assembler code for the function. The source filesare @file{final.c} plus @file{insn-output.c}; the latter is generatedautomatically from the machine description by the tool @file{genoutput}.The header file @file{conditions.h} is used for communication betweenthese files. If mudflap is enabled, the queue of deferred declarationsand any addressed constants (e.g., string literals) is processed by@code{mudflap_finish_file} into a synthetic constructor functioncontaining calls into the mudflap runtime.@item Debugging information outputThis is run after final because it must output the stack slot offsetsfor pseudo registers that did not get hard registers. Source filesare @file{dbxout.c} for DBX symbol table format, @file{sdbout.c} forSDB symbol table format, @file{dwarfout.c} for DWARF symbol tableformat, files @file{dwarf2out.c} and @file{dwarf2asm.c} for DWARF2symbol table format, and @file{vmsdbgout.c} for VMS debug symbol tableformat.@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -