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 @@ -3310,6 +3310,8 @@ def msimd128 : Flag<["-"], "msimd128">, Group; def mno_simd128 : Flag<["-"], "mno-simd128">, Group; +def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group; +def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, Group; def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, Group; def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, Group; def msign_ext : Flag<["-"], "msign-ext">, Group; 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 @@ -27,6 +27,7 @@ enum SIMDEnum { NoSIMD, SIMD128, + RelaxedSIMD, } SIMDLevel = NoSIMD; bool HasNontrappingFPToInt = false; 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 @@ -46,6 +46,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { return llvm::StringSwitch(Feature) .Case("simd128", SIMDLevel >= SIMD128) + .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD) .Case("nontrapping-fptoint", HasNontrappingFPToInt) .Case("sign-ext", HasSignExt) .Case("exception-handling", HasExceptionHandling) @@ -72,6 +73,8 @@ defineCPUMacros(Builder, "wasm", /*Tuning=*/false); if (SIMDLevel >= SIMD128) Builder.defineMacro("__wasm_simd128__"); + if (SIMDLevel >= RelaxedSIMD) + Builder.defineMacro("__wasm_relaxed_simd__"); if (HasNontrappingFPToInt) Builder.defineMacro("__wasm_nontrapping_fptoint__"); if (HasSignExt) @@ -99,6 +102,9 @@ case SIMD128: Features["simd128"] = true; LLVM_FALLTHROUGH; + case RelaxedSIMD: + Features["relaxed-simd"] = true; + LLVM_FALLTHROUGH; case NoSIMD: break; } @@ -109,6 +115,9 @@ case NoSIMD: case SIMD128: Features["simd128"] = false; + LLVM_FALLTHROUGH; + case RelaxedSIMD: + Features["relaxed-simd"] = false; break; } } @@ -118,6 +127,8 @@ bool Enabled) const { if (Name == "simd128") setSIMDLevel(Features, SIMD128, Enabled); + else if (Name == "relaxed-simd") + setSIMDLevel(Features, RelaxedSIMD, Enabled); else Features[Name] = Enabled; } @@ -149,6 +160,14 @@ SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1)); continue; } + if (Feature == "+relaxed-simd") { + SIMDLevel = std::max(SIMDLevel, RelaxedSIMD); + continue; + } + if (Feature == "-relaxed-simd") { + SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1)); + continue; + } if (Feature == "+nontrapping-fptoint") { HasNontrappingFPToInt = true; continue; 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 @@ -7,6 +7,15 @@ // // SIMD128:#define __wasm_simd128__ 1{{$}} +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mrelaxed-simd \ +// RUN: | FileCheck %s -check-prefix=RELAXED-SIMD +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mrelaxed-simd \ +// RUN: | FileCheck %s -check-prefix=RELAXED-SIMD +// +// RELAXED-SIMD:#define __wasm_relaxed_simd__ 1{{$}} + // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mnontrapping-fptoint \ // RUN: | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT