mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02: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
|
#define LLVM_MC_MCASSEMBLER_H
|
||||||
|
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
|
#include "llvm/ADT/PointerIntPair.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/ilist.h"
|
#include "llvm/ADT/ilist.h"
|
||||||
@ -684,34 +685,27 @@ public:
|
|||||||
|
|
||||||
// FIXME: Same concerns as with SectionData.
|
// FIXME: Same concerns as with SectionData.
|
||||||
class MCSymbolData : public ilist_node<MCSymbolData> {
|
class MCSymbolData : public ilist_node<MCSymbolData> {
|
||||||
public:
|
|
||||||
const MCSymbol *Symbol;
|
const MCSymbol *Symbol;
|
||||||
|
|
||||||
/// Fragment - The fragment this symbol's value is relative to, if any.
|
/// Fragment - The fragment this symbol's value is relative to, if any. Also
|
||||||
MCFragment *Fragment;
|
/// 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
|
union {
|
||||||
/// value.
|
/// Offset - The offset to apply to the fragment address to form this
|
||||||
|
/// symbol's value.
|
||||||
uint64_t Offset;
|
uint64_t Offset;
|
||||||
|
|
||||||
/// IsExternal - True if this symbol is visible outside this translation
|
/// CommonSize - The size of the symbol, if it is 'common'.
|
||||||
/// 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;
|
uint64_t CommonSize;
|
||||||
|
};
|
||||||
|
|
||||||
/// SymbolSize - An expression describing how to calculate the size of
|
/// SymbolSize - An expression describing how to calculate the size of
|
||||||
/// a symbol. If a symbol has no size this field will be NULL.
|
/// a symbol. If a symbol has no size this field will be NULL.
|
||||||
const MCExpr *SymbolSize;
|
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?
|
// FIXME: Pack this in with other fields?
|
||||||
unsigned CommonAlign;
|
unsigned CommonAlign;
|
||||||
@ -734,30 +728,41 @@ public:
|
|||||||
|
|
||||||
const MCSymbol &getSymbol() const { return *Symbol; }
|
const MCSymbol &getSymbol() const { return *Symbol; }
|
||||||
|
|
||||||
MCFragment *getFragment() const { return Fragment; }
|
MCFragment *getFragment() const { return Fragment.getPointer(); }
|
||||||
void setFragment(MCFragment *Value) { Fragment = Value; }
|
void setFragment(MCFragment *Value) { Fragment.setPointer(Value); }
|
||||||
|
|
||||||
uint64_t getOffset() const { return Offset; }
|
uint64_t getOffset() const {
|
||||||
void setOffset(uint64_t Value) { Offset = Value; }
|
assert(!isCommon());
|
||||||
|
return Offset;
|
||||||
|
}
|
||||||
|
void setOffset(uint64_t Value) {
|
||||||
|
assert(!isCommon());
|
||||||
|
Offset = Value;
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Symbol Attributes
|
/// @name Symbol Attributes
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
bool isExternal() const { return IsExternal; }
|
bool isExternal() const { return Fragment.getInt() & 1; }
|
||||||
void setExternal(bool Value) { IsExternal = Value; }
|
void setExternal(bool Value) {
|
||||||
|
Fragment.setInt((Fragment.getInt() & ~1) | unsigned(Value));
|
||||||
|
}
|
||||||
|
|
||||||
bool isPrivateExtern() const { return IsPrivateExtern; }
|
bool isPrivateExtern() const { return Fragment.getInt() & 2; }
|
||||||
void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
|
void setPrivateExtern(bool Value) {
|
||||||
|
Fragment.setInt((Fragment.getInt() & ~2) | (unsigned(Value) << 1));
|
||||||
|
}
|
||||||
|
|
||||||
/// isCommon - Is this a 'common' symbol.
|
/// 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'.
|
/// setCommon - Mark this symbol as being 'common'.
|
||||||
///
|
///
|
||||||
/// \param Size - The size of the symbol.
|
/// \param Size - The size of the symbol.
|
||||||
/// \param Align - The alignment of the symbol.
|
/// \param Align - The alignment of the symbol.
|
||||||
void setCommon(uint64_t Size, unsigned Align) {
|
void setCommon(uint64_t Size, unsigned Align) {
|
||||||
|
assert(getOffset() == 0);
|
||||||
CommonSize = Size;
|
CommonSize = Size;
|
||||||
CommonAlign = Align;
|
CommonAlign = Align;
|
||||||
}
|
}
|
||||||
|
@ -335,10 +335,7 @@ MCSymbolData::MCSymbolData() : Symbol(nullptr) {}
|
|||||||
MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
|
MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
|
||||||
uint64_t _Offset, MCAssembler *A)
|
uint64_t _Offset, MCAssembler *A)
|
||||||
: Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
|
: Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
|
||||||
IsExternal(false), IsPrivateExtern(false),
|
SymbolSize(nullptr), CommonAlign(-1U), Flags(0), Index(0) {
|
||||||
CommonSize(0), SymbolSize(nullptr), CommonAlign(0),
|
|
||||||
Flags(0), Index(0)
|
|
||||||
{
|
|
||||||
if (A)
|
if (A)
|
||||||
A->getSymbolList().push_back(this);
|
A->getSymbolList().push_back(this);
|
||||||
}
|
}
|
||||||
@ -1244,8 +1241,10 @@ void MCSymbolData::dump() const {
|
|||||||
raw_ostream &OS = llvm::errs();
|
raw_ostream &OS = llvm::errs();
|
||||||
|
|
||||||
OS << "<MCSymbolData Symbol:" << getSymbol()
|
OS << "<MCSymbolData Symbol:" << getSymbol()
|
||||||
<< " Fragment:" << getFragment() << " Offset:" << getOffset()
|
<< " Fragment:" << getFragment();
|
||||||
<< " Flags:" << getFlags() << " Index:" << getIndex();
|
if (!isCommon())
|
||||||
|
OS << " Offset:" << getOffset();
|
||||||
|
OS << " Flags:" << getFlags() << " Index:" << getIndex();
|
||||||
if (isCommon())
|
if (isCommon())
|
||||||
OS << " (common, size:" << getCommonSize()
|
OS << " (common, size:" << getCommonSize()
|
||||||
<< " align: " << getCommonAlignment() << ")";
|
<< " align: " << getCommonAlignment() << ")";
|
||||||
|
@ -41,7 +41,7 @@ void MachObjectWriter::reset() {
|
|||||||
bool MachObjectWriter::
|
bool MachObjectWriter::
|
||||||
doesSymbolRequireExternRelocation(const MCSymbolData *SD) {
|
doesSymbolRequireExternRelocation(const MCSymbolData *SD) {
|
||||||
// Undefined symbols are always extern.
|
// Undefined symbols are always extern.
|
||||||
if (SD->Symbol->isUndefined())
|
if (SD->getSymbol().isUndefined())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// References to weak definitions require external relocation entries; the
|
// 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;
|
coff_symbol->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
|
||||||
} else {
|
} else {
|
||||||
const MCSymbolData &BaseData = Assembler.getSymbolData(*Base);
|
const MCSymbolData &BaseData = Assembler.getSymbolData(*Base);
|
||||||
if (BaseData.Fragment) {
|
if (BaseData.getFragment()) {
|
||||||
COFFSection *Sec =
|
COFFSection *Sec =
|
||||||
SectionMap[&BaseData.Fragment->getParent()->getSection()];
|
SectionMap[&BaseData.getFragment()->getParent()->getSection()];
|
||||||
|
|
||||||
if (coff_symbol->Section && coff_symbol->Section != Sec)
|
if (coff_symbol->Section && coff_symbol->Section != Sec)
|
||||||
report_fatal_error("conflicting sections for symbol");
|
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.
|
// Turn relocations for temporary symbols into section relocations.
|
||||||
if (coff_symbol->MCData->getSymbol().isTemporary() || CrossSection) {
|
if (coff_symbol->MCData->getSymbol().isTemporary() || CrossSection) {
|
||||||
Reloc.Symb = coff_symbol->Section->Symbol;
|
Reloc.Symb = coff_symbol->Section->Symbol;
|
||||||
FixedValue += Layout.getFragmentOffset(coff_symbol->MCData->Fragment)
|
FixedValue += Layout.getFragmentOffset(coff_symbol->MCData->getFragment()) +
|
||||||
+ coff_symbol->MCData->getOffset();
|
coff_symbol->MCData->getOffset();
|
||||||
} else
|
} else
|
||||||
Reloc.Symb = coff_symbol;
|
Reloc.Symb = coff_symbol;
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
|
|||||||
// For external relocations, make sure to offset the fixup value to
|
// For external relocations, make sure to offset the fixup value to
|
||||||
// compensate for the addend of the symbol address, if it was
|
// compensate for the addend of the symbol address, if it was
|
||||||
// undefined. This occurs with weak definitions, for example.
|
// undefined. This occurs with weak definitions, for example.
|
||||||
if (!SD->Symbol->isUndefined())
|
if (!SD->getSymbol().isUndefined())
|
||||||
FixedValue -= Layout.getSymbolOffset(SD);
|
FixedValue -= Layout.getSymbolOffset(SD);
|
||||||
} else {
|
} else {
|
||||||
// The index is the section ordinal (1-based).
|
// 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
|
// For external relocations, make sure to offset the fixup value to
|
||||||
// compensate for the addend of the symbol address, if it was
|
// compensate for the addend of the symbol address, if it was
|
||||||
// undefined. This occurs with weak definitions, for example.
|
// undefined. This occurs with weak definitions, for example.
|
||||||
if (!SD->Symbol->isUndefined())
|
if (!SD->getSymbol().isUndefined())
|
||||||
FixedValue -= Layout.getSymbolOffset(SD);
|
FixedValue -= Layout.getSymbolOffset(SD);
|
||||||
} else {
|
} else {
|
||||||
// The index is the section ordinal (1-based).
|
// 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
|
// For external relocations, make sure to offset the fixup value to
|
||||||
// compensate for the addend of the symbol address, if it was
|
// compensate for the addend of the symbol address, if it was
|
||||||
// undefined. This occurs with weak definitions, for example.
|
// undefined. This occurs with weak definitions, for example.
|
||||||
if (!SD->Symbol->isUndefined())
|
if (!SD->getSymbol().isUndefined())
|
||||||
FixedValue -= Layout.getSymbolOffset(SD);
|
FixedValue -= Layout.getSymbolOffset(SD);
|
||||||
} else {
|
} else {
|
||||||
// The index is the section ordinal (1-based).
|
// The index is the section ordinal (1-based).
|
||||||
|
Loading…
Reference in New Issue
Block a user