Turn MCSectionData into a field of MCSection.

This also changes MCAssembler to store a vector of MCSections instead of an
iplist of MCSectionData.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238159 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-05-25 23:14:17 +00:00
parent 5e435847b0
commit e86bc46939
8 changed files with 87 additions and 56 deletions

View File

@@ -12,6 +12,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/ilist.h"
@@ -551,11 +552,11 @@ class MCAssembler {
friend class MCAsmLayout;
public:
typedef iplist<MCSectionData> SectionDataListType;
typedef SetVector<MCSection *> SectionListType;
typedef std::vector<const MCSymbol *> SymbolDataListType;
typedef SectionDataListType::const_iterator const_iterator;
typedef SectionDataListType::iterator iterator;
typedef pointee_iterator<SectionListType::const_iterator> const_iterator;
typedef pointee_iterator<SectionListType::iterator> iterator;
typedef pointee_iterator<SymbolDataListType::const_iterator>
const_symbol_iterator;
@@ -599,17 +600,12 @@ private:
raw_ostream &OS;
iplist<MCSectionData> Sections;
SectionListType Sections;
SymbolDataListType Symbols;
DenseSet<const MCSymbol *> LocalsUsedInReloc;
/// The map of sections to their associated assembler backend data.
//
// FIXME: Avoid this indirection?
DenseMap<const MCSection *, MCSectionData *> SectionMap;
std::vector<IndirectSymbolData> IndirectSymbols;
std::vector<DataRegionData> DataRegions;
@@ -888,24 +884,22 @@ public:
/// \name Backend Data Access
/// @{
MCSectionData &getSectionData(const MCSection &Section) const {
MCSectionData *Entry = SectionMap.lookup(&Section);
assert(Entry && "Missing section data!");
return *Entry;
MCSectionData &getSectionData(MCSection &Section) {
assert(Sections.count(&Section) && "Unknown Seciton");
return Section.getSectionData();
}
const MCSectionData &getSectionData(const MCSection &Section) const {
return const_cast<MCAssembler *>(this)
->getSectionData(const_cast<MCSection &>(Section));
}
MCSectionData &getOrCreateSectionData(MCSection &Section,
bool *Created = nullptr) {
MCSectionData *&Entry = SectionMap[&Section];
bool C = Sections.insert(&Section);
if (Created)
*Created = !Entry;
if (!Entry) {
Entry = new MCSectionData(Section);
Sections.push_back(Entry);
}
return *Entry;
*Created = C;
return Section.getSectionData();
}
bool hasSymbolData(const MCSymbol &Symbol) const { return Symbol.hasData(); }

View File

@@ -31,7 +31,7 @@ class MCSection;
class MCSymbol;
class raw_ostream;
class MCSectionData : public ilist_node<MCSectionData> {
class MCSectionData {
friend class MCAsmLayout;
MCSectionData(const MCSectionData &) = delete;
@@ -62,9 +62,7 @@ private:
/// @}
public:
// Only for use as sentinel.
MCSectionData();
MCSectionData(MCSection &Section);
explicit MCSectionData(MCSection &Section);
MCSection &getSection() const { return *Section; }
@@ -144,9 +142,10 @@ private:
/// Whether this section has had instructions emitted into it.
unsigned HasInstructions : 1;
MCSectionData Data;
protected:
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
: Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
SectionVariant Variant;
SectionKind Kind;
@@ -191,6 +190,31 @@ public:
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }
MCSectionData &getSectionData() { return Data; }
const MCSectionData &getSectionData() const {
return const_cast<MCSection *>(this)->getSectionData();
}
MCSectionData::FragmentListType &getFragmentList();
const MCSectionData::FragmentListType &getFragmentList() const {
return const_cast<MCSection *>(this)->getFragmentList();
}
MCSectionData::iterator begin();
MCSectionData::const_iterator begin() const {
return const_cast<MCSection *>(this)->begin();
}
MCSectionData::iterator end();
MCSectionData::const_iterator end() const {
return const_cast<MCSection *>(this)->end();
}
MCSectionData::reverse_iterator rend();
MCSectionData::const_reverse_iterator rend() const {
return const_cast<MCSection *>(this)->rend();
}
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
const MCExpr *Subsection) const = 0;