Skip to content

Commit

Permalink
Use alias linkage and visibility to decide tls access mode.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209543 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed May 23, 2014
1 parent b165140 commit ef72e73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
23 changes: 10 additions & 13 deletions lib/Target/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,13 @@ static TLSModel::Model getSelectedTLSModel(const GlobalVariable *Var) {
}

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) {
Expand All @@ -133,10 +127,13 @@ TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/CodeGen/Mips/tls-alias.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

define i32* @zed() {
; CHECK-DAG: __tls_get_addr
; CHECK-DAG: %tlsgd(bar)
; CHECK-DAG: %tlsldm(bar)
ret i32* @bar
}
4 changes: 2 additions & 2 deletions test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target triple = "i386-pc-linux-gnu"

define i32 @foo() {
; CHECK-LABEL: foo:
; CHECK: leal __libc_resp@TLSGD
; CHECK: leal __libc_resp@TLSLD
entry:
%retval = alloca i32 ; <i32*> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
Expand All @@ -27,7 +27,7 @@ return: ; preds = %entry

define i32 @bar() {
; CHECK-LABEL: bar:
; CHECK: leal __libc_resp@TLSGD
; CHECK: leal __libc_resp@TLSLD
entry:
%retval = alloca i32 ; <i32*> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
Expand Down

0 comments on commit ef72e73

Please sign in to comment.