Skip to content

Commit 5972666

Browse files
committed
[WebAssembly] Strip TLS when "atomics" is not enabled
With f3b4f99, the exclusive source of truth for whether threads are supported is the -matomics flag. Accordingly, strip TLS flags when -matomic is not specified, even if bulk-memory is specified and it would theoretically be supportable. This allows the backend to compile TLS variables when -mbulk-memory is enabled but threads are not enabled. Differential Revision: https://reviews.llvm.org/D125730
1 parent b369762 commit 5972666

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ class CoalesceFeaturesAndStripAtomics final : public ModulePass {
203203
bool StrippedAtomics = false;
204204
bool StrippedTLS = false;
205205

206-
if (!Features[WebAssembly::FeatureAtomics])
206+
if (!Features[WebAssembly::FeatureAtomics]) {
207207
StrippedAtomics = stripAtomics(M);
208-
209-
if (!Features[WebAssembly::FeatureBulkMemory])
210208
StrippedTLS = stripThreadLocals(M);
209+
} else if (!Features[WebAssembly::FeatureBulkMemory]) {
210+
StrippedTLS |= stripThreadLocals(M);
211+
}
211212

212213
if (StrippedAtomics && !StrippedTLS)
213214
stripThreadLocals(M);

llvm/test/CodeGen/WebAssembly/target-features-tls.ll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: llc < %s -mattr=-bulk-memory | FileCheck %s --check-prefixes NO-BULK-MEM
2-
; RUN: llc < %s -mattr=+bulk-memory | FileCheck %s --check-prefixes BULK-MEM
1+
; RUN: llc < %s -mattr=-bulk-memory,atomics | FileCheck %s --check-prefixes NO-BULK-MEM
2+
; RUN: llc < %s -mattr=+bulk-memory,atomics | FileCheck %s --check-prefixes BULK-MEM
33

44
; Test that the target features section contains -atomics or +atomics
55
; for modules that have thread local storage in their source.
@@ -10,15 +10,21 @@ target triple = "wasm32-unknown-unknown"
1010

1111
; -bulk-memory
1212
; NO-BULK-MEM-LABEL: .custom_section.target_features,"",@
13-
; NO-BULK-MEM-NEXT: .int8 1
13+
; NO-BULK-MEM-NEXT: .int8 2
14+
; NO-BULK-MEM-NEXT: .int8 43
15+
; NO-BULK-MEM-NEXT: .int8 7
16+
; NO-BULK-MEM-NEXT: .ascii "atomics"
1417
; NO-BULK-MEM-NEXT: .int8 45
1518
; NO-BULK-MEM-NEXT: .int8 10
1619
; NO-BULK-MEM-NEXT: .ascii "shared-mem"
1720
; NO-BULK-MEM-NEXT: .bss.foo,"",@
1821

1922
; +bulk-memory
2023
; BULK-MEM-LABEL: .custom_section.target_features,"",@
21-
; BULK-MEM-NEXT: .int8 1
24+
; BULK-MEM-NEXT: .int8 2
25+
; BULK-MEM-NEXT: .int8 43
26+
; BULK-MEM-NEXT: .int8 7
27+
; BULK-MEM-NEXT: .ascii "atomics"
2228
; BULK-MEM-NEXT: .int8 43
2329
; BULK-MEM-NEXT: .int8 11
2430
; BULK-MEM-NEXT: .ascii "bulk-memory"

llvm/test/CodeGen/WebAssembly/tls-general-dynamic.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
; RUN: not --crash llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory 2>&1 | FileCheck %s --check-prefix=ERROR
2-
; RUN: not --crash llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel 2>&1 | FileCheck %s --check-prefix=ERROR
3-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory --mtriple wasm32-unknown-emscripten | FileCheck %s --check-prefixes=CHECK,TLS
4-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory --mtriple wasm32-unknown-emscripten -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
5-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
1+
; RUN: not --crash llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics 2>&1 | FileCheck %s --check-prefix=ERROR
2+
; RUN: not --crash llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics -fast-isel 2>&1 | FileCheck %s --check-prefix=ERROR
3+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics --mtriple wasm32-unknown-emscripten | FileCheck %s --check-prefixes=CHECK,TLS
4+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics --mtriple wasm32-unknown-emscripten -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
5+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory,atomics | FileCheck %s --check-prefixes=CHECK,NO-TLS
66
target triple = "wasm32-unknown-unknown"
77

88
; ERROR: LLVM ERROR: only -ftls-model=local-exec is supported for now on non-Emscripten OSes: variable tls

llvm/test/CodeGen/WebAssembly/tls-local-exec.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
2-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
3-
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory | FileCheck %s --check-prefixes=CHECK,NO-TLS
1+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics | FileCheck %s --check-prefixes=CHECK,TLS
2+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=+bulk-memory,atomics -fast-isel | FileCheck %s --check-prefixes=CHECK,TLS
3+
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -mattr=-bulk-memory,atomics | FileCheck %s --check-prefixes=CHECK,NO-TLS
44
target triple = "wasm32-unknown-unknown"
55

66
; CHECK-LABEL: address_of_tls:

0 commit comments

Comments
 (0)