[llvm] r273921 - Teach shouldAssumeDSOLocal about tls.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 27 13:19:14 PDT 2016
Author: rafael
Date: Mon Jun 27 15:19:14 2016
New Revision: 273921
URL: http://llvm.org/viewvc/llvm-project?rev=273921&view=rev
Log:
Teach shouldAssumeDSOLocal about tls.
Fixes a fixme about handling other visibilities.
Modified:
llvm/trunk/lib/CodeGen/Analysis.cpp
llvm/trunk/lib/Target/TargetMachine.cpp
llvm/trunk/test/CodeGen/X86/tls.ll
Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=273921&r1=273920&r2=273921&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/Analysis.cpp Mon Jun 27 15:19:14 2016
@@ -651,33 +651,32 @@ bool llvm::shouldAssumeDSOLocal(Reloc::M
if (TT.isOSBinFormatCOFF())
return true;
- if (RM == Reloc::Static)
- return true;
-
if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
return true;
- if (TT.isOSBinFormatELF()) {
- assert(RM != Reloc::DynamicNoPIC);
- // Some linkers can use copy relocations with pie executables.
- if (M.getPIELevel() != PIELevel::Default) {
- if (CanUseCopyRelocWithPIE)
- return true;
-
- // If the symbol is defined, it cannot be preempted.
- if (GV && !GV->isDeclarationForLinker())
- return true;
- return false;
- }
-
- // ELF supports preemption of other symbols.
- return false;
+ if (TT.isOSBinFormatMachO()) {
+ if (RM == Reloc::Static)
+ return true;
+ return GV && GV->isStrongDefinitionForLinker();
}
- assert(TT.isOSBinFormatMachO());
- if (GV && GV->isStrongDefinitionForLinker())
- return true;
+ 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;
}
Modified: llvm/trunk/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=273921&r1=273920&r2=273921&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachine.cpp Mon Jun 27 15:19:14 2016
@@ -13,6 +13,7 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/Analysis.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
@@ -106,22 +107,19 @@ static TLSModel::Model getSelectedTLSMod
}
TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
- bool isLocal = GV->hasLocalLinkage();
- bool isDeclaration = GV->isDeclaration();
- bool isPIC = getRelocationModel() == Reloc::PIC_;
- bool isPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
- // FIXME: what should we do for protected and internal visibility?
- // For variables, is internal different from hidden?
- bool isHidden = GV->hasHiddenVisibility();
+ 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);
TLSModel::Model Model;
- if (isPIC && !isPIE) {
- if (isLocal || isHidden)
+ if (IsSharedLibrary) {
+ if (IsLocal)
Model = TLSModel::LocalDynamic;
else
Model = TLSModel::GeneralDynamic;
} else {
- if (!isDeclaration || isHidden)
+ if (IsLocal)
Model = TLSModel::LocalExec;
else
Model = TLSModel::InitialExec;
Modified: llvm/trunk/test/CodeGen/X86/tls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls.ll?rev=273921&r1=273920&r2=273921&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tls.ll Mon Jun 27 15:19:14 2016
@@ -10,6 +10,7 @@
@i3 = internal thread_local global i32 15
@i4 = hidden thread_local global i32 15
@i5 = external hidden thread_local global i32
+ at i6 = external protected thread_local global i32
@s1 = thread_local global i16 15
@b1 = thread_local global i8 0
@b2 = thread_local(localexec) global i8 0
@@ -438,3 +439,17 @@ entry:
ret i8* @b2
}
+
+define i32* @f16() {
+; X32_LINUX-LABEL: f16:
+; X32_LINUX: movl %gs:0, %eax
+; X32_LINUX-NEXT: leal i6 at NTPOFF(%eax), %eax
+; X32_LINUX-NEXT: ret
+
+; X64_LINUX-LABEL: f16:
+; X64_LINUX: movq %fs:0, %rax
+; X64_LINUX-NEXT: leaq i6 at TPOFF(%rax), %rax
+; X64_LINUX-NEXT: ret
+
+ ret i32* @i6
+}
More information about the llvm-commits
mailing list