diff options
Diffstat (limited to 'COFF/ICF.cpp')
-rw-r--r-- | COFF/ICF.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/COFF/ICF.cpp b/COFF/ICF.cpp index fe59de6efa54..9a43f2bd43f5 100644 --- a/COFF/ICF.cpp +++ b/COFF/ICF.cpp @@ -49,10 +49,10 @@ private: size_t findBoundary(size_t Begin, size_t End); - void forEachColorRange(size_t Begin, size_t End, + void forEachClassRange(size_t Begin, size_t End, std::function<void(size_t, size_t)> Fn); - void forEachColor(std::function<void(size_t, size_t)> Fn); + void forEachClass(std::function<void(size_t, size_t)> Fn); std::vector<SectionChunk *> Chunks; int Cnt = 0; @@ -85,7 +85,7 @@ bool ICF::isEligible(SectionChunk *C) { return C->isCOMDAT() && C->isLive() && Global && Executable && !Writable; } -// Split a range into smaller ranges by recoloring sections +// Split an equivalence class into smaller classes. void ICF::segregate(size_t Begin, size_t End, bool Constant) { while (Begin < End) { // Divide [Begin, End) into two. Let Mid be the start index of the @@ -101,7 +101,7 @@ void ICF::segregate(size_t Begin, size_t End, bool Constant) { // Split [Begin, End) into [Begin, Mid) and [Mid, End). uint32_t Id = NextId++; for (size_t I = Begin; I < Mid; ++I) - Chunks[I]->Color[(Cnt + 1) % 2] = Id; + Chunks[I]->Class[(Cnt + 1) % 2] = Id; // If we created a group, we need to iterate the main loop again. if (Mid != End) @@ -130,7 +130,7 @@ bool ICF::equalsConstant(const SectionChunk *A, const SectionChunk *B) { if (auto *D1 = dyn_cast<DefinedRegular>(B1)) if (auto *D2 = dyn_cast<DefinedRegular>(B2)) return D1->getValue() == D2->getValue() && - D1->getChunk()->Color[Cnt % 2] == D2->getChunk()->Color[Cnt % 2]; + D1->getChunk()->Class[Cnt % 2] == D2->getChunk()->Class[Cnt % 2]; return false; }; if (!std::equal(A->Relocs.begin(), A->Relocs.end(), B->Relocs.begin(), Eq)) @@ -155,7 +155,7 @@ bool ICF::equalsVariable(const SectionChunk *A, const SectionChunk *B) { return true; if (auto *D1 = dyn_cast<DefinedRegular>(B1)) if (auto *D2 = dyn_cast<DefinedRegular>(B2)) - return D1->getChunk()->Color[Cnt % 2] == D2->getChunk()->Color[Cnt % 2]; + return D1->getChunk()->Class[Cnt % 2] == D2->getChunk()->Class[Cnt % 2]; return false; }; return std::equal(A->Relocs.begin(), A->Relocs.end(), B->Relocs.begin(), Eq); @@ -163,12 +163,12 @@ bool ICF::equalsVariable(const SectionChunk *A, const SectionChunk *B) { size_t ICF::findBoundary(size_t Begin, size_t End) { for (size_t I = Begin + 1; I < End; ++I) - if (Chunks[Begin]->Color[Cnt % 2] != Chunks[I]->Color[Cnt % 2]) + if (Chunks[Begin]->Class[Cnt % 2] != Chunks[I]->Class[Cnt % 2]) return I; return End; } -void ICF::forEachColorRange(size_t Begin, size_t End, +void ICF::forEachClassRange(size_t Begin, size_t End, std::function<void(size_t, size_t)> Fn) { if (Begin > 0) Begin = findBoundary(Begin - 1, End); @@ -180,12 +180,12 @@ void ICF::forEachColorRange(size_t Begin, size_t End, } } -// Call Fn on each color group. -void ICF::forEachColor(std::function<void(size_t, size_t)> Fn) { +// Call Fn on each class group. +void ICF::forEachClass(std::function<void(size_t, size_t)> Fn) { // If the number of sections are too small to use threading, // call Fn sequentially. if (Chunks.size() < 1024) { - forEachColorRange(0, Chunks.size(), Fn); + forEachClassRange(0, Chunks.size(), Fn); return; } @@ -193,9 +193,9 @@ void ICF::forEachColor(std::function<void(size_t, size_t)> Fn) { size_t NumShards = 256; size_t Step = Chunks.size() / NumShards; parallel_for(size_t(0), NumShards, [&](size_t I) { - forEachColorRange(I * Step, (I + 1) * Step, Fn); + forEachClassRange(I * Step, (I + 1) * Step, Fn); }); - forEachColorRange(Step * NumShards, Chunks.size(), Fn); + forEachClassRange(Step * NumShards, Chunks.size(), Fn); } // Merge identical COMDAT sections. @@ -209,11 +209,11 @@ void ICF::run(const std::vector<Chunk *> &Vec) { continue; if (isEligible(SC)) { - // Set MSB to 1 to avoid collisions with non-hash colors. - SC->Color[0] = getHash(SC) | (1 << 31); + // Set MSB to 1 to avoid collisions with non-hash classs. + SC->Class[0] = getHash(SC) | (1 << 31); Chunks.push_back(SC); } else { - SC->Color[0] = NextId++; + SC->Class[0] = NextId++; } } @@ -224,25 +224,25 @@ void ICF::run(const std::vector<Chunk *> &Vec) { // the same group are consecutive in the vector. std::stable_sort(Chunks.begin(), Chunks.end(), [](SectionChunk *A, SectionChunk *B) { - return A->Color[0] < B->Color[0]; + return A->Class[0] < B->Class[0]; }); // Compare static contents and assign unique IDs for each static content. - forEachColor([&](size_t Begin, size_t End) { segregate(Begin, End, true); }); + forEachClass([&](size_t Begin, size_t End) { segregate(Begin, End, true); }); ++Cnt; // Split groups by comparing relocations until convergence is obtained. do { Repeat = false; - forEachColor( + forEachClass( [&](size_t Begin, size_t End) { segregate(Begin, End, false); }); ++Cnt; } while (Repeat); log("ICF needed " + Twine(Cnt) + " iterations"); - // Merge sections in the same colors. - forEachColor([&](size_t Begin, size_t End) { + // Merge sections in the same classs. + forEachClass([&](size_t Begin, size_t End) { if (End - Begin == 1) return; |