clang  6.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["hvx-double"] = false;
79  Features["long-calls"] = false;
80 
81  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
82 }
83 
84 bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
85  DiagnosticsEngine &Diags) {
86  for (auto &F : Features) {
87  if (F == "+hvx-length64b")
88  HasHVX = HasHVX64B = true;
89  else if (F == "+hvx-length128b")
90  HasHVX = HasHVX128B = true;
91  else if (F.find("+hvxv") != std::string::npos) {
92  HasHVX = true;
93  HVXVersion = F.substr(std::string("+hvxv").length());
94  } else if (F == "-hvx")
95  HasHVX = HasHVX64B = HasHVX128B = false;
96  else if (F == "+long-calls")
97  UseLongCalls = true;
98  else if (F == "-long-calls")
99  UseLongCalls = false;
100  }
101  return true;
102 }
103 
104 const char *const HexagonTargetInfo::GCCRegNames[] = {
105  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8",
106  "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
107  "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26",
108  "r27", "r28", "r29", "r30", "r31", "p0", "p1", "p2", "p3",
109  "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp"
110 };
111 
113  return llvm::makeArrayRef(GCCRegNames);
114 }
115 
116 const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
117  {{"sp"}, "r29"},
118  {{"fp"}, "r30"},
119  {{"lr"}, "r31"},
120 };
121 
123  return llvm::makeArrayRef(GCCRegAliases);
124 }
125 
126 const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
127 #define BUILTIN(ID, TYPE, ATTRS) \
128  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
129 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
130  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
131 #include "clang/Basic/BuiltinsHexagon.def"
132 };
133 
134 bool HexagonTargetInfo::hasFeature(StringRef Feature) const {
135  return llvm::StringSwitch<bool>(Feature)
136  .Case("hexagon", true)
137  .Case("hvx", HasHVX)
138  .Case("hvx-length64b", HasHVX64B)
139  .Case("hvx-length128b", HasHVX128B)
140  .Case("long-calls", UseLongCalls)
141  .Default(false);
142 }
143 
144 const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
145  return llvm::StringSwitch<const char *>(Name)
146  .Case("hexagonv4", "4")
147  .Case("hexagonv5", "5")
148  .Case("hexagonv55", "55")
149  .Case("hexagonv60", "60")
150  .Case("hexagonv62", "62")
151  .Case("hexagonv65", "65")
152  .Default(nullptr);
153 }
154 
156  return llvm::makeArrayRef(BuiltinInfo, clang::Hexagon::LastTSBuiltin -
158 }
Defines the clang::MacroBuilder utility class.
static const char * getHexagonCPUSuffix(StringRef Name)
Definition: Hexagon.cpp:144
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: Hexagon.cpp:155
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
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:84
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: Hexagon.cpp:134
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
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:347
ArrayRef< const char * > getGCCRegNames() const override
Definition: Hexagon.cpp:112
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:122
Dataflow Directional Tag Classes.
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