Move pass configuration out of pass constructors: MachineLICM.
[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
97 protected:
98   // Helper to verify the analysis is really immutable.
99   void setOpt(bool &Opt, bool Val);
100
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.
106   ///
107
108   /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
109   /// passes (which are run just before instruction selector).
110   virtual bool addPreISel() {
111     return true;
112   }
113
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() {
118     return false;
119   }
120
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() {
126     return false;
127   }
128
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() {
134     return false;
135   }
136
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() {
141     return false;
142   }
143
144   /// Utilities for targets to add passes to the pass manager.
145   ///
146
147   /// Add a target-independent CodeGen pass at this point in the pipeline.
148   void addPass(char &ID);
149
150   /// printNoVerify - Add a pass to dump the machine function, if debugging is
151   /// enabled.
152   ///
153   void printNoVerify(const char *Banner) const;
154
155   /// printAndVerify - Add a pass to dump then verify the machine function, if
156   /// those steps are enabled.
157   ///
158   void printAndVerify(const char *Banner) const;
159 };
160 } // namespace llvm
161
162 /// List of target independent CodeGen pass IDs.
163 namespace llvm {
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
169   /// the entry block.
170   FunctionPass *createUnreachableBlockEliminationPass();
171
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 ="");
177
178   /// MachineLoopInfo pass - This pass is a loop analysis pass.
179   ///
180   extern char &MachineLoopInfoID;
181
182   /// MachineLoopRanges pass - This pass is an on-demand loop coverage
183   /// analysis pass.
184   ///
185   extern char &MachineLoopRangesID;
186
187   /// MachineDominators pass - This pass is a machine dominators analysis pass.
188   ///
189   extern char &MachineDominatorsID;
190
191   /// EdgeBundles analysis - Bundle machine CFG edges.
192   ///
193   extern char &EdgeBundlesID;
194
195   /// PHIElimination pass - This pass eliminates machine instruction PHI nodes
196   /// by inserting copy instructions.  This destroys SSA information, but is the
197   /// desired input for some register allocators.  This pass is "required" by
198   /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
199   ///
200   extern char &PHIEliminationID;
201
202   /// StrongPHIElimination pass - This pass eliminates machine instruction PHI
203   /// nodes by inserting copy instructions.  This destroys SSA information, but
204   /// is the desired input for some register allocators.  This pass is
205   /// "required" by these register allocator like this:
206   ///    AU.addRequiredID(PHIEliminationID);
207   ///  This pass is still in development
208   extern char &StrongPHIEliminationID;
209
210   /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
211   extern char &LiveStacksID;
212
213   /// TwoAddressInstruction pass - This pass reduces two-address instructions to
214   /// use two operands. This destroys SSA information but it is desired by
215   /// register allocators.
216   extern char &TwoAddressInstructionPassID;
217
218   /// RegisteCoalescer pass - This pass merges live ranges to eliminate copies.
219   extern char &RegisterCoalescerPassID;
220
221   /// MachineScheduler pass - This pass schedules machine instructions.
222   extern char &MachineSchedulerID;
223
224   /// SpillPlacement analysis. Suggest optimal placement of spill code between
225   /// basic blocks.
226   ///
227   extern char &SpillPlacementID;
228
229   /// UnreachableMachineBlockElimination pass - This pass removes unreachable
230   /// machine basic blocks.
231   extern char &UnreachableMachineBlockElimID;
232
233   /// DeadMachineInstructionElim pass - This pass removes dead machine
234   /// instructions.
235   ///
236   FunctionPass *createDeadMachineInstructionElimPass();
237
238   /// Creates a register allocator as the user specified on the command line, or
239   /// picks one that matches OptLevel.
240   ///
241   FunctionPass *createRegisterAllocator(CodeGenOpt::Level OptLevel);
242
243   /// FastRegisterAllocation Pass - This pass register allocates as fast as
244   /// possible. It is best suited for debug code where live ranges are short.
245   ///
246   FunctionPass *createFastRegisterAllocator();
247
248   /// BasicRegisterAllocation Pass - This pass implements a degenerate global
249   /// register allocator using the basic regalloc framework.
250   ///
251   FunctionPass *createBasicRegisterAllocator();
252
253   /// Greedy register allocation pass - This pass implements a global register
254   /// allocator for optimized builds.
255   ///
256   FunctionPass *createGreedyRegisterAllocator();
257
258   /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
259   /// Quadratic Prograaming (PBQP) based register allocator.
260   ///
261   FunctionPass *createDefaultPBQPRegisterAllocator();
262
263   /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
264   /// and eliminates abstract frame references.
265   ///
266   FunctionPass *createPrologEpilogCodeInserter();
267
268   /// ExpandPostRAPseudos Pass - This pass expands pseudo instructions after
269   /// register allocation.
270   ///
271   FunctionPass *createExpandPostRAPseudosPass();
272
273   /// createPostRAScheduler - This pass performs post register allocation
274   /// scheduling.
275   FunctionPass *createPostRAScheduler();
276
277   /// BranchFolding Pass - This pass performs machine code CFG based
278   /// optimizations to delete branches to branches, eliminate branches to
279   /// successor blocks (creating fall throughs), and eliminating branches over
280   /// branches.
281   extern char &BranchFolderPassID;
282
283   /// TailDuplicate Pass - Duplicate blocks with unconditional branches
284   /// into tails of their predecessors.
285   FunctionPass *createTailDuplicatePass();
286
287   /// IfConverter Pass - This pass performs machine code if conversion.
288   FunctionPass *createIfConverterPass();
289
290   /// MachineBlockPlacement Pass - This pass places basic blocks based on branch
291   /// probabilities.
292   FunctionPass *createMachineBlockPlacementPass();
293
294   /// MachineBlockPlacementStats Pass - This pass collects statistics about the
295   /// basic block placement using branch probabilities and block frequency
296   /// information.
297   FunctionPass *createMachineBlockPlacementStatsPass();
298
299   /// Code Placement Pass - This pass optimize code placement and aligns loop
300   /// headers to target specific alignment boundary.
301   FunctionPass *createCodePlacementOptPass();
302
303   /// IntrinsicLowering Pass - Performs target-independent LLVM IR
304   /// transformations for highly portable strategies.
305   FunctionPass *createGCLoweringPass();
306
307   /// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
308   /// machine code. Must be added very late during code generation, just prior
309   /// to output, and importantly after all CFG transformations (such as branch
310   /// folding).
311   FunctionPass *createGCMachineCodeAnalysisPass();
312
313   /// Deleter Pass - Releases GC metadata.
314   ///
315   FunctionPass *createGCInfoDeleter();
316
317   /// Creates a pass to print GC metadata.
318   ///
319   FunctionPass *createGCInfoPrinter(raw_ostream &OS);
320
321   /// createMachineCSEPass - This pass performs global CSE on machine
322   /// instructions.
323   FunctionPass *createMachineCSEPass();
324
325   /// createMachineLICMPass - This pass performs LICM on machine instructions.
326   ///
327   FunctionPass *createMachineLICMPass();
328
329   /// createMachineSinkingPass - This pass performs sinking on machine
330   /// instructions.
331   FunctionPass *createMachineSinkingPass();
332
333   /// createMachineCopyPropagationPass - This pass performs copy propagation on
334   /// machine instructions.
335   FunctionPass *createMachineCopyPropagationPass();
336
337   /// createPeepholeOptimizerPass - This pass performs peephole optimizations -
338   /// like extension and comparison eliminations.
339   FunctionPass *createPeepholeOptimizerPass();
340
341   /// createOptimizePHIsPass - This pass optimizes machine instruction PHIs
342   /// to take advantage of opportunities created during DAG legalization.
343   FunctionPass *createOptimizePHIsPass();
344
345   /// createStackSlotColoringPass - This pass performs stack slot coloring.
346   FunctionPass *createStackSlotColoringPass();
347
348   /// createStackProtectorPass - This pass adds stack protectors to functions.
349   FunctionPass *createStackProtectorPass(const TargetLowering *tli);
350
351   /// createMachineVerifierPass - This pass verifies cenerated machine code
352   /// instructions for correctness.
353   FunctionPass *createMachineVerifierPass(const char *Banner = 0);
354
355   /// createDwarfEHPass - This pass mulches exception handling code into a form
356   /// adapted to code generation.  Required if using dwarf exception handling.
357   FunctionPass *createDwarfEHPass(const TargetMachine *tm);
358
359   /// createSjLjEHPass - This pass adapts exception handling code to use
360   /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
361   FunctionPass *createSjLjEHPass(const TargetLowering *tli);
362
363   /// createLocalStackSlotAllocationPass - This pass assigns local frame
364   /// indices to stack slots relative to one another and allocates
365   /// base registers to access them when it is estimated by the target to
366   /// be out of range of normal frame pointer or stack pointer index
367   /// addressing.
368   FunctionPass *createLocalStackSlotAllocationPass();
369
370   /// createExpandISelPseudosPass - This pass expands pseudo-instructions.
371   ///
372   FunctionPass *createExpandISelPseudosPass();
373
374   /// createExecutionDependencyFixPass - This pass fixes execution time
375   /// problems with dependent instructions, such as switching execution
376   /// domains to match.
377   ///
378   /// The pass will examine instructions using and defining registers in RC.
379   ///
380   FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
381
382   /// createUnpackMachineBundles - This pass unpack machine instruction bundles.
383   ///
384   FunctionPass *createUnpackMachineBundlesPass();
385
386   /// createFinalizeMachineBundles - This pass finalize machine instruction
387   /// bundles (created earlier, e.g. during pre-RA scheduling).
388   ///
389   FunctionPass *createFinalizeMachineBundlesPass();
390
391 } // End llvm namespace
392
393 #endif