[PATCH] D13743: Lazily sort ScopesWithImportedEntities to speed up LTO linking.

Ivan Krasin via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 14:02:14 PDT 2015


krasin created this revision.
krasin added reviewers: thakis, pcc.
krasin added subscribers: llvm-commits, kcc.

In particular, when not all the debug info is needed, Chrome linking is
1.8x faster.

See more details in https://crbug.com/542426

http://reviews.llvm.org/D13743

Files:
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.h

Index: lib/CodeGen/AsmPrinter/DwarfDebug.h
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -311,6 +311,7 @@
   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
   ImportedEntityMap;
   ImportedEntityMap ScopesWithImportedEntities;
+  bool IsScopesWithImportedEntitiesSorted;
 
   /// Map from MDNodes for user-defined types to the type units that
   /// describe them.
@@ -668,12 +669,7 @@
   const MachineFunction *getCurrentFunction() const { return CurFn; }
 
   iterator_range<ImportedEntityMap::const_iterator>
-  findImportedEntitiesForScope(const MDNode *Scope) const {
-    return make_range(std::equal_range(
-        ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
-        std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
-        less_first()));
-  }
+  findImportedEntitiesForScope(const MDNode *Scope);
 
   /// A helper function to check whether the DIE for a given Scope is
   /// going to be null.
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -503,11 +503,8 @@
     DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
     for (auto *IE : CUNode->getImportedEntities())
       ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(), IE));
-    // Stable sort to preserve the order of appearance of imported entities.
-    // This is to avoid out-of-order processing of interdependent declarations
-    // within the same scope, e.g. { namespace A = base; namespace B = A; }
-    std::stable_sort(ScopesWithImportedEntities.begin(),
-                     ScopesWithImportedEntities.end(), less_first());
+    IsScopesWithImportedEntitiesSorted = false;
+
     for (auto *GV : CUNode->getGlobalVariables())
       CU.getOrCreateGlobalVariableDIE(GV);
     for (auto *SP : CUNode->getSubprograms())
@@ -554,6 +551,23 @@
   }
 }
 
+iterator_range<DwarfDebug::ImportedEntityMap::const_iterator>
+DwarfDebug::findImportedEntitiesForScope(const MDNode *Scope) {
+    // Stable sort to preserve the order of appearance of imported entities.
+    // This is to avoid out-of-order processing of interdependent declarations
+    // within the same scope, e.g. { namespace A = base; namespace B = A; }
+    if (!IsScopesWithImportedEntitiesSorted) {
+      std::stable_sort(ScopesWithImportedEntities.begin(),
+                       ScopesWithImportedEntities.end(), less_first());
+      IsScopesWithImportedEntitiesSorted = true;
+    }
+
+    return make_range(std::equal_range(
+        ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
+        std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
+        less_first()));
+}
+
 void DwarfDebug::finishSubprogramDefinitions() {
   for (const auto &P : SPMap)
     forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13743.37388.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/8e7089e9/attachment.bin>


More information about the llvm-commits mailing list