From 2b8ad6b6040833f4f8702721ebaa7749e5c23e60 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 12 Aug 2020 11:35:08 -0700 Subject: [PATCH] [WebAssembly] Don't depend on the flags set by handleTargetFeatures in initFeatureMap. Properly set "simd128" in the feature map when "unimplemented-simd128" is requested. initFeatureMap is used to create the feature vector used by handleTargetFeatures. There are later calls to initFeatureMap in CodeGen that were using these flags to recreate the map. But the original feature vector should be passed to those calls. So that should be enough to rebuild the map. The only issue seemed to be that simd128 was not enabled in the map by the first call to initFeatureMap. Using the SIMDLevel set by handleTargetFeatures in the later calls allowed simd128 to be set in the later versions of the map. To fix this I've added an override of setFeatureEnabled that will update the map the first time with the correct simd dependency. Differential Revision: https://reviews.llvm.org/D85806 --- clang/lib/Basic/Targets/WebAssembly.cpp | 62 +++++++++++++------------ clang/lib/Basic/Targets/WebAssembly.h | 6 ++- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index 6746768090f5..dcb3d8fd7790 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -96,19 +96,43 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, } void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, - SIMDEnum Level) { + SIMDEnum Level, bool Enabled) { + if (Enabled) { + switch (Level) { + case UnimplementedSIMD128: + Features["unimplemented-simd128"] = true; + LLVM_FALLTHROUGH; + case SIMD128: + Features["simd128"] = true; + LLVM_FALLTHROUGH; + case NoSIMD: + break; + } + return; + } + switch (Level) { - case UnimplementedSIMD128: - Features["unimplemented-simd128"] = true; - LLVM_FALLTHROUGH; - case SIMD128: - Features["simd128"] = true; - LLVM_FALLTHROUGH; case NoSIMD: + case SIMD128: + Features["simd128"] = false; + LLVM_FALLTHROUGH; + case UnimplementedSIMD128: + Features["unimplemented-simd128"] = false; break; } } +void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap &Features, + StringRef Name, + bool Enabled) const { + if (Name == "simd128") + setSIMDLevel(Features, SIMD128, Enabled); + else if (Name == "unimplemented-simd128") + setSIMDLevel(Features, UnimplementedSIMD128, Enabled); + else + Features[Name] = Enabled; +} + bool WebAssemblyTargetInfo::initFeatureMap( llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeaturesVec) const { @@ -119,30 +143,8 @@ bool WebAssemblyTargetInfo::initFeatureMap( Features["atomics"] = true; Features["mutable-globals"] = true; Features["tail-call"] = true; - setSIMDLevel(Features, SIMD128); + setSIMDLevel(Features, SIMD128, true); } - // 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; - if (HasBulkMemory) - Features["bulk-memory"] = true; - if (HasAtomics) - Features["atomics"] = true; - if (HasMutableGlobals) - Features["mutable-globals"] = true; - if (HasMultivalue) - Features["multivalue"] = true; - if (HasTailCall) - Features["tail-call"] = true; - if (HasReferenceTypes) - Features["reference-types"] = true; return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 77a2fe9ae117..0068ccb5d71f 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -69,7 +69,8 @@ protected: MacroBuilder &Builder) const override; private: - static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level); + static void setSIMDLevel(llvm::StringMap &Features, SIMDEnum Level, + bool Enabled); bool initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, @@ -77,6 +78,9 @@ private: const std::vector &FeaturesVec) const override; bool hasFeature(StringRef Feature) const final; + void setFeatureEnabled(llvm::StringMap &Features, StringRef Name, + bool Enabled) const final; + bool handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) final;