Unbreak every backend.
[oota-llvm.git] / include / llvm / DefaultPasses.h
1 //===- llvm/DefaultPasses.h - Default Pass Support code --------*- 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 // This file defines the infrastructure for registering the standard pass list.
10 // This defines sets of standard optimizations that plugins can modify and
11 // front ends can use.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_DEFAULT_PASS_SUPPORT_H
15 #define LLVM_DEFAULT_PASS_SUPPORT_H
16
17 namespace llvm {
18
19 class PassManagerBase;
20
21 /// Unique identifiers for the default standard passes.  The addresses of
22 /// these symbols are used to uniquely identify passes from the default list.
23 namespace DefaultStandardPasses {
24 extern unsigned char AggressiveDCEID;
25 extern unsigned char ArgumentPromotionID;
26 extern unsigned char BasicAliasAnalysisID;
27 extern unsigned char CFGSimplificationID;
28 extern unsigned char ConstantMergeID;
29 extern unsigned char CorrelatedValuePropagationID;
30 extern unsigned char DeadArgEliminationID;
31 extern unsigned char DeadStoreEliminationID;
32 extern unsigned char DeadTypeEliminationID;
33 extern unsigned char EarlyCSEID;
34 extern unsigned char FunctionAttrsID;
35 extern unsigned char FunctionInliningID;
36 extern unsigned char GVNID;
37 extern unsigned char GlobalDCEID;
38 extern unsigned char GlobalOptimizerID;
39 extern unsigned char GlobalsModRefID;
40 extern unsigned char IPSCCPID;
41 extern unsigned char IndVarSimplifyID;
42 extern unsigned char InlinerPlaceholderID;
43 extern unsigned char InstructionCombiningID;
44 extern unsigned char JumpThreadingID;
45 extern unsigned char LICMID;
46 extern unsigned char LoopDeletionID;
47 extern unsigned char LoopIdiomID;
48 extern unsigned char LoopRotateID;
49 extern unsigned char LoopUnrollID;
50 extern unsigned char LoopUnswitchID;
51 extern unsigned char MemCpyOptID;
52 extern unsigned char PruneEHID;
53 extern unsigned char ReassociateID;
54 extern unsigned char SCCPID;
55 extern unsigned char ScalarReplAggregatesID;
56 extern unsigned char SimplifyLibCallsID;
57 extern unsigned char StripDeadPrototypesID;
58 extern unsigned char TailCallEliminationID;
59 extern unsigned char TypeBasedAliasAnalysisID;
60 }
61
62 /// StandardPass - The class responsible for maintaining the lists of standard 
63 class StandardPass {
64   friend class RegisterStandardPassLists;
65   public:
66   /// Predefined standard sets of passes
67   enum StandardSet {
68     AliasAnalysis,
69     Function,
70     Module,
71     LTO
72   };
73   /// Flags to specify whether a pass should be enabled.  Passes registered
74   /// with the standard sets may specify a minimum optimization level and one
75   /// or more flags that must be set when constructing the set for the pass to
76   /// be used.
77   enum OptimizationFlags {
78     /// Optimize for size was requested.
79     OptimizeSize = 1<<0,
80     /// Allow passes which may make global module changes.
81     UnitAtATime = 1<<1,
82     /// UnrollLoops - Allow loop unrolling.
83     UnrollLoops = 1<<2,
84     /// Allow library calls to be simplified.
85     SimplifyLibCalls = 1<<3,
86     /// Whether the module may have code using exceptions.
87     HaveExceptions = 1<<4,
88     // Run an inliner pass as part of this set.
89     RunInliner = 1<<5
90   };
91   enum OptimizationFlagComponents {
92     /// The low bits are used to store the optimization level.  When requesting
93     /// passes, this should store the requested optimisation level.  When
94     /// setting passes, this should set the minimum optimization level at which
95     /// the pass will run.
96     OptimizationLevelMask=0xf,
97     /// The maximum optimisation level at which the pass is run.
98     MaxOptimizationLevelMask=0xf0,
99     // Flags that must be set
100     RequiredFlagMask=0xff00,
101     // Flags that may not be set.
102     DisallowedFlagMask=0xff0000,
103     MaxOptimizationLevelShift=4,
104     RequiredFlagShift=8,
105     DisallowedFlagShift=16
106   };
107   /// Returns the optimisation level from a set of flags.
108   static unsigned OptimizationLevel(unsigned flags) {
109       return flags & OptimizationLevelMask;
110   }
111   /// Returns the maximum optimization level for this set of flags
112   static unsigned MaxOptimizationLevel(unsigned flags) {
113       return (flags & MaxOptimizationLevelMask) >> 4;
114   }
115   /// Constructs a set of flags from the specified minimum and maximum
116   /// optimisation level
117   static unsigned OptimzationFlags(unsigned minLevel=0, unsigned maxLevel=0xf,
118       unsigned requiredFlags=0, unsigned disallowedFlags=0) {
119     return ((minLevel & OptimizationLevelMask) |
120             ((maxLevel<<MaxOptimizationLevelShift) & MaxOptimizationLevelMask)
121             | ((requiredFlags<<RequiredFlagShift) & RequiredFlagMask)
122             | ((disallowedFlags<<DisallowedFlagShift) & DisallowedFlagMask));
123   }
124   /// Returns the flags that must be set for this to match
125   static unsigned RequiredFlags(unsigned flags) {
126       return (flags & RequiredFlagMask) >> RequiredFlagShift;
127   }
128   /// Returns the flags that must not be set for this to match
129   static unsigned DisallowedFlags(unsigned flags) {
130       return (flags & DisallowedFlagMask) >> DisallowedFlagShift;
131   }
132   /// Register a standard pass in the specified set.  If flags is non-zero,
133   /// then the pass will only be returned when the specified flags are set.
134   template<typename passName>
135   class RegisterStandardPass {
136     public:
137     RegisterStandardPass(StandardSet set, unsigned char *runBefore=0,
138         unsigned flags=0, unsigned char *ID=0) {
139       // Use the pass's ID if one is not specified
140       RegisterDefaultPass(PassInfo::NormalCtor_t(callDefaultCtor<passName>),
141                ID ? ID : (unsigned char*)&passName::ID, runBefore, set, flags);
142     }
143   };
144   /// Adds the passes from the specified set to the provided pass manager
145   static void AddPassesFromSet(PassManagerBase *PM,
146                                StandardSet set,
147                                unsigned flags=0,
148                                bool VerifyEach=false,
149                                Pass *inliner=0);
150   private:
151   /// Registers the default passes.  This is set by RegisterStandardPassLists
152   /// and is called lazily.
153   static void (*RegisterDefaultPasses)(void);
154   /// Creates the verifier pass that is inserted when a VerifyEach is passed to
155   /// AddPassesFromSet()
156   static Pass* (*CreateVerifierPass)(void);
157   /// Registers the pass
158   static void RegisterDefaultPass(PassInfo::NormalCtor_t constructor,
159                                   unsigned char *newPass,
160                                   unsigned char *oldPass,
161                                   StandardSet set,
162                                   unsigned flags=0);
163 };
164
165 } // namespace llvm
166
167 #endif