[lld] r246934 - COFF: Split doICF(). No functionality change.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 16:06:33 PDT 2015
Author: ruiu
Date: Sat Sep 5 18:06:32 2015
New Revision: 246934
URL: http://llvm.org/viewvc/llvm-project?rev=246934&view=rev
Log:
COFF: Split doICF(). No functionality change.
Modified:
lld/trunk/COFF/ICF.cpp
Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=246934&r1=246933&r2=246934&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Sat Sep 5 18:06:32 2015
@@ -95,6 +95,23 @@ static void link(SectionChunk *From, Sec
To->Ins.push_back(From);
}
+typedef std::vector<SectionChunk *>::iterator ChunkIterator;
+
+static void uniquefy(ChunkIterator Begin, ChunkIterator End) {
+ std::unordered_set<SectionChunk *, Hasher, Equals> Set;
+ for (auto It = Begin; It != End; ++It) {
+ SectionChunk *SC = *It;
+ auto P = Set.insert(SC);
+ bool Inserted = P.second;
+ if (Inserted)
+ continue;
+ SectionChunk *Existing = *P.first;
+ SC->replaceWith(Existing);
+ for (SectionChunk *In : SC->Ins)
+ --In->Outdegree;
+ }
+}
+
// Merge identical COMDAT sections.
// Two sections are considered the same if their section headers,
// contents and relocations are all the same.
@@ -118,23 +135,12 @@ void doICF(const std::vector<Chunk *> &C
// because two originally different relocations can now point to
// the same section. We process sections whose outdegree is zero
// first to deal with that.
+ auto Pred = [](SectionChunk *SC) { return SC->Outdegree > 0; };
for (;;) {
- std::unordered_set<SectionChunk *, Hasher, Equals> Set;
- auto Pred = [](SectionChunk *SC) { return SC->Outdegree > 0; };
auto Bound = std::partition(SChunks.begin(), SChunks.end(), Pred);
if (Bound == SChunks.end())
return;
- for (auto It = Bound, E = SChunks.end(); It != E; ++It) {
- SectionChunk *SC = *It;
- auto P = Set.insert(SC);
- bool Inserted = P.second;
- if (Inserted)
- continue;
- SectionChunk *Existing = *P.first;
- SC->replaceWith(Existing);
- for (SectionChunk *In : SC->Ins)
- --In->Outdegree;
- }
+ uniquefy(Bound, SChunks.end());
SChunks.erase(Bound, SChunks.end());
}
}
More information about the llvm-commits
mailing list