summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-06-27 23:15:57 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-06-27 23:15:57 +0000
commit3beef8d6db3688b8265728a3b05970cd9628f523 (patch)
tree310d78331dae592b820e026554e21456ed5535d7 /llvm/lib/Target
parent990ff38786ce2300a38eeaaba510c40170223ef6 (diff)
downloadbcm5719-llvm-3beef8d6db3688b8265728a3b05970cd9628f523.tar.gz
bcm5719-llvm-3beef8d6db3688b8265728a3b05970cd9628f523.zip
Move shouldAssumeDSOLocal to Target.
Should fix the shared library build. llvm-svn: 273958
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/AArch64/AArch64Subtarget.cpp3
-rw-r--r--llvm/lib/Target/ARM/ARMFastISel.cpp5
-rw-r--r--llvm/lib/Target/ARM/ARMISelLowering.cpp10
-rw-r--r--llvm/lib/Target/ARM/ARMSubtarget.cpp2
-rw-r--r--llvm/lib/Target/Hexagon/HexagonISelLowering.cpp3
-rw-r--r--llvm/lib/Target/PowerPC/PPCISelLowering.cpp4
-rw-r--r--llvm/lib/Target/PowerPC/PPCSubtarget.cpp3
-rw-r--r--llvm/lib/Target/SystemZ/SystemZISelLowering.cpp3
-rw-r--r--llvm/lib/Target/SystemZ/SystemZSubtarget.cpp3
-rw-r--r--llvm/lib/Target/SystemZ/SystemZSubtarget.h3
-rw-r--r--llvm/lib/Target/TargetMachine.cpp47
-rw-r--r--llvm/lib/Target/X86/X86Subtarget.cpp5
12 files changed, 60 insertions, 31 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
index 20faf8e6d2e..572cf7d7dca 100644
--- a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -112,8 +112,7 @@ AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
return AArch64II::MO_GOT;
- Reloc::Model RM = TM.getRelocationModel();
- if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV))
+ if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
return AArch64II::MO_GOT;
// The small code mode's direct accesses use ADRP, which cannot necessarily
diff --git a/llvm/lib/Target/ARM/ARMFastISel.cpp b/llvm/lib/Target/ARM/ARMFastISel.cpp
index 84160ce5e84..dc6782f9a3a 100644
--- a/llvm/lib/Target/ARM/ARMFastISel.cpp
+++ b/llvm/lib/Target/ARM/ARMFastISel.cpp
@@ -2935,10 +2935,7 @@ bool ARMFastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
unsigned ARMFastISel::ARMLowerPICELF(const GlobalValue *GV,
unsigned Align, MVT VT) {
- Reloc::Model RM = TM.getRelocationModel();
- const Triple &TargetTriple = TM.getTargetTriple();
- bool UseGOT_PREL =
- !shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV);
+ bool UseGOT_PREL = !TM.shouldAssumeDSOLocal(*GV->getParent(), GV);
LLVMContext *Context = &MF->getFunction()->getContext();
unsigned ARMPCLabelIndex = AFI->createPICLabelUId();
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index dd7f5218bd5..1ca216a60a2 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -1802,15 +1802,12 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
bool isDirect = false;
const TargetMachine &TM = getTargetMachine();
- Reloc::Model RM = TM.getRelocationModel();
- const Triple &TargetTriple = TM.getTargetTriple();
const Module *Mod = MF.getFunction()->getParent();
const GlobalValue *GV = nullptr;
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
GV = G->getGlobal();
bool isStub =
- !shouldAssumeDSOLocal(RM, TargetTriple, *Mod, GV) &&
- Subtarget->isTargetMachO();
+ !TM.shouldAssumeDSOLocal(*Mod, GV) && Subtarget->isTargetMachO();
bool isARMFunc = !Subtarget->isThumb() || (isStub && !Subtarget->isMClass());
bool isLocalARMFunc = false;
@@ -2799,11 +2796,8 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
SDLoc dl(Op);
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
const TargetMachine &TM = getTargetMachine();
- Reloc::Model RM = TM.getRelocationModel();
- const Triple &TargetTriple = TM.getTargetTriple();
if (isPositionIndependent()) {
- bool UseGOT_PREL =
- !shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV);
+ bool UseGOT_PREL = !TM.shouldAssumeDSOLocal(*GV->getParent(), GV);
MachineFunction &MF = DAG.getMachineFunction();
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
diff --git a/llvm/lib/Target/ARM/ARMSubtarget.cpp b/llvm/lib/Target/ARM/ARMSubtarget.cpp
index 8bc22d18920..719ac77e8dc 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ b/llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -264,7 +264,7 @@ bool ARMSubtarget::isAAPCS16_ABI() const {
bool
ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
Reloc::Model RelocM) const {
- if (!shouldAssumeDSOLocal(RelocM, TargetTriple, *GV->getParent(), GV))
+ if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
return true;
// 32 bit macho has no relocation for a-b if a is undefined, even if b is in
diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
index 2fa0bfd5765..98e4a27834c 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
@@ -1503,8 +1503,7 @@ HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const {
return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA);
}
- const Triple &TargetTriple = HTM.getTargetTriple();
- bool UsePCRel = shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV);
+ bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV);
if (UsePCRel) {
SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset,
HexagonII::MO_PCREL);
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index 3d3cd414942..b895f3fe80c 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -4278,7 +4278,7 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
// PC-relative references to external symbols should go through $stub, unless
// we're building with the leopard linker or later, which automatically
// synthesizes these stubs.
- Reloc::Model RM = DAG.getTarget().getRelocationModel();
+ const TargetMachine &TM = DAG.getTarget();
const Triple &TargetTriple = Subtarget.getTargetTriple();
bool OldMachOLinker =
TargetTriple.isMacOSX() && TargetTriple.isMacOSXVersionLT(10, 5);
@@ -4286,7 +4286,7 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
const GlobalValue *GV = nullptr;
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
GV = G->getGlobal();
- bool Local = shouldAssumeDSOLocal(RM, TargetTriple, *Mod, GV);
+ bool Local = TM.shouldAssumeDSOLocal(*Mod, GV);
bool UsePlt =
!Local && (OldMachOLinker || (Subtarget.isTargetELF() && !isPPC64));
diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
index 577d2d73895..312a2d4c0d5 100644
--- a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -153,8 +153,7 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const {
if (!HasLazyResolverStubs)
return false;
- if (!shouldAssumeDSOLocal(TM.getRelocationModel(), TM.getTargetTriple(),
- *GV->getParent(), GV))
+ if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
return true;
// 32 bit macho has no relocation for a-b if a is undefined, even if b is in
// the section that is being relocated. This means we have to use o load even
diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
index ec8740a9d8b..9c4c93df654 100644
--- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -2458,11 +2458,10 @@ SDValue SystemZTargetLowering::lowerGlobalAddress(GlobalAddressSDNode *Node,
const GlobalValue *GV = Node->getGlobal();
int64_t Offset = Node->getOffset();
EVT PtrVT = getPointerTy(DAG.getDataLayout());
- Reloc::Model RM = DAG.getTarget().getRelocationModel();
CodeModel::Model CM = DAG.getTarget().getCodeModel();
SDValue Result;
- if (Subtarget.isPC32DBLSymbol(GV, RM, CM)) {
+ if (Subtarget.isPC32DBLSymbol(GV, CM)) {
// Assign anchors at 1<<12 byte boundaries.
uint64_t Anchor = Offset & ~uint64_t(0xfff);
Result = DAG.getTargetGlobalAddress(GV, DL, PtrVT, Anchor);
diff --git a/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp b/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
index 5f947495e32..b8476309463 100644
--- a/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
@@ -46,7 +46,6 @@ SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
TSInfo(), FrameLowering() {}
bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
- Reloc::Model RM,
CodeModel::Model CM) const {
// PC32DBL accesses require the low bit to be clear. Note that a zero
// value selects the default alignment and is therefore OK.
@@ -55,7 +54,7 @@ bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
// For the small model, all locally-binding symbols are in range.
if (CM == CodeModel::Small)
- return shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV);
+ return TLInfo.getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV);
// For Medium and above, assume that the symbol is not within the 4GB range.
// Taking the address of locally-defined text would be OK, but that
diff --git a/llvm/lib/Target/SystemZ/SystemZSubtarget.h b/llvm/lib/Target/SystemZ/SystemZSubtarget.h
index fb157190a48..d091625f1b0 100644
--- a/llvm/lib/Target/SystemZ/SystemZSubtarget.h
+++ b/llvm/lib/Target/SystemZ/SystemZSubtarget.h
@@ -116,8 +116,7 @@ public:
// Return true if GV can be accessed using LARL for reloc model RM
// and code model CM.
- bool isPC32DBLSymbol(const GlobalValue *GV, Reloc::Model RM,
- CodeModel::Model CM) const;
+ bool isPC32DBLSymbol(const GlobalValue *GV, CodeModel::Model CM) const;
bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
};
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index d7617e73245..b703105eaf4 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -110,11 +110,56 @@ static TLSModel::Model getSelectedTLSModel(const GlobalValue *GV) {
llvm_unreachable("invalid TLS model");
}
+// FIXME: make this a proper option
+static bool CanUseCopyRelocWithPIE = false;
+
+bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
+ const GlobalValue *GV) const {
+ Reloc::Model RM = getRelocationModel();
+ const Triple &TT = getTargetTriple();
+
+ // DLLImport explicitly marks the GV as external.
+ if (GV && GV->hasDLLImportStorageClass())
+ return false;
+
+ // Every other GV is local on COFF
+ if (TT.isOSBinFormatCOFF())
+ return true;
+
+ if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
+ return true;
+
+ if (TT.isOSBinFormatMachO()) {
+ if (RM == Reloc::Static)
+ return true;
+ return GV && GV->isStrongDefinitionForLinker();
+ }
+
+ assert(TT.isOSBinFormatELF());
+ assert(RM != Reloc::DynamicNoPIC);
+
+ bool IsExecutable =
+ RM == Reloc::Static || M.getPIELevel() != PIELevel::Default;
+ if (IsExecutable) {
+ // If the symbol is defined, it cannot be preempted.
+ if (GV && !GV->isDeclarationForLinker())
+ return true;
+
+ bool IsTLS = GV && GV->isThreadLocal();
+ // Check if we can use copy relocations.
+ if (!IsTLS && (RM == Reloc::Static || CanUseCopyRelocWithPIE))
+ return true;
+ }
+
+ // ELF supports preemption of other symbols.
+ return false;
+}
+
TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
Reloc::Model RM = getRelocationModel();
bool IsSharedLibrary = RM == Reloc::PIC_ && !IsPIE;
- bool IsLocal = shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV);
+ bool IsLocal = shouldAssumeDSOLocal(*GV->getParent(), GV);
TLSModel::Model Model;
if (IsSharedLibrary) {
diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 4eddfacbafd..49ad9ccaef2 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -93,8 +93,7 @@ unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
if (TM.getCodeModel() == CodeModel::Large)
return X86II::MO_NO_FLAG;
- Reloc::Model RM = TM.getRelocationModel();
- if (shouldAssumeDSOLocal(RM, TargetTriple, M, GV))
+ if (TM.shouldAssumeDSOLocal(M, GV))
return classifyLocalReference(GV);
if (isTargetCOFF())
@@ -120,7 +119,7 @@ X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const {
unsigned char
X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
const Module &M) const {
- if (shouldAssumeDSOLocal(TM.getRelocationModel(), TargetTriple, M, GV))
+ if (TM.shouldAssumeDSOLocal(M, GV))
return X86II::MO_NO_FLAG;
assert(!isTargetCOFF());
OpenPOWER on IntegriCloud