[lld] r289414 - COFF: Use a DenseSet instead of a map to atomic_flag to track which archive members have been read.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 11 19:16:14 PST 2016


Author: pcc
Date: Sun Dec 11 21:16:14 2016
New Revision: 289414

URL: http://llvm.org/viewvc/llvm-project?rev=289414&view=rev
Log:
COFF: Use a DenseSet instead of a map to atomic_flag to track which archive members have been read.

Differential Revision: https://reviews.llvm.org/D27667

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/InputFiles.h

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=289414&r1=289413&r2=289414&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Sun Dec 11 21:16:14 2016
@@ -55,29 +55,19 @@ void ArchiveFile::parse() {
   // Parse a MemoryBufferRef as an archive file.
   File = check(Archive::create(MB), toString(this));
 
-  // Seen is a map from member files to boolean values. Initially
-  // all members are mapped to false, which indicates all these files
-  // are not read yet.
-  Error Err = Error::success();
-  for (auto &Child : File->children(Err))
-    Seen[Child.getChildOffset()].clear();
-  if (Err)
-    fatal(Err, toString(this));
-
   // Read the symbol table to construct Lazy objects.
   for (const Archive::Symbol &Sym : File->symbols())
     Symtab->addLazy(this, Sym);
 }
 
 // Returns a buffer pointing to a member file containing a given symbol.
-// This function is thread-safe.
 InputFile *ArchiveFile::getMember(const Archive::Symbol *Sym) {
   const Archive::Child &C =
       check(Sym->getMember(),
             "could not get the member for symbol " + Sym->getName());
 
   // Return an empty buffer if we have already returned the same buffer.
-  if (Seen[C.getChildOffset()].test_and_set())
+  if (!Seen.insert(C.getChildOffset()).second)
     return nullptr;
 
   MemoryBufferRef MB =

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=289414&r1=289413&r2=289414&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Sun Dec 11 21:16:14 2016
@@ -12,6 +12,7 @@
 
 #include "lld/Core/LLVM.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/LTO/legacy/LTOModule.h"
 #include "llvm/Object/Archive.h"
@@ -91,7 +92,7 @@ public:
 private:
   std::unique_ptr<Archive> File;
   std::string Filename;
-  std::map<uint64_t, std::atomic_flag> Seen;
+  llvm::DenseSet<uint64_t> Seen;
 };
 
 // .obj or .o file. This may be a member of an archive file.




More information about the llvm-commits mailing list