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