From: Benjamin Kramer Date: Sat, 11 Oct 2014 15:07:21 +0000 (+0000) Subject: MC: Bit pack MCSymbolData. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=fedd0e2a21c3216a8b50ff7d3c0dd830c014a573 MC: Bit pack MCSymbolData. On x86_64 this brings it from 80 bytes to 64 bytes. Also make any member variables private and clean up uses to go through the existing accessors. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219573 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 1cb34c2fe33..37dafb02606 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -11,6 +11,7 @@ #define LLVM_MC_MCASSEMBLER_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/ilist.h" @@ -684,34 +685,27 @@ public: // FIXME: Same concerns as with SectionData. class MCSymbolData : public ilist_node { -public: const MCSymbol *Symbol; - /// Fragment - The fragment this symbol's value is relative to, if any. - MCFragment *Fragment; - - /// Offset - The offset to apply to the fragment address to form this symbol's - /// value. - uint64_t Offset; + /// Fragment - The fragment this symbol's value is relative to, if any. Also + /// stores if this symbol is visible outside this translation unit (bit 0) or + /// if it is private extern (bit 1). + PointerIntPair Fragment; - /// IsExternal - True if this symbol is visible outside this translation - /// unit. - unsigned IsExternal : 1; + union { + /// Offset - The offset to apply to the fragment address to form this + /// symbol's value. + uint64_t Offset; - /// IsPrivateExtern - True if this symbol is private extern. - unsigned IsPrivateExtern : 1; - - /// CommonSize - The size of the symbol, if it is 'common', or 0. - // - // FIXME: Pack this in with other fields? We could put it in offset, since a - // common symbol can never get a definition. - uint64_t CommonSize; + /// CommonSize - The size of the symbol, if it is 'common'. + uint64_t CommonSize; + }; /// SymbolSize - An expression describing how to calculate the size of /// a symbol. If a symbol has no size this field will be NULL. const MCExpr *SymbolSize; - /// CommonAlign - The alignment of the symbol, if it is 'common'. + /// CommonAlign - The alignment of the symbol, if it is 'common', or -1. // // FIXME: Pack this in with other fields? unsigned CommonAlign; @@ -734,30 +728,41 @@ public: const MCSymbol &getSymbol() const { return *Symbol; } - MCFragment *getFragment() const { return Fragment; } - void setFragment(MCFragment *Value) { Fragment = Value; } + MCFragment *getFragment() const { return Fragment.getPointer(); } + void setFragment(MCFragment *Value) { Fragment.setPointer(Value); } - uint64_t getOffset() const { return Offset; } - void setOffset(uint64_t Value) { Offset = Value; } + uint64_t getOffset() const { + assert(!isCommon()); + return Offset; + } + void setOffset(uint64_t Value) { + assert(!isCommon()); + Offset = Value; + } /// @} /// @name Symbol Attributes /// @{ - bool isExternal() const { return IsExternal; } - void setExternal(bool Value) { IsExternal = Value; } + bool isExternal() const { return Fragment.getInt() & 1; } + void setExternal(bool Value) { + Fragment.setInt((Fragment.getInt() & ~1) | unsigned(Value)); + } - bool isPrivateExtern() const { return IsPrivateExtern; } - void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } + bool isPrivateExtern() const { return Fragment.getInt() & 2; } + void setPrivateExtern(bool Value) { + Fragment.setInt((Fragment.getInt() & ~2) | (unsigned(Value) << 1)); + } /// isCommon - Is this a 'common' symbol. - bool isCommon() const { return CommonSize != 0; } + bool isCommon() const { return CommonAlign != -1U; } /// setCommon - Mark this symbol as being 'common'. /// /// \param Size - The size of the symbol. /// \param Align - The alignment of the symbol. void setCommon(uint64_t Size, unsigned Align) { + assert(getOffset() == 0); CommonSize = Size; CommonAlign = Align; } diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 709a8defec5..25e12aa3323 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -334,11 +334,8 @@ MCSymbolData::MCSymbolData() : Symbol(nullptr) {} MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, MCAssembler *A) - : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset), - IsExternal(false), IsPrivateExtern(false), - CommonSize(0), SymbolSize(nullptr), CommonAlign(0), - Flags(0), Index(0) -{ + : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset), + SymbolSize(nullptr), CommonAlign(-1U), Flags(0), Index(0) { if (A) A->getSymbolList().push_back(this); } @@ -1244,8 +1241,10 @@ void MCSymbolData::dump() const { raw_ostream &OS = llvm::errs(); OS << "Symbol->isUndefined()) + if (SD->getSymbol().isUndefined()) return true; // References to weak definitions require external relocation entries; the diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 396683ffcea..3191ba30663 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -418,9 +418,9 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData, coff_symbol->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; } else { const MCSymbolData &BaseData = Assembler.getSymbolData(*Base); - if (BaseData.Fragment) { + if (BaseData.getFragment()) { COFFSection *Sec = - SectionMap[&BaseData.Fragment->getParent()->getSection()]; + SectionMap[&BaseData.getFragment()->getParent()->getSection()]; if (coff_symbol->Section && coff_symbol->Section != Sec) report_fatal_error("conflicting sections for symbol"); @@ -715,8 +715,8 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm, // Turn relocations for temporary symbols into section relocations. if (coff_symbol->MCData->getSymbol().isTemporary() || CrossSection) { Reloc.Symb = coff_symbol->Section->Symbol; - FixedValue += Layout.getFragmentOffset(coff_symbol->MCData->Fragment) - + coff_symbol->MCData->getOffset(); + FixedValue += Layout.getFragmentOffset(coff_symbol->MCData->getFragment()) + + coff_symbol->MCData->getOffset(); } else Reloc.Symb = coff_symbol; diff --git a/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp index 186776a1944..7da500390ed 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -428,7 +428,7 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer, // For external relocations, make sure to offset the fixup value to // compensate for the addend of the symbol address, if it was // undefined. This occurs with weak definitions, for example. - if (!SD->Symbol->isUndefined()) + if (!SD->getSymbol().isUndefined()) FixedValue -= Layout.getSymbolOffset(SD); } else { // The index is the section ordinal (1-based). diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp index 2d5857fc631..df2f14a91a7 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp @@ -360,7 +360,7 @@ void PPCMachObjectWriter::RecordPPCRelocation( // For external relocations, make sure to offset the fixup value to // compensate for the addend of the symbol address, if it was // undefined. This occurs with weak definitions, for example. - if (!SD->Symbol->isUndefined()) + if (!SD->getSymbol().isUndefined()) FixedValue -= Layout.getSymbolOffset(SD); } else { // The index is the section ordinal (1-based). diff --git a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index ead33383009..adf3fd8e491 100644 --- a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -572,7 +572,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer, // For external relocations, make sure to offset the fixup value to // compensate for the addend of the symbol address, if it was // undefined. This occurs with weak definitions, for example. - if (!SD->Symbol->isUndefined()) + if (!SD->getSymbol().isUndefined()) FixedValue -= Layout.getSymbolOffset(SD); } else { // The index is the section ordinal (1-based).