llvm.org GIT mirror llvm / b4aafff
move getNameWithPrefix and getSymbol to TargetMachine. TargetLoweringBase is implemented in CodeGen, so before this patch we had a dependency fom Target to CodeGen. This would show up as a link failure of llvm-stress when building with -DBUILD_SHARED_LIBS=ON. This fixes pr18900. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201711 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
14 changed file(s) with 60 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
13441344 return LibcallCallingConvs[Call];
13451345 }
13461346
1347 void getNameWithPrefix(SmallVectorImpl &Name, const GlobalValue *GV,
1348 Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
1349 MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
1350
13511347 private:
13521348 const TargetMachine &TM;
13531349 const DataLayout *DL;
2525 class InstrItineraryData;
2626 class JITCodeEmitter;
2727 class GlobalValue;
28 class Mangler;
2829 class MCAsmInfo;
2930 class MCCodeGenInfo;
3031 class MCContext;
32 class MCSymbol;
3133 class Target;
3234 class DataLayout;
3335 class TargetLibraryInfo;
288290 bool /*DisableVerify*/ = true) {
289291 return true;
290292 }
293
294 void getNameWithPrefix(SmallVectorImpl &Name, const GlobalValue *GV,
295 Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
296 MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
291297 };
292298
293299 /// LLVMTargetMachine - This class describes a target machine that is
312312
313313 void AsmPrinter::getNameWithPrefix(SmallVectorImpl &Name,
314314 const GlobalValue *GV) const {
315 TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
315 TM.getNameWithPrefix(Name, GV, *Mang);
316316 }
317317
318318 MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
319 return TM.getTargetLowering()->getSymbol(GV, *Mang);
319 return TM.getSymbol(GV, *Mang);
320320 }
321321
322322 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
14271427
14281428 return true;
14291429 }
1430
1431 void TargetLoweringBase::getNameWithPrefix(SmallVectorImpl &Name,
1432 const GlobalValue *GV,
1433 Mangler &Mang,
1434 bool MayAlwaysUsePrivate) const {
1435 if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
1436 // Simple case: If GV is not private, it is not important to find out if
1437 // private labels are legal in this case or not.
1438 Mang.getNameWithPrefix(Name, GV, false);
1439 return;
1440 }
1441 SectionKind GVKind =
1442 TargetLoweringObjectFile::getKindForGlobal(GV, getTargetMachine());
1443 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
1444 const MCSection *TheSection =
1445 TLOF.SectionForGlobal(GV, GVKind, Mang, getTargetMachine());
1446 bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
1447 Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
1448 }
1449
1450 MCSymbol *TargetLoweringBase::getSymbol(const GlobalValue *GV,
1451 Mangler &Mang) const {
1452 SmallString<60> NameStr;
1453 getNameWithPrefix(NameStr, GV, Mang);
1454 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
1455 return TLOF.getContext().GetOrCreateSymbol(NameStr.str());
1456 }
5151 default:
5252 report_fatal_error("We do not support this DWARF encoding yet!");
5353 case dwarf::DW_EH_PE_absptr:
54 return TM.getTargetLowering()->getSymbol(GV, Mang);
54 return TM.getSymbol(GV, Mang);
5555 case dwarf::DW_EH_PE_pcrel: {
5656 return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
57 TM.getTargetLowering()->getSymbol(GV, Mang)->getName());
57 TM.getSymbol(GV, Mang)->getName());
5858 }
5959 }
6060 }
100100 // gets emitted by the asmprinter.
101101 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
102102 if (StubSym.getPointer() == 0) {
103 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
103 MCSymbol *Sym = TM.getSymbol(GV, Mang);
104104 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
105105 }
106106
247247 Prefix = getSectionPrefixForGlobal(Kind);
248248
249249 SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
250 TM.getTargetLowering()->getNameWithPrefix(Name, GV, Mang, true);
250 TM.getNameWithPrefix(Name, GV, Mang, true);
251251
252252 StringRef Group = "";
253253 unsigned Flags = getELFSectionFlags(Kind);
650650 // FIXME: ObjC metadata is currently emitted as internal symbols that have
651651 // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and
652652 // this horrible hack can go away.
653 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
653 MCSymbol *Sym = TM.getSymbol(GV, Mang);
654654 if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
655655 return false;
656656 }
677677 GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
678678 MachOMMI.getGVStubEntry(SSym);
679679 if (StubSym.getPointer() == 0) {
680 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
680 MCSymbol *Sym = TM.getSymbol(GV, Mang);
681681 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
682682 }
683683
703703 // gets emitted by the asmprinter.
704704 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
705705 if (StubSym.getPointer() == 0) {
706 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
706 MCSymbol *Sym = TM.getSymbol(GV, Mang);
707707 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
708708 }
709709
759759 if (GV->isWeakForLinker()) {
760760 Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
761761 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
762 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
762 MCSymbol *Sym = TM.getSymbol(GV, Mang);
763763 COMDATSymName = Sym->getName();
764764 }
765765 return getContext().getCOFFSection(Name,
793793 unsigned Characteristics = getCOFFSectionFlags(Kind);
794794
795795 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
796 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
796 MCSymbol *Sym = TM.getSymbol(GV, Mang);
797797 return getContext().getCOFFSection(Name, Characteristics,
798798 Kind, Sym->getName(),
799799 COFF::IMAGE_COMDAT_SELECT_ANY);
371371 // load address of the symbol, not the local address.
372372 Mangler Mang(TM->getDataLayout());
373373 SmallString<128> Name;
374 TM->getTargetLowering()->getNameWithPrefix(Name, F, Mang);
374 TM->getNameWithPrefix(Name, F, Mang);
375375 return (void*)Dyld.getSymbolLoadAddress(Name);
376376 }
377377
343343 return;
344344
345345 SmallString<64> Buffer;
346 TargetMach->getTargetLowering()->getNameWithPrefix(Buffer, &GV, Mangler);
346 TargetMach->getNameWithPrefix(Buffer, &GV, Mangler);
347347
348348 if (MustPreserveSymbols.count(Buffer))
349349 MustPreserveList.push_back(GV.getName().data());
390390
391391 // string is owned by _defines
392392 SmallString<64> Buffer;
393 _target->getTargetLowering()->getNameWithPrefix(Buffer, def, _mangler);
393 _target->getNameWithPrefix(Buffer, def, _mangler);
394394
395395 // set alignment part log2() can have rounding errors
396396 uint32_t align = def->getAlignment();
526526 return;
527527
528528 SmallString<64> name;
529 _target->getTargetLowering()->getNameWithPrefix(name, decl, _mangler);
529 _target->getNameWithPrefix(name, decl, _mangler);
530530
531531 StringMap::value_type &entry =
532532 _undefines.GetOrCreateValue(name);
4646 MCStreamer &Streamer) const {
4747 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
4848
49 return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
49 return MCSymbolRefExpr::Create(TM.getSymbol(GV, Mang),
5050 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
5151 }
5252
5656 Mang->getNameWithPrefix(Name, MO.getSymbolName());
5757 } else {
5858 const GlobalValue *GV = MO.getGlobal();
59 TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
59 TM.getNameWithPrefix(Name, GV, *Mang);
6060 }
6161
6262 unsigned OrigLen = Name.size() - PrefixLen;
2828 // gets emitted by the asmprinter.
2929 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
3030 if (StubSym.getPointer() == 0) {
31 MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
31 MCSymbol *Sym = TM.getSymbol(GV, Mang);
3232 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
3333 }
3434
106106
107107 SmallString<60> NameStr;
108108 NameStr += DL->getPrivateGlobalPrefix();
109 TM.getTargetLowering()->getNameWithPrefix(NameStr, GV, Mang);
109 TM.getNameWithPrefix(NameStr, GV, Mang);
110110 NameStr.append(Suffix.begin(), Suffix.end());
111111 return Ctx->GetOrCreateSymbol(NameStr.str());
112112 }
114114 MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
115115 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
116116 MachineModuleInfo *MMI) const {
117 return TM.getTargetLowering()->getSymbol(GV, Mang);
117 return TM.getSymbol(GV, Mang);
118118 }
119119
120120 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
311311 const TargetMachine &TM, MachineModuleInfo *MMI,
312312 MCStreamer &Streamer) const {
313313 const MCSymbolRefExpr *Ref =
314 MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
315 getContext());
314 MCSymbolRefExpr::Create(TM.getSymbol(GV, Mang), getContext());
316315
317316 return getTTypeReference(Ref, Encoding, Streamer);
318317 }
1616 #include "llvm/IR/GlobalAlias.h"
1717 #include "llvm/IR/GlobalValue.h"
1818 #include "llvm/IR/GlobalVariable.h"
19 #include "llvm/IR/Mangler.h"
1920 #include "llvm/MC/MCAsmInfo.h"
2021 #include "llvm/MC/MCCodeGenInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/SectionKind.h"
2124 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Target/TargetLowering.h"
26 #include "llvm/Target/TargetLoweringObjectFile.h"
2227 using namespace llvm;
2328
2429 //---------------------------------------------------------------------------
191196 void TargetMachine::setDataSections(bool V) {
192197 DataSections = V;
193198 }
199
200 void TargetMachine::getNameWithPrefix(SmallVectorImpl &Name,
201 const GlobalValue *GV, Mangler &Mang,
202 bool MayAlwaysUsePrivate) const {
203 if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
204 // Simple case: If GV is not private, it is not important to find out if
205 // private labels are legal in this case or not.
206 Mang.getNameWithPrefix(Name, GV, false);
207 return;
208 }
209 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, *this);
210 const TargetLoweringObjectFile &TLOF =
211 getTargetLowering()->getObjFileLowering();
212 const MCSection *TheSection = TLOF.SectionForGlobal(GV, GVKind, Mang, *this);
213 bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
214 Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
215 }
216
217 MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV, Mangler &Mang) const {
218 SmallString<60> NameStr;
219 getNameWithPrefix(NameStr, GV, Mang);
220 const TargetLoweringObjectFile &TLOF =
221 getTargetLowering()->getObjFileLowering();
222 return TLOF.getContext().GetOrCreateSymbol(NameStr.str());
223 }
2626 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
2727 // is an indirect pc-relative reference.
2828 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
29 const MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
29 const MCSymbol *Sym = TM.getSymbol(GV, Mang);
3030 const MCExpr *Res =
3131 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
3232 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
4040 MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
4141 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
4242 MachineModuleInfo *MMI) const {
43 return TM.getTargetLowering()->getSymbol(GV, Mang);
43 return TM.getSymbol(GV, Mang);
4444 }
4545
4646 void
101101 if (GVLHS->isThreadLocal())
102102 return 0;
103103
104 return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GVLHS, Mang),
104 return MCSymbolRefExpr::Create(TM.getSymbol(GVLHS, Mang),
105105 MCSymbolRefExpr::VK_COFF_IMGREL32,
106106 getContext());
107107 }