diff options
| -rw-r--r-- | clang/include/clang/Driver/Options.td | 2 | ||||
| -rw-r--r-- | clang/lib/Basic/Targets/WebAssembly.cpp | 19 | ||||
| -rw-r--r-- | clang/lib/Basic/Targets/WebAssembly.h | 10 | ||||
| -rw-r--r-- | clang/test/Preprocessor/wasm-target-features.c | 56 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssembly.td | 4 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td | 40 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h | 2 | ||||
| -rw-r--r-- | llvm/test/CodeGen/WebAssembly/bulk-memory.ll | 7 |
8 files changed, 113 insertions, 27 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 92ea40596c1..2e450a5f239 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2155,6 +2155,8 @@ def msign_ext : Flag<["-"], "msign-ext">, Group<m_wasm_Features_Group>; def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group<m_wasm_Features_Group>; def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Features_Group>; def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>; +def mbulk_memory : Flag<["-"], "mbulk-memory">, Group<m_wasm_Features_Group>; +def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, Group<m_wasm_Features_Group>; def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">, Flags<[HelpHidden]>, diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index 7e6a113868c..48edaded512 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -40,6 +40,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { .Case("nontrapping-fptoint", HasNontrappingFPToInt) .Case("sign-ext", HasSignExt) .Case("exception-handling", HasExceptionHandling) + .Case("bulk-memory", HasBulkMemory) .Default(false); } @@ -59,6 +60,14 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__wasm_simd128__"); if (SIMDLevel >= UnimplementedSIMD128) Builder.defineMacro("__wasm_unimplemented_simd128__"); + if (HasNontrappingFPToInt) + Builder.defineMacro("__wasm_nontrapping_fptoint__"); + if (HasSignExt) + Builder.defineMacro("__wasm_sign_ext__"); + if (HasExceptionHandling) + Builder.defineMacro("__wasm_exception_handling__"); + if (HasBulkMemory) + Builder.defineMacro("__wasm_bulk_memory__"); } void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features, @@ -93,6 +102,8 @@ bool WebAssemblyTargetInfo::initFeatureMap( Features["sign-ext"] = true; if (HasExceptionHandling) Features["exception-handling"] = true; + if (HasBulkMemory) + Features["bulk-memory"] = true; return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } @@ -140,6 +151,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures( HasExceptionHandling = false; continue; } + if (Feature == "+bulk-memory") { + HasBulkMemory = true; + continue; + } + if (Feature == "-bulk-memory") { + HasBulkMemory = 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 b1723505348..1d41f2011bb 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -30,14 +30,14 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { UnimplementedSIMD128, } SIMDLevel = NoSIMD; - bool HasNontrappingFPToInt; - bool HasSignExt; - bool HasExceptionHandling; + bool HasNontrappingFPToInt = false; + bool HasSignExt = false; + bool HasExceptionHandling = false; + bool HasBulkMemory = false; public: explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &) - : TargetInfo(T), SIMDLevel(NoSIMD), HasNontrappingFPToInt(false), - HasSignExt(false), HasExceptionHandling(false) { + : TargetInfo(T) { NoAsmVariants = true; SuitableAlign = 128; LargeArrayMinWidth = 128; diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c index 92aaefd73c0..8c10cd7808a 100644 --- a/clang/test/Preprocessor/wasm-target-features.c +++ b/clang/test/Preprocessor/wasm-target-features.c @@ -17,6 +17,42 @@ // SIMD128-UNIMPLEMENTED:#define __wasm_unimplemented_simd128__ 1{{$}} // // RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mnontrapping-fptoint \ +// RUN: | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mnontrapping-fptoint \ +// RUN: | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT +// +// NONTRAPPING-FPTOINT:#define __wasm_nontrapping_fptoint__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -msign-ext \ +// RUN: | FileCheck %s -check-prefix=SIGN-EXT +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -msign-ext \ +// RUN: | FileCheck %s -check-prefix=SIGN-EXT +// +// SIGN-EXT:#define __wasm_sign_ext__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mexception-handling \ +// RUN: | FileCheck %s -check-prefix=EXCEPTION-HANDLING +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mexception-handling \ +// RUN: | FileCheck %s -check-prefix=EXCEPTION-HANDLING +// +// EXCEPTION-HANDLING:#define __wasm_exception_handling__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mbulk-memory \ +// RUN: | FileCheck %s -check-prefix=BULK-MEMORY +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mbulk-memory \ +// RUN: | FileCheck %s -check-prefix=BULK-MEMORY +// +// BULK-MEMORY:#define __wasm_bulk_memory__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=mvp \ // RUN: | FileCheck %s -check-prefix=MVP // RUN: %clang -E -dM %s -o - 2>&1 \ @@ -24,21 +60,29 @@ // RUN: | FileCheck %s -check-prefix=MVP // // MVP-NOT:#define __wasm_simd128__ +// MVP-NOT:#define __wasm_unimplemented_simd128__ +// MVP-NOT:#define __wasm_nontrapping_fptoint__ +// MVP-NOT:#define __wasm_sign_ext__ +// MVP-NOT:#define __wasm_exception_handling__ +// MVP-NOT:#define __wasm_bulk_memory__ // // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ -// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// RUN: | FileCheck %s -check-prefix=BLEEDING-EDGE // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge \ -// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// RUN: | FileCheck %s -check-prefix=BLEEDING-EDGE // -// BLEEDING_EDGE:#define __wasm_simd128__ 1{{$}} +// BLEEDING-EDGE:#define __wasm_nontrapping_fptoint__ 1{{$}} +// BLEEDING-EDGE:#define __wasm_sign_ext__ 1{{$}} +// BLEEDING-EDGE:#define __wasm_simd128__ 1{{$}} +// BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}} // // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ -// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// RUN: | FileCheck %s -check-prefix=BLEEDING-EDGE-NO-SIMD128 // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ -// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// RUN: | FileCheck %s -check-prefix=BLEEDING-EDGE-NO-SIMD128 // -// BLEEDING_EDGE_NO_SIMD128-NOT:#define __wasm_simd128__ +// BLEEDING-EDGE-NO-SIMD128-NOT:#define __wasm_simd128__ diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td index bb0cae9305d..230c1208e54 100644 --- a/llvm/lib/Target/WebAssembly/WebAssembly.td +++ b/llvm/lib/Target/WebAssembly/WebAssembly.td @@ -47,6 +47,10 @@ def FeatureExceptionHandling : SubtargetFeature<"exception-handling", "HasExceptionHandling", "true", "Enable Wasm exception handling">; +def FeatureBulkMemory : + SubtargetFeature<"bulk-memory", "HasBulkMemory", "true", + "Enable bulk memory operations">; + //===----------------------------------------------------------------------===// // Architectures. //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td index 35d663903e4..71d21094189 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -16,40 +16,48 @@ //===----------------------------------------------------------------------===// def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; + def HasAddr64 : Predicate<"Subtarget->hasAddr64()">; -def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">, - AssemblerPredicate<"FeatureSIMD128", "simd128">; + +def HasSIMD128 : + Predicate<"Subtarget->hasSIMD128()">, + AssemblerPredicate<"FeatureSIMD128", "simd128">; + def HasUnimplementedSIMD128 : Predicate<"Subtarget->hasUnimplementedSIMD128()">, AssemblerPredicate<"FeatureUnimplementedSIMD128", "unimplemented-simd128">; -def HasAtomics : Predicate<"Subtarget->hasAtomics()">, - AssemblerPredicate<"FeatureAtomics", "atomics">; + +def HasAtomics : + Predicate<"Subtarget->hasAtomics()">, + AssemblerPredicate<"FeatureAtomics", "atomics">; + def HasNontrappingFPToInt : Predicate<"Subtarget->hasNontrappingFPToInt()">, - AssemblerPredicate<"FeatureNontrappingFPToInt", - "nontrapping-fptoint">; + AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">; + def NotHasNontrappingFPToInt : Predicate<"!Subtarget->hasNontrappingFPToInt()">, - AssemblerPredicate<"!FeatureNontrappingFPToInt", - "nontrapping-fptoint">; + AssemblerPredicate<"!FeatureNontrappingFPToInt", "nontrapping-fptoint">; + def HasSignExt : Predicate<"Subtarget->hasSignExt()">, - AssemblerPredicate<"FeatureSignExt", - "sign-ext">; + AssemblerPredicate<"FeatureSignExt", "sign-ext">; + def NotHasSignExt : Predicate<"!Subtarget->hasSignExt()">, - AssemblerPredicate<"!FeatureSignExt", - "sign-ext">; + AssemblerPredicate<"!FeatureSignExt", "sign-ext">; def HasExceptionHandling : Predicate<"Subtarget->hasExceptionHandling()">, - AssemblerPredicate<"FeatureExceptionHandling", - "exception-handling">; + AssemblerPredicate<"FeatureExceptionHandling", "exception-handling">; def NotHasExceptionHandling : Predicate<"!Subtarget->hasExceptionHandling()">, - AssemblerPredicate<"!FeatureExceptionHandling", - "exception-handling">; + AssemblerPredicate<"!FeatureExceptionHandling", "exception-handling">; + +def HasBulkMemory : + Predicate<"Subtarget->hasBulkMemory()">, + AssemblerPredicate<"FeatureBulkMemory", "bulk-memory">; //===----------------------------------------------------------------------===// // WebAssembly-specific DAG Node Types. diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h index e6ee2f54c5e..b6f3e6b4a10 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -38,6 +38,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo { bool HasNontrappingFPToInt = false; bool HasSignExt = false; bool HasExceptionHandling = false; + bool HasBulkMemory = false; /// String name of used CPU. std::string CPUString; @@ -89,6 +90,7 @@ public: bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; } bool hasSignExt() const { return HasSignExt; } bool hasExceptionHandling() const { return HasExceptionHandling; } + bool hasBulkMemory() const { return HasBulkMemory; } /// Parses features string setting specified subtarget options. Definition of /// function is auto generated by tblgen. diff --git a/llvm/test/CodeGen/WebAssembly/bulk-memory.ll b/llvm/test/CodeGen/WebAssembly/bulk-memory.ll new file mode 100644 index 00000000000..aa0454b266a --- /dev/null +++ b/llvm/test/CodeGen/WebAssembly/bulk-memory.ll @@ -0,0 +1,7 @@ +; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+bulk-memory + +; Test that basic bulk memory codegen works correctly +; TODO: implement basic bulk memory codegen + +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" |

