clang  7.0.0svn
WebAssembly.cpp
Go to the documentation of this file.
1 //===--- WebAssembly.cpp - Implement WebAssembly target feature support ---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements WebAssembly TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "WebAssembly.h"
15 #include "Targets.h"
16 #include "clang/Basic/Builtins.h"
17 #include "clang/Basic/Diagnostic.h"
19 #include "llvm/ADT/StringSwitch.h"
20 
21 using namespace clang;
22 using namespace clang::targets;
23 
24 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
25 #define BUILTIN(ID, TYPE, ATTRS) \
26  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
27 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
28  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
29 #include "clang/Basic/BuiltinsWebAssembly.def"
30 };
31 
32 static constexpr llvm::StringLiteral ValidCPUNames[] = {
33  {"mvp"}, {"bleeding-edge"}, {"generic"}};
34 
35 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
36  return llvm::StringSwitch<bool>(Feature)
37  .Case("simd128", SIMDLevel >= SIMD128)
38  .Case("nontrapping-fptoint", HasNontrappingFPToInt)
39  .Case("sign-ext", HasSignExt)
40  .Default(false);
41 }
42 
43 bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name) const {
44  return llvm::find(ValidCPUNames, Name) != std::end(ValidCPUNames);
45 }
46 
47 void WebAssemblyTargetInfo::fillValidCPUList(
48  SmallVectorImpl<StringRef> &Values) const {
49  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
50 }
51 
53  MacroBuilder &Builder) const {
54  defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
55  if (SIMDLevel >= SIMD128)
56  Builder.defineMacro("__wasm_simd128__");
57 }
58 
59 bool WebAssemblyTargetInfo::handleTargetFeatures(
60  std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
61  for (const auto &Feature : Features) {
62  if (Feature == "+simd128") {
63  SIMDLevel = std::max(SIMDLevel, SIMD128);
64  continue;
65  }
66  if (Feature == "-simd128") {
67  SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
68  continue;
69  }
70  if (Feature == "+nontrapping-fptoint") {
71  HasNontrappingFPToInt = true;
72  continue;
73  }
74  if (Feature == "-nontrapping-fptoint") {
75  HasNontrappingFPToInt = false;
76  continue;
77  }
78  if (Feature == "+sign-ext") {
79  HasSignExt = true;
80  continue;
81  }
82  if (Feature == "-sign-ext") {
83  HasSignExt = false;
84  continue;
85  }
86 
87  Diags.Report(diag::err_opt_not_valid_with_opt)
88  << Feature << "-target-feature";
89  return false;
90  }
91  return true;
92 }
93 
94 ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
95  return llvm::makeArrayRef(BuiltinInfo, clang::WebAssembly::LastTSBuiltin -
97 }
98 
100  MacroBuilder &Builder) const {
102  defineCPUMacros(Builder, "wasm32", /*Tuning=*/false);
103 }
104 
106  MacroBuilder &Builder) const {
108  defineCPUMacros(Builder, "wasm64", /*Tuning=*/false);
109 }
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1294
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Defines the Diagnostic-related interfaces.
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 --------------------——===//
Definition: WebAssembly.cpp:99
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
static constexpr llvm::StringLiteral ValidCPUNames[]
Definition: WebAssembly.cpp:32
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: WebAssembly.cpp:52
__DEVICE__ int max(int __a, int __b)
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:71
__DEVICE__ int min(int __a, int __b)
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30
Defines enum values for all the target-independent builtin functions.