diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4580,6 +4580,8 @@ def mno_reference_types : Flag<["-"], "mno-reference-types">, Group; def mextended_const : Flag<["-"], "mextended-const">, Group; def mno_extended_const : Flag<["-"], "mno-extended-const">, Group; +def mmultimemory : Flag<["-"], "mmultimemory">, Group; +def mno_multimemory : Flag<["-"], "mno-multimemory">, Group; def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group, Values<"command,reactor">, HelpText<"Execution model (WebAssembly only)">, diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -63,6 +63,7 @@ bool HasTailCall = false; bool HasReferenceTypes = false; bool HasExtendedConst = false; + bool HasMultiMemory = false; std::string ABI; diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -57,6 +57,7 @@ .Case("tail-call", HasTailCall) .Case("reference-types", HasReferenceTypes) .Case("extended-const", HasExtendedConst) + .Case("multimemory", HasMultiMemory) .Default(false); } @@ -96,6 +97,8 @@ 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 @@ 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 @@ 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/test/Driver/wasm-features.c b/clang/test/Driver/wasm-features.c --- 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=MULTI-MEMORY +// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-multimemory 2>&1 | FileCheck %s -check-prefix=NO-MULTI-MEMORY + +// 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 --- 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 --- a/llvm/lib/Target/WebAssembly/WebAssembly.td +++ b/llvm/lib/Target/WebAssembly/WebAssembly.td @@ -71,6 +71,10 @@ 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 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -70,6 +70,10 @@ 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 --- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -49,6 +49,7 @@ 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 @@ 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. diff --git a/llvm/test/CodeGen/WebAssembly/multimemory.ll b/llvm/test/CodeGen/WebAssembly/multimemory.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/WebAssembly/multimemory.ll @@ -0,0 +1,15 @@ +; RUN: llc < %s -mcpu=mvp -mattr=+multimemory | FileCheck %s + +; Test that multimemory is properly emitted into the target features section + +target triple = "wasm32-unknown-unknown" + +define void @foo() { + ret void +} + +; CHECK-LABEL: .custom_section.target_features +; CHECK-NEXT: .int8 1 +; CHECK-NEXT: .int8 43 +; CHECK-NEXT: .int8 11 +; CHECK-NEXT: .ascii "multimemory"