[llvm] r237873 - MC: Simplify MCSymbolData initialization and remove MCSymbol pointer
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed May 20 18:33:04 PDT 2015
Author: dexonsmith
Date: Wed May 20 20:33:03 2015
New Revision: 237873
URL: http://llvm.org/viewvc/llvm-project?rev=237873&view=rev
Log:
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.)
Modified:
llvm/trunk/include/llvm/MC/MCAssembler.h
llvm/trunk/include/llvm/MC/MCSymbol.h
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=237873&r1=237872&r2=237873&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Wed May 20 20:33:03 2015
@@ -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<MCSymbolData &>(
@@ -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();
Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=237873&r1=237872&r2=237873&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbol.h Wed May 20 20:33:03 2015
@@ -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 unique
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
/// @{
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=237873&r1=237872&r2=237873&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed May 20 20:33:03 2015
@@ -352,23 +352,6 @@ void MCSectionData::setBundleLockState(B
/* *** */
-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_)
More information about the llvm-commits
mailing list