1 //===-- llvm/AllOpts.h - Header file to get all opt passes -------*- C++ -*--=//
3 // This file #include's all of the small optimization header files.
5 // Note that all optimizations return true if they modified the program, false
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_OPT_ALLOPTS_H
11 #define LLVM_OPT_ALLOPTS_H
13 #include "llvm/Module.h"
14 #include "llvm/BasicBlock.h"
15 #include "llvm/Tools/STLExtras.h"
19 //===----------------------------------------------------------------------===//
23 static inline bool ApplyOptToAllMethods(Module *C, bool (*Opt)(Method*)) {
24 return reduce_apply_bool(C->begin(), C->end(), ptr_fun(Opt));
27 //===----------------------------------------------------------------------===//
28 // Dead Code Elimination Pass
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
35 //===----------------------------------------------------------------------===//
36 // Constant Propogation Pass
39 bool DoConstantPropogation(Method *M);
41 static inline bool DoConstantPropogation(Module *C) {
42 return ApplyOptToAllMethods(C, DoConstantPropogation);
45 //===----------------------------------------------------------------------===//
46 // Constant Pool Merging Pass
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.
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());
60 //===----------------------------------------------------------------------===//
61 // Sparse Conditional Constant Propogation Pass
64 bool DoSparseConditionalConstantProp(Method *M);
66 static inline bool DoSparseConditionalConstantProp(Module *M) {
67 return ApplyOptToAllMethods(M, DoSparseConditionalConstantProp);
70 // Define a shorter version of the name...
71 template <class Unit> bool DoSCCP(Unit *M) {
72 return DoSparseConditionalConstantProp(M);
75 //===----------------------------------------------------------------------===//
76 // Method Inlining Pass
79 // DoMethodInlining - Use a heuristic based approach to inline methods that seem
82 bool DoMethodInlining(Method *M);
84 static inline bool DoMethodInlining(Module *C) {
85 return ApplyOptToAllMethods(C, DoMethodInlining);
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
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.
98 bool InlineMethod(CallInst *C);
99 bool InlineMethod(BasicBlock::iterator CI); // *CI must be CallInst
102 //===----------------------------------------------------------------------===//
103 // Symbol Stripping Pass
106 // DoSymbolStripping - Remove all symbolic information from a method
108 bool DoSymbolStripping(Method *M);
110 // DoSymbolStripping - Remove all symbolic information from all methods in a
113 static inline bool DoSymbolStripping(Module *M) {
114 return ApplyOptToAllMethods(M, DoSymbolStripping);
117 // DoFullSymbolStripping - Remove all symbolic information from all methods
118 // in a module, and all module level symbols. (method names, etc...)
120 bool DoFullSymbolStripping(Module *M);
123 //===----------------------------------------------------------------------===//
124 // Induction Variable Cannonicalization
127 // DoInductionVariableCannonicalize - Simplify induction variables in loops
129 bool DoInductionVariableCannonicalize(Method *M);
130 static inline bool DoInductionVariableCannonicalize(Module *M) {
131 return ApplyOptToAllMethods(M, DoInductionVariableCannonicalize);