llvm.org GIT mirror llvm / 80d692b
revert enough of devang's recent patches to get the tree basically working again git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36638 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
3 changed file(s) with 38 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
3333 #include
3434 #include
3535 #include
36 #include
3637 #include
37 #include
3838
3939 namespace llvm {
4040
7676 ///
7777 class Pass {
7878 AnalysisResolver *Resolver; // Used to resolve analysis
79 intptr_t PassID;
79 const PassInfo *PassInfoCache;
8080
8181 // AnalysisImpls - This keeps track of which passes implement the interfaces
8282 // that are required by the current pass (to implement getAnalysis()).
8686 void operator=(const Pass&); // DO NOT IMPLEMENT
8787 Pass(const Pass &); // DO NOT IMPLEMENT
8888 public:
89 Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
89 Pass(intptr_t pid = 0) : Resolver(0), PassInfoCache(0) {}
9090 virtual ~Pass();
9191
9292 /// getPassName - Return a nice clean name for a pass. This usually
162162
163163 template
164164 static const PassInfo *getClassPassInfo() {
165 return lookupPassInfo((intptr_t)&AnalysisClass::ID);
165 return lookupPassInfo(typeid(AnalysisClass));
166166 }
167167
168168 // lookupPassInfo - Return the pass info object for the specified pass class,
169169 // or null if it is not known.
170 static const PassInfo *lookupPassInfo(intptr_t TI);
170 static const PassInfo *lookupPassInfo(const std::type_info &TI);
171171
172172 /// getAnalysisToUpdate() - This function is used by subclasses
173173 /// to get to the analysis information that might be around that needs to be
273273 class FunctionPass : public Pass {
274274 public:
275275 FunctionPass(intptr_t pid) : Pass(pid) {}
276
276
277277 /// doInitialization - Virtual method overridden by subclasses to do
278278 /// any necessary per-module initialization.
279279 ///
324324 class BasicBlockPass : public Pass {
325325 public:
326326 BasicBlockPass(intptr_t pid) : Pass(pid) {}
327
327
328328 /// doInitialization - Virtual method overridden by subclasses to do
329329 /// any necessary per-module initialization.
330330 ///
3636 class PassInfo {
3737 const char *PassName; // Nice name for Pass
3838 const char *PassArgument; // Command Line argument to run this pass
39 intptr_t PassID;
39 const std::type_info &TypeInfo; // type_info object for this Pass class
4040 bool IsCFGOnlyPass; // Pass only looks at the CFG.
4141 bool IsAnalysisGroup; // True if an analysis group.
4242 std::vector ItfImpl;// Interfaces implemented by this pass
4343
44 Pass *(*NormalCtor)();
44 Pass *(*NormalCtor)(); // No argument ctor
4545
4646 public:
4747 /// PassInfo ctor - Do not call this directly, this should only be invoked
4848 /// through RegisterPass.
49 PassInfo(const char *name, const char *arg, intptr_t pi,
49 PassInfo(const char *name, const char *arg, const std::type_info &ti,
5050 Pass *(*normal)() = 0, bool isCFGOnly = false)
51 : PassName(name), PassArgument(arg), PassID(pi),
51 : PassName(name), PassArgument(arg), TypeInfo(ti),
5252 IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
5353 }
5454
6464 const char *getPassArgument() const { return PassArgument; }
6565
6666 /// getTypeInfo - Return the type_info object for the pass...
67 /// TODO : Rename
68 intptr_t getTypeInfo() const { return PassID; }
67 ///
68 const std::type_info &getTypeInfo() const { return TypeInfo; }
6969
7070 /// isAnalysisGroup - Return true if this is an analysis group, not a normal
7171 /// pass.
138138
139139 typedef Pass* (*NormalCtor_t)();
140140
141 RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
141 RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI,
142142 NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
143143 : PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
144144 registerPass();
145145 }
146 RegisterPassBase(intptr_t TI)
146 RegisterPassBase(const std::type_info &TI)
147147 : PIObj("", "", TI) {
148148 // This ctor may only be used for analysis groups: it does not auto-register
149149 // the pass.
164164
165165 // Register Pass using default constructor...
166166 RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
167 : RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID,
167 : RegisterPassBase(Name, PassArg, typeid(PassName),
168168 (RegisterPassBase::NormalCtor_t)callDefaultCtor, CFGOnly) {
169169 }
170170 };
194194 const PassInfo *ImplementationInfo;
195195 bool isDefaultImplementation;
196196 protected:
197 explicit RegisterAGBase(intptr_t InterfaceID,
198 intptr_t PassID = 0,
197 explicit RegisterAGBase(const std::type_info &Interface,
198 const std::type_info *Pass = 0,
199199 bool isDefault = false);
200200 void setGroupName(const char *Name);
201201 };
203203 template
204204 struct RegisterAnalysisGroup : public RegisterAGBase {
205205 explicit RegisterAnalysisGroup(RegisterPassBase &RPB)
206 : RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(),
206 : RegisterAGBase(typeid(Interface), &RPB.getPassInfo()->getTypeInfo(),
207207 Default) {
208208 }
209209
210210 explicit RegisterAnalysisGroup(const char *Name)
211 : RegisterAGBase((intptr_t) &Interface::ID) {
211 : RegisterAGBase(typeid(Interface)) {
212212 setGroupName(Name);
213213 }
214214 };
132132 class PassRegistrar {
133133 /// PassInfoMap - Keep track of the passinfo object for each registered llvm
134134 /// pass.
135 std::map<intptr_t, PassInfo*> PassInfoMap;
135 std::map<TypeInfo, PassInfo*> PassInfoMap;
136136
137137 /// AnalysisGroupInfo - Keep track of information for each analysis group.
138138 struct AnalysisGroupInfo {
146146
147147 public:
148148
149 const PassInfo *GetPassInfo(intptr_t TI) const {
150 std::map::const_iterator I = PassInfoMap.find(TI);
149 const PassInfo *GetPassInfo(const std::type_info &TI) const {
150 std::map::const_iterator I = PassInfoMap.find(TI);
151151 return I != PassInfoMap.end() ? I->second : 0;
152152 }
153153
154154 void RegisterPass(PassInfo &PI) {
155155 bool Inserted =
156 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
157 //assert(Inserted && "Pass registered multiple times!");
156 PassInfoMap.insert(std::make_pair(TypeInfo(PI.getTypeInfo()),&PI)).second;
157 assert(Inserted && "Pass registered multiple times!");
158158 }
159159
160160 void UnregisterPass(PassInfo &PI) {
161 std::map<intptr_t, PassInfo*>::iterator I =
161 std::map<TypeInfo, PassInfo*>::iterator I =
162162 PassInfoMap.find(PI.getTypeInfo());
163163 assert(I != PassInfoMap.end() && "Pass registered but not in map!");
164164
167167 }
168168
169169 void EnumerateWith(PassRegistrationListener *L) {
170 for (std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.begin(),
170 for (std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.begin(),
171171 E = PassInfoMap.end(); I != E; ++I)
172172 L->passEnumerate(I->second);
173173 }
209209 // getPassInfo - Return the PassInfo data structure that corresponds to this
210210 // pass...
211211 const PassInfo *Pass::getPassInfo() const {
212 return lookupPassInfo(PassID);
213 }
214
215 const PassInfo *Pass::lookupPassInfo(intptr_t TI) {
212 if (PassInfoCache) return PassInfoCache;
213 return lookupPassInfo(typeid(*this));
214 }
215
216 const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
216217 return getPassRegistrar()->GetPassInfo(TI);
217218 }
218219
236237
237238 // RegisterAGBase implementation
238239 //
239 RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
240 intptr_t PassID, bool isDefault)
241 : RegisterPassBase(InterfaceID),
240 RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
241 const std::type_info *Pass, bool isDefault)
242 : RegisterPassBase(Interface),
242243 ImplementationInfo(0), isDefaultImplementation(isDefault) {
243244
244 InterfaceInfo = const_cast(Pass::lookupPassInfo(InterfaceID));
245 InterfaceInfo = const_cast(Pass::lookupPassInfo(Interface));
245246 if (InterfaceInfo == 0) {
246247 // First reference to Interface, register it now.
247248 registerPass();
250251 assert(PIObj.isAnalysisGroup() &&
251252 "Trying to join an analysis group that is a normal pass!");
252253
253 if (PassID) {
254 ImplementationInfo = Pass::lookupPassInfo(PassID);
254 if (Pass) {
255 ImplementationInfo = Pass::lookupPassInfo(*Pass);
255256 assert(ImplementationInfo &&
256257 "Must register pass before adding to AnalysisGroup!");
257258