[PATCH] D113198: [lld-macho] Clear resolvedReads cache

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 12:06:29 PDT 2021


keith updated this revision to Diff 384839.
keith added a comment.

Update name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113198/new/

https://reviews.llvm.org/D113198

Files:
  lld/MachO/Driver.cpp
  lld/MachO/InputFiles.cpp
  lld/MachO/InputFiles.h


Index: lld/MachO/InputFiles.h
===================================================================
--- lld/MachO/InputFiles.h
+++ lld/MachO/InputFiles.h
@@ -14,6 +14,7 @@
 
 #include "lld/Common/LLVM.h"
 #include "lld/Common/Memory.h"
+#include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/BinaryFormat/MachO.h"
@@ -211,6 +212,7 @@
 };
 
 extern llvm::SetVector<InputFile *> inputFiles;
+extern llvm::DenseMap<llvm::CachedHashStringRef, MemoryBufferRef> cachedReads;
 
 llvm::Optional<MemoryBufferRef> readFile(StringRef path);
 
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -178,12 +178,12 @@
 // level, and other files like the filelist that are only read once.
 // Theoretically this caching could be more efficient by hoisting it, but that
 // would require altering many callers to track the state.
-static DenseMap<CachedHashStringRef, MemoryBufferRef> resolvedReads;
+DenseMap<CachedHashStringRef, MemoryBufferRef> macho::cachedReads;
 // Open a given file path and return it as a memory-mapped file.
 Optional<MemoryBufferRef> macho::readFile(StringRef path) {
   CachedHashStringRef key(path);
-  auto entry = resolvedReads.find(key);
-  if (entry != resolvedReads.end())
+  auto entry = cachedReads.find(key);
+  if (entry != cachedReads.end())
     return entry->second;
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
@@ -203,7 +203,7 @@
       read32be(&hdr->magic) != FAT_MAGIC) {
     if (tar)
       tar->append(relativeToRoot(path), mbref.getBuffer());
-    return resolvedReads[key] = mbref;
+    return cachedReads[key] = mbref;
   }
 
   // Object files and archive files may be fat files, which contain multiple
@@ -228,8 +228,8 @@
       error(path + ": slice extends beyond end of file");
     if (tar)
       tar->append(relativeToRoot(path), mbref.getBuffer());
-    return resolvedReads[key] = MemoryBufferRef(StringRef(buf + offset, size),
-                                                path.copy(bAlloc));
+    return cachedReads[key] = MemoryBufferRef(StringRef(buf + offset, size),
+                                              path.copy(bAlloc));
   }
 
   error("unable to find matching architecture in " + path);
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1100,6 +1100,7 @@
 
     resolvedFrameworks.clear();
     resolvedLibraries.clear();
+    cachedReads.clear();
     concatOutputSections.clear();
     inputFiles.clear();
     inputSections.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113198.384839.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211104/b6b6bcb5/attachment.bin>


More information about the llvm-commits mailing list