summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-06-08 08:26:28 +0000
committerRui Ueyama <ruiu@google.com>2015-06-08 08:26:28 +0000
commitf533d3e09d389ff99219914c4210ad6dc88dd178 (patch)
treeb913a0f6d4d5e08dff049fa9333ef4a95d42732a
parent32c0539691886d27abd8891641bb496a67f74747 (diff)
downloadbcm5719-llvm-f533d3e09d389ff99219914c4210ad6dc88dd178.tar.gz
bcm5719-llvm-f533d3e09d389ff99219914c4210ad6dc88dd178.zip
COFF: Avoid callign stable_sort.
MSVC profiler reported that this stable_sort takes 7% time when self-linking. As a result, createSection was taking 10% time. Now createSection takes 3%. This small change actually makes the linker a bit but perceptibly faster. llvm-svn: 239292
-rw-r--r--lld/COFF/Writer.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 967aa4f0819..d4ccc58b789 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -120,30 +120,30 @@ void Writer::createSections() {
C->printDiscardedMessage();
continue;
}
- // '$' and all following characters in input section names are
- // discarded when determining output section. So, .text$foo
- // contributes to .text, for example. See PE/COFF spec 3.2.
- Map[C->getSectionName().split('$').first].push_back(C);
+ Map[C->getSectionName()].push_back(C);
}
// Then create an OutputSection for each section.
+ // '$' and all following characters in input section names are
+ // discarded when determining output section. So, .text$foo
+ // contributes to .text, for example. See PE/COFF spec 3.2.
+ StringRef Name = Map.begin()->first.split('$').first;
+ auto Sec = new (CAlloc.Allocate()) OutputSection(Name, 0);
+ OutputSections.push_back(Sec);
for (auto &P : Map) {
StringRef SectionName = P.first;
+ StringRef Base = SectionName.split('$').first;
+ if (Base != Sec->getName()) {
+ size_t SectIdx = OutputSections.size();
+ Sec = new (CAlloc.Allocate()) OutputSection(Base, SectIdx);
+ OutputSections.push_back(Sec);
+ }
std::vector<Chunk *> &Chunks = P.second;
- // Input sections are ordered by their names including '$' parts,
- // which gives you some control over the output layout.
- std::stable_sort(Chunks.begin(), Chunks.end(),
- [](Chunk *A, Chunk *B) {
- return A->getSectionName() < B->getSectionName();
- });
- size_t SectIdx = OutputSections.size();
- auto Sec = new (CAlloc.Allocate()) OutputSection(SectionName, SectIdx);
for (Chunk *C : Chunks) {
C->setOutputSection(Sec);
Sec->addChunk(C);
Sec->addPermissions(C->getPermissions());
}
- OutputSections.push_back(Sec);
}
}
OpenPOWER on IntegriCloud