Use a PointerUnion in MCSymbol for Section and Fragment. NFC.

The Fragment and Section, and a bool for HasFragment were all used to create
a PointerUnion.  Just use a pointer union instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239324 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper
2015-06-08 18:41:57 +00:00
parent e2101ba7b5
commit d354befbbb
2 changed files with 20 additions and 28 deletions

View File

@@ -14,6 +14,7 @@
#ifndef LLVM_MC_MCSYMBOL_H #ifndef LLVM_MC_MCSYMBOL_H
#define LLVM_MC_MCSYMBOL_H #define LLVM_MC_MCSYMBOL_H
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCExpr.h"
@@ -58,16 +59,14 @@ protected:
/// one pointer. /// one pointer.
/// FIXME: We might be able to simplify this by having the asm streamer create /// FIXME: We might be able to simplify this by having the asm streamer create
/// dummy fragments. /// dummy fragments.
union { /// If this is a section, then it gives the symbol is defined in. This is null
/// The section the symbol is defined in. This is null for undefined /// for undefined symbols, and the special AbsolutePseudoSection value for
/// symbols, and the special AbsolutePseudoSection value for absolute /// absolute symbols. If this is a variable symbol, this caches the variable
/// symbols. If this is a variable symbol, this caches the variable value's /// value's section.
/// section. ///
mutable MCSection *Section; /// If this is a fragment, then it gives the fragment this symbol's value is
/// relative to, if any.
/// The fragment this symbol's value is relative to, if any. mutable PointerUnion<MCSection *, MCFragment *> SectionOrFragment;
mutable MCFragment *Fragment;
};
/// Value - If non-null, the value for a variable symbol. /// Value - If non-null, the value for a variable symbol.
const MCExpr *Value; const MCExpr *Value;
@@ -91,8 +90,6 @@ protected:
/// This symbol is private extern. /// This symbol is private extern.
mutable unsigned IsPrivateExtern : 1; mutable unsigned IsPrivateExtern : 1;
mutable unsigned HasFragment : 1;
SymbolKind Kind : 2; SymbolKind Kind : 2;
/// Index field, for use by the object file implementation. /// Index field, for use by the object file implementation.
@@ -119,9 +116,9 @@ protected: // MCContext creates and uniques these.
friend class MCExpr; friend class MCExpr;
friend class MCContext; friend class MCContext;
MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary) MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
: Name(Name), Section(nullptr), Value(nullptr), IsTemporary(isTemporary), : Name(Name), Value(nullptr), IsTemporary(isTemporary),
IsRedefinable(false), IsUsed(false), IsRegistered(false), IsRedefinable(false), IsUsed(false), IsRegistered(false),
IsExternal(false), IsPrivateExtern(false), HasFragment(false), IsExternal(false), IsPrivateExtern(false),
Kind(Kind) { Kind(Kind) {
Offset = 0; Offset = 0;
} }
@@ -132,7 +129,8 @@ private:
MCSection *getSectionPtr() const { MCSection *getSectionPtr() const {
if (MCFragment *F = getFragment()) if (MCFragment *F = getFragment())
return F->getParent(); return F->getParent();
assert(!HasFragment); assert(!SectionOrFragment.is<MCFragment *>() && "Section or null expected");
MCSection *Section = SectionOrFragment.dyn_cast<MCSection *>();
if (Section || !Value) if (Section || !Value)
return Section; return Section;
return Section = Value->findAssociatedSection(); return Section = Value->findAssociatedSection();
@@ -163,8 +161,7 @@ public:
void redefineIfPossible() { void redefineIfPossible() {
if (IsRedefinable) { if (IsRedefinable) {
Value = nullptr; Value = nullptr;
Section = nullptr; SectionOrFragment = nullptr;
HasFragment = false;
IsRedefinable = false; IsRedefinable = false;
} }
} }
@@ -197,14 +194,13 @@ public:
/// Mark the symbol as defined in the section \p S. /// Mark the symbol as defined in the section \p S.
void setSection(MCSection &S) { void setSection(MCSection &S) {
assert(!isVariable() && "Cannot set section of variable"); assert(!isVariable() && "Cannot set section of variable");
assert(!HasFragment); assert(!SectionOrFragment.is<MCFragment *>() && "Section or null expected");
Section = &S; SectionOrFragment = &S;
} }
/// Mark the symbol as undefined. /// Mark the symbol as undefined.
void setUndefined() { void setUndefined() {
HasFragment = false; SectionOrFragment = nullptr;
Section = nullptr;
} }
bool isELF() const { return Kind == SymbolKindELF; } bool isELF() const { return Kind == SymbolKindELF; }
@@ -291,13 +287,10 @@ public:
bool isCommon() const { return CommonAlign != -1U; } bool isCommon() const { return CommonAlign != -1U; }
MCFragment *getFragment() const { MCFragment *getFragment() const {
if (!HasFragment) return SectionOrFragment.dyn_cast<MCFragment *>();
return nullptr;
return Fragment;
} }
void setFragment(MCFragment *Value) const { void setFragment(MCFragment *Value) const {
HasFragment = true; SectionOrFragment = Value;
Fragment = Value;
} }
bool isExternal() const { return IsExternal; } bool isExternal() const { return IsExternal; }

View File

@@ -42,8 +42,7 @@ void MCSymbol::setVariableValue(const MCExpr *Value) {
assert(!IsUsed && "Cannot set a variable that has already been used."); assert(!IsUsed && "Cannot set a variable that has already been used.");
assert(Value && "Invalid variable value!"); assert(Value && "Invalid variable value!");
this->Value = Value; this->Value = Value;
Section = nullptr; SectionOrFragment = nullptr;
HasFragment = false;
} }
void MCSymbol::print(raw_ostream &OS) const { void MCSymbol::print(raw_ostream &OS) const {