Skip to content

Commit d884927

Browse files
committedMay 25, 2016
Make SectionPiece 8 bytes smaller on LP64.
This patch makes SectionPiece class 8 bytes smaller on platforms on which pointer size is 8 bytes. Sean suggested in a post commit review for r270340 that this could make a differentce, and it actually is. Time to link clang (with debug info) improved from 6.725 seconds to 6.589 seconds or by about 2%. Differential Revision: http://reviews.llvm.org/D20613 llvm-svn: 270717
1 parent bf9d1aa commit d884927

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎lld/ELF/InputSection.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,24 @@ template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded;
8787
// SectionPiece represents a piece of splittable section contents.
8888
struct SectionPiece {
8989
SectionPiece(size_t Off, ArrayRef<uint8_t> Data)
90-
: InputOff(Off), Data(Data), Live(!Config->GcSections) {}
91-
size_t size() const { return Data.size(); }
90+
: InputOff(Off), Data((uint8_t *)Data.data()), Size(Data.size()),
91+
Live(!Config->GcSections) {}
92+
93+
ArrayRef<uint8_t> data() { return {Data, Size}; }
94+
size_t size() const { return Size; }
9295

9396
size_t InputOff;
9497
size_t OutputOff = -1;
95-
ArrayRef<uint8_t> Data; // slice of the input section
96-
bool Live;
98+
99+
private:
100+
// We use bitfields because SplitInputSection is accessed by
101+
// std::upper_bound very often.
102+
// We want to save bits to make it cache friendly.
103+
uint8_t *Data;
104+
uint32_t Size : 31;
105+
106+
public:
107+
uint32_t Live : 1;
97108
};
98109

99110
// Usually sections are copied to the output as atomic chunks of data,

‎lld/ELF/OutputSections.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -946,15 +946,15 @@ CieRecord *EhOutputSection<ELFT>::addCie(SectionPiece &Piece,
946946
EhInputSection<ELFT> *Sec,
947947
ArrayRef<RelTy> &Rels) {
948948
const endianness E = ELFT::TargetEndianness;
949-
if (read32<E>(Piece.Data.data() + 4) != 0)
949+
if (read32<E>(Piece.data().data() + 4) != 0)
950950
fatal("CIE expected at beginning of .eh_frame: " + Sec->getSectionName());
951951

952952
SymbolBody *Personality = nullptr;
953953
if (const RelTy *Rel = getReloc(Piece.InputOff, Piece.size(), Rels))
954954
Personality = &Sec->getFile()->getRelocTargetSym(*Rel);
955955

956956
// Search for an existing CIE by CIE contents/relocation target pair.
957-
CieRecord *Cie = &CieMap[{Piece.Data, Personality}];
957+
CieRecord *Cie = &CieMap[{Piece.data(), Personality}];
958958

959959
// If not found, create a new one.
960960
if (Cie->Piece == nullptr) {
@@ -995,11 +995,11 @@ void EhOutputSection<ELFT>::addSectionAux(EhInputSection<ELFT> *Sec,
995995
DenseMap<size_t, CieRecord *> OffsetToCie;
996996
for (SectionPiece &Piece : Sec->Pieces) {
997997
// The empty record is the end marker.
998-
if (Piece.Data.size() == 4)
998+
if (Piece.size() == 4)
999999
return;
10001000

10011001
size_t Offset = Piece.InputOff;
1002-
uint32_t ID = read32<E>(Piece.Data.data() + 4);
1002+
uint32_t ID = read32<E>(Piece.data().data() + 4);
10031003
if (ID == 0) {
10041004
OffsetToCie[Offset] = addCie(Piece, Sec, Rels);
10051005
continue;
@@ -1106,11 +1106,11 @@ template <class ELFT> void EhOutputSection<ELFT>::writeTo(uint8_t *Buf) {
11061106
const endianness E = ELFT::TargetEndianness;
11071107
for (CieRecord *Cie : Cies) {
11081108
size_t CieOffset = Cie->Piece->OutputOff;
1109-
writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->Data);
1109+
writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->data());
11101110

11111111
for (SectionPiece *Fde : Cie->FdePieces) {
11121112
size_t Off = Fde->OutputOff;
1113-
writeCieFde<ELFT>(Buf + Off, Fde->Data);
1113+
writeCieFde<ELFT>(Buf + Off, Fde->data());
11141114

11151115
// FDE's second word should have the offset to an associated CIE.
11161116
// Write it.
@@ -1126,7 +1126,7 @@ template <class ELFT> void EhOutputSection<ELFT>::writeTo(uint8_t *Buf) {
11261126
// we obtain two addresses and pass them to EhFrameHdr object.
11271127
if (Out<ELFT>::EhFrameHdr) {
11281128
for (CieRecord *Cie : Cies) {
1129-
uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece->Data);
1129+
uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece->data());
11301130
for (SectionPiece *Fde : Cie->FdePieces) {
11311131
uintX_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
11321132
uintX_t FdeVA = this->getVA() + Fde->OutputOff;
@@ -1170,7 +1170,7 @@ void MergeOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
11701170
for (SectionPiece &Piece : Sec->Pieces) {
11711171
if (!Piece.Live)
11721172
continue;
1173-
uintX_t OutputOffset = Builder.add(toStringRef(Piece.Data));
1173+
uintX_t OutputOffset = Builder.add(toStringRef(Piece.data()));
11741174
if (!IsString || !shouldTailMerge())
11751175
Piece.OutputOff = OutputOffset;
11761176
}

0 commit comments

Comments
 (0)
Please sign in to comment.