#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>
class MCSection;
class MCSectionData;
class MCSubtargetInfo;
-class MCSymbol;
-class MCSymbolData;
class MCValue;
class MCAsmBackend;
/// Atom - The atom this fragment is in, as represented by it's defining
/// symbol.
- MCSymbolData *Atom;
+ const MCSymbol *Atom;
/// \name Assembler Backend Data
/// @{
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; }
private:
FragmentListType Fragments;
- const MCSection *Section;
+ MCSection *Section;
/// Ordinal - The section index in the assemblers section list.
unsigned Ordinal;
/// 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;
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; }
/// @}
};
-// 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;
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;
iplist<MCSectionData> Sections;
- iplist<MCSymbolData> Symbols;
+ SymbolDataListType Symbols;
DenseSet<const MCSymbol *> LocalsUsedInReloc;
// 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;
/// 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
return *Entry;
}
- MCSectionData &getOrCreateSectionData(const MCSection &Section,
+ MCSectionData &getOrCreateSectionData(MCSection &Section,
bool *Created = nullptr) {
MCSectionData *&Entry = SectionMap[&Section];
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 &>(
}
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 {