From f00654bc0f2a89ccb57301ce454d34e065d9f121 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 29 May 2015 20:21:02 +0000 Subject: [PATCH] Rename getOrCreateSymbolData to registerSymbol and return void. Another step in merging MCSymbol and MCSymbolData. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238607 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 4 +--- include/llvm/MC/MCObjectStreamer.h | 4 ++-- lib/MC/ELFObjectWriter.cpp | 2 +- lib/MC/MCELFStreamer.cpp | 21 +++++++++++-------- lib/MC/MCMachOStreamer.cpp | 17 ++++++++------- lib/MC/MCObjectStreamer.cpp | 7 ++++--- lib/MC/MachObjectWriter.cpp | 4 ++-- lib/MC/WinCOFFStreamer.cpp | 13 +++++++----- .../MCTargetDesc/AArch64ELFStreamer.cpp | 3 ++- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 3 ++- .../Mips/MCTargetDesc/MipsTargetStreamer.cpp | 2 +- 11 files changed, 45 insertions(+), 35 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 30aadacd52e..cfd9849a1ab 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -884,15 +884,13 @@ public: bool hasSymbolData(const MCSymbol &Symbol) const { return Symbol.hasData(); } - MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, - bool *Created = nullptr) { + void registerSymbol(const MCSymbol &Symbol, bool *Created = nullptr) { if (Created) *Created = !hasSymbolData(Symbol); if (!hasSymbolData(Symbol)) { Symbol.initializeData(); Symbols.push_back(&Symbol); } - return Symbol.getData(); } ArrayRef getFileNames() { return FileNames; } diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h index 4cc93c95ef6..a4d650b0219 100644 --- a/include/llvm/MC/MCObjectStreamer.h +++ b/include/llvm/MC/MCObjectStreamer.h @@ -56,8 +56,8 @@ public: /// Object streamers require the integrated assembler. bool isIntegratedAssemblerRequired() const override { return true; } - MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol) { - return getAssembler().getOrCreateSymbolData(*Symbol); + void getOrCreateSymbolData(const MCSymbol *Symbol) { + getAssembler().registerSymbol(*Symbol); } void EmitFrames(MCAsmBackend *MAB); void EmitCFISections(bool EH, bool Debug) override; diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 25d83d854df..6667f597bd0 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1256,7 +1256,7 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, MCSectionELF *RelSection = createRelocationSection(Ctx, Section); if (SignatureSymbol) { - Asm.getOrCreateSymbolData(*SignatureSymbol); + Asm.registerSymbol(*SignatureSymbol); unsigned &GroupIdx = RevGroupMap[SignatureSymbol]; if (!GroupIdx) { MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 7fb51ae4868..0554832dd5f 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -155,7 +155,7 @@ void MCELFStreamer::ChangeSection(MCSection *Section, auto *SectionELF = static_cast(Section); const MCSymbol *Grp = SectionELF->getGroup(); if (Grp) - Asm.getOrCreateSymbolData(*Grp); + Asm.registerSymbol(*Grp); this->MCObjectStreamer::ChangeSection(Section, Subsection); MCContext &Ctx = getContext(); @@ -165,13 +165,13 @@ void MCELFStreamer::ChangeSection(MCSection *Section, Section->setBeginSymbol(Begin); } if (Begin->isUndefined()) { - Asm.getOrCreateSymbolData(*Begin); + Asm.registerSymbol(*Begin); MCELF::SetType(*Begin, ELF::STT_SECTION); } } void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { - getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); const MCExpr *Value = MCSymbolRefExpr::Create( Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext()); Alias->setVariableValue(Value); @@ -211,9 +211,10 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, } // Adding a symbol attribute always introduces the symbol, note that an - // important side effect of calling getOrCreateSymbolData here is to register + // important side effect of calling registerSymbol here is to register // the symbol with the assembler. - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); // The implementation of symbol attributes is designed to match 'as', but it // leaves much to desired. It doesn't really make sense to arbitrarily add and @@ -311,8 +312,9 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, } void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) { - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + unsigned ByteAlignment) { + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); if (!BindingExplicitlySet.count(Symbol)) { MCELF::SetBinding(*Symbol, ELF::STB_GLOBAL); @@ -343,7 +345,8 @@ void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) { void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { // FIXME: Should this be caught and done earlier? - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); SD.setExternal(false); BindingExplicitlySet.insert(Symbol); @@ -460,7 +463,7 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) { case MCSymbolRefExpr::VK_PPC_TLSLD: break; } - getAssembler().getOrCreateSymbolData(symRef.getSymbol()); + getAssembler().registerSymbol(symRef.getSymbol()); MCELF::SetType(symRef.getSymbol(), ELF::STT_TLS); break; } diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 542a10cb855..9924c5d94ce 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -172,8 +172,8 @@ void MCMachOStreamer::ChangeSection(MCSection *Section, void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) { - MCSymbolData &SD = - getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); if (SD.isExternal()) EmitSymbolAttribute(EHSymbol, MCSA_Global); if (Symbol->getFlags() & SF_WeakDefinition) @@ -293,9 +293,10 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, } // Adding a symbol attribute always introduces the symbol, note that an - // important side effect of calling getOrCreateSymbolData here is to register + // important side effect of calling registerSymbol here is to register // the symbol with the assembler. - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); // The implementation of symbol attributes is designed to match 'as', but it // leaves much to desired. It doesn't really make sense to arbitrarily add and @@ -378,7 +379,7 @@ void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { // Encode the 'desc' value into the lowest implementation defined bits. assert(DescValue == (DescValue & SF_DescFlagsMask) && "Invalid .desc value!"); - getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); Symbol->setFlags(DescValue & SF_DescFlagsMask); } @@ -389,7 +390,8 @@ void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, AssignSection(Symbol, nullptr); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); SD.setExternal(true); Symbol->setCommon(Size, ByteAlignment); } @@ -414,7 +416,8 @@ void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); // Emit an align fragment if necessary. if (ByteAlignment != 1) diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index e608fe73f37..2a7aeab4d84 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -121,7 +121,7 @@ MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() { } void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) { - Assembler->getOrCreateSymbolData(Sym); + Assembler->registerSymbol(Sym); } void MCObjectStreamer::EmitCFISections(bool EH, bool Debug) { @@ -163,7 +163,8 @@ void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) { MCStreamer::EmitLabel(Symbol); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); assert(!SD.getFragment() && "Unexpected fragment on symbol data!"); // If there is a current fragment, mark the symbol as pointing into it. @@ -226,7 +227,7 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section, } void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { - getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); MCStreamer::EmitAssignment(Symbol, Value); } diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index 07427cf8b03..b84077b1a60 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -500,7 +500,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) { // Initialize the section indirect symbol base, if necessary. IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex)); - Asm.getOrCreateSymbolData(*it->Symbol); + Asm.registerSymbol(*it->Symbol); } // Then lazy symbol pointers and symbol stubs. @@ -520,7 +520,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) { // // FIXME: Do not hardcode. bool Created; - Asm.getOrCreateSymbolData(*it->Symbol, &Created); + Asm.registerSymbol(*it->Symbol, &Created); if (Created) it->Symbol->setFlags(it->Symbol->getFlags() | 0x0001); } diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 8b8d469c564..06c6a9780dd 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -96,7 +96,8 @@ bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, Symbol->getSection().getVariant() == MCSection::SV_COFF) && "Got non-COFF section in the COFF backend!"); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); switch (Attribute) { default: return false; @@ -136,7 +137,7 @@ void MCWinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) { FatalError("storage class value '" + Twine(StorageClass) + "' out of range"); - getAssembler().getOrCreateSymbolData(*CurSymbol); + getAssembler().registerSymbol(*CurSymbol); CurSymbol->modifyFlags(StorageClass << COFF::SF_ClassShift, COFF::SF_ClassMask); } @@ -148,7 +149,7 @@ void MCWinCOFFStreamer::EmitCOFFSymbolType(int Type) { if (Type & ~0xffff) FatalError("type value '" + Twine(Type) + "' out of range"); - getAssembler().getOrCreateSymbolData(*CurSymbol); + getAssembler().registerSymbol(*CurSymbol); CurSymbol->modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask); } @@ -195,7 +196,8 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, AssignSection(Symbol, nullptr); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); SD.setExternal(true); Symbol->setCommon(Size, ByteAlignment); @@ -224,7 +226,8 @@ void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, if (Section->getAlignment() < ByteAlignment) Section->setAlignment(ByteAlignment); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); SD.setExternal(false); AssignSection(Symbol, Section); diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 3bf480fb9a4..e80eeaee3c4 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -164,7 +164,8 @@ private: MCSymbol *Symbol = getContext().getOrCreateSymbol( Name + "." + Twine(MappingSymbolCounter++)); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); MCELF::SetType(*Symbol, ELF::STT_NOTYPE); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); SD.setExternal(false); diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 10d66e9d108..67762c59bfc 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -566,7 +566,8 @@ private: getContext().getOrCreateSymbol(Name + "." + Twine(MappingSymbolCounter++)); - MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); + getAssembler().registerSymbol(*Symbol); + MCSymbolData &SD = Symbol->getData(); MCELF::SetType(*Symbol, ELF::STT_NOTYPE); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); SD.setExternal(false); diff --git a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index aa414d73ac3..e947d1c2abc 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -689,7 +689,7 @@ void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) { StringRef SymName("_gp_disp"); MCAssembler &MCA = getStreamer().getAssembler(); MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName); - MCA.getOrCreateSymbolData(*GP_Disp); + MCA.registerSymbol(*GP_Disp); MCInst TmpInst; TmpInst.setOpcode(Mips::LUi);