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-simd", SIMDLevel >= RelaxedSIMD)
70 .Case(
"sign-ext", HasSignExt)
71 .Case(
"simd128", SIMDLevel >= SIMD128)
72 .Case(
"tail-call", HasTailCall)
73 .Case(
"wide-arithmetic", HasWideArithmetic)
77bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
81void WebAssemblyTargetInfo::fillValidCPUList(
90 Builder.defineMacro(
"__wasm_atomics__");
92 Builder.defineMacro(
"__wasm_bulk_memory__");
94 Builder.defineMacro(
"__wasm_bulk_memory_opt__");
95 if (HasExceptionHandling)
96 Builder.defineMacro(
"__wasm_exception_handling__");
98 Builder.defineMacro(
"__wasm_extended_const__");
100 Builder.defineMacro(
"__wasm_multimemory__");
102 Builder.defineMacro(
"__wasm_fp16__");
104 Builder.defineMacro(
"__wasm_gc__");
106 Builder.defineMacro(
"__wasm_multivalue__");
107 if (HasMutableGlobals)
108 Builder.defineMacro(
"__wasm_mutable_globals__");
109 if (HasNontrappingFPToInt)
110 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
111 if (HasReferenceTypes)
112 Builder.defineMacro(
"__wasm_reference_types__");
113 if (SIMDLevel >= RelaxedSIMD)
114 Builder.defineMacro(
"__wasm_relaxed_simd__");
116 Builder.defineMacro(
"__wasm_sign_ext__");
117 if (SIMDLevel >= SIMD128)
118 Builder.defineMacro(
"__wasm_simd128__");
120 Builder.defineMacro(
"__wasm_tail_call__");
121 if (HasWideArithmetic)
122 Builder.defineMacro(
"__wasm_wide_arithmetic__");
126 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
127 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
128 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
129 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
132void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
133 SIMDEnum Level,
bool Enabled) {
137 Features[
"relaxed-simd"] =
true;
140 Features[
"simd128"] =
true;
151 Features[
"simd128"] =
false;
154 Features[
"relaxed-simd"] =
false;
159void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
161 bool Enabled)
const {
162 if (Name ==
"simd128")
163 setSIMDLevel(Features, SIMD128, Enabled);
164 else if (Name ==
"relaxed-simd")
165 setSIMDLevel(Features, RelaxedSIMD, Enabled);
167 Features[Name] = Enabled;
170bool WebAssemblyTargetInfo::initFeatureMap(
171 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
172 const std::vector<std::string> &FeaturesVec)
const {
173 auto addGenericFeatures = [&]() {
174 Features[
"bulk-memory"] =
true;
175 Features[
"bulk-memory-opt"] =
true;
176 Features[
"call-indirect-overlong"] =
true;
177 Features[
"multivalue"] =
true;
178 Features[
"mutable-globals"] =
true;
179 Features[
"nontrapping-fptoint"] =
true;
180 Features[
"reference-types"] =
true;
181 Features[
"sign-ext"] =
true;
183 auto addLime1Features = [&]() {
186 Features[
"bulk-memory-opt"] =
true;
187 Features[
"call-indirect-overlong"] =
true;
188 Features[
"extended-const"] =
true;
189 Features[
"multivalue"] =
true;
190 Features[
"mutable-globals"] =
true;
191 Features[
"nontrapping-fptoint"] =
true;
192 Features[
"sign-ext"] =
true;
194 auto addBleedingEdgeFeatures = [&]() {
195 addGenericFeatures();
196 Features[
"atomics"] =
true;
197 Features[
"compact-imports"] =
true;
198 Features[
"exception-handling"] =
true;
199 Features[
"extended-const"] =
true;
200 Features[
"fp16"] =
true;
201 Features[
"gc"] =
true;
202 Features[
"multimemory"] =
true;
203 Features[
"tail-call"] =
true;
204 Features[
"wide-arithmetic"] =
true;
205 setSIMDLevel(Features, RelaxedSIMD,
true);
207 if (CPU ==
"generic") {
208 addGenericFeatures();
209 }
else if (CPU ==
"lime1") {
211 }
else if (CPU ==
"bleeding-edge") {
212 addBleedingEdgeFeatures();
218bool WebAssemblyTargetInfo::handleTargetFeatures(
219 std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
221 for (
const auto &
Feature : Features) {
230 if (
Feature ==
"+bulk-memory") {
231 HasBulkMemory =
true;
234 if (
Feature ==
"-bulk-memory") {
235 HasBulkMemory =
false;
238 if (
Feature ==
"+bulk-memory-opt") {
239 HasBulkMemoryOpt =
true;
242 if (
Feature ==
"-bulk-memory-opt") {
243 HasBulkMemoryOpt =
false;
246 if (
Feature ==
"+call-indirect-overlong") {
247 HasCallIndirectOverlong =
true;
250 if (
Feature ==
"-call-indirect-overlong") {
251 HasCallIndirectOverlong =
false;
254 if (
Feature ==
"+compact-imports") {
255 HasCompactImports =
true;
258 if (
Feature ==
"-compact-imports") {
259 HasCompactImports =
false;
262 if (
Feature ==
"+exception-handling") {
263 HasExceptionHandling =
true;
266 if (
Feature ==
"-exception-handling") {
267 HasExceptionHandling =
false;
270 if (
Feature ==
"+extended-const") {
271 HasExtendedConst =
true;
274 if (
Feature ==
"-extended-const") {
275 HasExtendedConst =
false;
279 SIMDLevel = std::max(SIMDLevel, SIMD128);
295 if (
Feature ==
"+multimemory") {
296 HasMultiMemory =
true;
299 if (
Feature ==
"-multimemory") {
300 HasMultiMemory =
false;
303 if (
Feature ==
"+multivalue") {
304 HasMultivalue =
true;
307 if (
Feature ==
"-multivalue") {
308 HasMultivalue =
false;
311 if (
Feature ==
"+mutable-globals") {
312 HasMutableGlobals =
true;
315 if (
Feature ==
"-mutable-globals") {
316 HasMutableGlobals =
false;
319 if (
Feature ==
"+nontrapping-fptoint") {
320 HasNontrappingFPToInt =
true;
323 if (
Feature ==
"-nontrapping-fptoint") {
324 HasNontrappingFPToInt =
false;
327 if (
Feature ==
"+reference-types") {
328 HasReferenceTypes =
true;
331 if (
Feature ==
"-reference-types") {
332 HasReferenceTypes =
false;
335 if (
Feature ==
"+relaxed-simd") {
336 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
339 if (
Feature ==
"-relaxed-simd") {
340 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
352 SIMDLevel = std::max(SIMDLevel, SIMD128);
356 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
369 if (
Feature ==
"+wide-arithmetic") {
370 HasWideArithmetic =
true;
373 if (
Feature ==
"-wide-arithmetic") {
374 HasWideArithmetic =
false;
378 Diags.
Report(diag::err_opt_not_valid_with_opt)
379 <<
Feature <<
"-target-feature";
385 HasReferenceTypes =
true;
390 HasBulkMemoryOpt =
true;
395 if (HasReferenceTypes) {
396 HasCallIndirectOverlong =
true;
402llvm::SmallVector<Builtin::InfosShard>
407void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
408 const TargetInfo *Aux) {
413 if (!HasAtomics || !HasBulkMemory) {
414 Opts.POSIXThreads =
false;
416 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.