Deleted Added
full compact
PassRegistry.cpp (276479) PassRegistry.cpp (280031)
1//===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
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//===----------------------------------------------------------------------===//

--- 22 unchanged lines hidden (view full) ---

31PassRegistry *PassRegistry::getPassRegistry() {
32 return &*PassRegistryObj;
33}
34
35//===----------------------------------------------------------------------===//
36// Accessors
37//
38
1//===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
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//===----------------------------------------------------------------------===//

--- 22 unchanged lines hidden (view full) ---

31PassRegistry *PassRegistry::getPassRegistry() {
32 return &*PassRegistryObj;
33}
34
35//===----------------------------------------------------------------------===//
36// Accessors
37//
38
39PassRegistry::~PassRegistry() {
40}
39PassRegistry::~PassRegistry() {}
41
42const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
43 sys::SmartScopedReader<true> Guard(Lock);
44 MapType::const_iterator I = PassInfoMap.find(TI);
45 return I != PassInfoMap.end() ? I->second : nullptr;
46}
47
48const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {

--- 4 unchanged lines hidden (view full) ---

53
54//===----------------------------------------------------------------------===//
55// Pass Registration mechanism
56//
57
58void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
59 sys::SmartScopedWriter<true> Guard(Lock);
60 bool Inserted =
40
41const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
42 sys::SmartScopedReader<true> Guard(Lock);
43 MapType::const_iterator I = PassInfoMap.find(TI);
44 return I != PassInfoMap.end() ? I->second : nullptr;
45}
46
47const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {

--- 4 unchanged lines hidden (view full) ---

52
53//===----------------------------------------------------------------------===//
54// Pass Registration mechanism
55//
56
57void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
58 sys::SmartScopedWriter<true> Guard(Lock);
59 bool Inserted =
61 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
60 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
62 assert(Inserted && "Pass registered multiple times!");
63 (void)Inserted;
64 PassInfoStringMap[PI.getPassArgument()] = &PI;
61 assert(Inserted && "Pass registered multiple times!");
62 (void)Inserted;
63 PassInfoStringMap[PI.getPassArgument()] = &PI;
65
64
66 // Notify any listeners.
65 // Notify any listeners.
67 for (std::vector<PassRegistrationListener*>::iterator
68 I = Listeners.begin(), E = Listeners.end(); I != E; ++I)
69 (*I)->passRegistered(&PI);
70
71 if (ShouldFree) ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
72}
66 for (auto *Listener : Listeners)
67 Listener->passRegistered(&PI);
73
68
74void PassRegistry::unregisterPass(const PassInfo &PI) {
75 sys::SmartScopedWriter<true> Guard(Lock);
76 MapType::iterator I = PassInfoMap.find(PI.getTypeInfo());
77 assert(I != PassInfoMap.end() && "Pass registered but not in map!");
78
79 // Remove pass from the map.
80 PassInfoMap.erase(I);
81 PassInfoStringMap.erase(PI.getPassArgument());
69 if (ShouldFree)
70 ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
82}
83
84void PassRegistry::enumerateWith(PassRegistrationListener *L) {
85 sys::SmartScopedReader<true> Guard(Lock);
71}
72
73void PassRegistry::enumerateWith(PassRegistrationListener *L) {
74 sys::SmartScopedReader<true> Guard(Lock);
86 for (auto I = PassInfoMap.begin(), E = PassInfoMap.end(); I != E; ++I)
87 L->passEnumerate(I->second);
75 for (auto PassInfoPair : PassInfoMap)
76 L->passEnumerate(PassInfoPair.second);
88}
89
77}
78
90
91/// Analysis Group Mechanisms.
79/// Analysis Group Mechanisms.
92void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
80void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
93 const void *PassID,
81 const void *PassID,
94 PassInfo& Registeree,
95 bool isDefault,
82 PassInfo &Registeree, bool isDefault,
96 bool ShouldFree) {
83 bool ShouldFree) {
97 PassInfo *InterfaceInfo = const_cast<PassInfo*>(getPassInfo(InterfaceID));
84 PassInfo *InterfaceInfo = const_cast<PassInfo *>(getPassInfo(InterfaceID));
98 if (!InterfaceInfo) {
99 // First reference to Interface, register it now.
100 registerPass(Registeree);
101 InterfaceInfo = &Registeree;
102 }
85 if (!InterfaceInfo) {
86 // First reference to Interface, register it now.
87 registerPass(Registeree);
88 InterfaceInfo = &Registeree;
89 }
103 assert(Registeree.isAnalysisGroup() &&
90 assert(Registeree.isAnalysisGroup() &&
104 "Trying to join an analysis group that is a normal pass!");
105
106 if (PassID) {
91 "Trying to join an analysis group that is a normal pass!");
92
93 if (PassID) {
107 PassInfo *ImplementationInfo = const_cast(getPassInfo(PassID));
94 PassInfo *ImplementationInfo = const_cast<PassInfo *>(getPassInfo(PassID));
108 assert(ImplementationInfo &&
109 "Must register pass before adding to AnalysisGroup!");
110
111 sys::SmartScopedWriter<true> Guard(Lock);
95 assert(ImplementationInfo &&
96 "Must register pass before adding to AnalysisGroup!");
97
98 sys::SmartScopedWriter<true> Guard(Lock);
112
99
113 // Make sure we keep track of the fact that the implementation implements
114 // the interface.
115 ImplementationInfo->addInterfaceImplemented(InterfaceInfo);
116
100 // Make sure we keep track of the fact that the implementation implements
101 // the interface.
102 ImplementationInfo->addInterfaceImplemented(InterfaceInfo);
103
117 AnalysisGroupInfo &AGI = AnalysisGroupInfoMap[InterfaceInfo];
118 assert(AGI.Implementations.count(ImplementationInfo) == 0 &&
119 "Cannot add a pass to the same analysis group more than once!");
120 AGI.Implementations.insert(ImplementationInfo);
121 if (isDefault) {
122 assert(InterfaceInfo->getNormalCtor() == nullptr &&
123 "Default implementation for analysis group already specified!");
104 if (isDefault) {
105 assert(InterfaceInfo->getNormalCtor() == nullptr &&
106 "Default implementation for analysis group already specified!");
124 assert(ImplementationInfo->getNormalCtor() &&
125 "Cannot specify pass as default if it does not have a default ctor");
107 assert(
108 ImplementationInfo->getNormalCtor() &&
109 "Cannot specify pass as default if it does not have a default ctor");
126 InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
127 InterfaceInfo->setTargetMachineCtor(
128 ImplementationInfo->getTargetMachineCtor());
129 }
130 }
110 InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
111 InterfaceInfo->setTargetMachineCtor(
112 ImplementationInfo->getTargetMachineCtor());
113 }
114 }
131
115
132 if (ShouldFree)
133 ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree));
134}
135
136void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
137 sys::SmartScopedWriter<true> Guard(Lock);
138 Listeners.push_back(L);
139}
140
141void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
142 sys::SmartScopedWriter<true> Guard(Lock);
116 if (ShouldFree)
117 ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree));
118}
119
120void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
121 sys::SmartScopedWriter<true> Guard(Lock);
122 Listeners.push_back(L);
123}
124
125void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
126 sys::SmartScopedWriter<true> Guard(Lock);
143
127
144 auto I = std::find(Listeners.begin(), Listeners.end(), L);
145 Listeners.erase(I);
146}
128 auto I = std::find(Listeners.begin(), Listeners.end(), L);
129 Listeners.erase(I);
130}