Skip to content

Commit 2b8ad6b

Browse files
committed
[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
1 parent 2ff1495 commit 2b8ad6b

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,43 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
9696
}
9797

9898
void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
99-
SIMDEnum Level) {
99+
SIMDEnum Level, bool Enabled) {
100+
if (Enabled) {
101+
switch (Level) {
102+
case UnimplementedSIMD128:
103+
Features["unimplemented-simd128"] = true;
104+
LLVM_FALLTHROUGH;
105+
case SIMD128:
106+
Features["simd128"] = true;
107+
LLVM_FALLTHROUGH;
108+
case NoSIMD:
109+
break;
110+
}
111+
return;
112+
}
113+
100114
switch (Level) {
101-
case UnimplementedSIMD128:
102-
Features["unimplemented-simd128"] = true;
103-
LLVM_FALLTHROUGH;
115+
case NoSIMD:
104116
case SIMD128:
105-
Features["simd128"] = true;
117+
Features["simd128"] = false;
106118
LLVM_FALLTHROUGH;
107-
case NoSIMD:
119+
case UnimplementedSIMD128:
120+
Features["unimplemented-simd128"] = false;
108121
break;
109122
}
110123
}
111124

125+
void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
126+
StringRef Name,
127+
bool Enabled) const {
128+
if (Name == "simd128")
129+
setSIMDLevel(Features, SIMD128, Enabled);
130+
else if (Name == "unimplemented-simd128")
131+
setSIMDLevel(Features, UnimplementedSIMD128, Enabled);
132+
else
133+
Features[Name] = Enabled;
134+
}
135+
112136
bool WebAssemblyTargetInfo::initFeatureMap(
113137
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
114138
const std::vector<std::string> &FeaturesVec) const {
@@ -119,30 +143,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
119143
Features["atomics"] = true;
120144
Features["mutable-globals"] = true;
121145
Features["tail-call"] = true;
122-
setSIMDLevel(Features, SIMD128);
146+
setSIMDLevel(Features, SIMD128, true);
123147
}
124-
// Other targets do not consider user-configured features here, but while we
125-
// are actively developing new features it is useful to let user-configured
126-
// features control availability of builtins
127-
setSIMDLevel(Features, SIMDLevel);
128-
if (HasNontrappingFPToInt)
129-
Features["nontrapping-fptoint"] = true;
130-
if (HasSignExt)
131-
Features["sign-ext"] = true;
132-
if (HasExceptionHandling)
133-
Features["exception-handling"] = true;
134-
if (HasBulkMemory)
135-
Features["bulk-memory"] = true;
136-
if (HasAtomics)
137-
Features["atomics"] = true;
138-
if (HasMutableGlobals)
139-
Features["mutable-globals"] = true;
140-
if (HasMultivalue)
141-
Features["multivalue"] = true;
142-
if (HasTailCall)
143-
Features["tail-call"] = true;
144-
if (HasReferenceTypes)
145-
Features["reference-types"] = true;
146148

147149
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
148150
}

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6969
MacroBuilder &Builder) const override;
7070

7171
private:
72-
static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level);
72+
static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level,
73+
bool Enabled);
7374

7475
bool
7576
initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
7677
StringRef CPU,
7778
const std::vector<std::string> &FeaturesVec) const override;
7879
bool hasFeature(StringRef Feature) const final;
7980

81+
void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
82+
bool Enabled) const final;
83+
8084
bool handleTargetFeatures(std::vector<std::string> &Features,
8185
DiagnosticsEngine &Diags) final;
8286

0 commit comments

Comments
 (0)