Skip to content

Commit 5bbf1ea

Browse files
authored
[WebAssembly] Enable multivalue and reference-types in generic CPU config (#80923)
This enables multivalue and reference-types in `-mcpu=generic` configuration. These proposals have been standardized and supported in all major browsers for several years at this point: https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md
1 parent 6f390ea commit 5bbf1ea

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ AIX Support
718718
WebAssembly Support
719719
^^^^^^^^^^^^^^^^^^^
720720

721+
The -mcpu=generic configuration now enables multivalue and reference-types.These
722+
proposals are standardized and available in all major engines. Enabling
723+
multivalue here only enables the language feature but does not turn on the
724+
multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
725+
721726
AVR Support
722727
^^^^^^^^^^^
723728

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,26 @@ void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
148148
bool WebAssemblyTargetInfo::initFeatureMap(
149149
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
150150
const std::vector<std::string> &FeaturesVec) const {
151-
if (CPU == "bleeding-edge") {
151+
auto addGenericFeatures = [&]() {
152+
Features["multivalue"] = true;
153+
Features["mutable-globals"] = true;
154+
Features["reference-types"] = true;
155+
Features["sign-ext"] = true;
156+
};
157+
auto addBleedingEdgeFeatures = [&]() {
158+
addGenericFeatures();
152159
Features["atomics"] = true;
153160
Features["bulk-memory"] = true;
154161
Features["multimemory"] = true;
155-
Features["mutable-globals"] = true;
156162
Features["nontrapping-fptoint"] = true;
157-
Features["reference-types"] = true;
158-
Features["sign-ext"] = true;
159163
Features["tail-call"] = true;
160164
Features["half-precision"] = true;
161165
setSIMDLevel(Features, SIMD128, true);
162-
} else if (CPU == "generic") {
163-
Features["mutable-globals"] = true;
164-
Features["sign-ext"] = true;
166+
};
167+
if (CPU == "generic") {
168+
addGenericFeatures();
169+
} else if (CPU == "bleeding-edge") {
170+
addBleedingEdgeFeatures();
165171
}
166172

167173
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);

clang/test/Preprocessor/wasm-target-features.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@
152152
// RUN: -target wasm64-unknown-unknown -mcpu=generic \
153153
// RUN: | FileCheck %s -check-prefix=GENERIC-INCLUDE
154154
//
155+
// GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
155156
// GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
157+
// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
156158
// GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
157159
//
158160
// RUN: %clang -E -dM %s -o - 2>&1 \
@@ -167,9 +169,7 @@
167169
// GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
168170
// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
169171
// GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
170-
// GENERIC-NOT: #define __wasm_multivalue__ 1{{$}}
171172
// GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
172-
// GENERIC-NOT: #define __wasm_reference_types__ 1{{$}}
173173
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
174174
// GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
175175
// GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}
@@ -184,6 +184,7 @@
184184
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_atomics__ 1{{$}}
185185
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
186186
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
187+
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
187188
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
188189
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
189190
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
@@ -200,7 +201,6 @@
200201
//
201202
// BLEEDING-EDGE-NOT: #define __wasm_exception_handling__ 1{{$}}
202203
// BLEEDING-EDGE-NOT: #define __wasm_extended_const__ 1{{$}}
203-
// BLEEDING-EDGE-NOT: #define __wasm_multivalue__ 1{{$}}
204204
// BLEEDING-EDGE-NOT: #define __wasm_relaxed_simd__ 1{{$}}
205205

206206
// RUN: %clang -E -dM %s -o - 2>&1 \

0 commit comments

Comments
 (0)