Skip to content

Commit

Permalink
[WebAssembly] Add multiple memories feature
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ashleynh authored and tlively committed Aug 21, 2023
1 parent 7db1853 commit 86ed8cb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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)">,
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/wasm-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 12 additions & 0 deletions clang/test/Preprocessor/wasm-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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{{$}}
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssembly.td
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 86ed8cb

Please sign in to comment.