move getNameWithPrefix and getSymbol to TargetMachine.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 19 Feb 2014 20:30:41 +0000 (20:30 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 19 Feb 2014 20:30:41 +0000 (20:30 +0000)
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

14 files changed:
include/llvm/Target/TargetLowering.h
include/llvm/Target/TargetMachine.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/TargetLoweringBase.cpp
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/ExecutionEngine/MCJIT/MCJIT.cpp
lib/LTO/LTOCodeGenerator.cpp
lib/LTO/LTOModule.cpp
lib/Target/ARM/ARMTargetObjectFile.cpp
lib/Target/PowerPC/PPCMCInstLower.cpp
lib/Target/Sparc/SparcTargetObjectFile.cpp
lib/Target/TargetLoweringObjectFile.cpp
lib/Target/TargetMachine.cpp
lib/Target/X86/X86TargetObjectFile.cpp

index 0b3428ed7a6a791f0a83a43e39cfb3fe4df2ded5..ddcb27cadfa68ba782b18f22430911c5b89f0e8e 100644 (file)
@@ -1345,10 +1345,6 @@ public:
     return LibcallCallingConvs[Call];
   }
 
-  void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
-                         Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
-  MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
-
 private:
   const TargetMachine &TM;
   const DataLayout *DL;
index 5bf8d01d63dd6a45e7046fc65edba19cf57e2d79..85b009afe88fbf762e9a22cb3fe91ccc754a4fd7 100644 (file)
@@ -26,9 +26,11 @@ namespace llvm {
 class InstrItineraryData;
 class JITCodeEmitter;
 class GlobalValue;
+class Mangler;
 class MCAsmInfo;
 class MCCodeGenInfo;
 class MCContext;
+class MCSymbol;
 class Target;
 class DataLayout;
 class TargetLibraryInfo;
@@ -289,6 +291,10 @@ public:
                                  bool /*DisableVerify*/ = true) {
     return true;
   }
+
+  void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
+                         Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
+  MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
 };
 
 /// LLVMTargetMachine - This class describes a target machine that is
index 6c4cddc3f6ed3f89c975d67e7d7a8b2199df00bb..6ed2991dede58e66b077b192280cc41b28097b3a 100644 (file)
@@ -313,11 +313,11 @@ void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
 
 void AsmPrinter::getNameWithPrefix(SmallVectorImpl<char> &Name,
                                    const GlobalValue *GV) const {
-  TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
+  TM.getNameWithPrefix(Name, GV, *Mang);
 }
 
 MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
-  return TM.getTargetLowering()->getSymbol(GV, *Mang);
+  return TM.getSymbol(GV, *Mang);
 }
 
 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
index d3c42be5e6c951899e609db6af5ff8c931a35025..47a86d601ba151d16eb12274cf223b196366f4d0 100644 (file)
@@ -1428,30 +1428,3 @@ bool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
 
   return true;
 }
-
-void TargetLoweringBase::getNameWithPrefix(SmallVectorImpl<char> &Name,
-                                           const GlobalValue *GV,
-                                           Mangler &Mang,
-                                           bool MayAlwaysUsePrivate) const {
-  if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
-    // Simple case: If GV is not private, it is not important to find out if
-    // private labels are legal in this case or not.
-    Mang.getNameWithPrefix(Name, GV, false);
-    return;
-  }
-  SectionKind GVKind =
-    TargetLoweringObjectFile::getKindForGlobal(GV, getTargetMachine());
-  const TargetLoweringObjectFile &TLOF = getObjFileLowering();
-  const MCSection *TheSection =
-    TLOF.SectionForGlobal(GV, GVKind, Mang, getTargetMachine());
-  bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
-  Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
-}
-
-MCSymbol *TargetLoweringBase::getSymbol(const GlobalValue *GV,
-                                        Mangler &Mang) const {
-  SmallString<60> NameStr;
-  getNameWithPrefix(NameStr, GV, Mang);
-  const TargetLoweringObjectFile &TLOF = getObjFileLowering();
-  return TLOF.getContext().GetOrCreateSymbol(NameStr.str());
-}
index bd54a871ca3cedf0d38eff3792c4dc6e4f353dd0..0f3fb4924b430c93b4f8fb3c379f32ea2d7ac7ac 100644 (file)
@@ -52,10 +52,10 @@ MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
   default:
     report_fatal_error("We do not support this DWARF encoding yet!");
   case dwarf::DW_EH_PE_absptr:
-    return TM.getTargetLowering()->getSymbol(GV, Mang);
+    return TM.getSymbol(GV, Mang);
   case dwarf::DW_EH_PE_pcrel: {
     return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
-                        TM.getTargetLowering()->getSymbol(GV, Mang)->getName());
+                                          TM.getSymbol(GV, Mang)->getName());
   }
   }
 }
