llvm.org GIT mirror llvm / 93cf093
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 Rafael Espindola 6 years ago
12 changed file(s) with 35 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
1919
2020 class GlobalValue;
2121 class MCContext;
22 class MCSymbol;
2322 template class SmallVectorImpl;
2423 class TargetMachine;
2524 class Twine;
3332 };
3433
3534 private:
36 MCContext &Context;
3735 const TargetMachine *TM;
3836
3937 /// AnonGlobalIDs - We need to give global values the same name every time
4745 unsigned NextAnonGlobalID;
4846
4947 public:
50 Mangler(MCContext &Context, const TargetMachine *TM)
51 : Context(Context), TM(TM), NextAnonGlobalID(1) {}
52
53 /// getSymbol - Return the MCSymbol for the specified global value. This
54 /// symbol is the main label that is the address of the global.
55 MCSymbol *getSymbol(const GlobalValue *GV);
48 Mangler(const TargetMachine *TM) : TM(TM), NextAnonGlobalID(1) {}
5649
5750 /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
5851 /// and the specified global variable's name. If the global variable doesn't
116116 MachineModuleInfo *MMI, unsigned Encoding,
117117 MCStreamer &Streamer) const;
118118
119 /// Return the MCSymbol for the specified global value. This symbol is the
120 /// main label that is the address of the global
121 MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
122
119123 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
120124 virtual MCSymbol *
121125 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
163163
164164 OutStreamer.InitStreamer();
165165
166 Mang = new Mangler(OutContext, &TM);
166 Mang = new Mangler(&TM);
167167
168168 // Allow the target to emit any magic that it wants at the start of the file.
169169 EmitStartOfAsmFile(M);
263263 }
264264
265265 MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
266 return Mang->getSymbol(GV);
266 return getObjFileLowering().getSymbol(*Mang, GV);
267267 }
268268
269269 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
5151 default:
5252 report_fatal_error("We do not support this DWARF encoding yet!");
5353 case dwarf::DW_EH_PE_absptr:
54 return Mang->getSymbol(GV);
54 return getSymbol(*Mang, GV);
5555 case dwarf::DW_EH_PE_pcrel: {
5656 return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
57 Mang->getSymbol(GV)->getName());
57 getSymbol(*Mang, GV)->getName());
5858 }
5959 }
6060 }
103103 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
104104 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
105105 if (StubSym.getPointer() == 0) {
106 MCSymbol *Sym = Mang->getSymbol(GV);
106 MCSymbol *Sym = getSymbol(*Mang, GV);
107107 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
108108 }
109109
251251 Prefix = getSectionPrefixForGlobal(Kind);
252252
253253 SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
254 MCSymbol *Sym = Mang->getSymbol(GV);
254 MCSymbol *Sym = getSymbol(*Mang, GV);
255255 Name.append(Sym->getName().begin(), Sym->getName().end());
256256 StringRef Group = "";
257257 unsigned Flags = getELFSectionFlags(Kind);
612612 // FIXME: ObjC metadata is currently emitted as internal symbols that have
613613 // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and
614614 // this horrible hack can go away.
615 MCSymbol *Sym = Mang->getSymbol(GV);
615 MCSymbol *Sym = getSymbol(*Mang, GV);
616616 if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
617617 return false;
618618 }
641641 GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
642642 MachOMMI.getGVStubEntry(SSym);
643643 if (StubSym.getPointer() == 0) {
644 MCSymbol *Sym = Mang->getSymbol(GV);
644 MCSymbol *Sym = getSymbol(*Mang, GV);
645645 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
646646 }
647647
670670 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
671671 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
672672 if (StubSym.getPointer() == 0) {
673 MCSymbol *Sym = Mang->getSymbol(GV);
673 MCSymbol *Sym = getSymbol(*Mang, GV);
674674 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
675675 }
676676
349349 passes.add(createVerifierPass());
350350
351351 // mark which symbols can not be internalized
352 MCContext MContext(TargetMach->getMCAsmInfo(), TargetMach->getRegisterInfo(),
353 NULL);
354 Mangler Mangler(MContext, TargetMach);
352 Mangler Mangler(TargetMach);
355353 std::vector MustPreserveList;
356354 std::vector DSOList;
357355 SmallPtrSet AsmUsed;
4242 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
4343 : _module(m), _target(t),
4444 _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
45 _mangler(_context, t) {}
45 _mangler(t) {}
4646
4747 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
4848 /// bitcode.
4646 MCStreamer &Streamer) const {
4747 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
4848
49 return MCSymbolRefExpr::Create(Mang->getSymbol(GV),
49 return MCSymbolRefExpr::Create(getSymbol(*Mang, GV),
5050 MCSymbolRefExpr::VK_ARM_TARGET2,
5151 getContext());
5252 }
110110 StringRef Name = GVName.toStringRef(TmpData);
111111 assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
112112
113 const MCAsmInfo *MAI = Context.getAsmInfo();
113 const MCAsmInfo *MAI = TM->getMCAsmInfo();
114114
115115 // If the global name is not led with \1, add the appropriate prefixes.
116116 if (Name[0] == '\1') {
211211
212212 // If we are supposed to add a microsoft-style suffix for stdcall/fastcall,
213213 // add it.
214 if (Context.getAsmInfo()->hasMicrosoftFastStdCallMangling()) {
214 if (TM->getMCAsmInfo()->hasMicrosoftFastStdCallMangling()) {
215215 if (const Function *F = dyn_cast(GV)) {
216216 CallingConv::ID CC = F->getCallingConv();
217217
235235 }
236236 }
237237 }
238
239 /// getSymbol - Return the MCSymbol for the specified global value. This
240 /// symbol is the main label that is the address of the global.
241 MCSymbol *Mangler::getSymbol(const GlobalValue *GV) {
242 SmallString<60> NameStr;
243 getNameWithPrefix(NameStr, GV, false);
244 return Context.GetOrCreateSymbol(NameStr.str());
245 }
246
247
886886 const_cast(getObjFileLowering())
887887 .Initialize(OutContext, TM);
888888
889 Mang = new Mangler(OutContext, &TM);
889 Mang = new Mangler(&TM);
890890
891891 // Emit header before any dwarf directives are emitted below.
892892 emitHeader(M, OS1);
6767 }
6868
6969 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
70 TargetLoweringObjectFile::Initialize(ctx, TM);
7071 TextSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getText());
7172 DataSection =
7273 new NVPTXSection(MCSection::SV_ELF, SectionKind::getDataRel());
9696 return false;
9797 }
9898
99 /// Return the MCSymbol for the specified global value. This
100 /// symbol is the main label that is the address of the global.
101 MCSymbol *TargetLoweringObjectFile::getSymbol(Mangler &M,
102 const GlobalValue *GV) const {
103 SmallString<60> NameStr;
104 M.getNameWithPrefix(NameStr, GV, false);
105 return Ctx->GetOrCreateSymbol(NameStr.str());
106 }
107
108
99109 MCSymbol *TargetLoweringObjectFile::
100110 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
101111 MachineModuleInfo *MMI) const {
102 return Mang->getSymbol(GV);
112 return getSymbol(*Mang, GV);
103113 }
104114
105115 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
292302 MachineModuleInfo *MMI, unsigned Encoding,
293303 MCStreamer &Streamer) const {
294304 const MCSymbolRefExpr *Ref =
295 MCSymbolRefExpr::Create(Mang->getSymbol(GV), getContext());
305 MCSymbolRefExpr::Create(getSymbol(*Mang, GV), getContext());
296306
297307 return getTTypeReference(Ref, Encoding, Streamer);
298308 }
2424 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
2525 // is an indirect pc-relative reference.
2626 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
27 const MCSymbol *Sym = Mang->getSymbol(GV);
27 const MCSymbol *Sym = getSymbol(*Mang, GV);
2828 const MCExpr *Res =
2929 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
3030 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
3838 MCSymbol *X86_64MachoTargetObjectFile::
3939 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
4040 MachineModuleInfo *MMI) const {
41 return Mang->getSymbol(GV);
41 return getSymbol(*Mang, GV);
4242 }
4343
4444 void