[clang] 86ed8cb - [WebAssembly] Add multiple memories feature
Thomas Lively via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 21 14:23:22 PDT 2023
Author: Ashley Nelson
Date: 2023-08-21T14:23:14-07:00
New Revision: 86ed8cb8fabe7716b9046317231f861fee5f126a
URL: https://github.com/llvm/llvm-project/commit/86ed8cb8fabe7716b9046317231f861fee5f126a
DIFF: https://github.com/llvm/llvm-project/commit/86ed8cb8fabe7716b9046317231f861fee5f126a.diff
LOG: [WebAssembly] Add multiple memories feature
Adding to allow users to get this flag into the target features section for
future use cases.
Reviewed By: tlively, aheejin
Differential Revision: https://reviews.llvm.org/D158409
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/WebAssembly.cpp
clang/lib/Basic/Targets/WebAssembly.h
clang/test/Driver/wasm-features.c
clang/test/Preprocessor/wasm-target-features.c
llvm/lib/Target/WebAssembly/WebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d668faf650a721..619c418365c262 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4583,6 +4583,8 @@ def mreference_types : Flag<["-"], "mreference-types">, Group<m_wasm_Features_Gr
def mno_reference_types : Flag<["-"], "mno-reference-types">, Group<m_wasm_Features_Group>;
def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Group>;
def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>;
+def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
+def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group<m_wasm_Features_Driver_Group>,
Values<"command,reactor">,
HelpText<"Execution model (WebAssembly only)">,
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index e9b77e03c03114..f1c925d90cb649 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -57,6 +57,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
.Case("tail-call", HasTailCall)
.Case("reference-types", HasReferenceTypes)
.Case("extended-const", HasExtendedConst)
+ .Case("multimemory", HasMultiMemory)
.Default(false);
}
@@ -96,6 +97,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__wasm_reference_types__");
if (HasExtendedConst)
Builder.defineMacro("__wasm_extended_const__");
+ if (HasMultiMemory)
+ Builder.defineMacro("__wasm_multimemory__");
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
@@ -152,6 +155,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
Features["mutable-globals"] = true;
Features["tail-call"] = true;
Features["reference-types"] = true;
+ Features["multimemory"] = true;
setSIMDLevel(Features, SIMD128, true);
} else if (CPU == "generic") {
Features["sign-ext"] = true;
@@ -260,6 +264,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasExtendedConst = false;
continue;
}
+ if (Feature == "+multimemory") {
+ HasMultiMemory = true;
+ continue;
+ }
+ if (Feature == "-multimemory") {
+ HasMultiMemory = false;
+ continue;
+ }
Diags.Report(diag::err_opt_not_valid_with_opt)
<< Feature << "-target-feature";
diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index 9484898fe1c575..83b1711f9fdf6a 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -63,6 +63,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
bool HasTailCall = false;
bool HasReferenceTypes = false;
bool HasExtendedConst = false;
+ bool HasMultiMemory = false;
std::string ABI;
diff --git a/clang/test/Driver/wasm-features.c b/clang/test/Driver/wasm-features.c
index e5f71b42b5055b..1a43361a4a1080 100644
--- a/clang/test/Driver/wasm-features.c
+++ b/clang/test/Driver/wasm-features.c
@@ -41,3 +41,12 @@
// DEFAULT-NOT: "-target-feature" "-nontrapping-fptoint"
// MVP-NOT: "-target-feature" "+nontrapping-fptoint"
// BLEEDING-EDGE-NOT: "-target-feature" "-nontrapping-fptoint"
+
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mmultimemory 2>&1 | FileCheck %s -check-prefix=MULTIMEMORY
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-multimemory 2>&1 | FileCheck %s -check-prefix=NO-MULTIMEMORY
+
+// MULTIMEMORY: "-target-feature" "+multimemory"
+// NO-MULTIMEMORY: "-target-feature" "-multimemory"
+// DEFAULT-NOT: "-target-feature" "-multimemory"
+// MVP-NOT: "-target-feature" "+multimemory"
+// BLEEDING-EDGE-NOT: "-target-feature" "-multimemory"
diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c
index c05b26a0c22784..c225e226b69ba1 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -114,6 +114,16 @@
// RUN: | FileCheck %s -check-prefix=EXTENDED-CONST
//
// EXTENDED-CONST:#define __wasm_extended_const__ 1{{$}}
+//
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mmultimemory \
+// RUN: | FileCheck %s -check-prefix=MULTIMEMORY
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mmultimemory \
+// RUN: | FileCheck %s -check-prefix=MULTIMEMORY
+//
+// MULTIMEMORY:#define __wasm_multimemory__ 1{{$}}
+//
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target wasm32-unknown-unknown -mcpu=mvp \
@@ -133,6 +143,7 @@
// MVP-NOT:#define __wasm_tail_call__
// MVP-NOT:#define __wasm_reference_types__
// MVP-NOT:#define __wasm_extended_const__
+// MVP-NOT:#define __wasm_multimemory__
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
@@ -148,6 +159,7 @@
// BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
// 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-NOT:#define __wasm_unimplemented_simd128__ 1{{$}}
// BLEEDING-EDGE-NOT:#define __wasm_exception_handling__ 1{{$}}
// BLEEDING-EDGE-NOT:#define __wasm_multivalue__ 1{{$}}
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 7531d36a74a64f..d538197450b65b 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -71,6 +71,10 @@ def FeatureExtendedConst :
SubtargetFeature<"extended-const", "HasExtendedConst", "true",
"Enable extended const expressions">;
+def FeatureMultiMemory :
+ SubtargetFeature<"multimemory", "HasMultiMemory", "true",
+ "Enable multiple memories">;
+
//===----------------------------------------------------------------------===//
// Architectures.
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
index 134a0efc682289..59ea9247bd86f5 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -70,6 +70,10 @@ def HasExtendedConst :
Predicate<"Subtarget->hasExtendedConst()">,
AssemblerPredicate<(all_of FeatureExtendedConst), "extended-const">;
+def HasMultiMemory :
+ Predicate<"Subtarget->hasMultiMemory()">,
+ AssemblerPredicate<(all_of FeatureMultiMemory), "multimemory">;
+
//===----------------------------------------------------------------------===//
// WebAssembly-specific DAG Node Types.
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
index 4c1b3da787aeac..85d02b087c786e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -49,6 +49,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
bool HasTailCall = false;
bool HasReferenceTypes = false;
bool HasExtendedConst = false;
+ bool HasMultiMemory = false;
/// What processor and OS we're targeting.
Triple TargetTriple;
@@ -101,6 +102,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
bool hasMutableGlobals() const { return HasMutableGlobals; }
bool hasTailCall() const { return HasTailCall; }
bool hasReferenceTypes() const { return HasReferenceTypes; }
+ bool hasMultiMemory() const { return HasMultiMemory; }
/// Parses features string setting specified subtarget options. Definition of
/// function is auto generated by tblgen.
More information about the cfe-commits
mailing list