Move alignment from MCSectionData to MCSection.
[oota-llvm.git] / include / llvm / MC / MCAssembler.h
index eb7936834f34f143d97ea716764299983d7c97ca..0116aed2442cb69d063ac09c28541259efd7f9c1 100644 (file)
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/ilist_node.h"
+#include "llvm/ADT/iterator.h"
 #include "llvm/MC/MCDirectives.h"
 #include "llvm/MC/MCFixup.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCLinkerOptimizationHint.h"
 #include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/DataTypes.h"
 #include <algorithm>
@@ -39,8 +40,6 @@ class MCObjectWriter;
 class MCSection;
 class MCSectionData;
 class MCSubtargetInfo;
-class MCSymbol;
-class MCSymbolData;
 class MCValue;
 class MCAsmBackend;
 
@@ -71,7 +70,7 @@ private:
 
   /// Atom - The atom this fragment is in, as represented by it's defining
   /// symbol.
-  MCSymbolData *Atom;
+  const MCSymbol *Atom;
 
   /// \name Assembler Backend Data
   /// @{
@@ -100,8 +99,8 @@ public:
   MCSectionData *getParent() const { return Parent; }
   void setParent(MCSectionData *Value) { Parent = Value; }
 
-  MCSymbolData *getAtom() const { return Atom; }
-  void setAtom(MCSymbolData *Value) { Atom = Value; }
+  const MCSymbol *getAtom() const { return Atom; }
+  void setAtom(const MCSymbol *Value) { Atom = Value; }
 
   unsigned getLayoutOrder() const { return LayoutOrder; }
   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
@@ -558,7 +557,7 @@ public:
 
 private:
   FragmentListType Fragments;
-  const MCSection *Section;
+  MCSection *Section;
 
   /// Ordinal - The section index in the assemblers section list.
   unsigned Ordinal;
@@ -566,9 +565,6 @@ private:
   /// LayoutOrder - The index of this section in the layout order.
   unsigned LayoutOrder;
 
-  /// Alignment - The maximum alignment seen in this section.
-  unsigned Alignment;
-
   /// \brief Keeping track of bundle-locked state.
   BundleLockStateType BundleLockState;
 
@@ -597,12 +593,12 @@ private:
 public:
   // Only for use as sentinel.
   MCSectionData();
-  MCSectionData(const MCSection &Section, MCAssembler *A = nullptr);
+  MCSectionData(MCSection &Section, MCAssembler *A = nullptr);
 
-  const MCSection &getSection() const { return *Section; }
+  MCSection &getSection() const { return *Section; }
 
-  unsigned getAlignment() const { return Alignment; }
-  void setAlignment(unsigned Value) { Alignment = Value; }
+  unsigned getAlignment() const;
+  void setAlignment(unsigned Value);
 
   bool hasInstructions() const { return HasInstructions; }
   void setHasInstructions(bool Value) { HasInstructions = Value; }
@@ -656,127 +652,6 @@ public:
   /// @}
 };
 
