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