[dragonegg] r177302 - Set TLS model on external variables.
Peter Collingbourne
peter at pcc.me.uk
Mon Mar 18 11:12:05 PDT 2013
Author: pcc
Date: Mon Mar 18 13:12:05 2013
New Revision: 177302
URL: http://llvm.org/viewvc/llvm-project?rev=177302&view=rev
Log:
Set TLS model on external variables.
Modified:
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/test/validator/c/ThreadLocalVariables.c
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=177302&r1=177301&r2=177302&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Mon Mar 18 13:12:05 2013
@@ -1030,30 +1030,6 @@ static void emit_global(tree decl) {
GV = NGV;
}
- // Set thread local (TLS)
- if (isa<VAR_DECL>(decl) && DECL_THREAD_LOCAL_P(decl)) {
- GV->setThreadLocal(true);
-
- switch (DECL_TLS_MODEL(decl)) {
- case TLS_MODEL_NONE:
- llvm_unreachable("TLS_MODEL_NONE for thread local var is impossible");
- case TLS_MODEL_EMULATED:
- llvm_unreachable("LLVM does not support TLS_MODEL_EMULATED");
- case TLS_MODEL_GLOBAL_DYNAMIC:
- GV->setThreadLocalMode(GlobalVariable::GeneralDynamicTLSModel);
- break;
- case TLS_MODEL_LOCAL_DYNAMIC:
- GV->setThreadLocalMode(GlobalVariable::LocalDynamicTLSModel);
- break;
- case TLS_MODEL_INITIAL_EXEC:
- GV->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
- break;
- case TLS_MODEL_LOCAL_EXEC:
- GV->setThreadLocalMode(GlobalVariable::LocalExecTLSModel);
- break;
- }
- }
-
// Set the linkage.
GlobalValue::LinkageTypes Linkage;
@@ -1426,9 +1402,29 @@ Value *make_decl_llvm(tree decl) {
}
// Set thread local (TLS)
- if (isa<VAR_DECL>(decl) && DECL_THREAD_LOCAL_P(decl))
+ if (isa<VAR_DECL>(decl) && DECL_THREAD_LOCAL_P(decl)) {
GV->setThreadLocal(true);
+ switch (DECL_TLS_MODEL(decl)) {
+ case TLS_MODEL_NONE:
+ llvm_unreachable("TLS_MODEL_NONE for thread local var is impossible");
+ case TLS_MODEL_EMULATED:
+ llvm_unreachable("LLVM does not support TLS_MODEL_EMULATED");
+ case TLS_MODEL_GLOBAL_DYNAMIC:
+ GV->setThreadLocalMode(GlobalVariable::GeneralDynamicTLSModel);
+ break;
+ case TLS_MODEL_LOCAL_DYNAMIC:
+ GV->setThreadLocalMode(GlobalVariable::LocalDynamicTLSModel);
+ break;
+ case TLS_MODEL_INITIAL_EXEC:
+ GV->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
+ break;
+ case TLS_MODEL_LOCAL_EXEC:
+ GV->setThreadLocalMode(GlobalVariable::LocalExecTLSModel);
+ break;
+ }
+ }
+
assert((GV->isDeclaration() || SizeOfGlobalMatchesDecl(GV, decl)) &&
"Global has unexpected initializer!");
Modified: dragonegg/trunk/test/validator/c/ThreadLocalVariables.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c/ThreadLocalVariables.c?rev=177302&r1=177301&r2=177302&view=diff
==============================================================================
--- dragonegg/trunk/test/validator/c/ThreadLocalVariables.c (original)
+++ dragonegg/trunk/test/validator/c/ThreadLocalVariables.c Mon Mar 18 13:12:05 2013
@@ -11,3 +11,19 @@ __thread int e;
// CHECK: @c = thread_local(initialexec) unnamed_addr global i32 0
// CHECK: @b = thread_local(localdynamic) unnamed_addr global i32 0
// CHECK: @a = thread_local unnamed_addr global i32 0
+
+extern __thread __attribute((tls_model("global-dynamic"))) int f;
+extern __thread __attribute((tls_model("local-dynamic"))) int g;
+extern __thread __attribute((tls_model("initial-exec"))) int h;
+extern __thread __attribute((tls_model("local-exec"))) int i;
+extern __thread int j;
+
+// CHECK: @f = external thread_local global i32
+// CHECK: @g = external thread_local(localdynamic) global i32
+// CHECK: @h = external thread_local(initialexec) global i32
+// CHECK: @i = external thread_local(localexec) global i32
+// CHECK: @j = external thread_local global i32
+
+int foo(void) {
+ return f + g + h + i + j;
+}
More information about the llvm-commits
mailing list