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) {
216 for (
const auto &
Feature : Features) {
225 if (
Feature ==
"+bulk-memory") {
226 HasBulkMemory =
true;
229 if (
Feature ==
"-bulk-memory") {
230 HasBulkMemory =
false;
233 if (
Feature ==
"+bulk-memory-opt") {
234 HasBulkMemoryOpt =
true;
237 if (
Feature ==
"-bulk-memory-opt") {
238 HasBulkMemoryOpt =
false;
241 if (
Feature ==
"+call-indirect-overlong") {
242 HasCallIndirectOverlong =
true;
245 if (
Feature ==
"-call-indirect-overlong") {
246 HasCallIndirectOverlong =
false;
249 if (
Feature ==
"+exception-handling") {
250 HasExceptionHandling =
true;
253 if (
Feature ==
"-exception-handling") {
254 HasExceptionHandling =
false;
257 if (
Feature ==
"+extended-const") {
258 HasExtendedConst =
true;
261 if (
Feature ==
"-extended-const") {
262 HasExtendedConst =
false;
266 SIMDLevel = std::max(SIMDLevel, SIMD128);
282 if (
Feature ==
"+multimemory") {
283 HasMultiMemory =
true;
286 if (
Feature ==
"-multimemory") {
287 HasMultiMemory =
false;
290 if (
Feature ==
"+multivalue") {
291 HasMultivalue =
true;
294 if (
Feature ==
"-multivalue") {
295 HasMultivalue =
false;
298 if (
Feature ==
"+mutable-globals") {
299 HasMutableGlobals =
true;
302 if (
Feature ==
"-mutable-globals") {
303 HasMutableGlobals =
false;
306 if (
Feature ==
"+nontrapping-fptoint") {
307 HasNontrappingFPToInt =
true;
310 if (
Feature ==
"-nontrapping-fptoint") {
311 HasNontrappingFPToInt =
false;
314 if (
Feature ==
"+reference-types") {
315 HasReferenceTypes =
true;
318 if (
Feature ==
"-reference-types") {
319 HasReferenceTypes =
false;
322 if (
Feature ==
"+relaxed-simd") {
323 SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
326 if (
Feature ==
"-relaxed-simd") {
327 SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
339 SIMDLevel = std::max(SIMDLevel, SIMD128);
343 SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
354 if (
Feature ==
"+wide-arithmetic") {
355 HasWideArithmetic =
true;
358 if (
Feature ==
"-wide-arithmetic") {
359 HasWideArithmetic =
false;
363 Diags.
Report(diag::err_opt_not_valid_with_opt)
364 <<
Feature <<
"-target-feature";
370 HasReferenceTypes =
true;
375 HasBulkMemoryOpt =
true;
380 if (HasReferenceTypes) {
381 HasCallIndirectOverlong =
true;
387llvm::SmallVector<Builtin::InfosShard>
392void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
393 const TargetInfo *Aux) {
398 if (!HasAtomics || !HasBulkMemory) {
399 Opts.POSIXThreads =
false;
401 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.