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(
"nontrapping-fptoint", HasNontrappingFPToInt)
51 .Case(
"sign-ext", HasSignExt)
52 .Case(
"exception-handling", HasExceptionHandling)
53 .Case(
"bulk-memory", HasBulkMemory)
54 .Case(
"atomics", HasAtomics)
55 .Case(
"mutable-globals", HasMutableGlobals)
56 .Case(
"multivalue", HasMultivalue)
57 .Case(
"tail-call", HasTailCall)
58 .Case(
"reference-types", HasReferenceTypes)
59 .Case(
"extended-const", HasExtendedConst)
60 .Case(
"multimemory", HasMultiMemory)
64bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
68void WebAssemblyTargetInfo::fillValidCPUList(
76 if (SIMDLevel >= SIMD128)
77 Builder.defineMacro(
"__wasm_simd128__");
78 if (SIMDLevel >= RelaxedSIMD)
79 Builder.defineMacro(
"__wasm_relaxed_simd__");
80 if (HasNontrappingFPToInt)
81 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
83 Builder.defineMacro(
"__wasm_sign_ext__");
84 if (HasExceptionHandling)
85 Builder.defineMacro(
"__wasm_exception_handling__");
87 Builder.defineMacro(
"__wasm_bulk_memory__");
89 Builder.defineMacro(
"__wasm_atomics__");
90 if (HasMutableGlobals)
91 Builder.defineMacro(
"__wasm_mutable_globals__");
93 Builder.defineMacro(
"__wasm_multivalue__");
95 Builder.defineMacro(
"__wasm_tail_call__");
96 if (HasReferenceTypes)
97 Builder.defineMacro(
"__wasm_reference_types__");
99 Builder.defineMacro(
"__wasm_extended_const__");
101 Builder.defineMacro(
"__wasm_multimemory__");
103 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
104 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
105 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
106 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
109void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
110 SIMDEnum Level,
bool Enabled) {
114 Features[
"relaxed-simd"] =
true;
117 Features[
"simd128"] =
true;
128 Features[
"simd128"] =
false;
131 Features[
"relaxed-simd"] =
false;
136void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
138 bool Enabled)
const {
139 if (Name ==
"simd128")
140 setSIMDLevel(Features, SIMD128, Enabled);
141 else if (Name ==
"relaxed-simd")
142 setSIMDLevel(Features, RelaxedSIMD, Enabled);
144 Features[Name] = Enabled;
147bool WebAssemblyTargetInfo::initFeatureMap(
149 const std::vector<std::string> &FeaturesVec)
const {
150 if (CPU ==
"bleeding-edge") {
151 Features[
"nontrapping-fptoint"] =
true;
152 Features[
"sign-ext"] =
true;
153 Features[
"bulk-memory"] =
true;
154 Features[
"atomics"] =
true;
155 Features[
"mutable-globals"] =
true;
156 Features[
"tail-call"] =
true;
157 Features[
"reference-types"] =
true;
158 Features[
"multimemory"] =
true;
159 setSIMDLevel(Features, SIMD128,
true);
160 }
else if (CPU ==
"generic") {
161 Features[
"sign-ext"] =
true;
162 Features[
"mutable-globals"] =
true;
168bool WebAssemblyTargetInfo::handleTargetFeatures(
170 for (
const auto &Feature : Features) {
171 if (Feature ==
"+simd128") {
172 SIMDLevel = std::max(SIMDLevel, SIMD128);
175 if (Feature ==
"-simd128") {
176 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
179 if (Feature ==
"+relaxed-simd") {
180 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
183 if (Feature ==
"-relaxed-simd") {
184 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
187 if (Feature ==
"+nontrapping-fptoint") {
188 HasNontrappingFPToInt =
true;
191 if (Feature ==
"-nontrapping-fptoint") {
192 HasNontrappingFPToInt =
false;
195 if (Feature ==
"+sign-ext") {
199 if (Feature ==
"-sign-ext") {
203 if (Feature ==
"+exception-handling") {
204 HasExceptionHandling =
true;
207 if (Feature ==
"-exception-handling") {
208 HasExceptionHandling =
false;
211 if (Feature ==
"+bulk-memory") {
212 HasBulkMemory =
true;
215 if (Feature ==
"-bulk-memory") {
216 HasBulkMemory =
false;
219 if (Feature ==
"+atomics") {
223 if (Feature ==
"-atomics") {
227 if (Feature ==
"+mutable-globals") {
228 HasMutableGlobals =
true;
231 if (Feature ==
"-mutable-globals") {
232 HasMutableGlobals =
false;
235 if (Feature ==
"+multivalue") {
236 HasMultivalue =
true;
239 if (Feature ==
"-multivalue") {
240 HasMultivalue =
false;
243 if (Feature ==
"+tail-call") {
247 if (Feature ==
"-tail-call") {
251 if (Feature ==
"+reference-types") {
252 HasReferenceTypes =
true;
255 if (Feature ==
"-reference-types") {
256 HasReferenceTypes =
false;
259 if (Feature ==
"+extended-const") {
260 HasExtendedConst =
true;
263 if (Feature ==
"-extended-const") {
264 HasExtendedConst =
false;
267 if (Feature ==
"+multimemory") {
268 HasMultiMemory =
true;
271 if (Feature ==
"-multimemory") {
272 HasMultiMemory =
false;
276 Diags.
Report(diag::err_opt_not_valid_with_opt)
277 << Feature <<
"-target-feature";
294 if (!HasAtomics || !HasBulkMemory) {
295 Opts.POSIXThreads =
false;
297 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.