18#include "llvm/ADT/StringSwitch.h"
28#define BUILTIN CLANG_BUILTIN_STR_TABLE
29#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_STR_TABLE
30#include "clang/Basic/BuiltinsWebAssembly.def"
34#define BUILTIN CLANG_BUILTIN_ENTRY
35#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_ENTRY
36#define LIBBUILTIN CLANG_LIBBUILTIN_ENTRY
37#include "clang/Basic/BuiltinsWebAssembly.def"
41 {
"mvp"}, {
"bleeding-edge"}, {
"generic"}, {
"lime1"}};
46 if (Name !=
"mvp" && Name !=
"experimental-mv")
53bool WebAssemblyTargetInfo::hasFeature(StringRef
Feature)
const {
54 return llvm::StringSwitch<bool>(
Feature)
55 .Case(
"atomics", HasAtomics)
56 .Case(
"bulk-memory", HasBulkMemory)
57 .Case(
"bulk-memory-opt", HasBulkMemoryOpt)
58 .Case(
"call-indirect-overlong", HasCallIndirectOverlong)
59 .Case(
"compact-imports", HasCompactImports)
60 .Case(
"exception-handling", HasExceptionHandling)
61 .Case(
"extended-const", HasExtendedConst)
62 .Case(
"fp16", HasFP16)
64 .Case(
"multimemory", HasMultiMemory)
65 .Case(
"multivalue", HasMultivalue)
66 .Case(
"mutable-globals", HasMutableGlobals)
67 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
68 .Case(
"reference-types", HasReferenceTypes)
69 .Case(
"relaxed-atomics", HasRelaxedAtomics)
70 .Case(
"relaxed-simd", SIMDLevel >= RelaxedSIMD)
71 .Case(
"sign-ext", HasSignExt)
72 .Case(
"simd128", SIMDLevel >= SIMD128)
73 .Case(
"tail-call", HasTailCall)
74 .Case(
"wide-arithmetic", HasWideArithmetic)
78bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
82void WebAssemblyTargetInfo::fillValidCPUList(
91 Builder.defineMacro(
"__wasm_atomics__");
93 Builder.defineMacro(
"__wasm_bulk_memory__");
95 Builder.defineMacro(
"__wasm_bulk_memory_opt__");
96 if (HasExceptionHandling)
97 Builder.defineMacro(
"__wasm_exception_handling__");
99 Builder.defineMacro(
"__wasm_extended_const__");
101 Builder.defineMacro(
"__wasm_multimemory__");
103 Builder.defineMacro(
"__wasm_fp16__");
105 Builder.defineMacro(
"__wasm_gc__");
107 Builder.defineMacro(
"__wasm_multivalue__");
108 if (HasMutableGlobals)
109 Builder.defineMacro(
"__wasm_mutable_globals__");
110 if (HasNontrappingFPToInt)
111 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
112 if (HasReferenceTypes)
113 Builder.defineMacro(
"__wasm_reference_types__");
114 if (HasRelaxedAtomics)
115 Builder.defineMacro(
"__wasm_relaxed_atomics__");
116 if (SIMDLevel >= RelaxedSIMD)
117 Builder.defineMacro(
"__wasm_relaxed_simd__");
119 Builder.defineMacro(
"__wasm_sign_ext__");
120 if (SIMDLevel >= SIMD128)
121 Builder.defineMacro(
"__wasm_simd128__");
123 Builder.defineMacro(
"__wasm_tail_call__");
124 if (HasWideArithmetic)
125 Builder.defineMacro(
"__wasm_wide_arithmetic__");
129 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
130 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
131 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
132 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
135void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
136 SIMDEnum Level,
bool Enabled) {
140 Features[
"relaxed-simd"] =
true;
143 Features[
"simd128"] =
true;
154 Features[
"simd128"] =
false;
157 Features[
"relaxed-simd"] =
false;
162void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
164 bool Enabled)
const {
165 if (Name ==
"simd128")
166 setSIMDLevel(Features, SIMD128, Enabled);
167 else if (Name ==
"relaxed-simd")
168 setSIMDLevel(Features, RelaxedSIMD, Enabled);
170 Features[Name] = Enabled;
173bool WebAssemblyTargetInfo::initFeatureMap(
174 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
175 const std::vector<std::string> &FeaturesVec)
const {
176 auto addGenericFeatures = [&]() {
177 Features[
"bulk-memory"] =
true;
178 Features[
"bulk-memory-opt"] =
true;
179 Features[
"call-indirect-overlong"] =
true;
180 Features[
"multivalue"] =
true;
181 Features[
"mutable-globals"] =
true;
182 Features[
"nontrapping-fptoint"] =
true;
183 Features[
"reference-types"] =
true;
184 Features[
"sign-ext"] =
true;
186 auto addLime1Features = [&]() {
189 Features[
"bulk-memory-opt"] =
true;
190 Features[
"call-indirect-overlong"] =
true;
191 Features[
"extended-const"] =
true;
192 Features[
"multivalue"] =
true;
193 Features[
"mutable-globals"] =
true;
194 Features[
"nontrapping-fptoint"] =
true;
195 Features[
"sign-ext"] =
true;
197 auto addBleedingEdgeFeatures = [&]() {
198 addGenericFeatures();
199 Features[
"atomics"] =
true;
200 Features[
"compact-imports"] =
true;
201 Features[
"exception-handling"] =
true;
202 Features[
"extended-const"] =
true;
203 Features[
"fp16"] =
true;
204 Features[
"gc"] =
true;
205 Features[
"multimemory"] =
true;
206 Features[
"relaxed-atomics"] =
true;
207 Features[
"tail-call"] =
true;
208 Features[
"wide-arithmetic"] =
true;
209 setSIMDLevel(Features, RelaxedSIMD,
true);
211 if (CPU ==
"generic") {
212 addGenericFeatures();
213 }
else if (CPU ==
"lime1") {
215 }
else if (CPU ==
"bleeding-edge") {
216 addBleedingEdgeFeatures();
222bool WebAssemblyTargetInfo::handleTargetFeatures(
223 std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
225 for (
const auto &
Feature : Features) {
234 if (
Feature ==
"+bulk-memory") {
235 HasBulkMemory =
true;
238 if (
Feature ==
"-bulk-memory") {
239 HasBulkMemory =
false;
242 if (
Feature ==
"+bulk-memory-opt") {
243 HasBulkMemoryOpt =
true;
246 if (
Feature ==
"-bulk-memory-opt") {
247 HasBulkMemoryOpt =
false;
250 if (
Feature ==
"+call-indirect-overlong") {
251 HasCallIndirectOverlong =
true;
254 if (
Feature ==
"-call-indirect-overlong") {
255 HasCallIndirectOverlong =
false;
258 if (
Feature ==
"+compact-imports") {
259 HasCompactImports =
true;
262 if (
Feature ==
"-compact-imports") {
263 HasCompactImports =
false;
266 if (
Feature ==
"+exception-handling") {
267 HasExceptionHandling =
true;
270 if (
Feature ==
"-exception-handling") {
271 HasExceptionHandling =
false;
274 if (
Feature ==
"+extended-const") {
275 HasExtendedConst =
true;
278 if (
Feature ==
"-extended-const") {
279 HasExtendedConst =
false;
283 SIMDLevel = std::max(SIMDLevel, SIMD128);
299 if (
Feature ==
"+multimemory") {
300 HasMultiMemory =
true;
303 if (
Feature ==
"-multimemory") {
304 HasMultiMemory =
false;
307 if (
Feature ==
"+multivalue") {
308 HasMultivalue =
true;
311 if (
Feature ==
"-multivalue") {
312 HasMultivalue =
false;
315 if (
Feature ==
"+mutable-globals") {
316 HasMutableGlobals =
true;
319 if (
Feature ==
"-mutable-globals") {
320 HasMutableGlobals =
false;
323 if (
Feature ==
"+nontrapping-fptoint") {
324 HasNontrappingFPToInt =
true;
327 if (
Feature ==
"-nontrapping-fptoint") {
328 HasNontrappingFPToInt =
false;
331 if (
Feature ==
"+reference-types") {
332 HasReferenceTypes =
true;
335 if (
Feature ==
"-reference-types") {
336 HasReferenceTypes =
false;
339 if (
Feature ==
"+relaxed-atomics") {
340 HasRelaxedAtomics =
true;
343 if (
Feature ==
"-relaxed-atomics") {
344 HasRelaxedAtomics =
false;
347 if (
Feature ==
"+relaxed-simd") {
348 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
351 if (
Feature ==
"-relaxed-simd") {
352 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
364 SIMDLevel = std::max(SIMDLevel, SIMD128);
368 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
381 if (
Feature ==
"+wide-arithmetic") {
382 HasWideArithmetic =
true;
385 if (
Feature ==
"-wide-arithmetic") {
386 HasWideArithmetic =
false;
390 Diags.
Report(diag::err_opt_not_valid_with_opt)
391 <<
Feature <<
"-target-feature";
397 HasReferenceTypes =
true;
402 HasBulkMemoryOpt =
true;
407 if (HasReferenceTypes) {
408 HasCallIndirectOverlong =
true;
414llvm::SmallVector<Builtin::InfosShard>
419void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
420 const TargetInfo *Aux) {
425 if (!HasAtomics || !HasBulkMemory) {
426 Opts.POSIXThreads =
false;
428 Opts.ThreadsafeStatics =
false;
Defines the Diagnostic-related interfaces.
static constexpr llvm::StringTable BuiltinStrings
static constexpr llvm::StringLiteral ValidCPUNames[]
static constexpr Builtin::Info BuiltinInfos[]
static constexpr unsigned NumBuiltins
Defines enum values for all the target-independent builtin functions.
#define CLANG_BUILTIN_STR_TABLE_START
Enumerates target-specific builtins in their own namespaces within namespace clang.
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 llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const =0
Return information about target-specific builtins for the current primary target, and info about whic...
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux)
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.
static constexpr std::array< Info, N > MakeInfos(std::array< Info, N > Infos)
A constexpr function to construct an infos array from X-macros.
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.