1 //===-- llvm/Support/StandardPasses.h - Standard pass lists -----*- 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 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.
14 // These are implemented as inline functions so that we do not have to worry
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_STANDARDPASSES_H
20 #define LLVM_SUPPORT_STANDARDPASSES_H
22 #include "llvm/PassManager.h"
23 #include "llvm/Transforms/Scalar.h"
24 #include "llvm/Transforms/IPO.h"
27 /// createStandardFunctionPasses - Add the standard list of function passes to
28 /// the provided pass manager.
30 /// \arg OptimizationLevel - The optimization level, corresponding to -O0,
32 static inline void createStandardFunctionPasses(FunctionPassManager *PM,
33 unsigned OptimizationLevel);
35 /// createStandardModulePasses - Add the standard list of module passes to the
36 /// provided pass manager.
38 /// \arg OptimizationLevel - The optimization level, corresponding to -O0,
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,
52 bool SimplifyLibCalls,
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());
65 PM->add(createScalarReplAggregatesPass());
66 PM->add(createInstructionCombiningPass());
70 static inline void createStandardModulePasses(PassManager *PM,
71 unsigned OptimizationLevel,
75 bool SimplifyLibCalls,
78 if (OptimizationLevel == 0) {
80 PM->add(InliningPass);
83 PM->add(createRaiseAllocationsPass()); // call %malloc -> malloc inst
84 PM->add(createCFGSimplificationPass()); // Clean up disgusting code
85 // Kill useless allocas
86 PM->add(createPromoteMemoryToRegisterPass());
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
94 PM->add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
95 PM->add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
98 PM->add(createPruneEHPass()); // Remove dead EH info
99 PM->add(createFunctionAttrsPass()); // Set readonly/readnone attrs
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 ? true : false));
119 PM->add(createLoopIndexSplitPass()); // Split loop index
120 PM->add(createInstructionCombiningPass());
121 PM->add(createIndVarSimplifyPass()); // Canonicalize indvars
122 PM->add(createLoopDeletionPass()); // Delete dead loops
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
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
139 PM->add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
140 PM->add(createDeadTypeEliminationPass()); // Eliminate dead types
143 if (OptimizationLevel > 1 && UnitAtATime)
144 PM->add(createConstantMergePass()); // Merge dup global constants