[PATCH] D126785: Cache file IDs of symbols in emitStabs for faster sorting

Michael Eisel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 10:20:19 PDT 2022


michaeleisel updated this revision to Diff 433446.
michaeleisel added a comment.

Rename to symbolsNeedingStabs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126785

Files:
  lld/MachO/SyntheticSections.cpp


Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -890,7 +890,9 @@
     stabs.emplace_back(std::move(astStab));
   }
 
-  std::vector<Defined *> symbolsNeedingStabs;
+  // Cache the file ID for each symbol in an std::pair for faster sorting
+  typedef std::pair<Defined *, int> SortingPair;
+  std::vector<SortingPair> symbolsNeedingStabs;
   for (const SymtabEntry &entry :
        concat<SymtabEntry>(localSymbols, externalSymbols)) {
     Symbol *sym = entry.sym;
@@ -913,19 +915,20 @@
       if (!file || !file->compileUnit)
         continue;
 
-      symbolsNeedingStabs.push_back(defined);
+      symbolsNeedingStabs.emplace_back(defined, defined->isec->getFile()->id);
     }
   }
 
-  llvm::stable_sort(symbolsNeedingStabs, [&](Defined *a, Defined *b) {
-    return a->isec->getFile()->id < b->isec->getFile()->id;
+  llvm::stable_sort(symbolsNeedingStabs, [&](const SortingPair &a, const SortingPair &b) {
+    return a.second < b.second;
   });
 
   // Emit STABS symbols so that dsymutil and/or the debugger can map address
   // regions in the final binary to the source and object files from which they
   // originated.
   InputFile *lastFile = nullptr;
-  for (Defined *defined : symbolsNeedingStabs) {
+  for (SortingPair &pair : symbolsNeedingStabs) {
+    Defined *defined = pair.first;
     InputSection *isec = defined->isec;
     ObjFile *file = cast<ObjFile>(isec->getFile());
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126785.433446.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220601/13efc455/attachment.bin>


More information about the llvm-commits mailing list