1 //===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PassRegistry, with which passes are registered on
11 // initialization, and supports the PassManager in dependency resolution.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/PassRegistry.h"
16 #include "llvm/System/Mutex.h"
18 const PassInfo *PassRegistry::getPassInfo(intptr_t TI) const {
19 sys::SmartScopedLock<true> Guard(Lock);
20 MapType::const_iterator I = PassInfoMap.find(TI);
21 return I != PassInfoMap.end() ? I->second : 0;
24 const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
25 sys::SmartScopedLock<true> Guard(Lock);
26 StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
27 return I != PassInfoStringMap.end() ? I->second : 0;
30 void PassRegistry::registerPass(const PassInfo &PI) {
31 sys::SmartScopedLock<true> Guard(Lock);
33 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
34 assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted;
35 PassInfoStringMap[PI.getPassArgument()] = &PI;
38 void PassRegistry::unregisterPass(const PassInfo &PI) {
39 sys::SmartScopedLock<true> Guard(Lock);
40 MapType::iterator I = PassInfoMap.find(PI.getTypeInfo());
41 assert(I != PassInfoMap.end() && "Pass registered but not in map!");
43 // Remove pass from the map.
45 PassInfoStringMap.erase(PI.getPassArgument());
48 void PassRegistry::enumerateWith(PassRegistrationListener *L) {
49 sys::SmartScopedLock<true> Guard(Lock);
50 for (MapType::const_iterator I = PassInfoMap.begin(),
51 E = PassInfoMap.end(); I != E; ++I)
52 L->passEnumerate(I->second);
56 /// Analysis Group Mechanisms.
57 void PassRegistry::registerAnalysisGroup(PassInfo *InterfaceInfo,
58 const PassInfo *ImplementationInfo,
60 sys::SmartScopedLock<true> Guard(Lock);
61 AnalysisGroupInfo &AGI = AnalysisGroupInfoMap[InterfaceInfo];
62 assert(AGI.Implementations.count(ImplementationInfo) == 0 &&
63 "Cannot add a pass to the same analysis group more than once!");
64 AGI.Implementations.insert(ImplementationInfo);
66 assert(InterfaceInfo->getNormalCtor() == 0 &&
67 "Default implementation for analysis group already specified!");
68 assert(ImplementationInfo->getNormalCtor() &&
69 "Cannot specify pass as default if it does not have a default ctor");
70 InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());