-
Notifications
You must be signed in to change notification settings - Fork 16.8k
[WebAssembly] WASIP3 and component model threading support #175800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 70 commits
48a90dd
540d785
8f222c9
e9775de
6d2b464
0bf29ae
4a18333
927daeb
e632709
f44bf29
18a1ee3
8980e38
08a3a16
9092b93
81ffb2b
a9e7310
c369bb2
d368838
61f03e5
c9665c1
07e122d
651c362
0175bd5
9a93078
85fab66
e577185
446d56d
3f10fe8
dbae3ef
e0dcb2a
e8babc7
822ea98
cb2fb8d
6cf7c2a
fa7eea8
cc1ea2f
b9039eb
1b490cd
b55ae63
a1c563b
69654ef
b98b9ab
7121ea5
70b3b93
43f756f
4ffe623
36c39bf
d953510
0656bbf
c5190ff
6e0c9c0
3386a11
5775592
4d7a81e
1001e65
7a44741
4c62c81
5bebe2a
e9fa9fc
10ed134
2ee9845
c6ddead
2bae426
557bfac
61c25c8
0fe07f0
7a58fce
8047c76
24cb457
ff172dc
d11664a
f04b74a
6bdff2c
a637ae1
0bf18a6
6c9c276
f019ea9
de9424c
5954755
1f9e903
f61837a
bde41fc
daf5b03
36ea1df
41f8893
0a8c6ec
90c342f
a42942c
13d3870
f75cb64
e1992e8
c3d46dc
9ecceef
9d296ec
95fc53a
ae859d0
abc859d
3749d9e
0028170
f9f40b7
c8d5420
9908d72
0e1a5a9
e187d8e
a2e3a85
b7bc6a3
a79dc2f
09f0fe3
1ee14c4
af1eb70
c661e66
e00d35f
742ae7c
9b688ca
3570777
45ff0f0
e841994
da1949c
8dfc97c
cdca5aa
7559ec5
4135d3d
a1cacc9
a2367c8
dfbfcd9
5c04563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { | |
| .Case("bulk-memory", HasBulkMemory) | ||
| .Case("bulk-memory-opt", HasBulkMemoryOpt) | ||
| .Case("call-indirect-overlong", HasCallIndirectOverlong) | ||
| .Case("component-model-thread-context", HasComponentModelThreadContext) | ||
| .Case("compact-imports", HasCompactImports) | ||
| .Case("exception-handling", HasExceptionHandling) | ||
| .Case("extended-const", HasExtendedConst) | ||
|
|
@@ -120,6 +121,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, | |
| Builder.defineMacro("__wasm_tail_call__"); | ||
| if (HasWideArithmetic) | ||
| Builder.defineMacro("__wasm_wide_arithmetic__"); | ||
| if (HasComponentModelThreadContext) | ||
| Builder.defineMacro("__wasm_component_model_thread_context__"); | ||
| // Note that not all wasm features appear here. For example, | ||
| // HasCompatctImports | ||
|
|
||
|
|
@@ -374,6 +377,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures( | |
| HasWideArithmetic = false; | ||
| continue; | ||
| } | ||
| if (Feature == "+component-model-thread-context") { | ||
| HasComponentModelThreadContext = true; | ||
| continue; | ||
| } | ||
| if (Feature == "-component-model-thread-context") { | ||
| HasComponentModelThreadContext = false; | ||
| continue; | ||
| } | ||
|
|
||
| Diags.Report(diag::err_opt_not_valid_with_opt) | ||
| << Feature << "-target-feature"; | ||
|
|
@@ -407,10 +418,11 @@ WebAssemblyTargetInfo::getTargetBuiltins() const { | |
| void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts, | ||
| const TargetInfo *Aux) { | ||
| TargetInfo::adjust(Diags, Opts, Aux); | ||
| // Turn off POSIXThreads and ThreadModel so that we don't predefine _REENTRANT | ||
| // or __STDCPP_THREADS__ if we will eventually end up stripping atomics | ||
| // because they are unsupported. | ||
| if (!HasAtomics || !HasBulkMemory) { | ||
| // If not using component model threading intrinsics, turn off POSIXThreads | ||
| // and ThreadModel so that we don't predefine _REENTRANT or __STDCPP_THREADS__ | ||
| // if we will eventually end up stripping atomics because they are unsupported. | ||
| if (!HasComponentModelThreadContext && | ||
| (!HasAtomics || !HasBulkMemory)) { | ||
|
||
| Opts.POSIXThreads = false; | ||
| Opts.setThreadModel(LangOptions::ThreadModelKind::Single); | ||
| Opts.ThreadsafeStatics = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Mark the feature as DISALLOWED | ||
| .section .custom_section.target_features,"",@ | ||
| .int8 1 | ||
| .int8 45 | ||
| .int8 30 | ||
| .ascii "component-model-thread-context" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .globaltype __stack_pointer, i32 | ||
|
|
||
| .globl _start | ||
| _start: | ||
| .functype _start () -> (i32) | ||
| global.get __stack_pointer | ||
| i32.const 16 | ||
| i32.sub | ||
| drop | ||
| i32.const 0 | ||
| end_function |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Mark the feature as USED | ||
| .section .custom_section.target_features,"",@ | ||
| .int8 1 | ||
| .int8 43 | ||
| .int8 30 | ||
| .ascii "component-model-thread-context" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,10 @@ _start: | |
| # CHECK-NEXT: GlobalType: I32 | ||
| # CHECK-NEXT: GlobalMutable: true | ||
| # CHECK-NEXT: - Module: env | ||
| # CHECK-NEXT: Field: external_func | ||
| # CHECK-NEXT: Kind: FUNCTION | ||
| # CHECK-NEXT: SigIndex: 1 | ||
| # CHECK-NEXT: - Module: env | ||
|
||
| # CHECK-NEXT: Field: __memory_base | ||
| # CHECK-NEXT: Kind: GLOBAL | ||
| # CHECK-NEXT: GlobalType: I32 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t-component-model.o %S/Inputs/use-component-model-thread-context.s | ||
| # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t-global.o %S/Inputs/disallow-component-model-thread-context.s | ||
TartanLlama marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s | ||
| # RUN: wasm-ld --component-model-thread-context -o %t-component-model.wasm %t-component-model.o %t.o | ||
| # RUN: obj2yaml %t-component-model.wasm | FileCheck %s --check-prefix=COMPONENT-MODEL | ||
| # RUN: wasm-ld -o %t-original.wasm %t-global.o %t.o | ||
| # RUN: obj2yaml %t-original.wasm | FileCheck %s --check-prefix=GLOBAL | ||
|
|
||
| .globl _start | ||
| _start: | ||
| .functype _start () -> () | ||
| end_function | ||
|
|
||
| # COMPONENT-MODEL: Name: __init_stack_pointer | ||
| # GLOBAL: Name: __stack_pointer | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the note I added on the line just below here. i.e. does the feature need to be exposed via a C macro like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it was better to have it and not need it when it comes to the libc implementation rather than need it and not have it. Happy to remove if you'd rather.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this'll be useful to have in wasi-libc, yeah, to enable conditional builds of wasm32-wasip3 with/without this feature.