1 ; Run the tests with the `localexec` TLS mode specified.
2 ; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics - | FileCheck --check-prefixes=CHECK,TLS %s
3 ; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics -fast-isel - | FileCheck --check-prefixes=CHECK,TLS %s
5 ; Also, run the same tests without a specified TLS mode--this should still emit `localexec` code on non-Emscripten targtes which don't currently support dynamic linking.
6 ; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics - | FileCheck --check-prefixes=CHECK,TLS %s
7 ; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics -fast-isel - | FileCheck --check-prefixes=CHECK,TLS %s
9 ; Finally, when bulk memory is disabled, no TLS code should be generated.
10 ; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory,atomics - | FileCheck --check-prefixes=CHECK,NO-TLS %s
11 target triple = "wasm32-unknown-unknown"
13 ; CHECK-LABEL: address_of_tls:
14 ; CHECK-NEXT: .functype address_of_tls () -> (i32)
15 define i32 @address_of_tls() {
16 ; TLS-DAG: global.get __tls_base
17 ; TLS-DAG: i32.const tls@TLSREL
21 ; NO-TLS-NEXT: i32.const tls
23 ret i32 ptrtoint(ptr @tls to i32)
26 ; CHECK-LABEL: address_of_tls_external:
27 ; CHECK-NEXT: .functype address_of_tls_external () -> (i32)
28 define i32 @address_of_tls_external() {
29 ; TLS-DAG: global.get __tls_base
30 ; TLS-DAG: i32.const tls_external@TLSREL
34 ; NO-TLS-NEXT: i32.const tls_external
36 ret i32 ptrtoint(ptr @tls_external to i32)
39 ; CHECK-LABEL: ptr_to_tls:
40 ; CHECK-NEXT: .functype ptr_to_tls () -> (i32)
41 define ptr @ptr_to_tls() {
42 ; TLS-DAG: global.get __tls_base
43 ; TLS-DAG: i32.const tls@TLSREL
47 ; NO-TLS-NEXT: i32.const tls
52 ; CHECK-LABEL: tls_load:
53 ; CHECK-NEXT: .functype tls_load () -> (i32)
54 define i32 @tls_load() {
55 ; TLS-DAG: global.get __tls_base
56 ; TLS-DAG: i32.const tls@TLSREL
58 ; TLS-NEXT: i32.load 0
61 ; NO-TLS-NEXT: i32.const 0
62 ; NO-TLS-NEXT: i32.load tls
64 %tmp = load i32, ptr @tls, align 4
68 ; CHECK-LABEL: tls_store:
69 ; CHECK-NEXT: .functype tls_store (i32) -> ()
70 define void @tls_store(i32 %x) {
71 ; TLS-DAG: global.get __tls_base
72 ; TLS-DAG: i32.const tls@TLSREL
74 ; TLS-NEXT: i32.store 0
77 ; NO-TLS-NEXT: i32.const 0
78 ; NO-TLS-NEXT: i32.store tls
80 store i32 %x, ptr @tls, align 4
84 ; CHECK-LABEL: tls_size:
85 ; CHECK-NEXT: .functype tls_size () -> (i32)
86 define i32 @tls_size() {
87 ; CHECK-NEXT: global.get __tls_size
89 %1 = call i32 @llvm.wasm.tls.size.i32()
93 ; CHECK: .type tls,@object
94 ; TLS-NEXT: .section .tbss.tls,"T",@
95 ; NO-TLS-NEXT: .section .bss.tls,"",@
96 ; CHECK-NEXT: .p2align 2
98 ; CHECK-NEXT: .int32 0
99 @tls = internal thread_local[[TLS_MODE]] global i32 0
101 @tls_external = external thread_local[[TLS_MODE]] global i32, align 4
103 declare i32 @llvm.wasm.tls.size.i32()