18#include "llvm/ADT/StringSwitch.h"
24#define BUILTIN(ID, TYPE, ATTRS) \
25 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
26#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
27 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
28#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
29 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::HEADER, ALL_LANGUAGES},
30#include "clang/Basic/BuiltinsWebAssembly.def"
34 {
"mvp"}, {
"bleeding-edge"}, {
"generic"}};
39 if (Name !=
"mvp" && Name !=
"experimental-mv")
46bool WebAssemblyTargetInfo::hasFeature(StringRef Feature)
const {
47 return llvm::StringSwitch<bool>(Feature)
48 .Case(
"atomics", HasAtomics)
49 .Case(
"bulk-memory", HasBulkMemory)
50 .Case(
"exception-handling", HasExceptionHandling)
51 .Case(
"extended-const", HasExtendedConst)
52 .Case(
"fp16", HasFP16)
53 .Case(
"multimemory", HasMultiMemory)
54 .Case(
"multivalue", HasMultivalue)
55 .Case(
"mutable-globals", HasMutableGlobals)
56 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
57 .Case(
"reference-types", HasReferenceTypes)
58 .Case(
"relaxed-simd", SIMDLevel >= RelaxedSIMD)
59 .Case(
"sign-ext", HasSignExt)
60 .Case(
"simd128", SIMDLevel >= SIMD128)
61 .Case(
"tail-call", HasTailCall)
65bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
69void WebAssemblyTargetInfo::fillValidCPUList(
78 Builder.defineMacro(
"__wasm_atomics__");
80 Builder.defineMacro(
"__wasm_bulk_memory__");
81 if (HasExceptionHandling)
82 Builder.defineMacro(
"__wasm_exception_handling__");
84 Builder.defineMacro(
"__wasm_extended_const__");
86 Builder.defineMacro(
"__wasm_multimemory__");
88 Builder.defineMacro(
"__wasm_fp16__");
90 Builder.defineMacro(
"__wasm_multivalue__");
91 if (HasMutableGlobals)
92 Builder.defineMacro(
"__wasm_mutable_globals__");
93 if (HasNontrappingFPToInt)
94 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
95 if (HasReferenceTypes)
96 Builder.defineMacro(
"__wasm_reference_types__");
97 if (SIMDLevel >= RelaxedSIMD)
98 Builder.defineMacro(
"__wasm_relaxed_simd__");
100 Builder.defineMacro(
"__wasm_sign_ext__");
101 if (SIMDLevel >= SIMD128)
102 Builder.defineMacro(
"__wasm_simd128__");
104 Builder.defineMacro(
"__wasm_tail_call__");
106 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
107 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
108 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
109 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
112void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
113 SIMDEnum Level,
bool Enabled) {
117 Features[
"relaxed-simd"] =
true;
120 Features[
"simd128"] =
true;
131 Features[
"simd128"] =
false;
134 Features[
"relaxed-simd"] =
false;
139void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
141 bool Enabled)
const {
142 if (Name ==
"simd128")
143 setSIMDLevel(Features, SIMD128, Enabled);
144 else if (Name ==
"relaxed-simd")
145 setSIMDLevel(Features, RelaxedSIMD, Enabled);
147 Features[Name] = Enabled;
150bool WebAssemblyTargetInfo::initFeatureMap(
152 const std::vector<std::string> &FeaturesVec)
const {
153 auto addGenericFeatures = [&]() {
154 Features[
"multivalue"] =
true;
155 Features[
"mutable-globals"] =
true;
156 Features[
"reference-types"] =
true;
157 Features[
"sign-ext"] =
true;
159 auto addBleedingEdgeFeatures = [&]() {
160 addGenericFeatures();
161 Features[
"atomics"] =
true;
162 Features[
"bulk-memory"] =
true;
163 Features[
"exception-handling"] =
true;
164 Features[
"extended-const"] =
true;
165 Features[
"fp16"] =
true;
166 Features[
"multimemory"] =
true;
167 Features[
"nontrapping-fptoint"] =
true;
168 Features[
"tail-call"] =
true;
169 setSIMDLevel(Features, RelaxedSIMD,
true);
171 if (CPU ==
"generic") {
172 addGenericFeatures();
173 }
else if (CPU ==
"bleeding-edge") {
174 addBleedingEdgeFeatures();
180bool WebAssemblyTargetInfo::handleTargetFeatures(
182 for (
const auto &Feature : Features) {
183 if (Feature ==
"+atomics") {
187 if (Feature ==
"-atomics") {
191 if (Feature ==
"+bulk-memory") {
192 HasBulkMemory =
true;
195 if (Feature ==
"-bulk-memory") {
196 HasBulkMemory =
false;
199 if (Feature ==
"+exception-handling") {
200 HasExceptionHandling =
true;
203 if (Feature ==
"-exception-handling") {
204 HasExceptionHandling =
false;
207 if (Feature ==
"+extended-const") {
208 HasExtendedConst =
true;
211 if (Feature ==
"-extended-const") {
212 HasExtendedConst =
false;
215 if (Feature ==
"+fp16") {
216 SIMDLevel = std::max(SIMDLevel, SIMD128);
220 if (Feature ==
"-fp16") {
224 if (Feature ==
"+multimemory") {
225 HasMultiMemory =
true;
228 if (Feature ==
"-multimemory") {
229 HasMultiMemory =
false;
232 if (Feature ==
"+multivalue") {
233 HasMultivalue =
true;
236 if (Feature ==
"-multivalue") {
237 HasMultivalue =
false;
240 if (Feature ==
"+mutable-globals") {
241 HasMutableGlobals =
true;
244 if (Feature ==
"-mutable-globals") {
245 HasMutableGlobals =
false;
248 if (Feature ==
"+nontrapping-fptoint") {
249 HasNontrappingFPToInt =
true;
252 if (Feature ==
"-nontrapping-fptoint") {
253 HasNontrappingFPToInt =
false;
256 if (Feature ==
"+reference-types") {
257 HasReferenceTypes =
true;
260 if (Feature ==
"-reference-types") {
261 HasReferenceTypes =
false;
264 if (Feature ==
"+relaxed-simd") {
265 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
268 if (Feature ==
"-relaxed-simd") {
269 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
272 if (Feature ==
"+sign-ext") {
276 if (Feature ==
"-sign-ext") {
280 if (Feature ==
"+simd128") {
281 SIMDLevel = std::max(SIMDLevel, SIMD128);
284 if (Feature ==
"-simd128") {
285 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
288 if (Feature ==
"+tail-call") {
292 if (Feature ==
"-tail-call") {
297 Diags.
Report(diag::err_opt_not_valid_with_opt)
298 << Feature <<
"-target-feature";
315 if (!HasAtomics || !HasBulkMemory) {
316 Opts.POSIXThreads =
false;
318 Opts.ThreadsafeStatics =
false;
Defines the Diagnostic-related interfaces.
static constexpr llvm::StringLiteral ValidCPUNames[]
static constexpr Builtin::Info BuiltinInfo[]
static constexpr llvm::StringLiteral ValidCPUNames[]
static constexpr Builtin::Info BuiltinInfo[]
Defines enum values for all the target-independent builtin functions.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
@ Single
Single Threaded Environment.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts)
Set forced language options.
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
StringRef getABI() const override
Get the ABI currently in use.
bool setABI(const std::string &Name) override
Use the specified ABI.
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
The JSON file list parser is used to communicate input to InstallAPI.