-// FIXME: Same concerns as with SectionData.
-class MCSymbolData : public ilist_node<MCSymbolData> {
-  const MCSymbol *Symbol;
-
-  /// 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;
-
-  union {
-    /// Offset - The offset to apply to the fragment address to form this
-    /// symbol's value.
-    uint64_t Offset;
-
-    /// 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', or -1.
-  //
-  // FIXME: Pack this in with other fields?
-  unsigned CommonAlign;
-
-  /// Flags - The Flags field is used by object file implementations to store
-  /// additional per symbol information which is not easily classified.
-  uint32_t Flags;
-
-  /// Index - Index field, for use by the object file implementation.
-  uint64_t Index;
-
-public:
-  // Only for use as sentinel.
-  MCSymbolData();
-  MCSymbolData(const MCSymbol &Symbol, MCFragment *Fragment, uint64_t Offset);
-
-  /// \name Accessors
-  /// @{
-
-  const MCSymbol &getSymbol() const { return *Symbol; }
-
-  MCFragment *getFragment() const { return Fragment.getPointer(); }
-  void setFragment(MCFragment *Value) { Fragment.setPointer(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 Fragment.getInt() & 1; }
-  void setExternal(bool Value) {
-    Fragment.setInt((Fragment.getInt() & ~1) | unsigned(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 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;
-  }
-
-  /// getCommonSize - Return the size of a 'common' symbol.
-  uint64_t getCommonSize() const {
-    assert(isCommon() && "Not a 'common' symbol!");
-    return CommonSize;
-  }
-
-  void setSize(const MCExpr *SS) { SymbolSize = SS; }
-
-  const MCExpr *getSize() const { return SymbolSize; }
-
-  /// getCommonAlignment - Return the alignment of a 'common' symbol.
-  unsigned getCommonAlignment() const {
-    assert(isCommon() && "Not a 'common' symbol!");
-    return CommonAlign;
-  }
-
-  /// getFlags - Get the (implementation defined) symbol flags.
-  uint32_t getFlags() const { return Flags; }
-
-  /// setFlags - Set the (implementation defined) symbol flags.
-  void setFlags(uint32_t Value) { Flags = Value; }
-
-  /// modifyFlags - Modify the flags via a mask
-  void modifyFlags(uint32_t Value, uint32_t Mask) {
-    Flags = (Flags & ~Mask) | Value;
-  }
-
-  /// getIndex - Get the (implementation defined) index.
-  uint64_t getIndex() const { return Index; }
-
-  /// setIndex - Set the (implementation defined) index.
-  void setIndex(uint64_t Value) { Index = Value; }
-
-  /// @}
-
-  void dump() const;
-};
-
 // FIXME: This really doesn't belong here. See comments below.
 struct IndirectSymbolData {
   MCSymbol *Symbol;
@@ -798,13 +673,14 @@ class MCAssembler {
 
 public:
   typedef iplist<MCSectionData> SectionDataListType;
-  typedef iplist<MCSymbolData> SymbolDataListType;
+  typedef std::vector<const MCSymbol *> SymbolDataListType;
 
   typedef SectionDataListType::const_iterator const_iterator;
   typedef SectionDataListType::iterator iterator;
 
-  typedef SymbolDataListType::const_iterator const_symbol_iterator;
-  typedef SymbolDataListType::iterator symbol_iterator;
+  typedef pointee_iterator<SymbolDataListType::const_iterator>
+  const_symbol_iterator;
+  typedef pointee_iterator<SymbolDataListType::iterator> symbol_iterator;
 
   typedef iterator_range<symbol_iterator> symbol_range;
   typedef iterator_range<const_symbol_iterator> const_symbol_range;
@@ -846,7 +722,7 @@ private:
 
   iplist<MCSectionData> Sections;
 
-  iplist<MCSymbolData> Symbols;
+  SymbolDataListType Symbols;
 
   DenseSet<const MCSymbol *> LocalsUsedInReloc;
 
@@ -855,11 +731,6 @@ private:
   // FIXME: Avoid this indirection?
   DenseMap<const MCSection *, MCSectionData *> SectionMap;
 
-  /// The map of symbols to their associated assembler backend data.
-  //
-  // FIXME: Avoid this indirection?
-  DenseMap<const MCSymbol *, MCSymbolData *> SymbolMap;
-
   std::vector<IndirectSymbolData> IndirectSymbols;
 
   std::vector<DataRegionData> DataRegions;
@@ -960,7 +831,7 @@ public:
 
   /// Find the symbol which defines the atom containing the given symbol, or
   /// null if there is no such symbol.
-  const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
+  const MCSymbol *getAtom(const MCSymbol &S) const;
 
   /// Check whether a particular symbol is visible to the linker and is required
   /// in the symbol table, or whether it can be discarded by the assembler. This
@@ -1147,7 +1018,7 @@ public:
     return *Entry;
   }
 
-  MCSectionData &getOrCreateSectionData(const MCSection &Section,
+  MCSectionData &getOrCreateSectionData(MCSection &Section,
                                         bool *Created = nullptr) {
     MCSectionData *&Entry = SectionMap[&Section];
 
@@ -1159,9 +1030,7 @@ public:
     return *Entry;
   }
 
-  bool hasSymbolData(const MCSymbol &Symbol) const {
-    return SymbolMap.lookup(&Symbol) != nullptr;
-  }
+  bool hasSymbolData(const MCSymbol &Symbol) const { return Symbol.hasData(); }
 
   MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
     return const_cast<MCSymbolData &>(
@@ -1169,23 +1038,18 @@ public:
   }
 
   const MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
-    MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
-    assert(Entry && "Missing symbol data!");
-    return *Entry;
+    return Symbol.getData();
   }
 
   MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
                                       bool *Created = nullptr) {
-    MCSymbolData *&Entry = SymbolMap[&Symbol];
-
     if (Created)
-      *Created = !Entry;
-    if (!Entry) {
-      Entry = new MCSymbolData(Symbol, nullptr, 0);
-      Symbols.push_back(Entry);
+      *Created = !hasSymbolData(Symbol);
+    if (!hasSymbolData(Symbol)) {
+      Symbol.initializeData();
+      Symbols.push_back(&Symbol);
     }
-
-    return *Entry;
+    return Symbol.getData();
   }
 
   const_file_name_iterator file_names_begin() const {