[PATCH] D57800: [WebAssembly] LTO: Set POSIX thread model when linking with -shared-memoey

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 15 22:03:11 PST 2019


sbc100 updated this revision to Diff 187129.
sbc100 added a comment.

- add test


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57800/new/

https://reviews.llvm.org/D57800

Files:
  test/wasm/lto/atomics.ll
  wasm/LTO.cpp


Index: wasm/LTO.cpp
===================================================================
--- wasm/LTO.cpp
+++ wasm/LTO.cpp
@@ -47,8 +47,12 @@
   C.Options.FunctionSections = true;
   C.Options.DataSections = true;
 
-  // Wasm currently only supports ThreadModel::Single
-  C.Options.ThreadModel = ThreadModel::Single;
+  // When shared memory is disabled wasm doesn't support atomics operations.
+  // Setting the thead model based on the SharedMemory option seems like
+  // reasonable default.  Idealy the bitcode metadata would set this on
+  // a per function basis instead.
+  C.Options.ThreadModel =
+      Config->SharedMemory ? ThreadModel::POSIX : ThreadModel::Single;
 
   C.DisableVerify = Config->DisableVerify;
   C.DiagHandler = diagnosticHandler;
Index: test/wasm/lto/atomics.ll
===================================================================
--- test/wasm/lto/atomics.ll
+++ test/wasm/lto/atomics.ll
@@ -1,5 +1,9 @@
 ; RUN: llvm-as %s -o %t.o
 ; RUN: wasm-ld %t.o -o %t.wasm -lto-O0
+; RUN: wasm-ld --shared-memory %t.o -o %t.shared.wasm -lto-O0
+; RUN: llvm-objdump -d %t.shared.wasm
+; RUN: llc %s -mattr=+atomics -o %t.threads.o
+
 ; Atomic operations with fail to compile if the ThreadModel is not
 ; correctly set to Single (i.e. if atomics are not lowered to regular ops).
 
@@ -8,7 +12,10 @@
 
 @foo = hidden global i32 1
 
-define void @_start() {
-  %1 = load atomic i32, i32* @foo unordered, align 4
+define void @_start() #0 {
+  %1 = load atomic i32, i32* @foo seq_cst, align 4
+  store atomic i32 %1, i32* @foo seq_cst, align 4
   ret void
 }
+
+attributes #0 = { noinline optnone "target-features"="+atomics" }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57800.187129.patch
Type: text/x-patch
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190216/c77b5454/attachment.bin>


More information about the llvm-commits mailing list