MC: Bit pack MCSymbolData.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 11 Oct 2014 15:07:21 +0000 (15:07 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 11 Oct 2014 15:07:21 +0000 (15:07 +0000)
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

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

index 1cb34c2fe33bfc2822b11a4798fdcaef4d873a3f..37dafb02606b68c0863cf3a801db46cef560b883 100644 (file)
@@ -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;
-
-  /// 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<MCFragment *, 2> 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;
   }
index 709a8defec586f38dc6a2d7b49fddc1472025ee4..25e12aa3323661a05f56d33ee97efc8c8bd7145e 100644 (file)
@@ -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() << ")";
index 7a1ab79e716cc606c62f2c50ad00d31ba2f239ad..7f6d12ce23866fa40540546981cbf310ec36c910 100644 (file)
@@ -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
index 396683ffceadbbaa194bc795f66b05f575bb77dc..3191ba30663f089114abe69dcbdd88da184cf219 100644 (file)
@@ -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;
 
index 186776a1944fd8e334be7d7a0371206a0e918745..7da500390ed1307aa4da0b81a7fc288d91cae2b2 100644 (file)
@@ -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).
index 2d5857fc63181e759f45c4e86cc8db873023ea3c..df2f14a91a7e2ed72ebe8cb1062be2bf7ea074a7 100644 (file)
@@ -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).
index ead333830090cbb667b2bdbec257b9800208c348..adf3fd8e4912ef2b2615dd0308a7e6743b9aaf54 100644 (file)
@@ -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).