[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

Heejin Ahn via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 22 16:32:47 PST 2024


https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/80923

>From d6fd48794112d6c1402222024d7cd55b5fe5e55e Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Tue, 6 Feb 2024 00:31:59 +0000
Subject: [PATCH 1/2] [WebAssembly] Add more features to generic CPU config

This enables nontrapping-fptoint, multivlaue, reference-types, and
bulk-memory 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
---
 clang/docs/ReleaseNotes.rst                    |  4 ++++
 clang/lib/Basic/Targets/WebAssembly.cpp        | 18 ++++++++++++------
 clang/test/Preprocessor/wasm-target-features.c |  8 ++++----
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..5a07dcca106876 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ AIX Support
 WebAssembly Support
 ^^^^^^^^^^^^^^^^^^^
 
+The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
+reference-types, and bulk-memory.These proposals are standardized and available
+in all major engines.
+
 AVR Support
 ^^^^^^^^^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index f1c925d90cb649..38fe4013090f40 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,19 +147,25 @@ void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
 bool WebAssemblyTargetInfo::initFeatureMap(
     llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
     const std::vector<std::string> &FeaturesVec) const {
-  if (CPU == "bleeding-edge") {
-    Features["nontrapping-fptoint"] = true;
+  auto addGenericFeatures = [&]() {
     Features["sign-ext"] = true;
+    Features["mutable-globals"] = true;
+    Features["nontrapping-fptoint"] = true;
     Features["bulk-memory"] = true;
+    Features["reference-types"] = true;
+    Features["multivalue"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
     Features["atomics"] = true;
-    Features["mutable-globals"] = true;
     Features["tail-call"] = true;
-    Features["reference-types"] = true;
     Features["multimemory"] = true;
     setSIMDLevel(Features, SIMD128, true);
+  };
+  if (CPU == "bleeding-edge") {
+    addGenericFeatures();
+    addBleedingEdgeFeatures();
   } else if (CPU == "generic") {
-    Features["sign-ext"] = true;
-    Features["mutable-globals"] = true;
+    addGenericFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c
index eccd432aa8eee6..5834e6d183bc9c 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,15 +155,15 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-DAG:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
 // GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
-// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \

>From 01ac8bd38aaa86e62b00709790a36e050528f853 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Fri, 23 Feb 2024 00:31:41 +0000
Subject: [PATCH 2/2] Mention that ABI is not turned on

---
 clang/docs/ReleaseNotes.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5a07dcca106876..ec85d8882c1861 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -261,7 +261,8 @@ WebAssembly Support
 
 The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
 reference-types, and bulk-memory.These proposals are standardized and available
-in all major engines.
+in all major engines. Enabling multivalue here only enables the language feature
+but does not turn on the multivalue ABI.
 
 AVR Support
 ^^^^^^^^^^^



More information about the cfe-commits mailing list