Remove some silly code.
[oota-llvm.git] / include / llvm / Support / StandardPasses.h
1 //===-- llvm/Support/StandardPasses.h - Standard pass lists -----*- 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 utility functions for creating a "standard" set of
11 // optimization passes, so that compilers and tools which use optimization
12 // passes use the same set of standard passes.
13 //
14 // These are implemented as inline functions so that we do not have to worry
15 // about link issues.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_SUPPORT_STANDARDPASSES_H
20 #define LLVM_SUPPORT_STANDARDPASSES_H
21
22 #include "llvm/PassManager.h"
23 #include "llvm/Transforms/Scalar.h"
24 #include "llvm/Transforms/IPO.h"
25
26 namespace llvm {
27   /// createStandardFunctionPasses - Add the standard list of function passes to
28   /// the provided pass manager.
29   ///
30   /// \arg OptimizationLevel - The optimization level, corresponding to -O0,
31   /// -O1, etc.
32   static inline void createStandardFunctionPasses(FunctionPassManager *PM,
33                                                   unsigned OptimizationLevel);
34
35   /// createStandardModulePasses - Add the standard list of module passes to the
36   /// provided pass manager.
37   ///
38   /// \arg OptimizationLevel - The optimization level, corresponding to -O0,
39   /// -O1, etc.
40   /// \arg OptimizeSize - Whether the transformations should optimize for size.
41   /// \arg UnitAtATime - Allow passes which may make global module changes.
42   /// \arg UnrollLoops - Allow loop unrolling.
43   /// \arg SimplifyLibCalls - Allow library calls to be simplified.
44   /// \arg HaveExceptions - Whether the module may have code using exceptions.
45   /// \arg InliningPass - The inlining pass to use, if any, or null. This will
46   /// always be added, even at -O0.a
47   static inline void createStandardModulePasses(PassManager *PM,
48                                                 unsigned OptimizationLevel,
49                                                 bool OptimizeSize,
50                                                 bool UnitAtATime,
51                                                 bool UnrollLoops,
52                                                 bool SimplifyLibCalls,
53                                                 bool HaveExceptions,
54                                                 Pass *InliningPass);
55
56   // Implementations
57
58   static inline void createStandardFunctionPasses(FunctionPassManager *PM,
59                                                   unsigned OptimizationLevel) {
60     if (OptimizationLevel > 0) {
61       PM->add(createCFGSimplificationPass());
62       if (OptimizationLevel == 1)
63         PM->add(createPromoteMemoryToRegisterPass());
64       else
65         PM->add(createScalarReplAggregatesPass());
66       PM->add(createInstructionCombiningPass());
67     }
68   }
69
70   static inline void createStandardModulePasses(PassManager *PM,
71                                                 unsigned OptimizationLevel,
72                                                 bool OptimizeSize,
73                                                 bool UnitAtATime,
74                                                 bool UnrollLoops,
75                                                 bool SimplifyLibCalls,
76                                                 bool HaveExceptions,
77                                                 Pass *InliningPass) {
78     if (OptimizationLevel == 0) {
79       if (InliningPass)
80         PM->add(InliningPass);
81     } else {
82       if (UnitAtATime)
83         PM->add(createRaiseAllocationsPass());    // call %malloc -> malloc inst
84       PM->add(createCFGSimplificationPass());     // Clean up disgusting code
85        // Kill useless allocas
86       PM->add(createPromoteMemoryToRegisterPass());
87       if (UnitAtATime) {
88         PM->add(createGlobalOptimizerPass());     // Optimize out global vars
89         PM->add(createGlobalDCEPass());           // Remove unused fns and globs
90         // IP Constant Propagation
91         PM->add(createIPConstantPropagationPass());
92         PM->add(createDeadArgEliminationPass());  // Dead argument elimination
93       }
94       PM->add(createInstructionCombiningPass());  // Clean up after IPCP & DAE
95       PM->add(createCFGSimplificationPass());     // Clean up after IPCP & DAE
96       if (UnitAtATime) {
97         if (HaveExceptions)
98           PM->add(createPruneEHPass());           // Remove dead EH info
99         PM->add(createFunctionAttrsPass());       // Set readonly/readnone attrs
100       }
101       if (InliningPass)
102         PM->add(InliningPass);
103       if (OptimizationLevel > 2)
104         PM->add(createArgumentPromotionPass());   // Scalarize uninlined fn args
105       if (SimplifyLibCalls)
106         PM->add(createSimplifyLibCallsPass());    // Library Call Optimizations
107       PM->add(createInstructionCombiningPass());  // Cleanup for scalarrepl.
108       PM->add(createJumpThreadingPass());         // Thread jumps.
109       PM->add(createCFGSimplificationPass());     // Merge & remove BBs
110       PM->add(createScalarReplAggregatesPass());  // Break up aggregate allocas
111       PM->add(createInstructionCombiningPass());  // Combine silly seq's
112       PM->add(createCondPropagationPass());       // Propagate conditionals
113       PM->add(createTailCallEliminationPass());   // Eliminate tail calls
114       PM->add(createCFGSimplificationPass());     // Merge & remove BBs
115       PM->add(createReassociatePass());           // Reassociate expressions
116       PM->add(createLoopRotatePass());            // Rotate Loop
117       PM->add(createLICMPass());                  // Hoist loop invariants
118       PM->add(createLoopUnswitchPass(OptimizeSize));
119       PM->add(createLoopIndexSplitPass());        // Split loop index
120       PM->add(createInstructionCombiningPass());  
121       PM->add(createIndVarSimplifyPass());        // Canonicalize indvars
122       PM->add(createLoopDeletionPass());          // Delete dead loops
123       if (UnrollLoops)
124         PM->add(createLoopUnrollPass());          // Unroll small loops
125       PM->add(createInstructionCombiningPass());  // Clean up after the unroller
126       PM->add(createGVNPass());                   // Remove redundancies
127       PM->add(createMemCpyOptPass());             // Remove memcpy / form memset
128       PM->add(createSCCPPass());                  // Constant prop with SCCP
129     
130       // Run instcombine after redundancy elimination to exploit opportunities
131       // opened up by them.
132       PM->add(createInstructionCombiningPass());
133       PM->add(createCondPropagationPass());       // Propagate conditionals
134       PM->add(createDeadStoreEliminationPass());  // Delete dead stores
135       PM->add(createAggressiveDCEPass());         // Delete dead instructions
136       PM->add(createCFGSimplificationPass());     // Merge & remove BBs
137
138       if (UnitAtATime) {
139         PM->add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
140         PM->add(createDeadTypeEliminationPass()); // Eliminate dead types
141       }
142
143       if (OptimizationLevel > 1 && UnitAtATime)
144         PM->add(createConstantMergePass());       // Merge dup global constants
145     }
146   }
147 }
148
149 #endif