[llvm] 2e46695 - [MC] Reorder members of MCFragment's subclasses to decrease padding

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 5 20:23:09 PST 2020


Author: Fangrui Song
Date: 2020-01-05T20:22:16-08:00
New Revision: 2e4669500314cc6ba08c59abf8ee0fedd590018e

URL: https://github.com/llvm/llvm-project/commit/2e4669500314cc6ba08c59abf8ee0fedd590018e
DIFF: https://github.com/llvm/llvm-project/commit/2e4669500314cc6ba08c59abf8ee0fedd590018e.diff

LOG: [MC] Reorder members of MCFragment's subclasses to decrease padding

On a 64-bit platform:

sizeof(MCBoundaryAlignFragment): 64 -> 56
sizeof(MCOrgFragment): 72 -> 64
sizeof(MCFillFragment): 80 -> 72
sizeof(MCLEBFragment): 88 -> 80

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCFragment.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index 4722e9b2fa2b..ed237eb1e884 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -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; }
@@ -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;
 
@@ -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; }
@@ -348,22 +343,20 @@ 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; }
 
@@ -371,31 +364,26 @@ class MCOrgFragment : public MCFragment {
 
   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; }
@@ -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;
   }
@@ -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;
   }
@@ -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;
   }
@@ -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;
   }
@@ -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;
@@ -556,10 +521,6 @@ 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
@@ -567,6 +528,9 @@ class MCBoundaryAlignFragment : public MCFragment {
   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,
@@ -574,8 +538,6 @@ class MCBoundaryAlignFragment : public MCFragment {
       : 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; }
 
@@ -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;


        


More information about the llvm-commits mailing list