Second pass at allowing plugins to modify default passes. This time without bonus...
[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   /// Returns the maximum optimization level for this set of flags
111   static unsigned MaxOptimizationLevel(unsigned flags) {
112       return (flags & MaxOptimizationLevelMask) >> 4; };
113   /// Constructs a set of flags from the specified minimum and maximum
114   /// optimisation level
115   static unsigned OptimzationFlags(unsigned minLevel=0, unsigned maxLevel=0xf,
116       unsigned requiredFlags=0, unsigned disallowedFlags=0) {
117     return ((minLevel & OptimizationLevelMask) |
118             ((maxLevel<<MaxOptimizationLevelShift) & MaxOptimizationLevelMask)
119             | ((requiredFlags<<RequiredFlagShift) & RequiredFlagMask)
120             | ((disallowedFlags<<DisallowedFlagShift) & DisallowedFlagMask)); }
121   /// Returns the flags that must be set for this to match
122   static unsigned RequiredFlags(unsigned flags) {
123       return (flags & RequiredFlagMask) >> RequiredFlagShift; };
124   /// Returns the flags that must not be set for this to match
125   static unsigned DisallowedFlags(unsigned flags) {
126       return (flags & DisallowedFlagMask) >> DisallowedFlagShift; };
127   /// Register a standard pass in the specified set.  If flags is non-zero,
128   /// then the pass will only be returned when the specified flags are set.
129   template<typename passName>
130   class RegisterStandardPass {
131     public:
132     RegisterStandardPass(StandardSet set, unsigned char *runBefore=0,
133         unsigned flags=0, unsigned char *ID=0) {
134       // Use the pass's ID if one is not specified
135       RegisterDefaultPass(PassInfo::NormalCtor_t(callDefaultCtor<passName>),
136                ID ? ID : (unsigned char*)&passName::ID, runBefore, set, flags);
137     };
138   };
139   /// Adds the passes from the specified set to the provided pass manager
140   static void AddPassesFromSet(PassManagerBase *PM,
141                                StandardSet set,
142                                unsigned flags=0,
143                                bool VerifyEach=false,
144                                Pass *inliner=0);
145   private:
146   /// Registers the default passes.  This is set by RegisterStandardPassLists
147   /// and is called lazily.
148   static void (*RegisterDefaultPasses)(void);
149   /// Creates the verifier pass that is inserted when a VerifyEach is passed to
150   /// AddPassesFromSet()
151   static Pass* (*CreateVerifierPass)(void);
152   /// Registers the pass
153   static void RegisterDefaultPass(PassInfo::NormalCtor_t constructor,
154                                   unsigned char *newPass,
155                                   unsigned char *oldPass,
156                                   StandardSet set,
157                                   unsigned flags=0);
158 };
159
160 } // namespace llvm
161
162 #endif