-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve code generation for thread_local variables:
Summary: * Don't bother using a thread wrapper when the variable is known to have constant initialization. * Emit the thread wrapper as discardable-if-unused in TUs that don't contain a definition of the thread_local variable. * Don't emit the thread wrapper at all if the thread_local variable is unused and discardable; it will be emitted by all TUs that need it. Reviewers: rjmccall, jdoerfert Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67429 llvm-svn: 371767
- Loading branch information
Showing
10 changed files
with
165 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2a %s -emit-llvm -o - | FileCheck %s | ||
|
|
||
| // CHECK-DAG: @a = external thread_local global i32 | ||
| extern thread_local int a; | ||
|
|
||
| // CHECK-DAG: @b = external thread_local global i32 | ||
| extern thread_local constinit int b; | ||
|
|
||
| // CHECK-LABEL: define i32 @_Z1fv() | ||
| // CHECK: call i32* @_ZTW1a() | ||
| // CHECK: } | ||
| int f() { return a; } | ||
|
|
||
| // CHECK-LABEL: define linkonce_odr {{.*}} @_ZTW1a() | ||
| // CHECK: br i1 | ||
| // CHECK: call void @_ZTH1a() | ||
| // CHECK: } | ||
|
|
||
| // CHECK-LABEL: define i32 @_Z1gv() | ||
| // CHECK-NOT: call | ||
| // CHECK: load i32, i32* @b | ||
| // CHECK-NOT: call | ||
| // CHECK: } | ||
| int g() { return b; } | ||
|
|
||
| // CHECK-NOT: define {{.*}} @_ZTW1b() | ||
|
|
||
| extern thread_local int c; | ||
|
|
||
| // CHECK-LABEL: define i32 @_Z1hv() | ||
| // CHECK: call i32* @_ZTW1c() | ||
| // CHECK: load i32, i32* % | ||
| // CHECK: } | ||
| int h() { return c; } | ||
|
|
||
| thread_local int c = 0; | ||
|
|
||
| int d_init(); | ||
| thread_local int d = d_init(); | ||
|
|
||
| // Note: use of 'c' does not trigger initialization of 'd', because 'c' has a | ||
| // constant initializer. | ||
| // CHECK-LABEL: define weak_odr {{.*}} @_ZTW1c() | ||
| // CHECK-NOT: br i1 | ||
| // CHECK-NOT: call | ||
| // CHECK: ret i32* @c | ||
| // CHECK: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...Gen/windows-on-arm-itanium-thread-local.c → ...X/windows-on-arm-itanium-thread-local.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| // RUN: %clang_cc1 -triple thumbv7--windows-itanium -fdeclspec -fms-compatibility -fms-compatibility-version=19.0 -S -emit-llvm -o - %s | FileCheck %s | ||
| // RUN: %clang_cc1 -triple thumbv7--windows-itanium -fdeclspec -fms-compatibility -fms-compatibility-version=19.0 -emit-llvm -o - %s | FileCheck %s | ||
|
|
||
| __declspec(thread) static void *c; | ||
| void *g(); | ||
| thread_local static void *c = g(); | ||
| void f(void *p) { | ||
| c = p; | ||
| } | ||
|
|
||
| // CHECK-LABEL: @f(i8* %p) | ||
| // CHECK-LABEL: @_Z1fPv(i8* %p) | ||
| // CHECK-NOT: call i8** @_ZTWL1c() | ||
| // CHECK: call arm_aapcs_vfpcc i8** @_ZTWL1c() | ||
|
|
Oops, something went wrong.