[clang] [WebAssembly] Enable multivalue and reference-types in generic CPU config (PR #80923)

Heejin Ahn via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 23:18:10 PDT 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/5] [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/5] 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
 ^^^^^^^^^^^

>From de6aa6aa0891bb11ae7402d2cbccbcd82cd4fc77 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Tue, 23 Apr 2024 13:21:15 +0000
Subject: [PATCH 3/5] Enable only multivalue and reference types

---
 clang/docs/ReleaseNotes.rst                    |  8 ++++----
 clang/lib/Basic/Targets/WebAssembly.cpp        | 10 +++++-----
 clang/test/Preprocessor/wasm-target-features.c |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 731dc198559928..68a16c00311523 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -668,10 +668,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. Enabling multivalue here only enables the language feature
-but does not turn on the multivalue ABI.
+The -mcpu=generic configuration now enables multivalue and reference-types.These
+proposals are standardized and available in all major engines. Enabling
+multivalue here only enables the language feature but does not turn on the
+multivalue ABI.
 
 AVR Support
 ^^^^^^^^^^^
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 38fe4013090f40..dd366093547308 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -150,22 +150,22 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   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 = [&]() {
+    addGenericFeatures();
+    Features["nontrapping-fptoint"] = true;
+    Features["bulk-memory"] = true;
     Features["atomics"] = true;
     Features["tail-call"] = true;
     Features["multimemory"] = true;
     setSIMDLevel(Features, SIMD128, true);
   };
-  if (CPU == "bleeding-edge") {
+  if (CPU == "generic") {
     addGenericFeatures();
+  } else if (CPU == "bleeding-edge") {
     addBleedingEdgeFeatures();
-  } else if (CPU == "generic") {
-    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 5834e6d183bc9c..150b4f4a6a8897 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,10 +155,10 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 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_nontrapping_fptoint__ 1{{$}}
+// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}

>From 91df749ad9e11b78adbb6e229da92eacf9294a24 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Tue, 23 Apr 2024 14:00:06 +0000
Subject: [PATCH 4/5] Enable multivalue and reference-types in bleeding-edge

---
 clang/test/Preprocessor/wasm-target-features.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c
index 150b4f4a6a8897..63ea812f289663 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -181,9 +181,10 @@
 // BLEEDING-EDGE-DAG:#define __wasm_mutable_globals__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_tail_call__ 1{{$}}
 // BLEEDING-EDGE-DAG:#define __wasm_multimemory__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_multivalue__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_reference_types__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_exception_handling__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_multivalue__ 1{{$}}
-// BLEEDING-EDGE-NOT:#define __wasm_reference_types__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_extended_const__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_relaxed_simd__ 1{{$}}
 

>From f4aee6037e3a7718fdaa64739419340b358b2d26 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 24 Apr 2024 14:35:32 +0900
Subject: [PATCH 5/5] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Alon Zakai <alonzakai at gmail.com>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 68a16c00311523..1d196ebeff8aa7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -671,7 +671,7 @@ WebAssembly Support
 The -mcpu=generic configuration now enables multivalue and reference-types.These
 proposals are standardized and available in all major engines. Enabling
 multivalue here only enables the language feature but does not turn on the
-multivalue ABI.
+multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
 
 AVR Support
 ^^^^^^^^^^^



More information about the cfe-commits mailing list