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(
"exception-handling", HasExceptionHandling)
60 .Case(
"extended-const", HasExtendedConst)
61 .Case(
"fp16", HasFP16)
63 .Case(
"multimemory", HasMultiMemory)
64 .Case(
"multivalue", HasMultivalue)
65 .Case(
"mutable-globals", HasMutableGlobals)
66 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
67 .Case(
"reference-types", HasReferenceTypes)
68 .Case(
"relaxed-simd", SIMDLevel >= RelaxedSIMD)
69 .Case(
"sign-ext", HasSignExt)
70 .Case(
"simd128", SIMDLevel >= SIMD128)
71 .Case(
"tail-call", HasTailCall)
72 .Case(
"wide-arithmetic", HasWideArithmetic)
76bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
80void WebAssemblyTargetInfo::fillValidCPUList(
89 Builder.defineMacro(
"__wasm_atomics__");
91 Builder.defineMacro(
"__wasm_bulk_memory__");
93 Builder.defineMacro(
"__wasm_bulk_memory_opt__");
94 if (HasExceptionHandling)
95 Builder.defineMacro(
"__wasm_exception_handling__");
97 Builder.defineMacro(
"__wasm_extended_const__");
99 Builder.defineMacro(
"__wasm_multimemory__");
101 Builder.defineMacro(
"__wasm_fp16__");
103 Builder.defineMacro(
"__wasm_gc__");
105 Builder.defineMacro(
"__wasm_multivalue__");
106 if (HasMutableGlobals)
107 Builder.defineMacro(
"__wasm_mutable_globals__");
108 if (HasNontrappingFPToInt)
109 Builder.defineMacro(
"__wasm_nontrapping_fptoint__");
110 if (HasReferenceTypes)
111 Builder.defineMacro(
"__wasm_reference_types__");
112 if (SIMDLevel >= RelaxedSIMD)
113 Builder.defineMacro(
"__wasm_relaxed_simd__");
115 Builder.defineMacro(
"__wasm_sign_ext__");
116 if (SIMDLevel >= SIMD128)
117 Builder.defineMacro(
"__wasm_simd128__");
119 Builder.defineMacro(
"__wasm_tail_call__");
120 if (HasWideArithmetic)
121 Builder.defineMacro(
"__wasm_wide_arithmetic__");
123 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
124 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
125 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
126 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
129void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
130 SIMDEnum Level,
bool Enabled) {
134 Features[
"relaxed-simd"] =
true;
137 Features[
"simd128"] =
true;
148 Features[
"simd128"] =
false;
151 Features[
"relaxed-simd"] =
false;
156void WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
158 bool Enabled)
const {
159 if (Name ==
"simd128")
160 setSIMDLevel(Features, SIMD128, Enabled);
161 else if (Name ==
"relaxed-simd")
162 setSIMDLevel(Features, RelaxedSIMD, Enabled);
164 Features[Name] = Enabled;
167bool WebAssemblyTargetInfo::initFeatureMap(
168 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
169 const std::vector<std::string> &FeaturesVec)
const {
170 auto addGenericFeatures = [&]() {
171 Features[
"bulk-memory"] =
true;
172 Features[
"bulk-memory-opt"] =
true;
173 Features[
"call-indirect-overlong"] =
true;
174 Features[
"multivalue"] =
true;
175 Features[
"mutable-globals"] =
true;
176 Features[
"nontrapping-fptoint"] =
true;
177 Features[
"reference-types"] =
true;
178 Features[
"sign-ext"] =
true;
180 auto addLime1Features = [&]() {
183 Features[
"bulk-memory-opt"] =
true;
184 Features[
"call-indirect-overlong"] =
true;
185 Features[
"extended-const"] =
true;
186 Features[
"multivalue"] =
true;
187 Features[
"mutable-globals"] =
true;
188 Features[
"nontrapping-fptoint"] =
true;
189 Features[
"sign-ext"] =
true;
191 auto addBleedingEdgeFeatures = [&]() {
192 addGenericFeatures();
193 Features[
"atomics"] =
true;
194 Features[
"exception-handling"] =
true;
195 Features[
"extended-const"] =
true;
196 Features[
"fp16"] =
true;
197 Features[
"gc"] =
true;
198 Features[
"multimemory"] =
true;
199 Features[
"tail-call"] =
true;
200 Features[
"wide-arithmetic"] =
true;
201 setSIMDLevel(Features, RelaxedSIMD,
true);
203 if (CPU ==
"generic") {
204 addGenericFeatures();
205 }
else if (CPU ==
"lime1") {
207 }
else if (CPU ==
"bleeding-edge") {
208 addBleedingEdgeFeatures();
214bool WebAssemblyTargetInfo::handleTargetFeatures(
215 std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
217 for (
const auto &
Feature : Features) {
226 if (
Feature ==
"+bulk-memory") {
227 HasBulkMemory =
true;
230 if (
Feature ==
"-bulk-memory") {
231 HasBulkMemory =
false;
234 if (
Feature ==
"+bulk-memory-opt") {
235 HasBulkMemoryOpt =
true;
238 if (
Feature ==
"-bulk-memory-opt") {
239 HasBulkMemoryOpt =
false;
242 if (
Feature ==
"+call-indirect-overlong") {
243 HasCallIndirectOverlong =
true;
246 if (
Feature ==
"-call-indirect-overlong") {
247 HasCallIndirectOverlong =
false;
250 if (
Feature ==
"+exception-handling") {
251 HasExceptionHandling =
true;
254 if (
Feature ==
"-exception-handling") {
255 HasExceptionHandling =
false;
258 if (
Feature ==
"+extended-const") {
259 HasExtendedConst =
true;
262 if (
Feature ==
"-extended-const") {
263 HasExtendedConst =
false;
267 SIMDLevel = std::max(SIMDLevel, SIMD128);
283 if (
Feature ==
"+multimemory") {
284 HasMultiMemory =
true;
287 if (
Feature ==
"-multimemory") {
288 HasMultiMemory =
false;
291 if (
Feature ==
"+multivalue") {
292 HasMultivalue =
true;
295 if (
Feature ==
"-multivalue") {
296 HasMultivalue =
false;
299 if (
Feature ==
"+mutable-globals") {
300 HasMutableGlobals =
true;
303 if (
Feature ==
"-mutable-globals") {
304 HasMutableGlobals =
false;
307 if (
Feature ==
"+nontrapping-fptoint") {
308 HasNontrappingFPToInt =
true;
311 if (
Feature ==
"-nontrapping-fptoint") {
312 HasNontrappingFPToInt =
false;
315 if (
Feature ==
"+reference-types") {
316 HasReferenceTypes =
true;
319 if (
Feature ==
"-reference-types") {
320 HasReferenceTypes =
false;
323 if (
Feature ==
"+relaxed-simd") {
324 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
327 if (
Feature ==
"-relaxed-simd") {
328 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
340 SIMDLevel = std::max(SIMDLevel, SIMD128);
344 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
357 if (
Feature ==
"+wide-arithmetic") {
358 HasWideArithmetic =
true;
361 if (
Feature ==
"-wide-arithmetic") {
362 HasWideArithmetic =
false;
366 Diags.
Report(diag::err_opt_not_valid_with_opt)
367 <<
Feature <<
"-target-feature";
373 HasReferenceTypes =
true;
378 HasBulkMemoryOpt =
true;
383 if (HasReferenceTypes) {
384 HasCallIndirectOverlong =
true;
390llvm::SmallVector<Builtin::InfosShard>
395void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
396 const TargetInfo *Aux) {
401 if (!HasAtomics || !HasBulkMemory) {
402 Opts.POSIXThreads =
false;
404 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.