COFF: Split doICF(). No functionality change.

llvm-svn: 246934
This commit is contained in:
Rui Ueyama 2015-09-05 23:06:32 +00:00
parent daa24b9789
commit 3c28ba38de
1 changed files with 19 additions and 13 deletions

View File

@ -95,6 +95,23 @@ static void link(SectionChunk *From, SectionChunk *To) {
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 *> &Chunks) {
// 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());
}
}