mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 03:24:09 +00:00
MC: Merge MCSymbol and MCSymbolData
Turn `MCSymbolData` into a field inside of `MCSymbol`. Keep all the old API alive for now, so that consumers can be updated in a later commit. This means we still temporarily need the back pointer from `MCSymbolData` to `MCSymbol`, but I'll remove it in a follow-up. This optimizes for object emission over assembly emission. By removing the `DenseMap` in `MCAssembler`, llc memory usage drops from around 1040 MB to 1001 MB (3.8%). (I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`; see r236629 for details.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -676,7 +676,7 @@ class MCAssembler {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
typedef iplist<MCSectionData> SectionDataListType;
|
typedef iplist<MCSectionData> SectionDataListType;
|
||||||
typedef std::vector<std::unique_ptr<MCSymbolData>> SymbolDataListType;
|
typedef std::vector<MCSymbolData *> SymbolDataListType;
|
||||||
|
|
||||||
typedef SectionDataListType::const_iterator const_iterator;
|
typedef SectionDataListType::const_iterator const_iterator;
|
||||||
typedef SectionDataListType::iterator iterator;
|
typedef SectionDataListType::iterator iterator;
|
||||||
@ -734,11 +734,6 @@ private:
|
|||||||
// FIXME: Avoid this indirection?
|
// FIXME: Avoid this indirection?
|
||||||
DenseMap<const MCSection *, MCSectionData *> SectionMap;
|
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<IndirectSymbolData> IndirectSymbols;
|
||||||
|
|
||||||
std::vector<DataRegionData> DataRegions;
|
std::vector<DataRegionData> DataRegions;
|
||||||
@ -1039,7 +1034,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasSymbolData(const MCSymbol &Symbol) const {
|
bool hasSymbolData(const MCSymbol &Symbol) const {
|
||||||
return SymbolMap.lookup(&Symbol) != nullptr;
|
return Symbol.getUnsafeData().isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
|
MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
|
||||||
@ -1048,23 +1043,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
|
const MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
|
||||||
MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
|
return Symbol.getData();
|
||||||
assert(Entry && "Missing symbol data!");
|
|
||||||
return *Entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
|
MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
|
||||||
bool *Created = nullptr) {
|
bool *Created = nullptr) {
|
||||||
MCSymbolData *&Entry = SymbolMap[&Symbol];
|
|
||||||
|
|
||||||
if (Created)
|
if (Created)
|
||||||
*Created = !Entry;
|
*Created = !hasSymbolData(Symbol);
|
||||||
if (!Entry) {
|
if (!hasSymbolData(Symbol)) {
|
||||||
Symbols.emplace_back(new MCSymbolData(Symbol, nullptr, 0));
|
Symbol.getUnsafeData().initialize(Symbol, nullptr, 0);
|
||||||
Entry = Symbols.back().get();
|
Symbols.push_back(&Symbol.getData());
|
||||||
}
|
}
|
||||||
|
return Symbol.getData();
|
||||||
return *Entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const_file_name_iterator file_names_begin() const {
|
const_file_name_iterator file_names_begin() const {
|
||||||
|
@ -27,7 +27,7 @@ class MCSection;
|
|||||||
class MCContext;
|
class MCContext;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
// FIXME: Same concerns as with SectionData.
|
// TODO: Merge completely with MCSymbol.
|
||||||
class MCSymbolData {
|
class MCSymbolData {
|
||||||
const MCSymbol *Symbol;
|
const MCSymbol *Symbol;
|
||||||
|
|
||||||
@ -64,10 +64,12 @@ class MCSymbolData {
|
|||||||
public:
|
public:
|
||||||
// Only for use as sentinel.
|
// Only for use as sentinel.
|
||||||
MCSymbolData();
|
MCSymbolData();
|
||||||
MCSymbolData(const MCSymbol &Symbol, MCFragment *Fragment, uint64_t Offset);
|
void initialize(const MCSymbol &Symbol, MCFragment *Fragment,
|
||||||
|
uint64_t Offset);
|
||||||
|
|
||||||
/// \name Accessors
|
/// \name Accessors
|
||||||
/// @{
|
/// @{
|
||||||
|
bool isInitialized() const { return Symbol; }
|
||||||
|
|
||||||
const MCSymbol &getSymbol() const { return *Symbol; }
|
const MCSymbol &getSymbol() const { return *Symbol; }
|
||||||
|
|
||||||
@ -185,6 +187,8 @@ class MCSymbol {
|
|||||||
/// IsUsed - True if this symbol has been used.
|
/// IsUsed - True if this symbol has been used.
|
||||||
mutable unsigned IsUsed : 1;
|
mutable unsigned IsUsed : 1;
|
||||||
|
|
||||||
|
mutable MCSymbolData Data;
|
||||||
|
|
||||||
private: // MCContext creates and uniques these.
|
private: // MCContext creates and uniques these.
|
||||||
friend class MCExpr;
|
friend class MCExpr;
|
||||||
friend class MCContext;
|
friend class MCContext;
|
||||||
@ -204,6 +208,17 @@ public:
|
|||||||
/// getName - Get the symbol name.
|
/// getName - Get the symbol name.
|
||||||
StringRef getName() const { return Name; }
|
StringRef getName() const { return Name; }
|
||||||
|
|
||||||
|
/// Get associated symbol data.
|
||||||
|
MCSymbolData &getData() const {
|
||||||
|
assert(Data.isInitialized() && "Missing symbol data!");
|
||||||
|
return Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get unsafe symbol data (even if uninitialized).
|
||||||
|
///
|
||||||
|
/// Don't assert on uninitialized data; just return it.
|
||||||
|
MCSymbolData &getUnsafeData() const { return Data; }
|
||||||
|
|
||||||
/// \name Accessors
|
/// \name Accessors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -360,10 +360,18 @@ void MCSectionData::setBundleLockState(BundleLockStateType NewState) {
|
|||||||
|
|
||||||
MCSymbolData::MCSymbolData() : Symbol(nullptr) {}
|
MCSymbolData::MCSymbolData() : Symbol(nullptr) {}
|
||||||
|
|
||||||
MCSymbolData::MCSymbolData(const MCSymbol &Symbol, MCFragment *Fragment,
|
void MCSymbolData::initialize(const MCSymbol &Symbol, MCFragment *Fragment,
|
||||||
uint64_t Offset)
|
uint64_t Offset) {
|
||||||
: Symbol(&Symbol), Fragment(Fragment), Offset(Offset), SymbolSize(nullptr),
|
assert(!isInitialized() && "Expected uninitialized symbol");
|
||||||
CommonAlign(-1U), Flags(0), Index(0) {}
|
|
||||||
|
this->Symbol = &Symbol;
|
||||||
|
this->Fragment.setPointer(Fragment);
|
||||||
|
this->Offset = Offset;
|
||||||
|
this->SymbolSize = nullptr;
|
||||||
|
this->CommonAlign = -1U;
|
||||||
|
this->Flags = 0;
|
||||||
|
this->Index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* *** */
|
/* *** */
|
||||||
|
|
||||||
@ -383,7 +391,6 @@ void MCAssembler::reset() {
|
|||||||
Sections.clear();
|
Sections.clear();
|
||||||
Symbols.clear();
|
Symbols.clear();
|
||||||
SectionMap.clear();
|
SectionMap.clear();
|
||||||
SymbolMap.clear();
|
|
||||||
IndirectSymbols.clear();
|
IndirectSymbols.clear();
|
||||||
DataRegions.clear();
|
DataRegions.clear();
|
||||||
LinkerOptions.clear();
|
LinkerOptions.clear();
|
||||||
|
Reference in New Issue
Block a user