summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/Targets/WebAssembly.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2019-01-10 23:49:00 +0000
committerThomas Lively <tlively@google.com>2019-01-10 23:49:00 +0000
commitb7b9fdc114c1f9c788da914dac5c343277805446 (patch)
treeb9510e1696315e7d935dc9d115b0e46c572beba0 /clang/lib/Basic/Targets/WebAssembly.cpp
parentf57a247df7ccf1d9bf358016d91bc26e6d8b3d92 (diff)
downloadbcm5719-llvm-b7b9fdc114c1f9c788da914dac5c343277805446.tar.gz
bcm5719-llvm-b7b9fdc114c1f9c788da914dac5c343277805446.zip
[WebAssembly] Add unimplemented-simd128 feature, gate builtins
Summary: Depends on D56501. Also adds a macro define `__wasm_unimplemented_simd128__` for feature detection of unimplemented SIMD builtins. Reviewers: aheejin, dschuff Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits, rrwinterton llvm-svn: 350909
Diffstat (limited to 'clang/lib/Basic/Targets/WebAssembly.cpp')
-rw-r--r--clang/lib/Basic/Targets/WebAssembly.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index b8a2a092aff..2fdc84bb8cc 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -24,6 +24,8 @@ using namespace clang::targets;
const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
#define BUILTIN(ID, TYPE, ATTRS) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
+ {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
{#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
#include "clang/Basic/BuiltinsWebAssembly.def"
@@ -35,6 +37,7 @@ static constexpr llvm::StringLiteral ValidCPUNames[] = {
bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
return llvm::StringSwitch<bool>(Feature)
.Case("simd128", SIMDLevel >= SIMD128)
+ .Case("unimplemented-simd128", SIMDLevel >= UnimplementedSIMD128)
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
.Case("sign-ext", HasSignExt)
.Case("exception-handling", HasExceptionHandling)
@@ -55,6 +58,44 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
if (SIMDLevel >= SIMD128)
Builder.defineMacro("__wasm_simd128__");
+ if (SIMDLevel >= UnimplementedSIMD128)
+ Builder.defineMacro("__wasm_unimplemented_simd128__");
+}
+
+void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
+ SIMDEnum Level) {
+ switch (Level) {
+ case UnimplementedSIMD128:
+ Features["unimplemented-simd128"] = true;
+ LLVM_FALLTHROUGH;
+ case SIMD128:
+ Features["simd128"] = true;
+ LLVM_FALLTHROUGH;
+ case NoSIMD:
+ break;
+ }
+}
+
+bool WebAssemblyTargetInfo::initFeatureMap(
+ llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
+ const std::vector<std::string> &FeaturesVec) const {
+ if (CPU == "bleeding-edge") {
+ Features["nontrapping-fptoint"] = true;
+ Features["sign-ext"] = true;
+ setSIMDLevel(Features, SIMD128);
+ }
+ // Other targets do not consider user-configured features here, but while we
+ // are actively developing new features it is useful to let user-configured
+ // features control availability of builtins
+ setSIMDLevel(Features, SIMDLevel);
+ if (HasNontrappingFPToInt)
+ Features["nontrapping-fptoint"] = true;
+ if (HasSignExt)
+ Features["sign-ext"] = true;
+ if (HasExceptionHandling)
+ Features["exception-handling"] = true;
+
+ return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
}
bool WebAssemblyTargetInfo::handleTargetFeatures(
@@ -68,6 +109,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
continue;
}
+ if (Feature == "+unimplemented-simd128") {
+ SIMDLevel = std::max(SIMDLevel, SIMDEnum(UnimplementedSIMD128));
+ continue;
+ }
+ if (Feature == "-unimplemented-simd128") {
+ SIMDLevel = std::min(SIMDLevel, SIMDEnum(UnimplementedSIMD128 - 1));
+ continue;
+ }
if (Feature == "+nontrapping-fptoint") {
HasNontrappingFPToInt = true;
continue;
OpenPOWER on IntegriCloud