[lld] r366504 - [WebAssembly] Use passive segments by default when memory is shared

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 14:50:25 PDT 2019


Author: tlively
Date: Thu Jul 18 14:50:24 2019
New Revision: 366504

URL: http://llvm.org/viewvc/llvm-project?rev=366504&view=rev
Log:
[WebAssembly] Use passive segments by default when memory is shared

Summary:
This change makes it so that passing --shared-memory is all a user
needs to do to get proper multithreaded code. This default can still
be explicitly overridden for any reason using --passive-segments and
--active-segments.

Reviewers: sbc100, quantum

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, jfb, llvm-commits

Tags: #llvm

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

Modified:
    lld/trunk/test/wasm/data-layout.ll
    lld/trunk/test/wasm/data-segments.ll
    lld/trunk/test/wasm/import-memory.test
    lld/trunk/test/wasm/shared-memory.yaml
    lld/trunk/test/wasm/tls.ll
    lld/trunk/wasm/Driver.cpp
    lld/trunk/wasm/Options.td

Modified: lld/trunk/test/wasm/data-layout.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/data-layout.ll?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/test/wasm/data-layout.ll (original)
+++ lld/trunk/test/wasm/data-layout.ll Thu Jul 18 14:50:24 2019
@@ -76,7 +76,7 @@ target triple = "wasm32-unknown-unknown"
 
 ; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
 ; RUN:     --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t.o \
-; RUN:     %t.hello.o
+; RUN:     --active-segments %t.hello.o
 ; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
 
 ; CHECK-SHARED:        - Type:            MEMORY

Modified: lld/trunk/test/wasm/data-segments.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/data-segments.ll?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/test/wasm/data-segments.ll (original)
+++ lld/trunk/test/wasm/data-segments.ll Thu Jul 18 14:50:24 2019
@@ -2,9 +2,8 @@
 ; RUN: llc -filetype=obj %s -o %t.bulk-mem.o -mattr=+bulk-memory
 ; RUN: llc -filetype=obj %s -o %t.atomics.bulk-mem.o -mattr=+atomics,+bulk-memory
 
-; atomics => active segments (TODO: error)
-; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.o -o %t.atomics.wasm
-; RUN: obj2yaml %t.atomics.wasm | FileCheck %s --check-prefixes ACTIVE,ACTIVE-TLS
+; atomics => error
+; RUN: not wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.o -o %t.atomics.wasm 2>&1 | FileCheck %s --check-prefix ERROR
 
 ; atomics, active segments => active segments
 ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 --active-segments %t.atomics.o -o %t.atomics.active.wasm
@@ -25,15 +24,15 @@
 ; RUN: wasm-ld -no-gc-sections --no-entry --passive-segments %t.bulk-mem.o -o %t.bulk-mem.passive.wasm
 ; RUN: obj2yaml %t.bulk-mem.passive.wasm | FileCheck %s --check-prefix PASSIVE
 
-; atomics, bulk memory => active segments (TODO: passive)
+; atomics, bulk memory => passive segments
 ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.o -o %t.atomics.bulk-mem.wasm
-; RUN: obj2yaml %t.atomics.bulk-mem.wasm | FileCheck %s --check-prefixes ACTIVE,ACTIVE-TLS
+; RUN: obj2yaml %t.atomics.bulk-mem.wasm | FileCheck %s --check-prefixes PASSIVE,PASSIVE-TLS
 
-; atomics, bulk memory, active segments   => active segments
+; atomics, bulk memory, active segments => active segments
 ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 --active-segments %t.atomics.bulk-mem.o -o %t.atomics.bulk-mem.active.wasm
 ; RUN: obj2yaml %t.atomics.bulk-mem.active.wasm | FileCheck %s --check-prefixes ACTIVE,ACTIVE-TLS
 
-; atomics, bulk memory, passive segments  => passive segments
+; atomics, bulk memory, passive segments => passive segments
 ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 --passive-segments %t.atomics.bulk-mem.o -o %t.atomics.bulk-mem.passive.wasm
 ; RUN: obj2yaml %t.atomics.bulk-mem.passive.wasm | FileCheck %s --check-prefixes PASSIVE,PASSIVE-TLS
 

Modified: lld/trunk/test/wasm/import-memory.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/import-memory.test?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/test/wasm/import-memory.test (original)
+++ lld/trunk/test/wasm/import-memory.test Thu Jul 18 14:50:24 2019
@@ -32,8 +32,8 @@
 # CHECK-MAX-NEXT:          Maximum:         0x00000005
 # CHECK-MAX-NEXT:  - Type:
 
-# RUN: wasm-ld --import-memory --shared-memory --initial-memory=262144 \
-# RUN:     --max-memory=327680 -o %t.max.wasm %t.start.o
+# RUN: wasm-ld --import-memory --shared-memory --active-segments \
+# RUN:     --initial-memory=262144 --max-memory=327680 -o %t.max.wasm %t.start.o
 # RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-SHARED %s
 
 # Verify the --shared-memory flag works with imports

