1 //===--- Hexagon.cpp - Implement Hexagon target feature support -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements Hexagon TargetInfo objects.
12 //===----------------------------------------------------------------------===//
16 #include "clang/Basic/MacroBuilder.h"
17 #include "clang/Basic/TargetBuiltins.h"
18 #include "llvm/ADT/StringSwitch.h"
20 using namespace clang;
21 using namespace clang::targets;
23 void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
24 MacroBuilder &Builder) const {
25 Builder.defineMacro("__qdsp6__", "1");
26 Builder.defineMacro("__hexagon__", "1");
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");
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");
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");
60 if (hasFeature("hvx-length64b")) {
61 Builder.defineMacro("__HVX__");
62 Builder.defineMacro("__HVX_ARCH__", HVXVersion);
63 Builder.defineMacro("__HVX_LENGTH__", "64");
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__");
75 bool HexagonTargetInfo::initFeatureMap(
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;
81 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
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) {
93 HVXVersion = F.substr(std::string("+hvxv").length());
94 } else if (F == "-hvx")
95 HasHVX = HasHVX64B = HasHVX128B = false;
96 else if (F == "+long-calls")
98 else if (F == "-long-calls")
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"
112 ArrayRef<const char *> HexagonTargetInfo::getGCCRegNames() const {
113 return llvm::makeArrayRef(GCCRegNames);
116 const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
122 ArrayRef<TargetInfo::GCCRegAlias> HexagonTargetInfo::getGCCRegAliases() const {
123 return llvm::makeArrayRef(GCCRegAliases);
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"
134 bool HexagonTargetInfo::hasFeature(StringRef Feature) const {
135 return llvm::StringSwitch<bool>(Feature)
136 .Case("hexagon", true)
138 .Case("hvx-length64b", HasHVX64B)
139 .Case("hvx-length128b", HasHVX128B)
140 .Case("long-calls", UseLongCalls)
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")
155 ArrayRef<Builtin::Info> HexagonTargetInfo::getTargetBuiltins() const {
156 return llvm::makeArrayRef(BuiltinInfo, clang::Hexagon::LastTSBuiltin -
157 Builtin::FirstTSBuiltin);