aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-06-26 08:50:09 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-06-26 08:50:09 +0000
commita3148f7504799777fd3a728baa15baf814f91e0f (patch)
tree4e8d5017fa61d4a19cecf7bc38f4d8f9c1f83914
parent7619c6a0df43ef5ee81e92a4a07e2a98747dc7ab (diff)
[ELF] - Change the way of sorting local symbols.linaro-local/peter.smith/pgo
rLLD329787 added the stable sorting to SymbolTableBaseSection::postThunkContents. I profiled the Mozilla (response-O0.txt) from lld-speed-test package and found std::stable_sort is showing up in profile results and consuming the 3.1% of the total CPU time in the RelWithDebug build. Total time of postThunkContents is 3.54%, 238ms. This change reduces postTimeContents time to 50ms, making it to take 0.73% of Total CPU time. So, instead of sorting the local part I suggest to just rebuild it. That is what this patch does. Differential revision: https://reviews.llvm.org/D45519 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@335583 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--ELF/SyntheticSections.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/ELF/SyntheticSections.cpp b/ELF/SyntheticSections.cpp
index 2cb41d595..1a19ec6dc 100644
--- a/ELF/SyntheticSections.cpp
+++ b/ELF/SyntheticSections.cpp
@@ -1762,19 +1762,19 @@ void SymbolTableBaseSection::postThunkContents() {
size_t NumLocals = E - Symbols.begin();
getParent()->Info = NumLocals + 1;
- // Assign the growing unique ID for each local symbol's file.
- DenseMap<InputFile *, unsigned> FileIDs;
- for (auto I = Symbols.begin(); I != E; ++I)
- FileIDs.insert({I->Sym->File, FileIDs.size()});
-
- // Sort the local symbols to group them by file. We do not need to care about
- // the STT_FILE symbols, they are already naturally placed first in each group.
- // That happens because STT_FILE is always the first symbol in the object and
- // hence precede all other local symbols we add for a file.
- std::stable_sort(Symbols.begin(), E,
- [&](const SymbolTableEntry &L, const SymbolTableEntry &R) {
- return FileIDs[L.Sym->File] < FileIDs[R.Sym->File];
- });
+ // We want to group the local symbols by file. For that we rebuild the local
+ // part of the symbols vector. We do not need to care about the STT_FILE
+ // symbols, they are already naturally placed first in each group. That
+ // happens because STT_FILE is always the first symbol in the object and hence
+ // precede all other local symbols we add for a file.
+ MapVector<InputFile *, std::vector<SymbolTableEntry>> Arr;
+ for (const SymbolTableEntry &S : llvm::make_range(Symbols.begin(), E))
+ Arr[S.Sym->File].push_back(S);
+
+ auto I = Symbols.begin();
+ for (std::pair<InputFile *, std::vector<SymbolTableEntry>> &P : Arr)
+ for (SymbolTableEntry &Entry : P.second)
+ *I++ = Entry;
}
void SymbolTableBaseSection::addSymbol(Symbol *B) {