Skip to content

Commit 1893caa

Browse files
committed
MCSymbol: Decrease the bitfield size of SymbolContents
Follow-up to 57b0843 The size of MCSymbol has been reduced to 24 bytes on 64-bit systems.
1 parent aa2fe4e commit 1893caa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

llvm/include/llvm/MC/MCSymbol.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class MCSymbol {
6565
/// relative to, if any.
6666
mutable MCFragment *Fragment = nullptr;
6767

68+
/// This is actually a Contents enumerator, but is unsigned to avoid sign
69+
/// extension and achieve better bitpacking with MSVC.
70+
unsigned SymbolContents : 2;
71+
6872
/// True if this symbol is named. A named symbol will have a pointer to the
6973
/// name allocated in the bytes immediately prior to the MCSymbol.
7074
unsigned HasName : 1;
@@ -95,10 +99,6 @@ class MCSymbol {
9599
/// Used to detect cyclic dependency like `a = a + 1` and `a = b; b = a`.
96100
unsigned IsResolving : 1;
97101

98-
/// This is actually a Contents enumerator, but is unsigned to avoid sign
99-
/// extension and achieve better bitpacking with MSVC.
100-
unsigned SymbolContents : 3;
101-
102102
/// The alignment of the symbol if it is 'common'.
103103
///
104104
/// Internally, this is stored as log2(align) + 1.
@@ -145,10 +145,10 @@ class MCSymbol {
145145
};
146146

147147
MCSymbol(const MCSymbolTableEntry *Name, bool isTemporary)
148-
: IsTemporary(isTemporary), IsRedefinable(false), IsRegistered(false),
149-
IsExternal(false), IsPrivateExtern(false), IsWeakExternal(false),
150-
IsUsedInReloc(false), IsResolving(0), SymbolContents(SymContentsUnset),
151-
CommonAlignLog2(0), Flags(0) {
148+
: SymbolContents(SymContentsUnset), IsTemporary(isTemporary),
149+
IsRedefinable(false), IsRegistered(false), IsExternal(false),
150+
IsPrivateExtern(false), IsWeakExternal(false), IsUsedInReloc(false),
151+
IsResolving(0), CommonAlignLog2(0), Flags(0) {
152152
Offset = 0;
153153
HasName = !!Name;
154154
if (Name)

llvm/lib/MC/MCSymbol.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
using namespace llvm;
2222

23+
// There are numerous MCSymbol objects, so keeping sizeof(MCSymbol) small is
24+
// crucial for minimizing peak memory usage.
25+
static_assert(sizeof(MCSymbol) <= 24, "Keep the base symbol small");
26+
2327
// Only the address of this fragment is ever actually used.
2428
static MCFragment SentinelFragment;
2529

0 commit comments

Comments
 (0)