[llvm] c60d822 - [WebAssembly] Make __wasm_lpad_context thread-local

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 15:57:04 PST 2022


Author: Heejin Ahn
Date: 2022-02-16T15:56:38-08:00
New Revision: c60d8229651c25ae869e9a3bfece3e74118a5ce0

URL: https://github.com/llvm/llvm-project/commit/c60d8229651c25ae869e9a3bfece3e74118a5ce0
DIFF: https://github.com/llvm/llvm-project/commit/c60d8229651c25ae869e9a3bfece3e74118a5ce0.diff

LOG: [WebAssembly] Make __wasm_lpad_context thread-local

This makes `__wasm_lpad_context`, a struct that is used as a
communication channel between compiler-generated code and personality
function in libunwind, thread local. The library code will be changed to
thread local in the emscripten side.

Reviewed By: sbc100, tlively

Differential Revision: https://reviews.llvm.org/D119803

Added: 
    

Modified: 
    llvm/lib/CodeGen/WasmEHPrepare.cpp
    llvm/test/CodeGen/WebAssembly/wasmehprepare.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/WasmEHPrepare.cpp b/llvm/lib/CodeGen/WasmEHPrepare.cpp
index c04a7b28eff9d..6b7df758e4579 100644
--- a/llvm/lib/CodeGen/WasmEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WasmEHPrepare.cpp
@@ -212,9 +212,21 @@ bool WasmEHPrepare::prepareEHPads(Function &F) {
 
   assert(F.hasPersonalityFn() && "Personality function not found");
 
-  // __wasm_lpad_context global variable
+  // __wasm_lpad_context global variable.
+  // If the target supports TLS, make this thread-local. We can't just
+  // unconditionally make it thread-local and depend on
+  // CoalesceFeaturesAndStripAtomics to downgrade it, because stripping TLS has
+  // the side effect of disallowing the object from being linked into a
+  // shared-memory module, which we don't want to be responsible for.
   LPadContextGV = cast<GlobalVariable>(
       M.getOrInsertGlobal("__wasm_lpad_context", LPadContextTy));
+  Attribute FSAttr = F.getFnAttribute("target-features");
+  if (FSAttr.isValid()) {
+    StringRef FS = FSAttr.getValueAsString();
+    if (FS.contains("+atomics") && FS.contains("+bulk-memory"))
+      LPadContextGV->setThreadLocalMode(GlobalValue::GeneralDynamicTLSModel);
+  }
+
   LPadIndexField = IRB.CreateConstGEP2_32(LPadContextTy, LPadContextGV, 0, 0,
                                           "lpad_index_gep");
   LSDAField =

diff  --git a/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll b/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
index 63bdf2c6bea08..081a9776fa9aa 100644
--- a/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
+++ b/llvm/test/CodeGen/WebAssembly/wasmehprepare.ll
@@ -1,9 +1,11 @@
-; RUN: opt < %s -winehprepare -demote-catchswitch-only -wasmehprepare -S | FileCheck %s
+; RUN: opt < %s -winehprepare -demote-catchswitch-only -wasmehprepare -S | FileCheck %s --check-prefixes=CHECK,NO-TLS
+; RUN: opt < %s -winehprepare -demote-catchswitch-only -wasmehprepare -S --mattr=+atomics,+bulk-memory | FileCheck %s --check-prefixes=CHECK,TLS
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; CHECK: @__wasm_lpad_context = external global { i32, i8*, i32 }
+; NO-TLS: @__wasm_lpad_context = external global { i32, i8*, i32 }
+; TLS: @__wasm_lpad_context = external thread_local global { i32, i8*, i32 }
 
 @_ZTIi = external constant i8*
 %struct.Temp = type { i8 }


        


More information about the llvm-commits mailing list