Skip to content

Commit

Permalink
[MC] Reorder members of MCFragment's subclasses to decrease padding
Browse files Browse the repository at this point in the history
On a 64-bit platform:

sizeof(MCBoundaryAlignFragment): 64 -> 56
sizeof(MCOrgFragment): 72 -> 64
sizeof(MCFillFragment): 80 -> 72
sizeof(MCLEBFragment): 88 -> 80
  • Loading branch information
MaskRay committed Jan 6, 2020
1 parent 806a2b1 commit 2e46695
Showing 1 changed file with 14 additions and 54 deletions.
68 changes: 14 additions & 54 deletions llvm/include/llvm/MC/MCFragment.h
Expand Up @@ -299,9 +299,6 @@ class MCAlignFragment : public MCFragment {
: MCFragment(FT_Align, false, Sec), Alignment(Alignment), EmitNops(false),
Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}

/// \name Accessors
/// @{

unsigned getAlignment() const { return Alignment; }

int64_t getValue() const { return Value; }
Expand All @@ -313,17 +310,15 @@ class MCAlignFragment : public MCFragment {
bool hasEmitNops() const { return EmitNops; }
void setEmitNops(bool Value) { EmitNops = Value; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Align;
}
};

class MCFillFragment : public MCFragment {
uint8_t ValueSize;
/// Value to use for filling bytes.
uint64_t Value;
uint8_t ValueSize;
/// The number of bytes to insert.
const MCExpr &NumValues;

Expand All @@ -333,7 +328,7 @@ class MCFillFragment : public MCFragment {
public:
MCFillFragment(uint64_t Value, uint8_t VSize, const MCExpr &NumValues,
SMLoc Loc, MCSection *Sec = nullptr)
: MCFragment(FT_Fill, false, Sec), Value(Value), ValueSize(VSize),
: MCFragment(FT_Fill, false, Sec), ValueSize(VSize), Value(Value),
NumValues(NumValues), Loc(Loc) {}

uint64_t getValue() const { return Value; }
Expand All @@ -348,54 +343,47 @@ class MCFillFragment : public MCFragment {
};

class MCOrgFragment : public MCFragment {
/// The offset this fragment should start at.
const MCExpr *Offset;

/// Value to use for filling bytes.
int8_t Value;

/// The offset this fragment should start at.
const MCExpr *Offset;

/// Source location of the directive that this fragment was created for.
SMLoc Loc;

public:
MCOrgFragment(const MCExpr &Offset, int8_t Value, SMLoc Loc,
MCSection *Sec = nullptr)
: MCFragment(FT_Org, false, Sec), Offset(&Offset), Value(Value), Loc(Loc) {}

/// \name Accessors
/// @{
: MCFragment(FT_Org, false, Sec), Value(Value), Offset(&Offset),
Loc(Loc) {}

const MCExpr &getOffset() const { return *Offset; }

uint8_t getValue() const { return Value; }

SMLoc getLoc() const { return Loc; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Org;
}
};

class MCLEBFragment : public MCFragment {
/// The value this fragment should contain.
const MCExpr *Value;

/// True if this is a sleb128, false if uleb128.
bool IsSigned;

/// The value this fragment should contain.
const MCExpr *Value;

SmallString<8> Contents;

public:
MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
: MCFragment(FT_LEB, false, Sec), Value(&Value_), IsSigned(IsSigned_) {
: MCFragment(FT_LEB, false, Sec), IsSigned(IsSigned_), Value(&Value_) {
Contents.push_back(0);
}

/// \name Accessors
/// @{

const MCExpr &getValue() const { return *Value; }

bool isSigned() const { return IsSigned; }
Expand Down Expand Up @@ -425,15 +413,10 @@ class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups<8, 1> {
: MCEncodedFragmentWithFixups<8, 1>(FT_Dwarf, false, Sec),
LineDelta(LineDelta), AddrDelta(&AddrDelta) {}

/// \name Accessors
/// @{

int64_t getLineDelta() const { return LineDelta; }

const MCExpr &getAddrDelta() const { return *AddrDelta; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Dwarf;
}
Expand All @@ -449,13 +432,8 @@ class MCDwarfCallFrameFragment : public MCEncodedFragmentWithFixups<8, 1> {
: MCEncodedFragmentWithFixups<8, 1>(FT_DwarfFrame, false, Sec),
AddrDelta(&AddrDelta) {}

/// \name Accessors
/// @{

const MCExpr &getAddrDelta() const { return *AddrDelta; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_DwarfFrame;
}
Expand All @@ -469,14 +447,9 @@ class MCSymbolIdFragment : public MCFragment {
MCSymbolIdFragment(const MCSymbol *Sym, MCSection *Sec = nullptr)
: MCFragment(FT_SymbolId, false, Sec), Sym(Sym) {}

/// \name Accessors
/// @{

const MCSymbol *getSymbol() { return Sym; }
const MCSymbol *getSymbol() const { return Sym; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_SymbolId;
}
Expand Down Expand Up @@ -505,17 +478,12 @@ class MCCVInlineLineTableFragment : public MCFragment {
StartFileId(StartFileId), StartLineNum(StartLineNum),
FnStartSym(FnStartSym), FnEndSym(FnEndSym) {}

/// \name Accessors
/// @{

const MCSymbol *getFnStartSym() const { return FnStartSym; }
const MCSymbol *getFnEndSym() const { return FnEndSym; }

SmallString<8> &getContents() { return Contents; }
const SmallString<8> &getContents() const { return Contents; }

/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_CVInlineLines;
}
Expand All @@ -538,14 +506,11 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
Ranges(Ranges.begin(), Ranges.end()),
FixedSizePortion(FixedSizePortion) {}

/// \name Accessors
/// @{
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> getRanges() const {
return Ranges;
}

StringRef getFixedSizePortion() const { return FixedSizePortion; }
/// @}

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_CVDefRange;
Expand All @@ -556,26 +521,23 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
/// does not cross a particular power-of-two boundary. The other fragments must
/// follow this one within the same section.
class MCBoundaryAlignFragment : public MCFragment {
private:
/// The size of the fragment. The size is lazily set during relaxation, and
/// is not meaningful before that.
uint64_t Size = 0;
/// The alignment requirement of the branch to be aligned.
Align AlignBoundary;
/// Flag to indicate whether the branch is fused. Use in determining the
/// region of fragments being aligned.
bool Fused : 1;
/// Flag to indicate whether NOPs should be emitted.
bool EmitNops : 1;
/// The size of the fragment. The size is lazily set during relaxation, and
/// is not meaningful before that.
uint64_t Size = 0;

public:
MCBoundaryAlignFragment(Align AlignBoundary, bool Fused = false,
bool EmitNops = false, MCSection *Sec = nullptr)
: MCFragment(FT_BoundaryAlign, false, Sec), AlignBoundary(AlignBoundary),
Fused(Fused), EmitNops(EmitNops) {}

/// \name Accessors
/// @{
uint64_t getSize() const { return Size; }
void setSize(uint64_t Value) { Size = Value; }

Expand All @@ -586,8 +548,6 @@ class MCBoundaryAlignFragment : public MCFragment {

bool canEmitNops() const { return EmitNops; }
void setEmitNops(bool Value) { EmitNops = Value; }
/// @}
//

static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_BoundaryAlign;
Expand Down

0 comments on commit 2e46695

Please sign in to comment.