/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/IR/PassRegistry.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements the PassRegistry, with which passes are registered on |
11 | | // initialization, and supports the PassManager in dependency resolution. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #include "llvm/PassRegistry.h" |
16 | | #include "llvm/ADT/STLExtras.h" |
17 | | #include "llvm/PassInfo.h" |
18 | | #include "llvm/PassSupport.h" |
19 | | #include "llvm/Support/ManagedStatic.h" |
20 | | #include <cassert> |
21 | | #include <memory> |
22 | | #include <utility> |
23 | | |
24 | | using namespace llvm; |
25 | | |
26 | | // FIXME: We use ManagedStatic to erase the pass registrar on shutdown. |
27 | | // Unfortunately, passes are registered with static ctors, and having |
28 | | // llvm_shutdown clear this map prevents successful resurrection after |
29 | | // llvm_shutdown is run. Ideally we should find a solution so that we don't |
30 | | // leak the map, AND can still resurrect after shutdown. |
31 | | static ManagedStatic<PassRegistry> PassRegistryObj; |
32 | 31.6M | PassRegistry *PassRegistry::getPassRegistry() { |
33 | 31.6M | return &*PassRegistryObj; |
34 | 31.6M | } |
35 | | |
36 | | //===----------------------------------------------------------------------===// |
37 | | // Accessors |
38 | | // |
39 | | |
40 | 95.7k | PassRegistry::~PassRegistry() = default; |
41 | | |
42 | 19.5M | const PassInfo *PassRegistry::getPassInfo(const void *TI) const { |
43 | 19.5M | sys::SmartScopedReader<true> Guard(Lock); |
44 | 19.5M | MapType::const_iterator I = PassInfoMap.find(TI); |
45 | 19.5M | return I != PassInfoMap.end() ? I->second7.61M : nullptr11.9M ; |
46 | 19.5M | } |
47 | | |
48 | 673 | const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const { |
49 | 673 | sys::SmartScopedReader<true> Guard(Lock); |
50 | 673 | StringMapType::const_iterator I = PassInfoStringMap.find(Arg); |
51 | 673 | return I != PassInfoStringMap.end() ? I->second669 : nullptr4 ; |
52 | 673 | } |
53 | | |
54 | | //===----------------------------------------------------------------------===// |
55 | | // Pass Registration mechanism |
56 | | // |
57 | | |
58 | 19.5M | void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) { |
59 | 19.5M | sys::SmartScopedWriter<true> Guard(Lock); |
60 | 19.5M | bool Inserted = |
61 | 19.5M | PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second; |
62 | 19.5M | assert(Inserted && "Pass registered multiple times!"); |
63 | 19.5M | (void)Inserted; |
64 | 19.5M | PassInfoStringMap[PI.getPassArgument()] = &PI; |
65 | 19.5M | |
66 | 19.5M | // Notify any listeners. |
67 | 19.5M | for (auto *Listener : Listeners) |
68 | 41.9M | Listener->passRegistered(&PI); |
69 | 19.5M | |
70 | 19.5M | if (ShouldFree) |
71 | 19.2M | ToFree.push_back(std::unique_ptr<const PassInfo>(&PI)); |
72 | 19.5M | } |
73 | | |
74 | 1.97M | void PassRegistry::enumerateWith(PassRegistrationListener *L) { |
75 | 1.97M | sys::SmartScopedReader<true> Guard(Lock); |
76 | 1.97M | for (auto PassInfoPair : PassInfoMap) |
77 | 445M | L->passEnumerate(PassInfoPair.second); |
78 | 1.97M | } |
79 | | |
80 | | /// Analysis Group Mechanisms. |
81 | | void PassRegistry::registerAnalysisGroup(const void *InterfaceID, |
82 | | const void *PassID, |
83 | | PassInfo &Registeree, bool isDefault, |
84 | 0 | bool ShouldFree) { |
85 | 0 | PassInfo *InterfaceInfo = const_cast<PassInfo *>(getPassInfo(InterfaceID)); |
86 | 0 | if (!InterfaceInfo0 ) { |
87 | 0 | // First reference to Interface, register it now. |
88 | 0 | registerPass(Registeree); |
89 | 0 | InterfaceInfo = &Registeree; |
90 | 0 | } |
91 | 0 | assert(Registeree.isAnalysisGroup() && |
92 | 0 | "Trying to join an analysis group that is a normal pass!"); |
93 | 0 |
|
94 | 0 | if (PassID0 ) { |
95 | 0 | PassInfo *ImplementationInfo = const_cast<PassInfo *>(getPassInfo(PassID)); |
96 | 0 | assert(ImplementationInfo && |
97 | 0 | "Must register pass before adding to AnalysisGroup!"); |
98 | 0 |
|
99 | 0 | sys::SmartScopedWriter<true> Guard(Lock); |
100 | 0 |
|
101 | 0 | // Make sure we keep track of the fact that the implementation implements |
102 | 0 | // the interface. |
103 | 0 | ImplementationInfo->addInterfaceImplemented(InterfaceInfo); |
104 | 0 |
|
105 | 0 | if (isDefault0 ) { |
106 | 0 | assert(InterfaceInfo->getNormalCtor() == nullptr && |
107 | 0 | "Default implementation for analysis group already specified!"); |
108 | 0 | assert( |
109 | 0 | ImplementationInfo->getNormalCtor() && |
110 | 0 | "Cannot specify pass as default if it does not have a default ctor"); |
111 | 0 | InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor()); |
112 | 0 | } |
113 | 0 | } |
114 | 0 |
|
115 | 0 | if (ShouldFree) |
116 | 0 | ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree)); |
117 | 0 | } |
118 | | |
119 | 208k | void PassRegistry::addRegistrationListener(PassRegistrationListener *L) { |
120 | 208k | sys::SmartScopedWriter<true> Guard(Lock); |
121 | 208k | Listeners.push_back(L); |
122 | 208k | } |
123 | | |
124 | 0 | void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) { |
125 | 0 | sys::SmartScopedWriter<true> Guard(Lock); |
126 | 0 |
|
127 | 0 | auto I = llvm::find(Listeners, L); |
128 | 0 | Listeners.erase(I); |
129 | 0 | } |