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