diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-11-19 20:15:55 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-11-19 20:15:55 +0000 |
| commit | a05134e837f7bbc79260bd92a77121e647fc2779 (patch) | |
| tree | a2e4f6c49ff375495d375f85ceaa83ff0a626970 /lld/ELF/ICF.cpp | |
| parent | 623a7c57b50559048415f34898c6610f7c22eb31 (diff) | |
| download | bcm5719-llvm-a05134e837f7bbc79260bd92a77121e647fc2779.tar.gz bcm5719-llvm-a05134e837f7bbc79260bd92a77121e647fc2779.zip | |
Use std::equal instead of hand-written loops.
llvm-svn: 287460
Diffstat (limited to 'lld/ELF/ICF.cpp')
| -rw-r--r-- | lld/ELF/ICF.cpp | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 5f6b41ef739..444ce89d8d7 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -64,6 +64,7 @@ #include "llvm/Object/ELF.h" #include "llvm/Support/ELF.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> using namespace lld; using namespace lld::elf; @@ -103,9 +104,8 @@ private: static bool relocationEq(ArrayRef<RelTy> RA, ArrayRef<RelTy> RB); template <class RelTy> - static bool variableEq(const InputSection<ELFT> *A, - const InputSection<ELFT> *B, ArrayRef<RelTy> RA, - ArrayRef<RelTy> RB); + static bool variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RA, + const InputSection<ELFT> *B, ArrayRef<RelTy> RB); static bool equalsConstant(const InputSection<ELFT> *A, const InputSection<ELFT> *B); @@ -119,8 +119,7 @@ private: // Returns a hash value for S. Note that the information about // relocation targets is not included in the hash value. template <class ELFT> uint64_t ICF<ELFT>::getHash(InputSection<ELFT> *S) { - uint64_t Flags = S->Flags; - return hash_combine(Flags, S->getSize(), S->NumRelocations); + return hash_combine(S->Flags, S->getSize(), S->NumRelocations); } // Returns true if Sec is subject of ICF. @@ -190,18 +189,14 @@ void ICF<ELFT>::forEachGroup(std::vector<InputSection<ELFT> *> &V, template <class ELFT> template <class RelTy> bool ICF<ELFT>::relocationEq(ArrayRef<RelTy> RelsA, ArrayRef<RelTy> RelsB) { - const RelTy *IA = RelsA.begin(); - const RelTy *EA = RelsA.end(); - const RelTy *IB = RelsB.begin(); - const RelTy *EB = RelsB.end(); - if (EA - IA != EB - IB) - return false; - for (; IA != EA; ++IA, ++IB) - if (IA->r_offset != IB->r_offset || - IA->getType(Config->Mips64EL) != IB->getType(Config->Mips64EL) || - getAddend<ELFT>(*IA) != getAddend<ELFT>(*IB)) - return false; - return true; + auto Eq = [](const RelTy &A, const RelTy &B) { + return A.r_offset == B.r_offset && + A.getType(Config->Mips64EL) == B.getType(Config->Mips64EL) && + getAddend<ELFT>(A) == getAddend<ELFT>(B); + }; + + return RelsA.size() == RelsB.size() && + std::equal(RelsA.begin(), RelsA.end(), RelsB.begin(), Eq); } // Compare "non-moving" part of two InputSections, namely everything @@ -226,17 +221,13 @@ bool ICF<ELFT>::equalsConstant(const InputSection<ELFT> *A, template <class ELFT> template <class RelTy> -bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, - const InputSection<ELFT> *B, ArrayRef<RelTy> RelsA, - ArrayRef<RelTy> RelsB) { - const RelTy *IA = RelsA.begin(); - const RelTy *EA = RelsA.end(); - const RelTy *IB = RelsB.begin(); - for (; IA != EA; ++IA, ++IB) { - SymbolBody &SA = A->File->getRelocTargetSym(*IA); - SymbolBody &SB = B->File->getRelocTargetSym(*IB); +bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, ArrayRef<RelTy> RelsA, + const InputSection<ELFT> *B, ArrayRef<RelTy> RelsB) { + auto Eq = [&](const RelTy &RA, const RelTy &RB) { + SymbolBody &SA = A->File->getRelocTargetSym(RA); + SymbolBody &SB = B->File->getRelocTargetSym(RB); if (&SA == &SB) - continue; + return true; // Or, the symbols should be pointing to the same section // in terms of the group ID. @@ -248,11 +239,10 @@ bool ICF<ELFT>::variableEq(const InputSection<ELFT> *A, return false; InputSection<ELFT> *X = dyn_cast<InputSection<ELFT>>(DA->Section); InputSection<ELFT> *Y = dyn_cast<InputSection<ELFT>>(DB->Section); - if (X && Y && X->GroupId && X->GroupId == Y->GroupId) - continue; - return false; - } - return true; + return X && Y && X->GroupId && X->GroupId == Y->GroupId; + }; + + return std::equal(RelsA.begin(), RelsA.end(), RelsB.begin(), Eq); } // Compare "moving" part of two InputSections, namely relocation targets. @@ -260,8 +250,8 @@ template <class ELFT> bool ICF<ELFT>::equalsVariable(const InputSection<ELFT> *A, const InputSection<ELFT> *B) { if (A->AreRelocsRela) - return variableEq(A, B, A->relas(), B->relas()); - return variableEq(A, B, A->rels(), B->rels()); + return variableEq(A, A->relas(), B, B->relas()); + return variableEq(A, A->rels(), B, B->rels()); } // The main function of ICF. |

