[llvm] r209543 - Use alias linkage and visibility to decide tls access mode.

Rafael Espindola rafael.espindola at gmail.com
Fri May 23 12:16:56 PDT 2014


Author: rafael
Date: Fri May 23 14:16:56 2014
New Revision: 209543

URL: http://llvm.org/viewvc/llvm-project?rev=209543&view=rev
Log:
Use alias linkage and visibility to decide tls access mode.

This matches both what we do for the non-thread case and what gcc does.

With this patch clang would match gcc's behaviour in

static __thread int a = 42;
extern __thread int b __attribute__((alias("a")));
int *f(void) { return &a; }
int *g(void) { return &b; }

if not for pr19843. Manually writing the IL does produce the same access modes.

It is also a step in the direction of fixing pr19844.

Modified:
    llvm/trunk/lib/Target/TargetMachine.cpp
    llvm/trunk/test/CodeGen/Mips/tls-alias.ll
    llvm/trunk/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll

Modified: llvm/trunk/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=209543&r1=209542&r2=209543&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachine.cpp Fri May 23 14:16:56 2014
@@ -106,19 +106,13 @@ static TLSModel::Model getSelectedTLSMod
 }
 
 TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
-  // If GV is an alias then use the aliasee for determining
-  // thread-localness.
-  if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
-    GV = GA->getAliasee();
-  const GlobalVariable *Var = cast<GlobalVariable>(GV);
-
-  bool isLocal = Var->hasLocalLinkage();
-  bool isDeclaration = Var->isDeclaration();
+  bool isLocal = GV->hasLocalLinkage();
+  bool isDeclaration = GV->isDeclaration();
   bool isPIC = getRelocationModel() == Reloc::PIC_;
   bool isPIE = Options.PositionIndependentExecutable;
   // FIXME: what should we do for protected and internal visibility?
   // For variables, is internal different from hidden?
-  bool isHidden = Var->hasHiddenVisibility();
+  bool isHidden = GV->hasHiddenVisibility();
 
   TLSModel::Model Model;
   if (isPIC && !isPIE) {
@@ -133,10 +127,13 @@ TLSModel::Model TargetMachine::getTLSMod
       Model = TLSModel::InitialExec;
   }
 
-  // If the user specified a more specific model, use that.
-  TLSModel::Model SelectedModel = getSelectedTLSModel(Var);
-  if (SelectedModel > Model)
-    return SelectedModel;
+  const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV);
+  if (Var) {
+    // If the user specified a more specific model, use that.
+    TLSModel::Model SelectedModel = getSelectedTLSModel(Var);
+    if (SelectedModel > Model)
+      return SelectedModel;
+  }
 
   return Model;
 }

Modified: llvm/trunk/test/CodeGen/Mips/tls-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/tls-alias.ll?rev=209543&r1=209542&r2=209543&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/tls-alias.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/tls-alias.ll Fri May 23 14:16:56 2014
@@ -5,6 +5,6 @@
 
 define i32* @zed() {
 ; CHECK-DAG: __tls_get_addr
-; CHECK-DAG: %tlsgd(bar)
+; CHECK-DAG: %tlsldm(bar)
        ret i32* @bar
 }

Modified: llvm/trunk/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll?rev=209543&r1=209542&r2=209543&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll Fri May 23 14:16:56 2014
@@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"
 
 define i32 @foo() {
 ; CHECK-LABEL: foo:
-; CHECK: leal    __libc_resp at TLSGD
+; CHECK: leal    __libc_resp at TLSLD
 entry:
 	%retval = alloca i32		; <i32*> [#uses=1]
 	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
@@ -27,7 +27,7 @@ return:		; preds = %entry
 
 define i32 @bar() {
 ; CHECK-LABEL: bar:
-; CHECK: leal    __libc_resp at TLSGD
+; CHECK: leal    __libc_resp at TLSLD
 entry:
 	%retval = alloca i32		; <i32*> [#uses=1]
 	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]





More information about the llvm-commits mailing list