forked from OSchip/llvm-project
[ELF] - Refactor of SymbolBody::compare()
That makes it a bit shorter. Differential revision: http://reviews.llvm.org/D18004 llvm-svn: 263144
This commit is contained in:
parent
0556e2217d
commit
3498c7fbd0
|
@ -106,10 +106,17 @@ static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
|
||||||
return std::min(VA, VB);
|
return std::min(VA, VB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int compareCommons(DefinedCommon *A, DefinedCommon *B) {
|
||||||
|
A->MaxAlignment = B->MaxAlignment =
|
||||||
|
std::max(A->MaxAlignment, B->MaxAlignment);
|
||||||
|
if (A->Size < B->Size)
|
||||||
|
return -1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns 1, 0 or -1 if this symbol should take precedence
|
// Returns 1, 0 or -1 if this symbol should take precedence
|
||||||
// over the Other, tie or lose, respectively.
|
// over the Other, tie or lose, respectively.
|
||||||
template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
|
template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
|
||||||
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
|
|
||||||
assert(!isLazy() && !Other->isLazy());
|
assert(!isLazy() && !Other->isLazy());
|
||||||
std::tuple<bool, bool, bool> L(isDefined(), !isShared(), !isWeak());
|
std::tuple<bool, bool, bool> L(isDefined(), !isShared(), !isWeak());
|
||||||
std::tuple<bool, bool, bool> R(Other->isDefined(), !Other->isShared(),
|
std::tuple<bool, bool, bool> R(Other->isDefined(), !Other->isShared(),
|
||||||
|
@ -134,24 +141,14 @@ template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
|
||||||
|
|
||||||
if (L != R)
|
if (L != R)
|
||||||
return -1;
|
return -1;
|
||||||
if (!std::get<0>(L) || !std::get<1>(L) || !std::get<2>(L))
|
if (!isDefined() || isShared() || isWeak())
|
||||||
return 1;
|
return 1;
|
||||||
if (isCommon()) {
|
if (!isCommon() && !Other->isCommon())
|
||||||
if (!Other->isCommon())
|
return 0;
|
||||||
return -1;
|
if (isCommon() && Other->isCommon())
|
||||||
auto *ThisC = cast<DefinedCommon>(this);
|
return compareCommons(cast<DefinedCommon>(this),
|
||||||
auto *OtherC = cast<DefinedCommon>(Other);
|
cast<DefinedCommon>(Other));
|
||||||
uintX_t Align = std::max(ThisC->MaxAlignment, OtherC->MaxAlignment);
|
return isCommon() ? -1 : 1;
|
||||||
if (ThisC->Size >= OtherC->Size) {
|
|
||||||
ThisC->MaxAlignment = Align;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
OtherC->MaxAlignment = Align;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (Other->isCommon())
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Defined::Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
|
Defined::Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
|
||||||
|
|
Loading…
Reference in New Issue