llvm.org GIT mirror llvm / c3f6be5
[WebAssembly] Strip threadlocal attribute from globals in single thread mode The default thread model for wasm is single, and in this mode thread-local global variables can be lowered identically to non-thread-local variables. Differential Revision: https://reviews.llvm.org/D44703 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328049 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Schuff 2 years ago
2 changed file(s) with 37 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
125125 }
126126
127127 namespace {
128 class StripThreadLocal final : public ModulePass {
129 // The default thread model for wasm is single, where thread-local variables
130 // are identical to regular globals and should be treated the same. So this
131 // pass just converts all GlobalVariables to NotThreadLocal
132 static char ID;
133
134 public:
135 StripThreadLocal() : ModulePass(ID) {}
136 bool runOnModule(Module &M) override {
137 for (auto &GV : M.globals())
138 GV.setThreadLocalMode(GlobalValue::ThreadLocalMode::NotThreadLocal);
139 return true;
140 }
141 };
142 char StripThreadLocal::ID = 0;
143
128144 /// WebAssembly Code Generator Pass Configuration Options.
129145 class WebAssemblyPassConfig final : public TargetPassConfig {
130146 public:
165181 //===----------------------------------------------------------------------===//
166182
167183 void WebAssemblyPassConfig::addIRPasses() {
168 if (TM->Options.ThreadModel == ThreadModel::Single)
184 if (TM->Options.ThreadModel == ThreadModel::Single) {
169185 // In "single" mode, atomics get lowered to non-atomics.
170186 addPass(createLowerAtomicPass());
171 else
187 addPass(new StripThreadLocal());
188 } else {
172189 // Expand some atomic operations. WebAssemblyTargetLowering has hooks which
173190 // control specifically what gets lowered.
174191 addPass(createAtomicExpandPass());
192 }
175193
176194 // Lower .llvm.global_dtors into .llvm_global_ctors with __cxa_atexit calls.
177195 addPass(createWebAssemblyLowerGlobalDtors());
0 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -thread-model=single | FileCheck --check-prefix=SINGLE %s
1 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
2 target triple = "wasm32-unknown-unknown-wasm"
3
4 ; SINGLE-LABEL: address_of_tls:
5 define i32 @address_of_tls() {
6 ; SINGLE: i32.const $push0=, tls
7 ; SINGLE-NEXT: return $pop0
8 ret i32 ptrtoint(i32* @tls to i32)
9 }
10
11 ; SINGLE: .type tls,@object
12 ; SINGLE-NEXT: .section .bss.tls,"",@
13 ; SINGLE-NEXT: .p2align 2
14 ; SINGLE-NEXT: tls:
15 ; SINGLE-NEXT: .int32 0
16 @tls = internal thread_local global i32 0