mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
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. llvm-svn: 219573
This commit is contained in:
parent
c0e0dff487
commit
8a11a14550
@ -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<MCSymbolData> {
|
||||
public:
|
||||
const MCSymbol *Symbol;
|
||||
|
||||
/// Fragment - The fragment this symbol's value is relative to, if any.
|
||||
MCFragment *Fragment;
|
||||
/// 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<MCFragment *, 2> Fragment;
|
||||
|
||||
/// Offset - The offset to apply to the fragment address to form this symbol's
|
||||
/// value.
|
||||
uint64_t Offset;
|
||||
union {
|
||||
/// Offset - The offset to apply to the fragment address to form this
|
||||
/// symbol's value.
|
||||
uint64_t Offset;
|
||||
|
||||
/// IsExternal - True if this symbol is visible outside this translation
|
||||
/// unit.
|
||||
unsigned IsExternal : 1;
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
@ -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 << "<MCSymbolData Symbol:" << getSymbol()
|
||||
<< " Fragment:" << getFragment() << " Offset:" << getOffset()
|
||||
<< " Flags:" << getFlags() << " Index:" << getIndex();
|
||||
<< " Fragment:" << getFragment();
|
||||
if (!isCommon())
|
||||
OS << " Offset:" << getOffset();
|
||||
OS << " Flags:" << getFlags() << " Index:" << getIndex();
|
||||
if (isCommon())
|
||||
OS << " (common, size:" << getCommonSize()
|
||||
<< " align: " << getCommonAlignment() << ")";
|
||||
|
@ -41,7 +41,7 @@ void MachObjectWriter::reset() {
|
||||
bool MachObjectWriter::
|
||||
doesSymbolRequireExternRelocation(const MCSymbolData *SD) {
|
||||
// Undefined symbols are always extern.
|
||||
if (SD->Symbol->isUndefined())
|
||||
if (SD->getSymbol().isUndefined())
|
||||
return true;
|
||||
|
||||
// References to weak definitions require external relocation entries; the
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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).
|
||||
|
@ -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).
|
||||
|
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user