@@ -101,7 +101,7 @@ const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
     // gets emitted by the asmprinter.
     MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
     if (StubSym.getPointer() == 0) {
-      MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+      MCSymbol *Sym = TM.getSymbol(GV, Mang);
       StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
     }
 
@@ -248,7 +248,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
     Prefix = getSectionPrefixForGlobal(Kind);
 
     SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
-    TM.getTargetLowering()->getNameWithPrefix(Name, GV, Mang, true);
+    TM.getNameWithPrefix(Name, GV, Mang, true);
 
     StringRef Group = "";
     unsigned Flags = getELFSectionFlags(Kind);
@@ -651,7 +651,7 @@ bool TargetLoweringObjectFileMachO::shouldEmitUsedDirectiveFor(
     // 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 = TM.getTargetLowering()->getSymbol(GV, Mang);
+    MCSymbol *Sym = TM.getSymbol(GV, Mang);
     if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
       return false;
   }
@@ -678,7 +678,7 @@ const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
       GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
                                   MachOMMI.getGVStubEntry(SSym);
     if (StubSym.getPointer() == 0) {
-      MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+      MCSymbol *Sym = TM.getSymbol(GV, Mang);
       StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
     }
 
@@ -704,7 +704,7 @@ MCSymbol *TargetLoweringObjectFileMachO::getCFIPersonalitySymbol(
   // gets emitted by the asmprinter.
   MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
   if (StubSym.getPointer() == 0) {
-    MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+    MCSymbol *Sym = TM.getSymbol(GV, Mang);
     StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
   }
 
@@ -760,7 +760,7 @@ const MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
   if (GV->isWeakForLinker()) {
     Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
     Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
-    MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+    MCSymbol *Sym = TM.getSymbol(GV, Mang);
     COMDATSymName = Sym->getName();
   }
   return getContext().getCOFFSection(Name,
@@ -794,7 +794,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
     unsigned Characteristics = getCOFFSectionFlags(Kind);
 
     Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
-    MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+    MCSymbol *Sym = TM.getSymbol(GV, Mang);
     return getContext().getCOFFSection(Name, Characteristics,
                                        Kind, Sym->getName(),
                                        COFF::IMAGE_COMDAT_SELECT_ANY);
index 4d5723a7a1369022c049f9e638d07b37caf326f6..f94185d4a46da24e2347a9f0dc6d8371d2fe6a62 100644 (file)
@@ -372,7 +372,7 @@ void *MCJIT::getPointerToFunction(Function *F) {
   // load address of the symbol, not the local address.
   Mangler Mang(TM->getDataLayout());
   SmallString<128> Name;
-  TM->getTargetLowering()->getNameWithPrefix(Name, F, Mang);
+  TM->getNameWithPrefix(Name, F, Mang);
   return (void*)Dyld.getSymbolLoadAddress(Name);
 }
 
index b03b1da01af3ae0bf19513dd7d29e4eaaf05379f..2b37802efc4a71b2487820a1936e79f19f9d09c6 100644 (file)
@@ -344,7 +344,7 @@ applyRestriction(GlobalValue &GV,
     return;
 
   SmallString<64> Buffer;
-  TargetMach->getTargetLowering()->getNameWithPrefix(Buffer, &GV, Mangler);
+  TargetMach->getNameWithPrefix(Buffer, &GV, Mangler);
 
   if (MustPreserveSymbols.count(Buffer))
     MustPreserveList.push_back(GV.getName().data());
index 86b67ef205e92b300e10ba32eeb962329e7b2bd8..fb20806634878fd9382981167aba20bfcc727fa4 100644 (file)
@@ -391,7 +391,7 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) {
 
   // string is owned by _defines
   SmallString<64> Buffer;
-  _target->getTargetLowering()->getNameWithPrefix(Buffer, def, _mangler);
+  _target->getNameWithPrefix(Buffer, def, _mangler);
 
   // set alignment part log2() can have rounding errors
   uint32_t align = def->getAlignment();
@@ -527,7 +527,7 @@ LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) {
     return;
 
   SmallString<64> name;
-  _target->getTargetLowering()->getNameWithPrefix(name, decl, _mangler);
+  _target->getNameWithPrefix(name, decl, _mangler);
 
   StringMap<NameAndAttributes>::value_type &entry =
     _undefines.GetOrCreateValue(name);
index 4e81fcdc3abbd873854b4b233c7cec9d5fac881b..3379f85b4ec12e5b0a31bcf2a7a0d7b0d6c6696c 100644 (file)
@@ -47,7 +47,7 @@ const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
     MCStreamer &Streamer) const {
   assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
 
-  return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
+  return MCSymbolRefExpr::Create(TM.getSymbol(GV, Mang),
                                  MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
 }
 
index cc40361cfc74ec6717799d01720c0989b8f7ca55..029bb8a70a55a5296a1cec2d350c4c1a2a19b977 100644 (file)
@@ -57,7 +57,7 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
     Mang->getNameWithPrefix(Name, MO.getSymbolName());
   } else {
     const GlobalValue *GV = MO.getGlobal();
-    TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
+    TM.getNameWithPrefix(Name, GV, *Mang);
   }
 
   unsigned OrigLen = Name.size() - PrefixLen;
index b732e18d816e676af5efe4d3190b3d513beaf8a9..f1630e0c319c62e00c99dca815e8bbdf6205ecdf 100644 (file)
@@ -29,7 +29,7 @@ const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
     // gets emitted by the asmprinter.
     MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
     if (StubSym.getPointer() == 0) {
-      MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
+      MCSymbol *Sym = TM.getSymbol(GV, Mang);
       StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
     }
 
index 9fff220d47dfa34805966908222ea39d7215245e..dea52474345c583074be277a2a82f2fcd81706db 100644 (file)
@@ -107,7 +107,7 @@ MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
 
   SmallString<60> NameStr;
   NameStr += DL->getPrivateGlobalPrefix();
-  TM.getTargetLowering()->getNameWithPrefix(NameStr, GV, Mang);
+  TM.getNameWithPrefix(NameStr, GV, Mang);
   NameStr.append(Suffix.begin(), Suffix.end());
   return Ctx->GetOrCreateSymbol(NameStr.str());
 }
@@ -115,7 +115,7 @@ MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
 MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
     const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
     MachineModuleInfo *MMI) const {
-  return TM.getTargetLowering()->getSymbol(GV, Mang);
+  return TM.getSymbol(GV, Mang);
 }
 
 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
