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"}, {
"lime1"}};
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(
"bulk-memory-opt", HasBulkMemoryOpt)
51 .Case(
"call-indirect-overlong", HasCallIndirectOverlong)
52 .Case(
"exception-handling", HasExceptionHandling)
53 .Case(
"extended-const", HasExtendedConst)
54 .Case(
"fp16", HasFP16)
55 .Case(
"multimemory", HasMultiMemory)
56 .Case(
"multivalue", HasMultivalue)
57 .Case(
"mutable-globals", HasMutableGlobals)
58 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
59 .Case(
"reference-types", HasReferenceTypes)
60 .Case(
"relaxed-simd", SIMDLevel >= RelaxedSIMD)
61 .Case(
"sign-ext", HasSignExt)
62 .Case(
"simd128", SIMDLevel >= SIMD128)
63 .Case(
"tail-call", HasTailCall)
64 .Case(
"wide-arithmetic", HasWideArithmetic)
68bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
72void WebAssemblyTargetInfo::fillValidCPUList(
81 Builder.defineMacro(
"__wasm_atomics__");
83 Builder.defineMacro(
"__wasm_bulk_memory__");
85 Builder.defineMacro(
"__wasm_bulk_memory_opt__");
86 if (HasExceptionHandling)
87 Builder.defineMacro(
"__wasm_exception_handling__");
89 Builder.defineMacro(
"__wasm_extended_const__");
91 Builder.defineMacro(
"__wasm_multimemory__");
93 Builder.defineMacro(
"__wasm_fp16__");
95 Builder.defineMacro(
"__wasm_multivalue__");
96 if (HasMutableGlobals)
97 Builder.defineMacro(
"__wasm_mutable_globals__");
98 if (HasNontrappingFPToInt)
99 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
100 if (HasReferenceTypes)
101 Builder.defineMacro(
"__wasm_reference_types__");
102 if (SIMDLevel >= RelaxedSIMD)
103 Builder.defineMacro(
"__wasm_relaxed_simd__");
105 Builder.defineMacro(
"__wasm_sign_ext__");
106 if (SIMDLevel >= SIMD128)
107 Builder.defineMacro(
"__wasm_simd128__");
109 Builder.defineMacro(
"__wasm_tail_call__");
110 if (HasWideArithmetic)
111 Builder.defineMacro(
"__wasm_wide_arithmetic__");
113 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
114 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
115 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
116 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
119void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
120 SIMDEnum Level,
bool Enabled) {
124 Features[
"relaxed-simd"] =
true;
127 Features[
"simd128"] =
true;
138 Features[
"simd128"] =
false;
141 Features[
"relaxed-simd"] =
false;
146void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
148 bool Enabled)
const {
149 if (Name ==
"simd128")
150 setSIMDLevel(Features, SIMD128, Enabled);
151 else if (Name ==
"relaxed-simd")
152 setSIMDLevel(Features, RelaxedSIMD, Enabled);
154 Features[Name] = Enabled;
157bool WebAssemblyTargetInfo::initFeatureMap(
159 const std::vector<std::string> &FeaturesVec)
const {
160 auto addGenericFeatures = [&]() {
161 Features[
"bulk-memory"] =
true;
162 Features[
"bulk-memory-opt"] =
true;
163 Features[
"call-indirect-overlong"] =
true;
164 Features[
"multivalue"] =
true;
165 Features[
"mutable-globals"] =
true;
166 Features[
"nontrapping-fptoint"] =
true;
167 Features[
"reference-types"] =
true;
168 Features[
"sign-ext"] =
true;
170 auto addLime1Features = [&]() {
173 Features[
"bulk-memory-opt"] =
true;
174 Features[
"call-indirect-overlong"] =
true;
175 Features[
"extended-const"] =
true;
176 Features[
"multivalue"] =
true;
177 Features[
"mutable-globals"] =
true;
178 Features[
"nontrapping-fptoint"] =
true;
179 Features[
"sign-ext"] =
true;
181 auto addBleedingEdgeFeatures = [&]() {
182 addGenericFeatures();
183 Features[
"atomics"] =
true;
184 Features[
"exception-handling"] =
true;
185 Features[
"extended-const"] =
true;
186 Features[
"fp16"] =
true;
187 Features[
"multimemory"] =
true;
188 Features[
"tail-call"] =
true;
189 Features[
"wide-arithmetic"] =
true;
190 setSIMDLevel(Features, RelaxedSIMD,
true);
192 if (CPU ==
"generic") {
193 addGenericFeatures();
194 }
else if (CPU ==
"lime1") {
196 }
else if (CPU ==
"bleeding-edge") {
197 addBleedingEdgeFeatures();
203bool WebAssemblyTargetInfo::handleTargetFeatures(
205 for (
const auto &Feature : Features) {
206 if (Feature ==
"+atomics") {
210 if (Feature ==
"-atomics") {
214 if (Feature ==
"+bulk-memory") {
215 HasBulkMemory =
true;
218 if (Feature ==
"-bulk-memory") {
219 HasBulkMemory =
false;
222 if (Feature ==
"+bulk-memory-opt") {
223 HasBulkMemoryOpt =
true;
226 if (Feature ==
"-bulk-memory-opt") {
227 HasBulkMemoryOpt =
false;
230 if (Feature ==
"+call-indirect-overlong") {
231 HasCallIndirectOverlong =
true;
234 if (Feature ==
"-call-indirect-overlong") {
235 HasCallIndirectOverlong =
false;
238 if (Feature ==
"+exception-handling") {
239 HasExceptionHandling =
true;
242 if (Feature ==
"-exception-handling") {
243 HasExceptionHandling =
false;
246 if (Feature ==
"+extended-const") {
247 HasExtendedConst =
true;
250 if (Feature ==
"-extended-const") {
251 HasExtendedConst =
false;
254 if (Feature ==
"+fp16") {
255 SIMDLevel = std::max(SIMDLevel, SIMD128);
259 if (Feature ==
"-fp16") {
263 if (Feature ==
"+multimemory") {
264 HasMultiMemory =
true;
267 if (Feature ==
"-multimemory") {
268 HasMultiMemory =
false;
271 if (Feature ==
"+multivalue") {
272 HasMultivalue =
true;
275 if (Feature ==
"-multivalue") {
276 HasMultivalue =
false;
279 if (Feature ==
"+mutable-globals") {
280 HasMutableGlobals =
true;
283 if (Feature ==
"-mutable-globals") {
284 HasMutableGlobals =
false;
287 if (Feature ==
"+nontrapping-fptoint") {
288 HasNontrappingFPToInt =
true;
291 if (Feature ==
"-nontrapping-fptoint") {
292 HasNontrappingFPToInt =
false;
295 if (Feature ==
"+reference-types") {
296 HasReferenceTypes =
true;
299 if (Feature ==
"-reference-types") {
300 HasReferenceTypes =
false;
303 if (Feature ==
"+relaxed-simd") {
304 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
307 if (Feature ==
"-relaxed-simd") {
308 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
311 if (Feature ==
"+sign-ext") {
315 if (Feature ==
"-sign-ext") {
319 if (Feature ==
"+simd128") {
320 SIMDLevel = std::max(SIMDLevel, SIMD128);
323 if (Feature ==
"-simd128") {
324 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
327 if (Feature ==
"+tail-call") {
331 if (Feature ==
"-tail-call") {
335 if (Feature ==
"+wide-arithmetic") {
336 HasWideArithmetic =
true;
339 if (Feature ==
"-wide-arithmetic") {
340 HasWideArithmetic =
false;
344 Diags.
Report(diag::err_opt_not_valid_with_opt)
345 << Feature <<
"-target-feature";
351 HasBulkMemoryOpt =
true;
356 if (HasReferenceTypes) {
357 HasCallIndirectOverlong =
true;
374 if (!HasAtomics || !HasBulkMemory) {
375 Opts.POSIXThreads =
false;
377 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.
LLVM_LIBRARY_VISIBILITY void defineCPUMacros(clang::MacroBuilder &Builder, llvm::StringRef CPUName, bool Tuning=true)
The JSON file list parser is used to communicate input to InstallAPI.