clang  8.0.0svn
Hexagon.cpp
Go to the documentation of this file.
1 //===--- Hexagon.cpp - Implement Hexagon 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 Hexagon TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Hexagon.h"
15 #include "Targets.h"
18 #include "llvm/ADT/StringSwitch.h"
19 
20 using namespace clang;
21 using namespace clang::targets;
22 
24  MacroBuilder &Builder) const {
25  Builder.defineMacro("__qdsp6__", "1");
26  Builder.defineMacro("__hexagon__", "1");
27 
28  if (CPU == "hexagonv4") {
29  Builder.defineMacro("__HEXAGON_V4__");
30  Builder.defineMacro("__HEXAGON_ARCH__", "4");
31  if (Opts.HexagonQdsp6Compat) {
32  Builder.defineMacro("__QDSP6_V4__");
33  Builder.defineMacro("__QDSP6_ARCH__", "4");
34  }
35  } else if (CPU == "hexagonv5") {
36  Builder.defineMacro("__HEXAGON_V5__");
37  Builder.defineMacro("__HEXAGON_ARCH__", "5");
38  if (Opts.HexagonQdsp6Compat) {
39  Builder.defineMacro("__QDSP6_V5__");
40  Builder.defineMacro("__QDSP6_ARCH__", "5");
41  }
42  } else if (CPU == "hexagonv55") {
43  Builder.defineMacro("__HEXAGON_V55__");
44  Builder.defineMacro("__HEXAGON_ARCH__", "55");
45  Builder.defineMacro("__QDSP6_V55__");
46  Builder.defineMacro("__QDSP6_ARCH__", "55");
47  } else if (CPU == "hexagonv60") {
48  Builder.defineMacro("__HEXAGON_V60__");
49  Builder.defineMacro("__HEXAGON_ARCH__", "60");
50  Builder.defineMacro("__QDSP6_V60__");
51  Builder.defineMacro("__QDSP6_ARCH__", "60");
52  } else if (CPU == "hexagonv62") {
53  Builder.defineMacro("__HEXAGON_V62__");
54  Builder.defineMacro("__HEXAGON_ARCH__", "62");
55  } else if (CPU == "hexagonv65") {
56  Builder.defineMacro("__HEXAGON_V65__");
57  Builder.defineMacro("__HEXAGON_ARCH__", "65");
58  }
59 
60  if (hasFeature("hvx-length64b")) {
61  Builder.defineMacro("__HVX__");
62  Builder.defineMacro("__HVX_ARCH__", HVXVersion);
63  Builder.defineMacro("__HVX_LENGTH__", "64");
64  }
65 
66  if (hasFeature("hvx-length128b")) {
67  Builder.defineMacro("__HVX__");
68  Builder.defineMacro("__HVX_ARCH__", HVXVersion);
69  Builder.defineMacro("__HVX_LENGTH__", "128");
70  // FIXME: This macro is deprecated.
71  Builder.defineMacro("__HVXDBL__");
72  }
73 }
74 
76  llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
77  const std::vector<std::string> &FeaturesVec) const {
78  Features["long-calls"] = false;
79 
80  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
81 }
82 
83 bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
84  DiagnosticsEngine &Diags) {
85  for (auto &F : Features) {
86  if (F == "+hvx-length64b")
87  HasHVX = HasHVX64B = true;
88  else if (F == "+hvx-length128b")
89  HasHVX = HasHVX128B = true;
90  else if (F.find("+hvxv") != std::string::npos) {
91  HasHVX = true;
92  HVXVersion = F.substr(std::string("+hvxv").length());
93  } else if (F == "-hvx")
94  HasHVX = HasHVX64B = HasHVX128B = false;
95  else if (F == "+long-calls")
96  UseLongCalls = true;
97  else if (F == "-long-calls")
98  UseLongCalls = false;
99  }
100  return true;
101 }
102 
103 const char *const HexagonTargetInfo::GCCRegNames[] = {
104  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8",
105  "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
106  "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26",
107  "r27", "r28", "r29", "r30", "r31", "p0", "p1", "p2", "p3",
108  "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp"
109 };
110 
112  return llvm::makeArrayRef(GCCRegNames);
113 }
114 
115 const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
116  {{"sp"}, "r29"},
117  {{"fp"}, "r30"},
118  {{"lr"}, "r31"},
119 };
120 
122  return llvm::makeArrayRef(GCCRegAliases);
123 }
124 
125 const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
126 #define BUILTIN(ID, TYPE, ATTRS) \
127  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
128 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
129  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
130 #include "clang/Basic/BuiltinsHexagon.def"
131 };
132 
133 bool HexagonTargetInfo::hasFeature(StringRef Feature) const {
134  std::string VS = "hvxv" + HVXVersion;
135  if (Feature == VS)
136  return true;
137 
138  return llvm::StringSwitch<bool>(Feature)
139  .Case("hexagon", true)
140  .Case("hvx", HasHVX)
141  .Case("hvx-length64b", HasHVX64B)
142  .Case("hvx-length128b", HasHVX128B)
143  .Case("long-calls", UseLongCalls)
144  .Default(false);
145 }
146 
147 struct CPUSuffix {
148  llvm::StringLiteral Name;
149  llvm::StringLiteral Suffix;
150 };
151 
152 static constexpr CPUSuffix Suffixes[] = {
153  {{"hexagonv4"}, {"4"}}, {{"hexagonv5"}, {"5"}},
154  {{"hexagonv55"}, {"55"}}, {{"hexagonv60"}, {"60"}},
155  {{"hexagonv62"}, {"62"}}, {{"hexagonv65"}, {"65"}},
156 };
157 
158 const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
159  const CPUSuffix *Item = llvm::find_if(
160  Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
161  if (Item == std::end(Suffixes))
162  return nullptr;
163  return Item->Suffix.data();
164 }
165 
167  SmallVectorImpl<StringRef> &Values) const {
168  for (const CPUSuffix &Suffix : Suffixes)
169  Values.push_back(Suffix.Name);
170 }
171 
173  return llvm::makeArrayRef(BuiltinInfo, clang::Hexagon::LastTSBuiltin -
175 }
llvm::StringLiteral Name
Definition: Hexagon.cpp:148
Defines the clang::MacroBuilder utility class.
static const char * getHexagonCPUSuffix(StringRef Name)
Definition: Hexagon.cpp:158
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: Hexagon.cpp:172
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition: Hexagon.cpp:83
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: Hexagon.cpp:133
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: Hexagon.cpp:75
llvm::StringLiteral Suffix
Definition: Hexagon.cpp:149
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 ...
Definition: TargetInfo.cpp:385
ArrayRef< const char * > getGCCRegNames() const override
Definition: Hexagon.cpp:111
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
Enumerates target-specific builtins in their own namespaces within namespace clang.
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: Hexagon.cpp:121
Dataflow Directional Tag Classes.
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: Hexagon.cpp:166
static constexpr CPUSuffix Suffixes[]
Definition: Hexagon.cpp:152
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
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: Hexagon.cpp:23