Move pass configuration out of pass constructors: TailDuplicate::PreRegAlloc
[oota-llvm.git] / include / llvm / CodeGen / Passes.h
1 //===-- Passes.h - Target independent code generation passes ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines interfaces to access the target independent code generation
11 // passes provided by the LLVM backend.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_PASSES_H
16 #define LLVM_CODEGEN_PASSES_H
17
18 #include "llvm/Pass.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include <string>
21
22 namespace llvm {
23
24   class FunctionPass;
25   class MachineFunctionPass;
26   class PassInfo;
27   class TargetLowering;
28   class TargetRegisterClass;
29   class raw_ostream;
30 }
31
32 namespace llvm {
33
34 /// Target-Independent Code Generator Pass Configuration Options.
35 ///
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 {
39 protected:
40   TargetMachine *TM;
41   PassManagerBase &PM;
42
43   // Target Pass Options
44   //
45   bool DisableVerify;
46
47 public:
48   TargetPassConfig(TargetMachine *tm, PassManagerBase &pm);
49   // Dummy constructor.
50   TargetPassConfig();
51
52   virtual ~TargetPassConfig();
53
54   static char ID;
55
56   /// Get the right type of TargetMachine for this target.
57   template<typename TMC> TMC &getTM() const {
58     return *static_cast<TMC*>(TM);
59   }
60
61   const TargetLowering *getTargetLowering() const {
62     return TM->getTargetLowering();
63   }
64
65   CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); }
66
67   void setDisableVerify(bool disable) { DisableVerify = disable; }
68
69   /// Add common target configurable passes that perform LLVM IR to IR
70   /// transforms following machine independent optimization.
71   virtual void addIRPasses();
72
73   /// Add common passes that perform LLVM IR to IR transforms in preparation for
74   /// instruction selection.
75   virtual void addISelPrepare();
76
77   /// addInstSelector - This method should install an instruction selector pass,
78   /// which converts from LLVM code to machine instructions.
79   virtual bool addInstSelector() {
80     return true;
81   }
82
83   /// Add the complete, standard set of LLVM CodeGen passes.
84   /// Fully developed targets will not generally override this.
85   virtual void addMachinePasses();
86 protected:
87   /// Methods with trivial inline returns are convenient points in the common
88   /// codegen pass pipeline where targets may insert passes. Methods with
89   /// out-of-line standard implementations are major CodeGen stages called by
90   /// addMachinePasses. Some targets may override major stages when inserting
91   /// passes is insufficient, but maintaining overriden stages is more work.
92   ///
93
94   /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
95   /// passes (which are run just before instruction selector).
96   virtual bool addPreISel() {
97     return true;
98   }
99
100   /// addPreRegAlloc - This method may be implemented by targets that want to
101   /// run passes immediately before register allocation. This should return
102   /// true if -print-machineinstrs should print after these passes.
103   virtual bool addPreRegAlloc() {
104     return false;
105   }
106
107   /// addPostRegAlloc - This method may be implemented by targets that want
108   /// to run passes after register allocation but before prolog-epilog
109   /// insertion.  This should return true if -print-machineinstrs should print
110   /// after these passes.
111   virtual bool addPostRegAlloc() {
112     return false;
113   }
114
115   /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
116   /// on this target.  User flag overrides.
117   virtual bool getEnableTailMergeDefault() const { return true; }
118
119   /// addPreSched2 - This method may be implemented by targets that want to
120   /// run passes after prolog-epilog insertion and before the second instruction
121   /// scheduling pass.  This should return true if -print-machineinstrs should
122   /// print after these passes.
123   virtual bool addPreSched2() {
124     return false;
125   }
126
127   /// addPreEmitPass - This pass may be implemented by targets that want to run
128   /// passes immediately before machine code is emitted.  This should return
129   /// true if -print-machineinstrs should print out the code after the passes.
130   virtual bool addPreEmitPass() {
131     return false;
132   }
133
134   /// Utilities for targets to add passes to the pass manager.
135   ///
136
137   /// Add a target-independent CodeGen pass at this point in the pipeline.
138   void addCommonPass(char &ID);
139
140   /// printNoVerify - Add a pass to dump the machine function, if debugging is
141   /// enabled.
142   ///
143   void printNoVerify(const char *Banner) const;
144
145   /// printAndVerify - Add a pass to dump then verify the machine function, if
146   /// those steps are enabled.
147   ///
148   void printAndVerify(const char *Banner) const;
149 };
150 } // namespace llvm
151
152 /// List of target independent CodeGen pass IDs.
153 namespace llvm {
154   /// createUnreachableBlockEliminationPass - The LLVM code generator does not
155   /// work well with unreachable basic blocks (what live ranges make sense for a
156   /// block that cannot be reached?).  As such, a code generator should either
157   /// not instruction select unreachable blocks, or run this pass as its
158   /// last LLVM modifying pass to clean up blocks that are not reachable from
159   /// the entry block.
160   FunctionPass *createUnreachableBlockEliminationPass();
161
162   /// MachineFunctionPrinter pass - This pass prints out the machine function to
163   /// the given stream as a debugging tool.
164   MachineFunctionPass *
165   createMachineFunctionPrinterPass(raw_ostream &OS,
166                                    const std::string &Banner ="");
167
168   /// MachineLoopInfo pass - This pass is a loop analysis pass.
169   ///
170   extern char &MachineLoopInfoID;
171
172   /// MachineLoopRanges pass - This pass is an on-demand loop coverage
173   /// analysis pass.
174   ///
175   extern char &MachineLoopRangesID;
176
177   /// MachineDominators pass - This pass is a machine dominators analysis pass.
178   ///
179   extern char &MachineDominatorsID;
180
181   /// EdgeBundles analysis - Bundle machine CFG edges.
182   ///
183   extern char &EdgeBundlesID;
184
185   /// PHIElimination pass - This pass eliminates machine instruction PHI nodes
186   /// by inserting copy instructions.  This destroys SSA information, but is the
187   /// desired input for some register allocators.  This pass is "required" by
188   /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
189   ///
190   extern char &PHIEliminationID;
191
192   /// StrongPHIElimination pass - This pass eliminates machine instruction PHI
193   /// nodes by inserting copy instructions.  This destroys SSA information, but
194   /// is the desired input for some register allocators.  This pass is
195   /// "required" by these register allocator like this:
196   ///    AU.addRequiredID(PHIEliminationID);
197   ///  This pass is still in development
198   extern char &StrongPHIEliminationID;
199
200   /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
201   extern char &LiveStacksID;
202
203   /// TwoAddressInstruction pass - This pass reduces two-address instructions to
204   /// use two operands. This destroys SSA information but it is desired by
205   /// register allocators.
206   extern char &TwoAddressInstructionPassID;
207
208   /// RegisteCoalescer pass - This pass merges live ranges to eliminate copies.
209   extern char &RegisterCoalescerPassID;
210
211   /// MachineScheduler pass - This pass schedules machine instructions.
212   extern char &MachineSchedulerID;
213
214   /// SpillPlacement analysis. Suggest optimal placement of spill code between
215   /// basic blocks.
216   ///
217   extern char &SpillPlacementID;
218
219   /// UnreachableMachineBlockElimination pass - This pass removes unreachable
220   /// machine basic blocks.
221   extern char &UnreachableMachineBlockElimID;
222
223   /// DeadMachineInstructionElim pass - This pass removes dead machine
224   /// instructions.
225   ///
226   FunctionPass *createDeadMachineInstructionElimPass();
227
228   /// Creates a register allocator as the user specified on the command line, or
229   /// picks one that matches OptLevel.
230   ///
231   FunctionPass *createRegisterAllocator(CodeGenOpt::Level OptLevel);
232
233   /// FastRegisterAllocation Pass - This pass register allocates as fast as
234   /// possible. It is best suited for debug code where live ranges are short.
235   ///
236   FunctionPass *createFastRegisterAllocator();
237
238   /// BasicRegisterAllocation Pass - This pass implements a degenerate global
239   /// register allocator using the basic regalloc framework.
240   ///
241   FunctionPass *createBasicRegisterAllocator();
242
243   /// Greedy register allocation pass - This pass implements a global register
244   /// allocator for optimized builds.
245   ///
246   FunctionPass *createGreedyRegisterAllocator();
247
248   /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
249   /// Quadratic Prograaming (PBQP) based register allocator.
250   ///
251   FunctionPass *createDefaultPBQPRegisterAllocator();
252
253   /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
254   /// and eliminates abstract frame references.
255   ///
256   FunctionPass *createPrologEpilogCodeInserter();
257
258   /// ExpandPostRAPseudos Pass - This pass expands pseudo instructions after
259   /// register allocation.
260   ///
261   FunctionPass *createExpandPostRAPseudosPass();
262
263   /// createPostRAScheduler - This pass performs post register allocation
264   /// scheduling.
265   FunctionPass *createPostRAScheduler(CodeGenOpt::Level OptLevel);
266
267   /// BranchFolding Pass - This pass performs machine code CFG based
268   /// optimizations to delete branches to branches, eliminate branches to
269   /// successor blocks (creating fall throughs), and eliminating branches over
270   /// branches.
271   FunctionPass *createBranchFoldingPass(bool DefaultEnableTailMerge);
272
273   /// TailDuplicate Pass - Duplicate blocks with unconditional branches
274   /// into tails of their predecessors.
275   FunctionPass *createTailDuplicatePass();
276
277   /// IfConverter Pass - This pass performs machine code if conversion.
278   FunctionPass *createIfConverterPass();
279
280   /// MachineBlockPlacement Pass - This pass places basic blocks based on branch
281   /// probabilities.
282   FunctionPass *createMachineBlockPlacementPass();
283
284   /// MachineBlockPlacementStats Pass - This pass collects statistics about the
285   /// basic block placement using branch probabilities and block frequency
286   /// information.
287   FunctionPass *createMachineBlockPlacementStatsPass();
288
289   /// Code Placement Pass - This pass optimize code placement and aligns loop
290   /// headers to target specific alignment boundary.
291   FunctionPass *createCodePlacementOptPass();
292
293   /// IntrinsicLowering Pass - Performs target-independent LLVM IR
294   /// transformations for highly portable strategies.
295   FunctionPass *createGCLoweringPass();
296
297   /// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
298   /// machine code. Must be added very late during code generation, just prior
299   /// to output, and importantly after all CFG transformations (such as branch
300   /// folding).
301   FunctionPass *createGCMachineCodeAnalysisPass();
302
303   /// Deleter Pass - Releases GC metadata.
304   ///
305   FunctionPass *createGCInfoDeleter();
306
307   /// Creates a pass to print GC metadata.
308   ///
309   FunctionPass *createGCInfoPrinter(raw_ostream &OS);
310
311   /// createMachineCSEPass - This pass performs global CSE on machine
312   /// instructions.
313   FunctionPass *createMachineCSEPass();
314
315   /// createMachineLICMPass - This pass performs LICM on machine instructions.
316   ///
317   FunctionPass *createMachineLICMPass(bool PreRegAlloc = true);
318
319   /// createMachineSinkingPass - This pass performs sinking on machine
320   /// instructions.
321   FunctionPass *createMachineSinkingPass();
322
323   /// createMachineCopyPropagationPass - This pass performs copy propagation on
324   /// machine instructions.
325   FunctionPass *createMachineCopyPropagationPass();
326
327   /// createPeepholeOptimizerPass - This pass performs peephole optimizations -
328   /// like extension and comparison eliminations.
329   FunctionPass *createPeepholeOptimizerPass();
330
331   /// createOptimizePHIsPass - This pass optimizes machine instruction PHIs
332   /// to take advantage of opportunities created during DAG legalization.
333   FunctionPass *createOptimizePHIsPass();
334
335   /// createStackSlotColoringPass - This pass performs stack slot coloring.
336   FunctionPass *createStackSlotColoringPass(bool);
337
338   /// createStackProtectorPass - This pass adds stack protectors to functions.
339   FunctionPass *createStackProtectorPass(const TargetLowering *tli);
340
341   /// createMachineVerifierPass - This pass verifies cenerated machine code
342   /// instructions for correctness.
343   FunctionPass *createMachineVerifierPass(const char *Banner = 0);
344
345   /// createDwarfEHPass - This pass mulches exception handling code into a form
346   /// adapted to code generation.  Required if using dwarf exception handling.
347   FunctionPass *createDwarfEHPass(const TargetMachine *tm);
348
349   /// createSjLjEHPass - This pass adapts exception handling code to use
350   /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
351   FunctionPass *createSjLjEHPass(const TargetLowering *tli);
352
353   /// createLocalStackSlotAllocationPass - This pass assigns local frame
354   /// indices to stack slots relative to one another and allocates
355   /// base registers to access them when it is estimated by the target to
356   /// be out of range of normal frame pointer or stack pointer index
357   /// addressing.
358   FunctionPass *createLocalStackSlotAllocationPass();
359
360   /// createExpandISelPseudosPass - This pass expands pseudo-instructions.
361   ///
362   FunctionPass *createExpandISelPseudosPass();
363
364   /// createExecutionDependencyFixPass - This pass fixes execution time
365   /// problems with dependent instructions, such as switching execution
366   /// domains to match.
367   ///
368   /// The pass will examine instructions using and defining registers in RC.
369   ///
370   FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
371
372   /// createUnpackMachineBundles - This pass unpack machine instruction bundles.
373   ///
374   FunctionPass *createUnpackMachineBundlesPass();
375
376   /// createFinalizeMachineBundles - This pass finalize machine instruction
377   /// bundles (created earlier, e.g. during pre-RA scheduling).
378   ///
379   FunctionPass *createFinalizeMachineBundlesPass();
380
381 } // End llvm namespace
382
383 #endif