1 //===-- Passes.h - Target independent code generation passes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines interfaces to access the target independent code generation
11 // passes provided by the LLVM backend.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_PASSES_H
16 #define LLVM_CODEGEN_PASSES_H
18 #include "llvm/Pass.h"
19 #include "llvm/Target/TargetMachine.h"
25 class MachineFunctionPass;
28 class TargetRegisterClass;
34 /// Target-Independent Code Generator Pass Configuration Options.
36 /// This is an ImmutablePass solely for the purpose of exposing CodeGen options
37 /// to the internals of other CodeGen passes.
38 class TargetPassConfig : public ImmutablePass {
42 bool Initialized; // Flagged after all passes are configured.
44 // Target Pass Options
45 // Targets provide a default setting, user flags override.
49 /// Default setting for -enable-tail-merge on this target.
53 TargetPassConfig(TargetMachine *tm, PassManagerBase &pm);
57 virtual ~TargetPassConfig();
61 /// Get the right type of TargetMachine for this target.
62 template<typename TMC> TMC &getTM() const {
63 return *static_cast<TMC*>(TM);
66 const TargetLowering *getTargetLowering() const {
67 return TM->getTargetLowering();
70 void setInitialized() { Initialized = true; }
72 CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); }
74 void setDisableVerify(bool Disable) { setOpt(DisableVerify, Disable); }
76 bool getEnableTailMerge() const { return EnableTailMerge; }
77 void setEnableTailMerge(bool Enable) { setOpt(EnableTailMerge, Enable); }
79 /// Add common target configurable passes that perform LLVM IR to IR
80 /// transforms following machine independent optimization.
81 virtual void addIRPasses();
83 /// Add common passes that perform LLVM IR to IR transforms in preparation for
84 /// instruction selection.
85 virtual void addISelPrepare();
87 /// addInstSelector - This method should install an instruction selector pass,
88 /// which converts from LLVM code to machine instructions.
89 virtual bool addInstSelector() {
93 /// Add the complete, standard set of LLVM CodeGen passes.
94 /// Fully developed targets will not generally override this.
95 virtual void addMachinePasses();
98 // Helper to verify the analysis is really immutable.
99 void setOpt(bool &Opt, bool Val);
101 /// Methods with trivial inline returns are convenient points in the common
102 /// codegen pass pipeline where targets may insert passes. Methods with
103 /// out-of-line standard implementations are major CodeGen stages called by
104 /// addMachinePasses. Some targets may override major stages when inserting
105 /// passes is insufficient, but maintaining overriden stages is more work.
108 /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
109 /// passes (which are run just before instruction selector).
110 virtual bool addPreISel() {
114 /// addPreRegAlloc - This method may be implemented by targets that want to
115 /// run passes immediately before register allocation. This should return
116 /// true if -print-machineinstrs should print after these passes.
117 virtual bool addPreRegAlloc() {
121 /// addPostRegAlloc - This method may be implemented by targets that want
122 /// to run passes after register allocation but before prolog-epilog
123 /// insertion. This should return true if -print-machineinstrs should print
124 /// after these passes.
125 virtual bool addPostRegAlloc() {
129 /// addPreSched2 - This method may be implemented by targets that want to
130 /// run passes after prolog-epilog insertion and before the second instruction
131 /// scheduling pass. This should return true if -print-machineinstrs should
132 /// print after these passes.
133 virtual bool addPreSched2() {
137 /// addPreEmitPass - This pass may be implemented by targets that want to run
138 /// passes immediately before machine code is emitted. This should return
139 /// true if -print-machineinstrs should print out the code after the passes.
140 virtual bool addPreEmitPass() {
144 /// Utilities for targets to add passes to the pass manager.
147 /// Add a target-independent CodeGen pass at this point in the pipeline.
148 void addPass(char &ID);
150 /// printNoVerify - Add a pass to dump the machine function, if debugging is
153 void printNoVerify(const char *Banner) const;
155 /// printAndVerify - Add a pass to dump then verify the machine function, if
156 /// those steps are enabled.
158 void printAndVerify(const char *Banner) const;
162 /// List of target independent CodeGen pass IDs.
164 /// createUnreachableBlockEliminationPass - The LLVM code generator does not
165 /// work well with unreachable basic blocks (what live ranges make sense for a
166 /// block that cannot be reached?). As such, a code generator should either
167 /// not instruction select unreachable blocks, or run this pass as its
168 /// last LLVM modifying pass to clean up blocks that are not reachable from
170 FunctionPass *createUnreachableBlockEliminationPass();
172 /// MachineFunctionPrinter pass - This pass prints out the machine function to
173 /// the given stream as a debugging tool.
174 MachineFunctionPass *
175 createMachineFunctionPrinterPass(raw_ostream &OS,
176 const std::string &Banner ="");
178 /// MachineLoopInfo - This pass is a loop analysis pass.
179 extern char &MachineLoopInfoID;
181 /// MachineLoopRanges - This pass is an on-demand loop coverage analysis.
182 extern char &MachineLoopRangesID;
184 /// MachineDominators - This pass is a machine dominators analysis pass.
185 extern char &MachineDominatorsID;
187 /// EdgeBundles analysis - Bundle machine CFG edges.
188 extern char &EdgeBundlesID;
190 /// PHIElimination - This pass eliminates machine instruction PHI nodes
191 /// by inserting copy instructions. This destroys SSA information, but is the
192 /// desired input for some register allocators. This pass is "required" by
193 /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
194 extern char &PHIEliminationID;
196 /// StrongPHIElimination - This pass eliminates machine instruction PHI
197 /// nodes by inserting copy instructions. This destroys SSA information, but
198 /// is the desired input for some register allocators. This pass is
199 /// "required" by these register allocator like this:
200 /// AU.addRequiredID(PHIEliminationID);
201 /// This pass is still in development
202 extern char &StrongPHIEliminationID;
204 /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
205 extern char &LiveStacksID;
207 /// TwoAddressInstruction - This pass reduces two-address instructions to
208 /// use two operands. This destroys SSA information but it is desired by
209 /// register allocators.
210 extern char &TwoAddressInstructionPassID;
212 /// RegisteCoalescer - This pass merges live ranges to eliminate copies.
213 extern char &RegisterCoalescerPassID;
215 /// MachineScheduler - This pass schedules machine instructions.
216 extern char &MachineSchedulerID;
218 /// SpillPlacement analysis. Suggest optimal placement of spill code between
220 extern char &SpillPlacementID;
222 /// UnreachableMachineBlockElimination - This pass removes unreachable
223 /// machine basic blocks.
224 extern char &UnreachableMachineBlockElimID;
226 /// DeadMachineInstructionElim - This pass removes dead machine instructions.
227 extern char &DeadMachineInstructionElimID;
229 /// Creates a register allocator as the user specified on the command line, or
230 /// picks one that matches OptLevel.
232 FunctionPass *createRegisterAllocator(CodeGenOpt::Level OptLevel);
234 /// FastRegisterAllocation Pass - This pass register allocates as fast as
235 /// possible. It is best suited for debug code where live ranges are short.
237 FunctionPass *createFastRegisterAllocator();
239 /// BasicRegisterAllocation Pass - This pass implements a degenerate global
240 /// register allocator using the basic regalloc framework.
242 FunctionPass *createBasicRegisterAllocator();
244 /// Greedy register allocation pass - This pass implements a global register
245 /// allocator for optimized builds.
247 FunctionPass *createGreedyRegisterAllocator();
249 /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
250 /// Quadratic Prograaming (PBQP) based register allocator.
252 FunctionPass *createDefaultPBQPRegisterAllocator();
254 /// PrologEpilogCodeInserter - This pass inserts prolog and epilog code,
255 /// and eliminates abstract frame references.
256 extern char &PrologEpilogCodeInserterID;
258 /// ExpandPostRAPseudos - This pass expands pseudo instructions after
259 /// register allocation.
260 extern char &ExpandPostRAPseudosID;
262 /// createPostRAScheduler - This pass performs post register allocation
264 extern char &PostRASchedulerID;
266 /// BranchFolding - This pass performs machine code CFG based
267 /// optimizations to delete branches to branches, eliminate branches to
268 /// successor blocks (creating fall throughs), and eliminating branches over
270 extern char &BranchFolderPassID;
272 /// TailDuplicate - Duplicate blocks with unconditional branches
273 /// into tails of their predecessors.
274 extern char &TailDuplicateID;
276 /// IfConverter - This pass performs machine code if conversion.
277 extern char &IfConverterID;
279 /// MachineBlockPlacement - This pass places basic blocks based on branch
281 extern char &MachineBlockPlacementID;
283 /// MachineBlockPlacementStats - This pass collects statistics about the
284 /// basic block placement using branch probabilities and block frequency
286 extern char &MachineBlockPlacementStatsID;
288 /// Code Placement - This pass optimize code placement and aligns loop
289 /// headers to target specific alignment boundary.
290 extern char &CodePlacementOptID;
292 /// GCLowering Pass - Performs target-independent LLVM IR transformations for
293 /// highly portable strategies.
295 FunctionPass *createGCLoweringPass();
297 /// GCMachineCodeAnalysis - Target-independent pass to mark safe points
298 /// in machine code. Must be added very late during code generation, just
299 /// prior to output, and importantly after all CFG transformations (such as
301 extern char &GCMachineCodeAnalysisID;
303 /// Deleter Pass - Releases GC metadata.
305 FunctionPass *createGCInfoDeleter();
307 /// Creates a pass to print GC metadata.
309 FunctionPass *createGCInfoPrinter(raw_ostream &OS);
311 /// MachineCSE - This pass performs global CSE on machine instructions.
312 extern char &MachineCSEID;
314 /// MachineLICM - This pass performs LICM on machine instructions.
315 extern char &MachineLICMID;
317 /// MachineSinking - This pass performs sinking on machine instructions.
318 extern char &MachineSinkingID;
320 /// MachineCopyPropagation - This pass performs copy propagation on
321 /// machine instructions.
322 extern char &MachineCopyPropagationID;
324 /// PeepholeOptimizer - This pass performs peephole optimizations -
325 /// like extension and comparison eliminations.
326 extern char &PeepholeOptimizerID;
328 /// OptimizePHIs - This pass optimizes machine instruction PHIs
329 /// to take advantage of opportunities created during DAG legalization.
330 extern char &OptimizePHIsID;
332 /// StackSlotColoring - This pass performs stack slot coloring.
333 extern char &StackSlotColoringID;
335 /// createStackProtectorPass - This pass adds stack protectors to functions.
337 FunctionPass *createStackProtectorPass(const TargetLowering *tli);
339 /// createMachineVerifierPass - This pass verifies cenerated machine code
340 /// instructions for correctness.
342 FunctionPass *createMachineVerifierPass(const char *Banner = 0);
344 /// createDwarfEHPass - This pass mulches exception handling code into a form
345 /// adapted to code generation. Required if using dwarf exception handling.
346 FunctionPass *createDwarfEHPass(const TargetMachine *tm);
348 /// createSjLjEHPass - This pass adapts exception handling code to use
349 /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
351 FunctionPass *createSjLjEHPass(const TargetLowering *tli);
353 /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
354 /// slots relative to one another and allocates base registers to access them
355 /// when it is estimated by the target to be out of range of normal frame
356 /// pointer or stack pointer index addressing.
357 extern char &LocalStackSlotAllocationID;
359 /// ExpandISelPseudos - This pass expands pseudo-instructions.
360 extern char &ExpandISelPseudosID;
362 /// createExecutionDependencyFixPass - This pass fixes execution time
363 /// problems with dependent instructions, such as switching execution
364 /// domains to match.
366 /// The pass will examine instructions using and defining registers in RC.
368 FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
370 /// UnpackMachineBundles - This pass unpack machine instruction bundles.
371 extern char &UnpackMachineBundlesID;
373 /// FinalizeMachineBundles - This pass finalize machine instruction
374 /// bundles (created earlier, e.g. during pre-RA scheduling).
375 extern char &FinalizeMachineBundlesID;
377 } // End llvm namespace