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__");
126 if (HasLibcallThreadContext)
127 Builder.defineMacro(
"__wasm_libcall_thread_context__");
131 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
132 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
133 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
134 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
137void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
138 SIMDEnum Level,
bool Enabled) {
142 Features[
"relaxed-simd"] =
true;
145 Features[
"simd128"] =
true;
156 Features[
"simd128"] =
false;
159 Features[
"relaxed-simd"] =
false;
164void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
166 bool Enabled)
const {
167 if (Name ==
"simd128")
168 setSIMDLevel(Features, SIMD128, Enabled);
169 else if (Name ==
"relaxed-simd")
170 setSIMDLevel(Features, RelaxedSIMD, Enabled);
172 Features[Name] = Enabled;
175bool WebAssemblyTargetInfo::initFeatureMap(
176 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
177 const std::vector<std::string> &FeaturesVec)
const {
178 auto addGenericFeatures = [&]() {
179 Features[
"bulk-memory"] =
true;
180 Features[
"bulk-memory-opt"] =
true;
181 Features[
"call-indirect-overlong"] =
true;
182 Features[
"multivalue"] =
true;
183 Features[
"mutable-globals"] =
true;
184 Features[
"nontrapping-fptoint"] =
true;
185 Features[
"reference-types"] =
true;
186 Features[
"sign-ext"] =
true;
188 auto addLime1Features = [&]() {
191 Features[
"bulk-memory-opt"] =
true;
192 Features[
"call-indirect-overlong"] =
true;
193 Features[
"extended-const"] =
true;
194 Features[
"multivalue"] =
true;
195 Features[
"mutable-globals"] =
true;
196 Features[
"nontrapping-fptoint"] =
true;
197 Features[
"sign-ext"] =
true;
199 auto addBleedingEdgeFeatures = [&]() {
200 addGenericFeatures();
201 Features[
"atomics"] =
true;
202 Features[
"compact-imports"] =
true;
203 Features[
"exception-handling"] =
true;
204 Features[
"extended-const"] =
true;
205 Features[
"fp16"] =
true;
206 Features[
"gc"] =
true;
207 Features[
"multimemory"] =
true;
208 Features[
"relaxed-atomics"] =
true;
209 Features[
"tail-call"] =
true;
210 Features[
"wide-arithmetic"] =
true;
211 setSIMDLevel(Features, RelaxedSIMD,
true);
213 if (CPU ==
"generic") {
214 addGenericFeatures();
215 }
else if (CPU ==
"lime1") {
217 }
else if (CPU ==
"bleeding-edge") {
218 addBleedingEdgeFeatures();
224bool WebAssemblyTargetInfo::handleTargetFeatures(
225 std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
227 for (
const auto &
Feature : Features) {
236 if (
Feature ==
"+bulk-memory") {
237 HasBulkMemory =
true;
240 if (
Feature ==
"-bulk-memory") {
241 HasBulkMemory =
false;
244 if (
Feature ==
"+bulk-memory-opt") {
245 HasBulkMemoryOpt =
true;
248 if (
Feature ==
"-bulk-memory-opt") {
249 HasBulkMemoryOpt =
false;
252 if (
Feature ==
"+call-indirect-overlong") {
253 HasCallIndirectOverlong =
true;
256 if (
Feature ==
"-call-indirect-overlong") {
257 HasCallIndirectOverlong =
false;
260 if (
Feature ==
"+compact-imports") {
261 HasCompactImports =
true;
264 if (
Feature ==
"-compact-imports") {
265 HasCompactImports =
false;
268 if (
Feature ==
"+exception-handling") {
269 HasExceptionHandling =
true;
272 if (
Feature ==
"-exception-handling") {
273 HasExceptionHandling =
false;
276 if (
Feature ==
"+extended-const") {
277 HasExtendedConst =
true;
280 if (
Feature ==
"-extended-const") {
281 HasExtendedConst =
false;
285 SIMDLevel = std::max(SIMDLevel, SIMD128);
301 if (
Feature ==
"+multimemory") {
302 HasMultiMemory =
true;
305 if (
Feature ==
"-multimemory") {
306 HasMultiMemory =
false;
309 if (
Feature ==
"+multivalue") {
310 HasMultivalue =
true;
313 if (
Feature ==
"-multivalue") {
314 HasMultivalue =
false;
317 if (
Feature ==
"+mutable-globals") {
318 HasMutableGlobals =
true;
321 if (
Feature ==
"-mutable-globals") {
322 HasMutableGlobals =
false;
325 if (
Feature ==
"+nontrapping-fptoint") {
326 HasNontrappingFPToInt =
true;
329 if (
Feature ==
"-nontrapping-fptoint") {
330 HasNontrappingFPToInt =
false;
333 if (
Feature ==
"+reference-types") {
334 HasReferenceTypes =
true;
337 if (
Feature ==
"-reference-types") {
338 HasReferenceTypes =
false;
341 if (
Feature ==
"+relaxed-atomics") {
342 HasRelaxedAtomics =
true;
345 if (
Feature ==
"-relaxed-atomics") {
346 HasRelaxedAtomics =
false;
349 if (
Feature ==
"+relaxed-simd") {
350 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
353 if (
Feature ==
"-relaxed-simd") {
354 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
366 SIMDLevel = std::max(SIMDLevel, SIMD128);
370 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
383 if (
Feature ==
"+wide-arithmetic") {
384 HasWideArithmetic =
true;
387 if (
Feature ==
"-wide-arithmetic") {
388 HasWideArithmetic =
false;
392 Diags.
Report(diag::err_opt_not_valid_with_opt)
393 <<
Feature <<
"-target-feature";
399 HasReferenceTypes =
true;
404 HasBulkMemoryOpt =
true;
409 if (HasReferenceTypes) {
410 HasCallIndirectOverlong =
true;
416llvm::SmallVector<Builtin::InfosShard>
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.
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 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)
Top level wrappers for InstallAPI frontend operations.