Mercurial > hg > CbC > CbC_llvm
comparison llvm/tools/dsymutil/BinaryHolder.cpp @ 236:c4bab56944e8 llvm-original
LLVM 16
author | kono |
---|---|
date | Wed, 09 Nov 2022 17:45:10 +0900 |
parents | 79ff65ed7e25 |
children | 1f2b6ac9f198 |
comparison
equal
deleted
inserted
replaced
232:70dce7da266c | 236:c4bab56944e8 |
---|---|
166 TimestampTy Timestamp, | 166 TimestampTy Timestamp, |
167 bool Verbose) { | 167 bool Verbose) { |
168 StringRef ArchiveFilename; | 168 StringRef ArchiveFilename; |
169 StringRef ObjectFilename; | 169 StringRef ObjectFilename; |
170 std::tie(ArchiveFilename, ObjectFilename) = getArchiveAndObjectName(Filename); | 170 std::tie(ArchiveFilename, ObjectFilename) = getArchiveAndObjectName(Filename); |
171 KeyTy Key = {ObjectFilename, Timestamp}; | |
171 | 172 |
172 // Try the cache first. | 173 // Try the cache first. |
173 KeyTy Key = {ObjectFilename, Timestamp}; | 174 std::lock_guard<std::mutex> Lock(MemberCacheMutex); |
174 | 175 if (MemberCache.count(Key)) |
175 { | 176 return *MemberCache[Key].get(); |
176 std::lock_guard<std::mutex> Lock(MemberCacheMutex); | |
177 if (MemberCache.count(Key)) | |
178 return MemberCache[Key]; | |
179 } | |
180 | 177 |
181 // Create a new ObjectEntry, but don't add it to the cache yet. Loading of | 178 // Create a new ObjectEntry, but don't add it to the cache yet. Loading of |
182 // the archive members might fail and we don't want to lock the whole archive | 179 // the archive members might fail and we don't want to lock the whole archive |
183 // during this operation. | 180 // during this operation. |
184 ObjectEntry OE; | 181 auto OE = std::make_unique<ObjectEntry>(); |
185 | 182 |
186 for (const auto &Archive : Archives) { | 183 for (const auto &Archive : Archives) { |
187 Error Err = Error::success(); | 184 Error Err = Error::success(); |
188 for (auto Child : Archive->children(Err)) { | 185 for (auto Child : Archive->children(Err)) { |
189 if (auto NameOrErr = Child.getName()) { | 186 if (auto NameOrErr = Child.getName()) { |
214 auto ErrOrObjectFile = | 211 auto ErrOrObjectFile = |
215 object::ObjectFile::createObjectFile(*ErrOrMem); | 212 object::ObjectFile::createObjectFile(*ErrOrMem); |
216 if (!ErrOrObjectFile) | 213 if (!ErrOrObjectFile) |
217 return ErrOrObjectFile.takeError(); | 214 return ErrOrObjectFile.takeError(); |
218 | 215 |
219 OE.Objects.push_back(std::move(*ErrOrObjectFile)); | 216 OE->Objects.push_back(std::move(*ErrOrObjectFile)); |
220 } | 217 } |
221 } | 218 } |
222 } | 219 } |
223 if (Err) | 220 if (Err) |
224 return std::move(Err); | 221 return std::move(Err); |
225 } | 222 } |
226 | 223 |
227 if (OE.Objects.empty()) | 224 if (OE->Objects.empty()) |
228 return errorCodeToError(errc::no_such_file_or_directory); | 225 return errorCodeToError(errc::no_such_file_or_directory); |
229 | 226 |
230 std::lock_guard<std::mutex> Lock(MemberCacheMutex); | 227 MemberCache[Key] = std::move(OE); |
231 MemberCache.try_emplace(Key, std::move(OE)); | 228 return *MemberCache[Key]; |
232 return MemberCache[Key]; | |
233 } | 229 } |
234 | 230 |
235 Expected<const BinaryHolder::ObjectEntry &> | 231 Expected<const BinaryHolder::ObjectEntry &> |
236 BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) { | 232 BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) { |
237 if (Verbose) | 233 if (Verbose) |
241 // cached. In this case we can load it without accessing the file system. | 237 // cached. In this case we can load it without accessing the file system. |
242 if (isArchive(Filename)) { | 238 if (isArchive(Filename)) { |
243 StringRef ArchiveFilename = getArchiveAndObjectName(Filename).first; | 239 StringRef ArchiveFilename = getArchiveAndObjectName(Filename).first; |
244 std::lock_guard<std::mutex> Lock(ArchiveCacheMutex); | 240 std::lock_guard<std::mutex> Lock(ArchiveCacheMutex); |
245 if (ArchiveCache.count(ArchiveFilename)) { | 241 if (ArchiveCache.count(ArchiveFilename)) { |
246 return ArchiveCache[ArchiveFilename].getObjectEntry(Filename, Timestamp, | 242 return ArchiveCache[ArchiveFilename]->getObjectEntry(Filename, Timestamp, |
247 Verbose); | 243 Verbose); |
248 } else { | 244 } else { |
249 ArchiveEntry &AE = ArchiveCache[ArchiveFilename]; | 245 auto AE = std::make_unique<ArchiveEntry>(); |
250 auto Err = AE.load(VFS, Filename, Timestamp, Verbose); | 246 auto Err = AE->load(VFS, Filename, Timestamp, Verbose); |
251 if (Err) { | 247 if (Err) { |
252 ArchiveCache.erase(ArchiveFilename); | |
253 // Don't return the error here: maybe the file wasn't an archive. | 248 // Don't return the error here: maybe the file wasn't an archive. |
254 llvm::consumeError(std::move(Err)); | 249 llvm::consumeError(std::move(Err)); |
255 } else { | 250 } else { |
256 return ArchiveCache[ArchiveFilename].getObjectEntry(Filename, Timestamp, | 251 ArchiveCache[ArchiveFilename] = std::move(AE); |
257 Verbose); | 252 return ArchiveCache[ArchiveFilename]->getObjectEntry( |
253 Filename, Timestamp, Verbose); | |
258 } | 254 } |
259 } | 255 } |
260 } | 256 } |
261 | 257 |
262 // If this is an object, we might have it cached. If not we'll have to load | 258 // If this is an object, we might have it cached. If not we'll have to load |
263 // it from the file system and cache it now. | 259 // it from the file system and cache it now. |
264 std::lock_guard<std::mutex> Lock(ObjectCacheMutex); | 260 std::lock_guard<std::mutex> Lock(ObjectCacheMutex); |
265 if (!ObjectCache.count(Filename)) { | 261 if (!ObjectCache.count(Filename)) { |
266 ObjectEntry &OE = ObjectCache[Filename]; | 262 auto OE = std::make_unique<ObjectEntry>(); |
267 auto Err = OE.load(VFS, Filename, Timestamp, Verbose); | 263 auto Err = OE->load(VFS, Filename, Timestamp, Verbose); |
268 if (Err) { | 264 if (Err) |
269 ObjectCache.erase(Filename); | |
270 return std::move(Err); | 265 return std::move(Err); |
271 } | 266 ObjectCache[Filename] = std::move(OE); |
272 } | 267 } |
273 | 268 |
274 return ObjectCache[Filename]; | 269 return *ObjectCache[Filename]; |
275 } | 270 } |
276 | 271 |
277 void BinaryHolder::clear() { | 272 void BinaryHolder::clear() { |
278 std::lock_guard<std::mutex> ArchiveLock(ArchiveCacheMutex); | 273 std::lock_guard<std::mutex> ArchiveLock(ArchiveCacheMutex); |
279 std::lock_guard<std::mutex> ObjectLock(ObjectCacheMutex); | 274 std::lock_guard<std::mutex> ObjectLock(ObjectCacheMutex); |