Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Basic/Targets/Hexagon.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Hexagon.cpp - Implement Hexagon target feature support -----------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements Hexagon TargetInfo objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "Hexagon.h"
14
#include "Targets.h"
15
#include "clang/Basic/MacroBuilder.h"
16
#include "clang/Basic/TargetBuiltins.h"
17
#include "llvm/ADT/StringSwitch.h"
18
19
using namespace clang;
20
using namespace clang::targets;
21
22
void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
23
34
                                         MacroBuilder &Builder) const {
24
34
  Builder.defineMacro("__qdsp6__", "1");
25
34
  Builder.defineMacro("__hexagon__", "1");
26
34
27
34
  if (CPU == "hexagonv5") {
28
1
    Builder.defineMacro("__HEXAGON_V5__");
29
1
    Builder.defineMacro("__HEXAGON_ARCH__", "5");
30
1
    if (Opts.HexagonQdsp6Compat) {
31
0
      Builder.defineMacro("__QDSP6_V5__");
32
0
      Builder.defineMacro("__QDSP6_ARCH__", "5");
33
0
    }
34
33
  } else if (CPU == "hexagonv55") {
35
2
    Builder.defineMacro("__HEXAGON_V55__");
36
2
    Builder.defineMacro("__HEXAGON_ARCH__", "55");
37
2
    Builder.defineMacro("__QDSP6_V55__");
38
2
    Builder.defineMacro("__QDSP6_ARCH__", "55");
39
31
  } else if (CPU == "hexagonv60") {
40
5
    Builder.defineMacro("__HEXAGON_V60__");
41
5
    Builder.defineMacro("__HEXAGON_ARCH__", "60");
42
5
    Builder.defineMacro("__QDSP6_V60__");
43
5
    Builder.defineMacro("__QDSP6_ARCH__", "60");
44
26
  } else if (CPU == "hexagonv62") {
45
3
    Builder.defineMacro("__HEXAGON_V62__");
46
3
    Builder.defineMacro("__HEXAGON_ARCH__", "62");
47
23
  } else if (CPU == "hexagonv65") {
48
6
    Builder.defineMacro("__HEXAGON_V65__");
49
6
    Builder.defineMacro("__HEXAGON_ARCH__", "65");
50
17
  } else if (CPU == "hexagonv66") {
51
4
    Builder.defineMacro("__HEXAGON_V66__");
52
4
    Builder.defineMacro("__HEXAGON_ARCH__", "66");
53
4
  }
54
34
55
34
  if (hasFeature("hvx-length64b")) {
56
5
    Builder.defineMacro("__HVX__");
57
5
    Builder.defineMacro("__HVX_ARCH__", HVXVersion);
58
5
    Builder.defineMacro("__HVX_LENGTH__", "64");
59
5
  }
60
34
61
34
  if (hasFeature("hvx-length128b")) {
62
7
    Builder.defineMacro("__HVX__");
63
7
    Builder.defineMacro("__HVX_ARCH__", HVXVersion);
64
7
    Builder.defineMacro("__HVX_LENGTH__", "128");
65
7
    // FIXME: This macro is deprecated.
66
7
    Builder.defineMacro("__HVXDBL__");
67
7
  }
68
34
}
69
70
bool HexagonTargetInfo::initFeatureMap(
71
    llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
72
34
    const std::vector<std::string> &FeaturesVec) const {
73
34
  Features["long-calls"] = false;
74
34
75
34
  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
76
34
}
77
78
bool HexagonTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
79
34
                                             DiagnosticsEngine &Diags) {
80
59
  for (auto &F : Features) {
81
59
    if (F == "+hvx-length64b")
82
5
      HasHVX = HasHVX64B = true;
83
54
    else if (F == "+hvx-length128b")
84
7
      HasHVX = HasHVX128B = true;
85
47
    else if (F.find("+hvxv") != std::string::npos) {
86
12
      HasHVX = true;
87
12
      HVXVersion = F.substr(std::string("+hvxv").length());
88
35
    } else if (F == "-hvx")
89
0
      HasHVX = HasHVX64B = HasHVX128B = false;
90
35
    else if (F == "+long-calls")
91
0
      UseLongCalls = true;
92
35
    else if (F == "-long-calls")
93
34
      UseLongCalls = false;
94
59
  }
95
34
  return true;
96
34
}
97
98
const char *const HexagonTargetInfo::GCCRegNames[] = {
99
    "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",  "r8",
100
    "r9",  "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
101
    "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26",
102
    "r27", "r28", "r29", "r30", "r31", "p0",  "p1",  "p2",  "p3",
103
    "sa0", "lc0", "sa1", "lc1", "m0",  "m1",  "usr", "ugp"
104
};
105
106
1
ArrayRef<const char *> HexagonTargetInfo::getGCCRegNames() const {
107
1
  return llvm::makeArrayRef(GCCRegNames);
108
1
}
109
110
const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
111
    {{"sp"}, "r29"},
112
    {{"fp"}, "r30"},
113
    {{"lr"}, "r31"},
114
};
115
116
1
ArrayRef<TargetInfo::GCCRegAlias> HexagonTargetInfo::getGCCRegAliases() const {
117
1
  return llvm::makeArrayRef(GCCRegAliases);
118
1
}
119
120
const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
121
#define BUILTIN(ID, TYPE, ATTRS)                                               \
122
  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
123
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER)                                    \
124
  {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr},
125
#include "clang/Basic/BuiltinsHexagon.def"
126
};
127
128
2.79k
bool HexagonTargetInfo::hasFeature(StringRef Feature) const {
129
2.79k
  std::string VS = "hvxv" + HVXVersion;
130
2.79k
  if (Feature == VS)
131
738
    return true;
132
2.06k
133
2.06k
  return llvm::StringSwitch<bool>(Feature)
134
2.06k
      .Case("hexagon", true)
135
2.06k
      .Case("hvx", HasHVX)
136
2.06k
      .Case("hvx-length64b", HasHVX64B)
137
2.06k
      .Case("hvx-length128b", HasHVX128B)
138
2.06k
      .Case("long-calls", UseLongCalls)
139
2.06k
      .Default(false);
140
2.06k
}
141
142
struct CPUSuffix {
143
  llvm::StringLiteral Name;
144
  llvm::StringLiteral Suffix;
145
};
146
147
static constexpr CPUSuffix Suffixes[] = {
148
    {{"hexagonv5"},  {"5"}},  {{"hexagonv55"}, {"55"}},
149
    {{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}},
150
    {{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}},
151
};
152
153
22
const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
154
22
  const CPUSuffix *Item = llvm::find_if(
155
92
      Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
156
22
  if (Item == std::end(Suffixes))
157
1
    return nullptr;
158
21
  return Item->Suffix.data();
159
21
}
160
161
void HexagonTargetInfo::fillValidCPUList(
162
1
    SmallVectorImpl<StringRef> &Values) const {
163
1
  for (const CPUSuffix &Suffix : Suffixes)
164
6
    Values.push_back(Suffix.Name);
165
1
}
166
167
34
ArrayRef<Builtin::Info> HexagonTargetInfo::getTargetBuiltins() const {
168
34
  return llvm::makeArrayRef(BuiltinInfo, clang::Hexagon::LastTSBuiltin -
169
34
                                             Builtin::FirstTSBuiltin);
170
34
}