Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Add option to emit passive segments
Summary: Adds `--passive-segments` and `--active-segments` flags to control what kind of segments are emitted. For now the default is always to emit active segments so this is not a breaking change, but in the future the default will be changed to passive segments when shared memory is requested and active segments otherwise. When passive segments are emitted, corresponding memory.init and data.drop instructions are emitted in a `__wasm_init_memory` function that is automatically called at the beginning of `__wasm_call_ctors`. Reviewers: sbc100, aheejin, dschuff Subscribers: azakai, dschuff, jgravelle-google, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59343 llvm-svn: 365088
- Loading branch information
Showing
13 changed files
with
329 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
; RUN: llc -filetype=obj %s -o %t.atomics.o -mattr=+atomics | ||
; 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-prefix ACTIVE | ||
|
||
; 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 | ||
; RUN: obj2yaml %t.atomics.active.wasm | FileCheck %s --check-prefix ACTIVE | ||
|
||
; atomics, passive segments => error | ||
; RUN: not wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 --passive-segments %t.atomics.o -o %t.atomics.passive.wasm 2>&1 | FileCheck %s --check-prefix ERROR | ||
|
||
; bulk memory => active segments | ||
; RUN: wasm-ld -no-gc-sections --no-entry %t.bulk-mem.o -o %t.bulk-mem.wasm | ||
; RUN: obj2yaml %t.bulk-mem.wasm | FileCheck %s --check-prefix ACTIVE | ||
|
||
; bulk-memory, active segments => active segments | ||
; RUN: wasm-ld -no-gc-sections --no-entry --active-segments %t.bulk-mem.o -o %t.bulk-mem.active.wasm | ||
; RUN: obj2yaml %t.bulk-mem.active.wasm | FileCheck %s --check-prefix ACTIVE | ||
|
||
; bulk memory, passive segments => passive segments | ||
; 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) | ||
; 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-prefix ACTIVE | ||
|
||
; 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-prefix ACTIVE | ||
|
||
; 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-prefix PASSIVE | ||
|
||
target triple = "wasm32-unknown-unknown" | ||
|
||
@a = hidden global [6 x i8] c"hello\00", align 1 | ||
@b = hidden global [8 x i8] c"goodbye\00", align 1 | ||
@c = hidden global [9 x i8] c"whatever\00", align 1 | ||
@d = hidden global i32 42, align 4 | ||
|
||
@e = private constant [9 x i8] c"constant\00", align 1 | ||
@f = private constant i8 43, align 4 | ||
|
||
; ERROR: 'bulk-memory' feature must be used in order to emit passive segments | ||
|
||
; ACTIVE-LABEL: - Type: CODE | ||
; ACTIVE-NEXT: Functions: | ||
; ACTIVE-NEXT: - Index: 0 | ||
; ACTIVE-NEXT: Locals: [] | ||
; ACTIVE-NEXT: Body: 0B | ||
; ACTIVE-NEXT: - Type: DATA | ||
; ACTIVE-NEXT: Segments: | ||
; ACTIVE-NEXT: - SectionOffset: 7 | ||
; ACTIVE-NEXT: InitFlags: 0 | ||
; ACTIVE-NEXT: Offset: | ||
; ACTIVE-NEXT: Opcode: I32_CONST | ||
; ACTIVE-NEXT: Value: 1024 | ||
; ACTIVE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 | ||
; ACTIVE-NEXT: - SectionOffset: 41 | ||
; ACTIVE-NEXT: InitFlags: 0 | ||
; ACTIVE-NEXT: Offset: | ||
; ACTIVE-NEXT: Opcode: I32_CONST | ||
; ACTIVE-NEXT: Value: 1052 | ||
; ACTIVE-NEXT: Content: 636F6E7374616E74000000002B | ||
; ACTIVE-NEXT: - Type: CUSTOM | ||
; ACTIVE-NEXT: Name: name | ||
; ACTIVE-NEXT: FunctionNames: | ||
; ACTIVE-NEXT: - Index: 0 | ||
; ACTIVE-NEXT: Name: __wasm_call_ctors | ||
|
||
; PASSIVE-LABEL: - Type: CODE | ||
; PASSIVE-NEXT: Functions: | ||
; PASSIVE-NEXT: - Index: 0 | ||
; PASSIVE-NEXT: Locals: [] | ||
; PASSIVE-NEXT: Body: 10010B | ||
; PASSIVE-NEXT: - Index: 1 | ||
; PASSIVE-NEXT: Locals: [] | ||
; PASSIVE-NEXT: Body: 4180084100411CFC080000FC0900419C084100410DFC080100FC09010B | ||
; PASSIVE-NEXT: - Type: DATA | ||
; PASSIVE-NEXT: Segments: | ||
; PASSIVE-NEXT: - SectionOffset: 3 | ||
; PASSIVE-NEXT: InitFlags: 1 | ||
; PASSIVE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 | ||
; PASSIVE-NEXT: - SectionOffset: 33 | ||
; PASSIVE-NEXT: InitFlags: 1 | ||
; PASSIVE-NEXT: Content: 636F6E7374616E74000000002B | ||
; PASSIVE-NEXT: - Type: CUSTOM | ||
; PASSIVE-NEXT: Name: name | ||
; PASSIVE-NEXT: FunctionNames: | ||
; PASSIVE-NEXT: - Index: 0 | ||
; PASSIVE-NEXT: Name: __wasm_call_ctors | ||
; PASSIVE-NEXT: - Index: 1 | ||
; PASSIVE-NEXT: Name: __wasm_init_memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.