[clang] [llvm] [WebAssembly] Enable extended-const feature by default (PR #127721)

Sam Clegg via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 15:46:20 PST 2025


https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/127721

None

>From 6d8b255090f08835b8b6b22e7c3d2abfe5ef7531 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Tue, 18 Feb 2025 15:34:13 -0800
Subject: [PATCH] [WebAssembly] Enable extended-const feature by default

---
 clang/docs/ReleaseNotes.rst                           | 7 +++++++
 clang/lib/Basic/Targets/WebAssembly.cpp               | 1 +
 clang/test/Preprocessor/wasm-target-features.c        | 2 +-
 llvm/docs/ReleaseNotes.md                             | 7 +++++++
 llvm/lib/Target/WebAssembly/WebAssembly.td            | 7 ++++---
 llvm/test/CodeGen/WebAssembly/target-features-cpus.ll | 5 ++++-
 6 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6056a6964fbcc..7b90d4686d96f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,13 @@ NetBSD Support
 WebAssembly Support
 ^^^^^^^^^^^^^^^^^^^
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 AVR Support
 ^^^^^^^^^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index f19c57f1a3a50..848b28441e22d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -168,6 +168,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
     Features["bulk-memory"] = true;
     Features["bulk-memory-opt"] = true;
     Features["call-indirect-overlong"] = true;
+    Features["extended-const"] = true;
     Features["multivalue"] = true;
     Features["mutable-globals"] = true;
     Features["nontrapping-fptoint"] = true;
diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c
index 71b7cf6a5d43c..ed1917b7e1b77 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,6 +164,7 @@
 // RUN:   | FileCheck %s -check-prefix=GENERIC-INCLUDE
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
@@ -179,7 +180,6 @@
 //
 // GENERIC-NOT: #define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index c9543ff09217a..e83962184d953 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -110,6 +110,13 @@ Changes to the RISC-V Backend
 Changes to the WebAssembly Backend
 ----------------------------------
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 Changes to the Windows Target
 -----------------------------
 
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 13603f8181198..d574f27f2f226 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -123,9 +123,10 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
 // the importance of the features.
 def : ProcessorModel<"generic", NoSchedModel,
                       [FeatureBulkMemory, FeatureBulkMemoryOpt,
-                       FeatureCallIndirectOverlong, FeatureMultivalue,
-                       FeatureMutableGlobals, FeatureNontrappingFPToInt,
-                       FeatureReferenceTypes, FeatureSignExt]>;
+                       FeatureCallIndirectOverlong, FeatureExtendedConst,
+                       FeatureMultivalue, FeatureMutableGlobals,
+                       FeatureNontrappingFPToInt, FeatureReferenceTypes,
+                       FeatureSignExt]>;
 
 // Lime1: <https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
 def : ProcessorModel<"lime1", NoSchedModel,
diff --git a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
index 1c77ad5c049a5..e363910726934 100644
--- a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
+++ b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
@@ -14,7 +14,7 @@ target triple = "wasm32-unknown-unknown"
 
 ; generic: +call-indirect-overlong, +multivalue, +mutable-globals, +reference-types, +sign-ext
 ; GENERIC-LABEL: .custom_section.target_features,"",@
-; GENERIC-NEXT: .int8  8
+; GENERIC-NEXT: .int8  9
 ; GENERIC-NEXT: .int8  43
 ; GENERIC-NEXT: .int8  11
 ; GENERIC-NEXT: .ascii  "bulk-memory"
@@ -25,6 +25,9 @@ target triple = "wasm32-unknown-unknown"
 ; GENERIC-NEXT: .int8  22
 ; GENERIC-NEXT: .ascii  "call-indirect-overlong"
 ; GENERIC-NEXT: .int8  43
+; GENERIC-NEXT: .int8  14
+; GENERIC-NEXT: .ascii  "extended-const"
+; GENERIC-NEXT: .int8  43
 ; GENERIC-NEXT: .int8  10
 ; GENERIC-NEXT: .ascii  "multivalue"
 ; GENERIC-NEXT: .int8  43



More information about the cfe-commits mailing list