[llvm] faa931b - MCFragment: Store the number of variable-size tail fixups as uint8_t
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 2 15:17:05 PDT 2025
Author: Fangrui Song
Date: 2025-08-02T15:17:00-07:00
New Revision: faa931b717c02d57f0814caa9133219040e6a85b
URL: https://github.com/llvm/llvm-project/commit/faa931b717c02d57f0814caa9133219040e6a85b
DIFF: https://github.com/llvm/llvm-project/commit/faa931b717c02d57f0814caa9133219040e6a85b.diff
LOG: MCFragment: Store the number of variable-size tail fixups as uint8_t
Decrease sizeof(MCFragment) by 8 on 64-bit machines.
Added:
Modified:
llvm/include/llvm/MC/MCSection.h
llvm/lib/MC/MCCodeView.cpp
llvm/lib/MC/MCSection.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index cec2387912aea..4022ea7763e50 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -80,11 +80,13 @@ class MCFragment {
FragmentType Kind;
-protected:
+ //== Used by certain fragment types for better packing.
+
+ // The number of fixups for the optional variable-size tail must be small.
+ uint8_t VarFixupSize = 0;
+
bool LinkerRelaxable : 1;
- /// Used by certain fragment types for better packing.
- ///
/// FT_Data, FT_Relaxable
bool HasInstructions : 1;
/// FT_Relaxable, x86-specific
@@ -103,7 +105,6 @@ class MCFragment {
uint32_t VarContentStart = 0;
uint32_t VarContentEnd = 0;
uint32_t VarFixupStart = 0;
- uint32_t VarFixupEnd = 0;
const MCSubtargetInfo *STI = nullptr;
@@ -643,11 +644,10 @@ inline ArrayRef<MCFixup> MCFragment::getFixups() const {
inline MutableArrayRef<MCFixup> MCFragment::getVarFixups() {
return MutableArrayRef(getParent()->FixupStorage)
- .slice(VarFixupStart, VarFixupEnd - VarFixupStart);
+ .slice(VarFixupStart, VarFixupSize);
}
inline ArrayRef<MCFixup> MCFragment::getVarFixups() const {
- return ArrayRef(getParent()->FixupStorage)
- .slice(VarFixupStart, VarFixupEnd - VarFixupStart);
+ return ArrayRef(getParent()->FixupStorage).slice(VarFixupStart, VarFixupSize);
}
//== FT_Relaxable functions
diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp
index 7d528a55432e6..3a5f01c2af607 100644
--- a/llvm/lib/MC/MCCodeView.cpp
+++ b/llvm/lib/MC/MCCodeView.cpp
@@ -695,5 +695,7 @@ void CodeViewContext::encodeDefRange(const MCAssembler &Asm,
}
Frag.setVarContents(Contents);
+ assert(Fixups.size() < 256 && "Store fixups outside of MCFragment's VarFixup "
+ "storage if the number ever exceeds 256");
Frag.setVarFixups(Fixups);
}
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 4f282672afbbf..27ca1314074fe 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -83,12 +83,14 @@ void MCFragment::appendFixups(ArrayRef<MCFixup> Fixups) {
}
void MCFragment::setVarFixups(ArrayRef<MCFixup> Fixups) {
+ assert(Fixups.size() < 256 &&
+ "variable-size tail cannot have more than 256 fixups");
auto &S = getParent()->FixupStorage;
- if (VarFixupStart + Fixups.size() > VarFixupEnd) {
+ if (Fixups.size() > VarFixupSize) {
VarFixupStart = S.size();
S.resize_for_overwrite(S.size() + Fixups.size());
}
- VarFixupEnd = VarFixupStart + Fixups.size();
+ VarFixupSize = Fixups.size();
// Source fixup offsets are relative to the variable part's start. Add the
// fixed part size to make them relative to the fixed part's start.
std::transform(Fixups.begin(), Fixups.end(), S.begin() + VarFixupStart,
More information about the llvm-commits
mailing list