comparison lib/IR/LLVMContextImpl.cpp @ 85:5e5d649e25d2

Update LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Thu, 19 Feb 2015 15:19:25 +0900
parents 67baa08a3894 60c9769439b8
children b0dd3743370f
comparison
equal deleted inserted replaced
82:e218c19a8176 85:5e5d649e25d2
41 Int64Ty(C, 64) { 41 Int64Ty(C, 64) {
42 InlineAsmDiagHandler = nullptr; 42 InlineAsmDiagHandler = nullptr;
43 InlineAsmDiagContext = nullptr; 43 InlineAsmDiagContext = nullptr;
44 DiagnosticHandler = nullptr; 44 DiagnosticHandler = nullptr;
45 DiagnosticContext = nullptr; 45 DiagnosticContext = nullptr;
46 RespectDiagnosticFilters = false;
46 YieldCallback = nullptr; 47 YieldCallback = nullptr;
47 YieldOpaqueHandle = nullptr; 48 YieldOpaqueHandle = nullptr;
48 NamedStructTypesUniqueID = 0; 49 NamedStructTypesUniqueID = 0;
49 } 50 }
50 51
72 // NOTE: We need to delete the contents of OwnedModules, but Module's dtor 73 // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
73 // will call LLVMContextImpl::removeModule, thus invalidating iterators into 74 // will call LLVMContextImpl::removeModule, thus invalidating iterators into
74 // the container. Avoid iterators during this operation: 75 // the container. Avoid iterators during this operation:
75 while (!OwnedModules.empty()) 76 while (!OwnedModules.empty())
76 delete *OwnedModules.begin(); 77 delete *OwnedModules.begin();
77 78
78 // Free the constants. This is important to do here to ensure that they are 79 // Drop references for MDNodes. Do this before Values get deleted to avoid
79 // freed before the LeakDetector is torn down. 80 // unnecessary RAUW when nodes are still unresolved.
81 for (auto *I : DistinctMDNodes)
82 I->dropAllReferences();
83 #define HANDLE_MDNODE_LEAF(CLASS) \
84 for (auto *I : CLASS##s) \
85 I->dropAllReferences();
86 #include "llvm/IR/Metadata.def"
87
88 // Also drop references that come from the Value bridges.
89 for (auto &Pair : ValuesAsMetadata)
90 Pair.second->dropUsers();
91 for (auto &Pair : MetadataAsValues)
92 Pair.second->dropUse();
93
94 // Destroy MDNodes.
95 for (MDNode *I : DistinctMDNodes)
96 I->deleteAsSubclass();
97 #define HANDLE_MDNODE_LEAF(CLASS) \
98 for (CLASS *I : CLASS##s) \
99 delete I;
100 #include "llvm/IR/Metadata.def"
101
102 // Free the constants.
80 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(), 103 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
81 DropFirst()); 104 DropFirst());
82 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(), 105 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
83 DropFirst()); 106 DropFirst());
84 std::for_each(StructConstants.map_begin(), StructConstants.map_end(), 107 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
120 E = AttrsSetNodes.end(); I != E; ) { 143 E = AttrsSetNodes.end(); I != E; ) {
121 FoldingSetIterator<AttributeSetNode> Elem = I++; 144 FoldingSetIterator<AttributeSetNode> Elem = I++;
122 delete &*Elem; 145 delete &*Elem;
123 } 146 }
124 147
125 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet 148 // Destroy MetadataAsValues.
126 // and the NonUniquedMDNodes sets, so copy the values out first. 149 {
127 SmallVector<MDNode*, 8> MDNodes; 150 SmallVector<MetadataAsValue *, 8> MDVs;
128 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size()); 151 MDVs.reserve(MetadataAsValues.size());
129 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end(); 152 for (auto &Pair : MetadataAsValues)
130 I != E; ++I) 153 MDVs.push_back(Pair.second);
131 MDNodes.push_back(&*I); 154 MetadataAsValues.clear();
132 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end()); 155 for (auto *V : MDVs)
133 for (SmallVectorImpl<MDNode *>::iterator I = MDNodes.begin(), 156 delete V;
134 E = MDNodes.end(); I != E; ++I) 157 }
135 (*I)->destroy(); 158
136 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() && 159 // Destroy ValuesAsMetadata.
137 "Destroying all MDNodes didn't empty the Context's sets."); 160 for (auto &Pair : ValuesAsMetadata)
161 delete Pair.second;
138 162
139 // Destroy MDStrings. 163 // Destroy MDStrings.
140 DeleteContainerSeconds(MDStringCache); 164 MDStringCache.clear();
165 }
166
167 void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
168 bool Changed;
169 do {
170 Changed = false;
171
172 for (auto I = ArrayConstants.map_begin(), E = ArrayConstants.map_end();
173 I != E; ) {
174 auto *C = I->first;
175 I++;
176 if (C->use_empty()) {
177 Changed = true;
178 C->destroyConstant();
179 }
180 }
181
182 } while (Changed);
183 }
184
185 void Module::dropTriviallyDeadConstantArrays() {
186 Context.pImpl->dropTriviallyDeadConstantArrays();
187 }
188
189 namespace llvm {
190 /// \brief Make MDOperand transparent for hashing.
191 ///
192 /// This overload of an implementation detail of the hashing library makes
193 /// MDOperand hash to the same value as a \a Metadata pointer.
194 ///
195 /// Note that overloading \a hash_value() as follows:
196 ///
197 /// \code
198 /// size_t hash_value(const MDOperand &X) { return hash_value(X.get()); }
199 /// \endcode
200 ///
201 /// does not cause MDOperand to be transparent. In particular, a bare pointer
202 /// doesn't get hashed before it's combined, whereas \a MDOperand would.
203 static const Metadata *get_hashable_data(const MDOperand &X) { return X.get(); }
204 }
205
206 unsigned MDNodeOpsKey::calculateHash(MDNode *N, unsigned Offset) {
207 unsigned Hash = hash_combine_range(N->op_begin() + Offset, N->op_end());
208 #ifndef NDEBUG
209 {
210 SmallVector<Metadata *, 8> MDs(N->op_begin() + Offset, N->op_end());
211 unsigned RawHash = calculateHash(MDs);
212 assert(Hash == RawHash &&
213 "Expected hash of MDOperand to equal hash of Metadata*");
214 }
215 #endif
216 return Hash;
217 }
218
219 unsigned MDNodeOpsKey::calculateHash(ArrayRef<Metadata *> Ops) {
220 return hash_combine_range(Ops.begin(), Ops.end());
141 } 221 }
142 222
143 // ConstantsContext anchors 223 // ConstantsContext anchors
144 void UnaryConstantExpr::anchor() { } 224 void UnaryConstantExpr::anchor() { }
145 225
158 void InsertValueConstantExpr::anchor() { } 238 void InsertValueConstantExpr::anchor() { }
159 239
160 void GetElementPtrConstantExpr::anchor() { } 240 void GetElementPtrConstantExpr::anchor() { }
161 241
162 void CompareConstantExpr::anchor() { } 242 void CompareConstantExpr::anchor() { }
243