Modified: lld/trunk/test/wasm/shared-memory.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/shared-memory.yaml?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/test/wasm/shared-memory.yaml (original)
+++ lld/trunk/test/wasm/shared-memory.yaml Thu Jul 18 14:50:24 2019
@@ -1,18 +1,18 @@
 # RUN: yaml2obj %s -o %t1.o
 
-# RUN: not wasm-ld --no-entry --shared-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-MAX
+# RUN: not wasm-ld --no-entry --shared-memory --active-segments %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-MAX
 
-# RUN: not wasm-ld --no-entry --shared-memory --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED
+# RUN: not wasm-ld --no-entry --shared-memory --active-segments --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED
 
-# RUN: wasm-ld --no-entry --shared-memory --max-memory=131072 %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
+# RUN: wasm-ld --no-entry --shared-memory --active-segments --max-memory=131072 %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
 
 # RUN: not wasm-ld --no-entry --features=atomics %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-NO-SHARED
 
-# RUN: not wasm-ld --no-entry --features=atomics --shared-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-NO-MAX
+# RUN: not wasm-ld --no-entry --features=atomics --shared-memory --active-segments %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-NO-MAX
 
-# RUN: not wasm-ld --no-entry --features=atomics --shared-memory --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-UNALIGNED
+# RUN: not wasm-ld --no-entry --features=atomics --shared-memory --active-segments --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-UNALIGNED
 
-# RUN: wasm-ld --no-entry --features=atomics --shared-memory --max-memory=131072 %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
+# RUN: wasm-ld --no-entry --features=atomics --shared-memory --active-segments --max-memory=131072 %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
 
 
 --- !WASM

Modified: lld/trunk/test/wasm/tls.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/tls.ll?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/test/wasm/tls.ll (original)
+++ lld/trunk/test/wasm/tls.ll Thu Jul 18 14:50:24 2019
@@ -44,10 +44,8 @@ define i32* @tls2_addr() {
 
 ; CHECK:      - Type:            CODE
 ; CHECK-NEXT:   Functions:
-; CHECK-NEXT:     - Index:           0
-; CHECK-NEXT:       Locals:          []
-; CHECK-NEXT:       Body:            0B
-; CHECK-NEXT:     - Index:           1
+; Skip __wasm_call_ctors and __wasm_init_memory
+; CHECK:          - Index:           2
 ; CHECK-NEXT:       Locals:          []
 ; CHECK-NEXT:       Body:            20002401200041004108FC0801000B
 
@@ -60,7 +58,7 @@ define i32* @tls2_addr() {
 ;   memory.init 1, 0
 ;   end
 
-; CHECK-NEXT:     - Index:           2
+; CHECK-NEXT:     - Index:           3
 ; CHECK-NEXT:       Locals:          []
 ; CHECK-NEXT:       Body:            2381808080004180808080006A0B
 
@@ -70,7 +68,7 @@ define i32* @tls2_addr() {
 ;   i32.add
 ;   end
 
-; CHECK-NEXT:     - Index:           3
+; CHECK-NEXT:     - Index:           4
 ; CHECK-NEXT:       Locals:          []
 ; CHECK-NEXT:       Body:            2381808080004184808080006A0B
 

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Thu Jul 18 14:50:24 2019
@@ -320,9 +320,8 @@ static void readConfigs(opt::InputArgLis
       args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
   config->importMemory = args.hasArg(OPT_import_memory);
   config->sharedMemory = args.hasArg(OPT_shared_memory);
-  // TODO: Make passive segments the default with shared memory
-  config->passiveSegments =
-      args.hasFlag(OPT_passive_segments, OPT_active_segments, false);
+  config->passiveSegments = args.hasFlag(
+      OPT_passive_segments, OPT_active_segments, config->sharedMemory);
   config->importTable = args.hasArg(OPT_import_table);
   config->ltoo = args::getInteger(args, OPT_lto_O, 2);
   config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);

Modified: lld/trunk/wasm/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Options.td?rev=366504&r1=366503&r2=366504&view=diff
==============================================================================
--- lld/trunk/wasm/Options.td (original)
+++ lld/trunk/wasm/Options.td Thu Jul 18 14:50:24 2019
@@ -144,10 +144,10 @@ def shared_memory: F<"shared-memory">,
   HelpText<"Use shared linear memory">;
 
 def active_segments: F<"active-segments">,
-  HelpText<"Force segments to be active">;
+  HelpText<"Force segments to be active (default with unshared memory)">;
 
 def passive_segments: F<"passive-segments">,
-  HelpText<"Force segments to be passive">;
+  HelpText<"Force segments to be passive (default with shared memory)">;
 
 def import_table: F<"import-table">,
   HelpText<"Import function table from the environment">;




More information about the llvm-commits mailing list