* Use the new reduce_apply_bool template
[oota-llvm.git] / include / llvm / Optimizations / AllOpts.h
1 //===-- llvm/AllOpts.h - Header file to get all opt passes -------*- C++ -*--=//
2 //
3 // This file #include's all of the small optimization header files.
4 //
5 // Note that all optimizations return true if they modified the program, false
6 // if not.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_OPT_ALLOPTS_H
11 #define LLVM_OPT_ALLOPTS_H
12
13 #include "llvm/Module.h"
14 #include "llvm/BasicBlock.h"
15 #include "llvm/Tools/STLExtras.h"
16 class Method;
17 class CallInst;
18
19 //===----------------------------------------------------------------------===//
20 // Helper functions
21 //
22
23 static inline bool ApplyOptToAllMethods(Module *C, bool (*Opt)(Method*)) {
24   return reduce_apply_bool(C->begin(), C->end(), ptr_fun(Opt));
25 }
26
27 //===----------------------------------------------------------------------===//
28 // Dead Code Elimination Pass
29 //
30
31 bool DoDeadCodeElimination(Method *M);         // DCE a method
32 bool DoRemoveUnusedConstants(SymTabValue *S);  // RUC a method or module
33 bool DoDeadCodeElimination(Module *C);         // DCE & RUC a whole module
34
35 //===----------------------------------------------------------------------===//
36 // Constant Propogation Pass
37 //
38
39 bool DoConstantPropogation(Method *M);
40
41 static inline bool DoConstantPropogation(Module *C) { 
42   return ApplyOptToAllMethods(C, DoConstantPropogation); 
43 }
44
45 //===----------------------------------------------------------------------===//
46 // Constant Pool Merging Pass
47 //
48 // This function merges all constants in the specified constant pool that have
49 // identical types and values.  This is useful for passes that generate lots of
50 // constants as a side effect of running.
51 //
52 bool DoConstantPoolMerging(ConstantPool &CP);
53 bool DoConstantPoolMerging(Method *M);
54 static inline bool DoConstantPoolMerging(Module *M) {
55   return ApplyOptToAllMethods(M, DoConstantPoolMerging) |
56          DoConstantPoolMerging(M->getConstantPool());
57 }
58
59
60 //===----------------------------------------------------------------------===//
61 // Sparse Conditional Constant Propogation Pass
62 //
63
64 bool DoSparseConditionalConstantProp(Method *M);
65
66 static inline bool DoSparseConditionalConstantProp(Module *M) {
67   return ApplyOptToAllMethods(M, DoSparseConditionalConstantProp);
68 }
69
70 // Define a shorter version of the name...
71 template <class Unit> bool DoSCCP(Unit *M) { 
72   return DoSparseConditionalConstantProp(M); 
73 }
74
75 //===----------------------------------------------------------------------===//
76 // Method Inlining Pass
77 //
78
79 // DoMethodInlining - Use a heuristic based approach to inline methods that seem
80 // to look good.
81 //
82 bool DoMethodInlining(Method *M);
83
84 static inline bool DoMethodInlining(Module *C) { 
85   return ApplyOptToAllMethods(C, DoMethodInlining); 
86 }
87
88 // InlineMethod - This function forcibly inlines the called method into the
89 // basic block of the caller.  This returns true if it is not possible to inline
90 // this call.  The program is still in a well defined state if this occurs 
91 // though.
92 //
93 // Note that this only does one level of inlining.  For example, if the 
94 // instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now 
95 // exists in the instruction stream.  Similiarly this will inline a recursive
96 // method by one level.
97 //
98 bool InlineMethod(CallInst *C);
99 bool InlineMethod(BasicBlock::iterator CI);  // *CI must be CallInst
100
101
102 //===----------------------------------------------------------------------===//
103 // Symbol Stripping Pass
104 //
105
106 // DoSymbolStripping - Remove all symbolic information from a method
107 //
108 bool DoSymbolStripping(Method *M);
109
110 // DoSymbolStripping - Remove all symbolic information from all methods in a 
111 // module
112 //
113 static inline bool DoSymbolStripping(Module *M) { 
114   return ApplyOptToAllMethods(M, DoSymbolStripping); 
115 }
116
117 // DoFullSymbolStripping - Remove all symbolic information from all methods 
118 // in a module, and all module level symbols. (method names, etc...)
119 //
120 bool DoFullSymbolStripping(Module *M);
121
122
123 //===----------------------------------------------------------------------===//
124 // Induction Variable Cannonicalization
125 //
126
127 // DoInductionVariableCannonicalize - Simplify induction variables in loops
128 //
129 bool DoInductionVariableCannonicalize(Method *M);
130 static inline bool DoInductionVariableCannonicalize(Module *M) { 
131   return ApplyOptToAllMethods(M, DoInductionVariableCannonicalize); 
132 }
133
134 #endif