[llvm] 1893caa - MCSymbol: Decrease the bitfield size of SymbolContents
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 16 10:43:10 PDT 2025
Author: Fangrui Song
Date: 2025-08-16T10:43:05-07:00
New Revision: 1893caa9bc9782eaef95d747658e070b132468a5
URL: https://github.com/llvm/llvm-project/commit/1893caa9bc9782eaef95d747658e070b132468a5
DIFF: https://github.com/llvm/llvm-project/commit/1893caa9bc9782eaef95d747658e070b132468a5.diff
LOG: MCSymbol: Decrease the bitfield size of SymbolContents
Follow-up to 57b0843f68f5f349c73d1bf54e321a1a6d1800bf
The size of MCSymbol has been reduced to 24 bytes on 64-bit systems.
Added:
Modified:
llvm/include/llvm/MC/MCSymbol.h
llvm/lib/MC/MCSymbol.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index ddc560ec52501..ce160bd2c3cc9 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -65,6 +65,10 @@ class MCSymbol {
/// relative to, if any.
mutable MCFragment *Fragment = nullptr;
+ /// This is actually a Contents enumerator, but is unsigned to avoid sign
+ /// extension and achieve better bitpacking with MSVC.
+ unsigned SymbolContents : 2;
+
/// True if this symbol is named. A named symbol will have a pointer to the
/// name allocated in the bytes immediately prior to the MCSymbol.
unsigned HasName : 1;
@@ -95,10 +99,6 @@ class MCSymbol {
/// Used to detect cyclic dependency like `a = a + 1` and `a = b; b = a`.
unsigned IsResolving : 1;
- /// This is actually a Contents enumerator, but is unsigned to avoid sign
- /// extension and achieve better bitpacking with MSVC.
- unsigned SymbolContents : 3;
-
/// The alignment of the symbol if it is 'common'.
///
/// Internally, this is stored as log2(align) + 1.
@@ -145,10 +145,10 @@ class MCSymbol {
};
MCSymbol(const MCSymbolTableEntry *Name, bool isTemporary)
- : IsTemporary(isTemporary), IsRedefinable(false), IsRegistered(false),
- IsExternal(false), IsPrivateExtern(false), IsWeakExternal(false),
- IsUsedInReloc(false), IsResolving(0), SymbolContents(SymContentsUnset),
- CommonAlignLog2(0), Flags(0) {
+ : SymbolContents(SymContentsUnset), IsTemporary(isTemporary),
+ IsRedefinable(false), IsRegistered(false), IsExternal(false),
+ IsPrivateExtern(false), IsWeakExternal(false), IsUsedInReloc(false),
+ IsResolving(0), CommonAlignLog2(0), Flags(0) {
Offset = 0;
HasName = !!Name;
if (Name)
diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp
index 8192896eeb6bb..b19842aae46ce 100644
--- a/llvm/lib/MC/MCSymbol.cpp
+++ b/llvm/lib/MC/MCSymbol.cpp
@@ -20,6 +20,10 @@
using namespace llvm;
+// There are numerous MCSymbol objects, so keeping sizeof(MCSymbol) small is
+// crucial for minimizing peak memory usage.
+static_assert(sizeof(MCSymbol) <= 24, "Keep the base symbol small");
+
// Only the address of this fragment is ever actually used.
static MCFragment SentinelFragment;
More information about the llvm-commits
mailing list