Skip to content

Commit faa931b

Browse files
committed
MCFragment: Store the number of variable-size tail fixups as uint8_t
Decrease sizeof(MCFragment) by 8 on 64-bit machines.
1 parent 21f1f95 commit faa931b

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ class MCFragment {
8080

8181
FragmentType Kind;
8282

83-
protected:
83+
//== Used by certain fragment types for better packing.
84+
85+
// The number of fixups for the optional variable-size tail must be small.
86+
uint8_t VarFixupSize = 0;
87+
8488
bool LinkerRelaxable : 1;
8589

86-
/// Used by certain fragment types for better packing.
87-
///
8890
/// FT_Data, FT_Relaxable
8991
bool HasInstructions : 1;
9092
/// FT_Relaxable, x86-specific
@@ -103,7 +105,6 @@ class MCFragment {
103105
uint32_t VarContentStart = 0;
104106
uint32_t VarContentEnd = 0;
105107
uint32_t VarFixupStart = 0;
106-
uint32_t VarFixupEnd = 0;
107108

108109
const MCSubtargetInfo *STI = nullptr;
109110

@@ -643,11 +644,10 @@ inline ArrayRef<MCFixup> MCFragment::getFixups() const {
643644

644645
inline MutableArrayRef<MCFixup> MCFragment::getVarFixups() {
645646
return MutableArrayRef(getParent()->FixupStorage)
646-
.slice(VarFixupStart, VarFixupEnd - VarFixupStart);
647+
.slice(VarFixupStart, VarFixupSize);
647648
}
648649
inline ArrayRef<MCFixup> MCFragment::getVarFixups() const {
649-
return ArrayRef(getParent()->FixupStorage)
650-
.slice(VarFixupStart, VarFixupEnd - VarFixupStart);
650+
return ArrayRef(getParent()->FixupStorage).slice(VarFixupStart, VarFixupSize);
651651
}
652652

653653
//== FT_Relaxable functions

llvm/lib/MC/MCCodeView.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,5 +695,7 @@ void CodeViewContext::encodeDefRange(const MCAssembler &Asm,
695695
}
696696

697697
Frag.setVarContents(Contents);
698+
assert(Fixups.size() < 256 && "Store fixups outside of MCFragment's VarFixup "
699+
"storage if the number ever exceeds 256");
698700
Frag.setVarFixups(Fixups);
699701
}

llvm/lib/MC/MCSection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ void MCFragment::appendFixups(ArrayRef<MCFixup> Fixups) {
8383
}
8484

8585
void MCFragment::setVarFixups(ArrayRef<MCFixup> Fixups) {
86+
assert(Fixups.size() < 256 &&
87+
"variable-size tail cannot have more than 256 fixups");
8688
auto &S = getParent()->FixupStorage;
87-
if (VarFixupStart + Fixups.size() > VarFixupEnd) {
89+
if (Fixups.size() > VarFixupSize) {
8890
VarFixupStart = S.size();
8991
S.resize_for_overwrite(S.size() + Fixups.size());
9092
}
91-
VarFixupEnd = VarFixupStart + Fixups.size();
93+
VarFixupSize = Fixups.size();
9294
// Source fixup offsets are relative to the variable part's start. Add the
9395
// fixed part size to make them relative to the fixed part's start.
9496
std::transform(Fixups.begin(), Fixups.end(), S.begin() + VarFixupStart,

0 commit comments

Comments
 (0)