From 93cf0939f95b3d580d9c05375a7c84164e1ba72e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 29 Oct 2013 17:28:26 +0000 Subject: Move getSymbol to TargetLoweringObjectFile. This allows constructing a Mangler with just a TargetMachine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193630 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/Mangler.h | 9 +-------- include/llvm/Target/TargetLoweringObjectFile.h | 4 ++++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 4 ++-- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 14 +++++++------- lib/LTO/LTOCodeGenerator.cpp | 4 +--- lib/LTO/LTOModule.cpp | 2 +- lib/Target/ARM/ARMTargetObjectFile.cpp | 2 +- lib/Target/Mangler.cpp | 14 ++------------ lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 2 +- lib/Target/NVPTX/NVPTXTargetObjectFile.h | 1 + lib/Target/TargetLoweringObjectFile.cpp | 14 ++++++++++++-- lib/Target/X86/X86TargetObjectFile.cpp | 4 ++-- 12 files changed, 35 insertions(+), 39 deletions(-) diff --git a/include/llvm/Target/Mangler.h b/include/llvm/Target/Mangler.h index e925cd5164..eee7bf6d69 100644 --- a/include/llvm/Target/Mangler.h +++ b/include/llvm/Target/Mangler.h @@ -20,7 +20,6 @@ namespace llvm { class GlobalValue; class MCContext; -class MCSymbol; template class SmallVectorImpl; class TargetMachine; class Twine; @@ -34,7 +33,6 @@ public: }; private: - MCContext &Context; const TargetMachine *TM; /// AnonGlobalIDs - We need to give global values the same name every time @@ -48,12 +46,7 @@ private: unsigned NextAnonGlobalID; public: - Mangler(MCContext &Context, const TargetMachine *TM) - : Context(Context), TM(TM), NextAnonGlobalID(1) {} - - /// getSymbol - Return the MCSymbol for the specified global value. This - /// symbol is the main label that is the address of the global. - MCSymbol *getSymbol(const GlobalValue *GV); + Mangler(const TargetMachine *TM) : TM(TM), NextAnonGlobalID(1) {} /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix /// and the specified global variable's name. If the global variable doesn't diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index 7f15b74258..284b6bbdb8 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -117,6 +117,10 @@ public: MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const; + /// Return the MCSymbol for the specified global value. This symbol is the + /// main label that is the address of the global + MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const; + // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality. virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 61f67e955f..37df93693e 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -164,7 +164,7 @@ bool AsmPrinter::doInitialization(Module &M) { OutStreamer.InitStreamer(); - Mang = new Mangler(OutContext, &TM); + Mang = new Mangler(&TM); // Allow the target to emit any magic that it wants at the start of the file. EmitStartOfAsmFile(M); @@ -264,7 +264,7 @@ void AsmPrinter::EmitLinkage(unsigned L, MCSymbol *GVSym) const { } MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const { - return Mang->getSymbol(GV); + return getObjFileLowering().getSymbol(*Mang, GV); } /// EmitGlobalVariable - Emit the specified global variable to the .s file. diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 085e8f4018..5d16f043e2 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -52,10 +52,10 @@ TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV, default: report_fatal_error("We do not support this DWARF encoding yet!"); case dwarf::DW_EH_PE_absptr: - return Mang->getSymbol(GV); + return getSymbol(*Mang, GV); case dwarf::DW_EH_PE_pcrel: { return getContext().GetOrCreateSymbol(StringRef("DW.ref.") + - Mang->getSymbol(GV)->getName()); + getSymbol(*Mang, GV)->getName()); } } } @@ -104,7 +104,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } @@ -252,7 +252,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Prefix = getSectionPrefixForGlobal(Kind); SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); Name.append(Sym->getName().begin(), Sym->getName().end()); StringRef Group = ""; unsigned Flags = getELFSectionFlags(Kind); @@ -613,7 +613,7 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { // FIXME: ObjC metadata is currently emitted as internal symbols that have // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and // this horrible hack can go away. - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l') return false; } @@ -642,7 +642,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) : MachOMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } @@ -671,7 +671,7 @@ getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 88f606160d..c55eccb7e3 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -350,9 +350,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { passes.add(createVerifierPass()); // mark which symbols can not be internalized - MCContext MContext(TargetMach->getMCAsmInfo(), TargetMach->getRegisterInfo(), - NULL); - Mangler Mangler(MContext, TargetMach); + Mangler Mangler(TargetMach); std::vector MustPreserveList; std::vector DSOList; SmallPtrSet AsmUsed; diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 98c5416d8d..db9b9c9dee 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -43,7 +43,7 @@ using namespace llvm; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) : _module(m), _target(t), _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL), - _mangler(_context, t) {} + _mangler(t) {} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// bitcode. diff --git a/lib/Target/ARM/ARMTargetObjectFile.cpp b/lib/Target/ARM/ARMTargetObjectFile.cpp index dfdf6ab356..7ec71b20c6 100644 --- a/lib/Target/ARM/ARMTargetObjectFile.cpp +++ b/lib/Target/ARM/ARMTargetObjectFile.cpp @@ -47,7 +47,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MCStreamer &Streamer) const { assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only"); - return MCSymbolRefExpr::Create(Mang->getSymbol(GV), + return MCSymbolRefExpr::Create(getSymbol(*Mang, GV), MCSymbolRefExpr::VK_ARM_TARGET2, getContext()); } diff --git a/lib/Target/Mangler.cpp b/lib/Target/Mangler.cpp index f86428cff2..1deaf2b115 100644 --- a/lib/Target/Mangler.cpp +++ b/lib/Target/Mangler.cpp @@ -111,7 +111,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl &OutName, StringRef Name = GVName.toStringRef(TmpData); assert(!Name.empty() && "getNameWithPrefix requires non-empty name"); - const MCAsmInfo *MAI = Context.getAsmInfo(); + const MCAsmInfo *MAI = TM->getMCAsmInfo(); // If the global name is not led with \1, add the appropriate prefixes. if (Name[0] == '\1') { @@ -212,7 +212,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl &OutName, // If we are supposed to add a microsoft-style suffix for stdcall/fastcall, // add it. - if (Context.getAsmInfo()->hasMicrosoftFastStdCallMangling()) { + if (TM->getMCAsmInfo()->hasMicrosoftFastStdCallMangling()) { if (const Function *F = dyn_cast(GV)) { CallingConv::ID CC = F->getCallingConv(); @@ -236,13 +236,3 @@ void Mangler::getNameWithPrefix(SmallVectorImpl &OutName, } } } - -/// getSymbol - Return the MCSymbol for the specified global value. This -/// symbol is the main label that is the address of the global. -MCSymbol *Mangler::getSymbol(const GlobalValue *GV) { - SmallString<60> NameStr; - getNameWithPrefix(NameStr, GV, false); - return Context.GetOrCreateSymbol(NameStr.str()); -} - - diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index e5ca860f9e..0f8649f813 100644 --- a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -887,7 +887,7 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) { const_cast(getObjFileLowering()) .Initialize(OutContext, TM); - Mang = new Mangler(OutContext, &TM); + Mang = new Mangler(&TM); // Emit header before any dwarf directives are emitted below. emitHeader(M, OS1); diff --git a/lib/Target/NVPTX/NVPTXTargetObjectFile.h b/lib/Target/NVPTX/NVPTXTargetObjectFile.h index bfd6ab12f4..1449f52a96 100644 --- a/lib/Target/NVPTX/NVPTXTargetObjectFile.h +++ b/lib/Target/NVPTX/NVPTXTargetObjectFile.h @@ -68,6 +68,7 @@ public: } virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { + TargetLoweringObjectFile::Initialize(ctx, TM); TextSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getText()); DataSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getDataRel()); diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index cd810b624f..7b8d1108f1 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -97,10 +97,20 @@ static bool IsNullTerminatedString(const Constant *C) { return false; } +/// Return the MCSymbol for the specified global value. This +/// symbol is the main label that is the address of the global. +MCSymbol *TargetLoweringObjectFile::getSymbol(Mangler &M, + const GlobalValue *GV) const { + SmallString<60> NameStr; + M.getNameWithPrefix(NameStr, GV, false); + return Ctx->GetOrCreateSymbol(NameStr.str()); +} + + MCSymbol *TargetLoweringObjectFile:: getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI) const { - return Mang->getSymbol(GV); + return getSymbol(*Mang, GV); } void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer, @@ -293,7 +303,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const { const MCSymbolRefExpr *Ref = - MCSymbolRefExpr::Create(Mang->getSymbol(GV), getContext()); + MCSymbolRefExpr::Create(getSymbol(*Mang, GV), getContext()); return getTTypeReference(Ref, Encoding, Streamer); } diff --git a/lib/Target/X86/X86TargetObjectFile.cpp b/lib/Target/X86/X86TargetObjectFile.cpp index a19c5a601e..086cd4de53 100644 --- a/lib/Target/X86/X86TargetObjectFile.cpp +++ b/lib/Target/X86/X86TargetObjectFile.cpp @@ -25,7 +25,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which // is an indirect pc-relative reference. if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { - const MCSymbol *Sym = Mang->getSymbol(GV); + const MCSymbol *Sym = getSymbol(*Mang, GV); const MCExpr *Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext()); const MCExpr *Four = MCConstantExpr::Create(4, getContext()); @@ -39,7 +39,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MCSymbol *X86_64MachoTargetObjectFile:: getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI) const { - return Mang->getSymbol(GV); + return getSymbol(*Mang, GV); } void -- cgit v1.2.3