1//===--- Hexagon.h - Declare Hexagon target feature support -----*- C++ -*-===//
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 declares Hexagon TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H
15
16#include "clang/Basic/TargetInfo.h"
17#include "clang/Basic/TargetOptions.h"
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20#include <optional>
21
22namespace clang {
23namespace targets {
24
25// Hexagon abstract base class
26class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
27
28 static const char *const GCCRegNames[];
29 static const TargetInfo::GCCRegAlias GCCRegAliases[];
30 std::string CPU;
31 std::string HVXVersion;
32 bool HasHVX = false;
33 bool HasHVX64B = false;
34 bool HasHVX128B = false;
35 bool HasHVXIeeeFp = false;
36 bool HasAudio = false;
37 bool HasHLX = false;
38 bool UseLongCalls = false;
39 bool HasHMX = false;
40
41public:
42 HexagonTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
43 : TargetInfo(Triple) {
44 resetDataLayout();
45 SizeType = UnsignedInt;
46 PtrDiffType = SignedInt;
47 IntPtrType = SignedInt;
48
49 // {} in inline assembly are packet specifiers, not assembly variant
50 // specifiers.
51 NoAsmVariants = true;
52
53 LargeArrayMinWidth = 64;
54 LargeArrayAlign = 64;
55 UseBitFieldTypeAlignment = true;
56 ZeroLengthBitfieldBoundary = 32;
57 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
58
59 // These are the default values anyway, but explicitly make sure
60 // that the size of the boolean type is 8 bits. Bool vectors are used
61 // for modeling predicate registers in HVX, and the bool -> byte
62 // correspondence matches the HVX architecture.
63 BoolWidth = BoolAlign = 8;
64 BFloat16Width = BFloat16Align = 16;
65 BFloat16Format = &llvm::APFloat::BFloat();
66 }
67
68 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
69
70 bool validateAsmConstraint(const char *&Name,
71 TargetInfo::ConstraintInfo &Info) const override {
72 switch (*Name) {
73 case 'v':
74 case 'q':
75 if (HasHVX) {
76 Info.setAllowsRegister();
77 return true;
78 }
79 break;
80 case 'a': // Modifier register m0-m1.
81 Info.setAllowsRegister();
82 return true;
83 case 's':
84 // Relocatable constant.
85 return true;
86 }
87 return false;
88 }
89
90 void getTargetDefines(const LangOptions &Opts,
91 MacroBuilder &Builder) const override;
92
93 bool isCLZForZeroUndef() const override { return false; }
94
95 bool hasFeature(StringRef Feature) const override;
96
97 bool hasBFloat16Type() const override;
98
99 bool
100 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
101 StringRef CPU,
102 const std::vector<std::string> &FeaturesVec) const override;
103
104 bool handleTargetFeatures(std::vector<std::string> &Features,
105 DiagnosticsEngine &Diags) override;
106
107 BuiltinVaListKind getBuiltinVaListKind() const override {
108 if (getTriple().isMusl())
109 return TargetInfo::HexagonBuiltinVaList;
110 return TargetInfo::CharPtrBuiltinVaList;
111 }
112
113 ArrayRef<const char *> getGCCRegNames() const override;
114
115 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
116
117 std::string_view getClobbers() const override { return ""; }
118
119 static const char *getHexagonCPUSuffix(StringRef Name);
120 static std::optional<unsigned> getHexagonCPURev(StringRef Name);
121
122 bool isValidCPUName(StringRef Name) const override {
123 return getHexagonCPUSuffix(Name);
124 }
125
126 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
127
128 bool setCPU(StringRef Name) override {
129 if (!isValidCPUName(Name))
130 return false;
131 CPU = Name;
132 return true;
133 }
134
135 int getEHDataRegisterNumber(unsigned RegNo) const override {
136 return RegNo < 2 ? RegNo : -1;
137 }
138
139 bool isTinyCore() const {
140 // We can write more stricter checks later.
141 return CPU.find(c: 't') != std::string::npos;
142 }
143
144 bool hasBitIntType() const override { return true; }
145
146 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
147 std::optional<unsigned> Rev = getHexagonCPURev(Name: CPU);
148
149 // V73 and later have 64-byte cache lines.
150 unsigned CacheLineSizeBytes = Rev >= 73U ? 64 : 32;
151 return std::make_pair(x&: CacheLineSizeBytes, y&: CacheLineSizeBytes);
152 }
153};
154} // namespace targets
155} // namespace clang
156#endif // LLVM_CLANG_LIB_BASIC_TARGETS_HEXAGON_H
157