18 #include "llvm/ADT/StringSwitch.h" 20 using namespace clang;
24 #define BUILTIN(ID, TYPE, ATTRS) \ 25 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, 26 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ 27 {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, 28 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \ 29 {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr}, 30 #include "clang/Basic/BuiltinsWebAssembly.def" 34 {
"mvp"}, {
"bleeding-edge"}, {
"generic"}};
36 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature)
const {
37 return llvm::StringSwitch<bool>(Feature)
38 .Case(
"simd128", SIMDLevel >= SIMD128)
39 .Case(
"unimplemented-simd128", SIMDLevel >= UnimplementedSIMD128)
40 .Case(
"nontrapping-fptoint", HasNontrappingFPToInt)
41 .Case(
"sign-ext", HasSignExt)
42 .Case(
"exception-handling", HasExceptionHandling)
43 .Case(
"bulk-memory", HasBulkMemory)
44 .Case(
"atomics", HasAtomics)
45 .Case(
"mutable-globals", HasMutableGlobals)
46 .Case(
"multivalue", HasMultivalue)
47 .Case(
"tail-call", HasTailCall)
51 bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name)
const {
55 void WebAssemblyTargetInfo::fillValidCPUList(
63 if (SIMDLevel >= SIMD128)
65 if (SIMDLevel >= UnimplementedSIMD128)
66 Builder.
defineMacro(
"__wasm_unimplemented_simd128__");
67 if (HasNontrappingFPToInt)
68 Builder.
defineMacro(
"__wasm_nontrapping_fptoint__");
71 if (HasExceptionHandling)
77 if (HasMutableGlobals)
85 void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
88 case UnimplementedSIMD128:
89 Features[
"unimplemented-simd128"] =
true;
92 Features[
"simd128"] =
true;
99 bool WebAssemblyTargetInfo::initFeatureMap(
101 const std::vector<std::string> &FeaturesVec)
const {
102 if (CPU ==
"bleeding-edge") {
103 Features[
"nontrapping-fptoint"] =
true;
104 Features[
"sign-ext"] =
true;
105 Features[
"atomics"] =
true;
106 Features[
"mutable-globals"] =
true;
107 setSIMDLevel(Features, SIMD128);
112 setSIMDLevel(Features, SIMDLevel);
113 if (HasNontrappingFPToInt)
114 Features[
"nontrapping-fptoint"] =
true;
116 Features[
"sign-ext"] =
true;
117 if (HasExceptionHandling)
118 Features[
"exception-handling"] =
true;
120 Features[
"bulk-memory"] =
true;
122 Features[
"atomics"] =
true;
123 if (HasMutableGlobals)
124 Features[
"mutable-globals"] =
true;
126 Features[
"multivalue"] =
true;
128 Features[
"tail-call"] =
true;
133 bool WebAssemblyTargetInfo::handleTargetFeatures(
135 for (
const auto &Feature : Features) {
136 if (Feature ==
"+simd128") {
137 SIMDLevel =
std::max(SIMDLevel, SIMD128);
140 if (Feature ==
"-simd128") {
141 SIMDLevel =
std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
144 if (Feature ==
"+unimplemented-simd128") {
145 SIMDLevel =
std::max(SIMDLevel, SIMDEnum(UnimplementedSIMD128));
148 if (Feature ==
"-unimplemented-simd128") {
149 SIMDLevel =
std::min(SIMDLevel, SIMDEnum(UnimplementedSIMD128 - 1));
152 if (Feature ==
"+nontrapping-fptoint") {
153 HasNontrappingFPToInt =
true;
156 if (Feature ==
"-nontrapping-fptoint") {
157 HasNontrappingFPToInt =
false;
160 if (Feature ==
"+sign-ext") {
164 if (Feature ==
"-sign-ext") {
168 if (Feature ==
"+exception-handling") {
169 HasExceptionHandling =
true;
172 if (Feature ==
"-exception-handling") {
173 HasExceptionHandling =
false;
176 if (Feature ==
"+bulk-memory") {
177 HasBulkMemory =
true;
180 if (Feature ==
"-bulk-memory") {
181 HasBulkMemory =
false;
184 if (Feature ==
"+atomics") {
188 if (Feature ==
"-atomics") {
192 if (Feature ==
"+mutable-globals") {
193 HasMutableGlobals =
true;
196 if (Feature ==
"-mutable-globals") {
197 HasMutableGlobals =
false;
200 if (Feature ==
"+multivalue") {
201 HasMultivalue =
true;
204 if (Feature ==
"-multivalue") {
205 HasMultivalue =
false;
208 if (Feature ==
"+tail-call") {
212 if (Feature ==
"-tail-call") {
217 Diags.
Report(diag::err_opt_not_valid_with_opt)
218 << Feature <<
"-target-feature";
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
__DEVICE__ int max(int __a, int __b)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Concrete class used by the front-end to report problems and issues.
Defines the Diagnostic-related interfaces.
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 ...
Enumerates target-specific builtins in their own namespaces within namespace clang.
Dataflow Directional Tag Classes.
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 --------------------——===//
static constexpr llvm::StringLiteral ValidCPUNames[]
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
__DEVICE__ int min(int __a, int __b)
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Defines enum values for all the target-independent builtin functions.