[PATCH] D39609: Remove a std::map and std::set that show up in LLD profiles

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 11:33:23 PDT 2017


rnk created this revision.

For GC roots, add a bit to SymbolBody to ensure that we don't add the
same root twice, and switch to a vector. This is an improvement, since
we iterate the GCRoot list later and it the order should be
deterministic.

For fixupExports, we can just use DenseMap. This is a simple string
uniquing task, and we don't iterate the map.


https://reviews.llvm.org/D39609

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/COFF/Symbols.h


Index: lld/COFF/Symbols.h
===================================================================
--- lld/COFF/Symbols.h
+++ lld/COFF/Symbols.h
@@ -77,7 +77,8 @@
   friend SymbolTable;
   explicit SymbolBody(Kind K, StringRef N = "")
       : SymbolKind(K), IsExternal(true), IsCOMDAT(false),
-        WrittenToSymtab(false), Name(N) {}
+        WrittenToSymtab(false), PendingArchiveLoad(false), IsGCRoot(false),
+        Name(N) {}
 
   const unsigned SymbolKind : 8;
   unsigned IsExternal : 1;
@@ -98,6 +99,9 @@
   // not load any more archive members to resolve the same symbol.
   unsigned PendingArchiveLoad : 1;
 
+  /// True if we've already added this symbol to the list of GC roots.
+  unsigned IsGCRoot : 1;
+
 protected:
   StringRef Name;
 };
Index: lld/COFF/DriverUtils.cpp
===================================================================
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -594,7 +594,7 @@
   }
 
   // Uniquefy by name.
-  std::map<StringRef, Export *> Map;
+  DenseMap<StringRef, Export *> Map(Config->Exports.size());
   std::vector<Export> V;
   for (Export &E : Config->Exports) {
     auto Pair = Map.insert(std::make_pair(E.ExportName, &E));
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -355,7 +355,10 @@
 
 SymbolBody *LinkerDriver::addUndefined(StringRef Name) {
   SymbolBody *B = Symtab->addUndefined(Name);
-  Config->GCRoot.insert(B);
+  if (!B->IsGCRoot) {
+    B->IsGCRoot = true;
+    Config->GCRoot.push_back(B);
+  }
   return B;
 }
 
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -94,7 +94,7 @@
   std::vector<llvm::StringRef> Argv;
 
   // Symbols in this set are considered as live by the garbage collector.
-  std::set<SymbolBody *> GCRoot;
+  std::vector<SymbolBody *> GCRoot;
 
   std::set<StringRef> NoDefaultLibs;
   bool NoDefaultLibAll = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39609.121517.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171103/fb7a5bca/attachment.bin>


More information about the llvm-commits mailing list