From 4652459f64ed33e0bc21e9044b0a351c39c067c7 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 21 May 2015 01:33:03 +0000 Subject: [PATCH] MC: Simplify MCSymbolData initialization and remove MCSymbol pointer Finally remove the `MCSymbolData::Symbol` pointer. It was still being used to track whether `MCSymbolData` had been initialized, but this is better tracked by the bitfield in `MCSymbol`. The only caller of `MCSymbolData::initialize()` was `MCAssembler`, which (other than `Symbol`) passed in all-0 values. Replace all that indirection with a default constructor. The main point is a cleanup (and there's more cleanup to do), but there are also some small memory savings. I measured ~989 MB down to ~975 MB, cutting a little over 1% off the top of `llc`. (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@237873 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 6 ++---- include/llvm/MC/MCSymbol.h | 36 +++++++++++++++-------------------- lib/MC/MCAssembler.cpp | 17 ----------------- 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index f6ca21ab6ff..4c360646c6d 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -1033,9 +1033,7 @@ public: return *Entry; } - bool hasSymbolData(const MCSymbol &Symbol) const { - return Symbol.getUnsafeData().isInitialized(); - } + bool hasSymbolData(const MCSymbol &Symbol) const { return Symbol.hasData(); } MCSymbolData &getSymbolData(const MCSymbol &Symbol) { return const_cast( @@ -1051,7 +1049,7 @@ public: if (Created) *Created = !hasSymbolData(Symbol); if (!hasSymbolData(Symbol)) { - Symbol.getUnsafeData().initialize(Symbol, nullptr, 0); + Symbol.initializeData(); Symbols.push_back(&Symbol); } return Symbol.getData(); diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h index 0ed3d06acf9..26b416e47bc 100644 --- a/include/llvm/MC/MCSymbol.h +++ b/include/llvm/MC/MCSymbol.h @@ -29,8 +29,6 @@ class raw_ostream; // TODO: Merge completely with MCSymbol. class 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). @@ -39,7 +37,7 @@ class MCSymbolData { union { /// Offset - The offset to apply to the fragment address to form this /// symbol's value. - uint64_t Offset; + uint64_t Offset = 0; /// CommonSize - The size of the symbol, if it is 'common'. uint64_t CommonSize; @@ -47,30 +45,21 @@ class MCSymbolData { /// 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; + const MCExpr *SymbolSize = nullptr; /// CommonAlign - The alignment of the symbol, if it is 'common', or -1. // // FIXME: Pack this in with other fields? - unsigned CommonAlign; + unsigned CommonAlign = -1U; /// Flags - The Flags field is used by object file implementations to store /// additional per symbol information which is not easily classified. - uint32_t Flags; + uint32_t Flags = 0; /// Index - Index field, for use by the object file implementation. - uint64_t Index; + uint64_t Index = 0; public: - // Only for use as sentinel. - MCSymbolData(); - void initialize(const MCSymbol &Symbol, MCFragment *Fragment, - uint64_t Offset); - - /// \name Accessors - /// @{ - bool isInitialized() const { return Symbol; } - MCFragment *getFragment() const { return Fragment.getPointer(); } void setFragment(MCFragment *Value) { Fragment.setPointer(Value); } @@ -185,6 +174,7 @@ class MCSymbol { /// IsUsed - True if this symbol has been used. mutable unsigned IsUsed : 1; + mutable bool HasData : 1; mutable MCSymbolData Data; private: // MCContext creates and uniques these. @@ -192,7 +182,7 @@ private: // MCContext creates and uniques these. friend class MCContext; MCSymbol(StringRef name, bool isTemporary) : Name(name), Section(nullptr), Value(nullptr), IsTemporary(isTemporary), - IsRedefinable(false), IsUsed(false) {} + IsRedefinable(false), IsUsed(false), HasData(false) {} MCSymbol(const MCSymbol &) = delete; void operator=(const MCSymbol &) = delete; @@ -206,16 +196,20 @@ public: /// getName - Get the symbol name. StringRef getName() const { return Name; } + bool hasData() const { return HasData; } + /// Get associated symbol data. MCSymbolData &getData() const { - assert(Data.isInitialized() && "Missing symbol data!"); + assert(HasData && "Missing symbol data!"); return Data; } - /// Get unsafe symbol data (even if uninitialized). + /// Initialize symbol data. /// - /// Don't assert on uninitialized data; just return it. - MCSymbolData &getUnsafeData() const { return Data; } + /// Nothing really to do here, but this is enables an assertion that \a + /// MCAssembler::getOrCreateSymbolData() has actually been called before + /// anyone calls \a getData(). + void initializeData() const { HasData = true; } /// \name Accessors /// @{ diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c8ed7d1b1f6..8f9320af2b1 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -352,23 +352,6 @@ void MCSectionData::setBundleLockState(BundleLockStateType NewState) { /* *** */ -MCSymbolData::MCSymbolData() : Symbol(nullptr) {} - -void MCSymbolData::initialize(const MCSymbol &Symbol, MCFragment *Fragment, - uint64_t Offset) { - assert(!isInitialized() && "Expected uninitialized symbol"); - - this->Symbol = &Symbol; - this->Fragment.setPointer(Fragment); - this->Offset = Offset; - this->SymbolSize = nullptr; - this->CommonAlign = -1U; - this->Flags = 0; - this->Index = 0; -} - -/* *** */ - MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_, MCCodeEmitter &Emitter_, MCObjectWriter &Writer_, raw_ostream &OS_)