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(
"simd128", SIMDLevel >= SIMD128)
49 .Case(
"relaxed-simd", SIMDLevel >= RelaxedSIMD)
50 .Case(
"half-precision", HasHalfPrecision)
51 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
52 .Case(
"sign-ext", HasSignExt)
53 .Case(
"exception-handling", HasExceptionHandling)
54 .Case(
"bulk-memory", HasBulkMemory)
55 .Case(
"atomics", HasAtomics)
56 .Case(
"mutable-globals", HasMutableGlobals)
57 .Case(
"multivalue", HasMultivalue)
58 .Case(
"tail-call", HasTailCall)
59 .Case(
"reference-types", HasReferenceTypes)
60 .Case(
"extended-const", HasExtendedConst)
61 .Case(
"multimemory", HasMultiMemory)
65bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
69void WebAssemblyTargetInfo::fillValidCPUList(
77 if (SIMDLevel >= SIMD128)
78 Builder.defineMacro(
"__wasm_simd128__");
79 if (SIMDLevel >= RelaxedSIMD)
80 Builder.defineMacro(
"__wasm_relaxed_simd__");
81 if (HasNontrappingFPToInt)
82 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
84 Builder.defineMacro(
"__wasm_sign_ext__");
85 if (HasExceptionHandling)
86 Builder.defineMacro(
"__wasm_exception_handling__");
88 Builder.defineMacro(
"__wasm_bulk_memory__");
90 Builder.defineMacro(
"__wasm_atomics__");
91 if (HasMutableGlobals)
92 Builder.defineMacro(
"__wasm_mutable_globals__");
94 Builder.defineMacro(
"__wasm_multivalue__");
96 Builder.defineMacro(
"__wasm_tail_call__");
97 if (HasReferenceTypes)
98 Builder.defineMacro(
"__wasm_reference_types__");
100 Builder.defineMacro(
"__wasm_extended_const__");
102 Builder.defineMacro(
"__wasm_multimemory__");
103 if (HasHalfPrecision)
104 Builder.defineMacro(
"__wasm_half_precision__");
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[
"multimemory"] =
true;
164 Features[
"nontrapping-fptoint"] =
true;
165 Features[
"tail-call"] =
true;
166 Features[
"half-precision"] =
true;
167 setSIMDLevel(Features, SIMD128,
true);
169 if (CPU ==
"generic") {
170 addGenericFeatures();
171 }
else if (CPU ==
"bleeding-edge") {
172 addBleedingEdgeFeatures();
178bool WebAssemblyTargetInfo::handleTargetFeatures(
180 for (
const auto &Feature : Features) {
181 if (Feature ==
"+simd128") {
182 SIMDLevel = std::max(SIMDLevel, SIMD128);
185 if (Feature ==
"-simd128") {
186 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
189 if (Feature ==
"+relaxed-simd") {
190 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
193 if (Feature ==
"-relaxed-simd") {
194 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
197 if (Feature ==
"+nontrapping-fptoint") {
198 HasNontrappingFPToInt =
true;
201 if (Feature ==
"-nontrapping-fptoint") {
202 HasNontrappingFPToInt =
false;
205 if (Feature ==
"+sign-ext") {
209 if (Feature ==
"-sign-ext") {
213 if (Feature ==
"+exception-handling") {
214 HasExceptionHandling =
true;
217 if (Feature ==
"-exception-handling") {
218 HasExceptionHandling =
false;
221 if (Feature ==
"+bulk-memory") {
222 HasBulkMemory =
true;
225 if (Feature ==
"-bulk-memory") {
226 HasBulkMemory =
false;
229 if (Feature ==
"+half-precision") {
230 SIMDLevel = std::max(SIMDLevel, SIMD128);
231 HasHalfPrecision =
true;
234 if (Feature ==
"-half-precision") {
235 HasHalfPrecision =
false;
238 if (Feature ==
"+atomics") {
242 if (Feature ==
"-atomics") {
246 if (Feature ==
"+mutable-globals") {
247 HasMutableGlobals =
true;
250 if (Feature ==
"-mutable-globals") {
251 HasMutableGlobals =
false;
254 if (Feature ==
"+multivalue") {
255 HasMultivalue =
true;
258 if (Feature ==
"-multivalue") {
259 HasMultivalue =
false;
262 if (Feature ==
"+tail-call") {
266 if (Feature ==
"-tail-call") {
270 if (Feature ==
"+reference-types") {
271 HasReferenceTypes =
true;
274 if (Feature ==
"-reference-types") {
275 HasReferenceTypes =
false;
278 if (Feature ==
"+extended-const") {
279 HasExtendedConst =
true;
282 if (Feature ==
"-extended-const") {
283 HasExtendedConst =
false;
286 if (Feature ==
"+multimemory") {
287 HasMultiMemory =
true;
290 if (Feature ==
"-multimemory") {
291 HasMultiMemory =
false;
295 Diags.
Report(diag::err_opt_not_valid_with_opt)
296 << Feature <<
"-target-feature";
313 if (!HasAtomics || !HasBulkMemory) {
314 Opts.POSIXThreads =
false;
316 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.