@@ -312,8 +312,7 @@ const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
     const TargetMachine &TM, MachineModuleInfo *MMI,
     MCStreamer &Streamer) const {
   const MCSymbolRefExpr *Ref =
-    MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
-                            getContext());
+      MCSymbolRefExpr::Create(TM.getSymbol(GV, Mang), getContext());
 
   return getTTypeReference(Ref, Encoding, Streamer);
 }
index 8c99bffc00f201ddd720d34a9840c348a0a96147..f8a58ec2922c26d627f26ea582ee23fbe3382a33 100644 (file)
 #include "llvm/IR/GlobalAlias.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Mangler.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCCodeGenInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/SectionKind.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
 using namespace llvm;
 
 //---------------------------------------------------------------------------
@@ -192,3 +197,28 @@ void TargetMachine::setFunctionSections(bool V) {
 void TargetMachine::setDataSections(bool V) {
   DataSections = V;
 }
+
+void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
+                                      const GlobalValue *GV, Mangler &Mang,
+                                      bool MayAlwaysUsePrivate) const {
+  if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
+    // Simple case: If GV is not private, it is not important to find out if
+    // private labels are legal in this case or not.
+    Mang.getNameWithPrefix(Name, GV, false);
+    return;
+  }
+  SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, *this);
+  const TargetLoweringObjectFile &TLOF =
+      getTargetLowering()->getObjFileLowering();
+  const MCSection *TheSection = TLOF.SectionForGlobal(GV, GVKind, Mang, *this);
+  bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
+  Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
+}
+
+MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV, Mangler &Mang) const {
+  SmallString<60> NameStr;
+  getNameWithPrefix(NameStr, GV, Mang);
+  const TargetLoweringObjectFile &TLOF =
+      getTargetLowering()->getObjFileLowering();
+  return TLOF.getContext().GetOrCreateSymbol(NameStr.str());
+}
index 95fccba48ac6442042e9174c940576cdb4f694bd..0a88e984c8babbec20f5af8616e4383dd1745256 100644 (file)
@@ -27,7 +27,7 @@ const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
   // 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 = TM.getTargetLowering()->getSymbol(GV, Mang);
+    const MCSymbol *Sym = TM.getSymbol(GV, Mang);
     const MCExpr *Res =
       MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
     const MCExpr *Four = MCConstantExpr::Create(4, getContext());
@@ -41,7 +41,7 @@ const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
 MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
     const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
     MachineModuleInfo *MMI) const {
-  return TM.getTargetLowering()->getSymbol(GV, Mang);
+  return TM.getSymbol(GV, Mang);
 }
 
 void
@@ -102,7 +102,7 @@ const MCExpr *X86WindowsTargetObjectFile::getExecutableRelativeSymbol(
   if (GVLHS->isThreadLocal())
     return 0;
 
-  return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GVLHS, Mang),
+  return MCSymbolRefExpr::Create(TM.getSymbol(GVLHS, Mang),
                                  MCSymbolRefExpr::VK_COFF_IMGREL32,
                                  getContext());
 }