+ AnalysisUsage &AU) {
+ PM->addPass(this, AU);
+}
+
+
+//===----------------------------------------------------------------------===//
+// Pass Registration mechanism
+//
+static std::map<TypeInfo, PassInfo*> *PassInfoMap = 0;
+static std::vector<PassRegistrationListener*> *Listeners = 0;
+
+// getPassInfo - Return the PassInfo data structure that corresponds to this
+// pass...
+const PassInfo *Pass::getPassInfo() const {
+ if (PassInfoCache) return PassInfoCache;
+ return lookupPassInfo(typeid(*this));
+}
+
+const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
+ if (PassInfoMap == 0) return 0;
+ std::map<TypeInfo, PassInfo*>::iterator I = PassInfoMap->find(TI);
+ return (I != PassInfoMap->end()) ? I->second : 0;
+}
+
+void RegisterPassBase::registerPass(PassInfo *PI) {
+ if (PassInfoMap == 0)
+ PassInfoMap = new std::map<TypeInfo, PassInfo*>();
+
+ assert(PassInfoMap->find(PI->getTypeInfo()) == PassInfoMap->end() &&
+ "Pass already registered!");
+ PIObj = PI;
+ PassInfoMap->insert(std::make_pair(TypeInfo(PI->getTypeInfo()), PI));
+
+ // Notify any listeners...
+ if (Listeners)
+ for (std::vector<PassRegistrationListener*>::iterator
+ I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
+ (*I)->passRegistered(PI);
+}
+
+void RegisterPassBase::unregisterPass(PassInfo *PI) {
+ assert(PassInfoMap && "Pass registered but not in map!");
+ std::map<TypeInfo, PassInfo*>::iterator I =
+ PassInfoMap->find(PI->getTypeInfo());
+ assert(I != PassInfoMap->end() && "Pass registered but not in map!");
+
+ // Remove pass from the map...
+ PassInfoMap->erase(I);
+ if (PassInfoMap->empty()) {
+ delete PassInfoMap;
+ PassInfoMap = 0;
+ }
+
+ // Notify any listeners...
+ if (Listeners)
+ for (std::vector<PassRegistrationListener*>::iterator
+ I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
+ (*I)->passUnregistered(PI);
+
+ // Delete the PassInfo object itself...
+ delete PI;
+}
+
+//===----------------------------------------------------------------------===//
+// Analysis Group Implementation Code
+//===----------------------------------------------------------------------===//
+
+struct AnalysisGroupInfo {
+ const PassInfo *DefaultImpl;
+ std::set<const PassInfo *> Implementations;
+ AnalysisGroupInfo() : DefaultImpl(0) {}
+};
+
+static std::map<const PassInfo *, AnalysisGroupInfo> *AnalysisGroupInfoMap = 0;
+
+// RegisterAGBase implementation
+//
+RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
+ const std::type_info *Pass, bool isDefault)
+ : ImplementationInfo(0), isDefaultImplementation(isDefault) {
+
+ InterfaceInfo = const_cast<PassInfo*>(Pass::lookupPassInfo(Interface));
+ if (InterfaceInfo == 0) { // First reference to Interface, add it now.
+ InterfaceInfo = // Create the new PassInfo for the interface...
+ new PassInfo("", "", Interface, PassInfo::AnalysisGroup, 0, 0);
+ registerPass(InterfaceInfo);
+ PIObj = 0;
+ }
+ assert(InterfaceInfo->getPassType() == PassInfo::AnalysisGroup &&
+ "Trying to join an analysis group that is a normal pass!");
+
+ if (Pass) {
+ ImplementationInfo = Pass::lookupPassInfo(*Pass);
+ assert(ImplementationInfo &&
+ "Must register pass before adding to AnalysisGroup!");
+
+ // Make sure we keep track of the fact that the implementation implements
+ // the interface.
+ PassInfo *IIPI = const_cast<PassInfo*>(ImplementationInfo);
+ IIPI->addInterfaceImplemented(InterfaceInfo);
+
+ // Lazily allocate to avoid nasty initialization order dependencies
+ if (AnalysisGroupInfoMap == 0)
+ AnalysisGroupInfoMap = new std::map<const PassInfo *,AnalysisGroupInfo>();
+
+ AnalysisGroupInfo &AGI = (*AnalysisGroupInfoMap)[InterfaceInfo];
+ assert(AGI.Implementations.count(ImplementationInfo) == 0 &&
+ "Cannot add a pass to the same analysis group more than once!");
+ AGI.Implementations.insert(ImplementationInfo);
+ if (isDefault) {
+ assert(AGI.DefaultImpl == 0 && InterfaceInfo->getNormalCtor() == 0 &&
+ "Default implementation for analysis group already specified!");
+ assert(ImplementationInfo->getNormalCtor() &&
+ "Cannot specify pass as default if it does not have a default ctor");
+ AGI.DefaultImpl = ImplementationInfo;
+ InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
+ }
+ }
+}
+
+void RegisterAGBase::setGroupName(const char *Name) {
+ assert(InterfaceInfo->getPassName()[0] == 0 && "Interface Name already set!");
+ InterfaceInfo->setPassName(Name);