1//===--- Sparc.h - declare sparc 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 Sparc TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
15#include "clang/Basic/TargetInfo.h"
16#include "clang/Basic/TargetOptions.h"
17#include "llvm/Support/Compiler.h"
18#include "llvm/TargetParser/Triple.h"
19namespace clang {
20namespace targets {
21// Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
22class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
23 static const TargetInfo::GCCRegAlias GCCRegAliases[];
24 static const char *const GCCRegNames[];
25 bool SoftFloat;
26
27public:
28 SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
29 : TargetInfo(Triple), SoftFloat(false) {
30 HasStrictFP = true;
31 }
32
33 int getEHDataRegisterNumber(unsigned RegNo) const override {
34 if (RegNo == 0)
35 return 24;
36 if (RegNo == 1)
37 return 25;
38 return -1;
39 }
40
41 bool handleTargetFeatures(std::vector<std::string> &Features,
42 DiagnosticsEngine &Diags) override {
43 // Check if software floating point is enabled
44 if (llvm::is_contained(Range&: Features, Element: "+soft-float"))
45 SoftFloat = true;
46 return true;
47 }
48 void getTargetDefines(const LangOptions &Opts,
49 MacroBuilder &Builder) const override;
50
51 bool hasFeature(StringRef Feature) const override;
52
53 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override {
54 // FIXME: Implement!
55 return {};
56 }
57 BuiltinVaListKind getBuiltinVaListKind() const override {
58 return TargetInfo::VoidPtrBuiltinVaList;
59 }
60 ArrayRef<const char *> getGCCRegNames() const override;
61 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
62 bool validateAsmConstraint(const char *&Name,
63 TargetInfo::ConstraintInfo &info) const override {
64 // FIXME: Implement!
65 switch (*Name) {
66 case 'I': // Signed 13-bit constant
67 case 'J': // Zero
68 case 'K': // 32-bit constant with the low 12 bits clear
69 case 'L': // A constant in the range supported by movcc (11-bit signed imm)
70 case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
71 case 'N': // Same as 'K' but zext (required for SIMode)
72 case 'O': // The constant 4096
73 return true;
74
75 case 'f':
76 case 'e':
77 info.setAllowsRegister();
78 return true;
79 }
80 return false;
81 }
82 std::string_view getClobbers() const override { return "~{y}"; }
83
84 // No Sparc V7 for now, the backend doesn't support it anyway.
85 enum CPUKind {
86 CK_GENERIC,
87 CK_V8,
88 CK_SUPERSPARC,
89 CK_SPARCLITE,
90 CK_F934,
91 CK_HYPERSPARC,
92 CK_SPARCLITE86X,
93 CK_SPARCLET,
94 CK_TSC701,
95 CK_V9,
96 CK_ULTRASPARC,
97 CK_ULTRASPARC3,
98 CK_NIAGARA,
99 CK_NIAGARA2,
100 CK_NIAGARA3,
101 CK_NIAGARA4,
102 CK_MYRIAD2100,
103 CK_MYRIAD2150,
104 CK_MYRIAD2155,
105 CK_MYRIAD2450,
106 CK_MYRIAD2455,
107 CK_MYRIAD2x5x,
108 CK_MYRIAD2080,
109 CK_MYRIAD2085,
110 CK_MYRIAD2480,
111 CK_MYRIAD2485,
112 CK_MYRIAD2x8x,
113 CK_LEON2,
114 CK_LEON2_AT697E,
115 CK_LEON2_AT697F,
116 CK_LEON3,
117 CK_LEON3_UT699,
118 CK_LEON3_GR712RC,
119 CK_LEON4,
120 CK_LEON4_GR740,
121 CK_LEON5,
122 } CPU = CK_GENERIC;
123
124 enum CPUGeneration {
125 CG_V8,
126 CG_V9,
127 };
128
129 enum CPUFamily {
130 CF_NONE,
131 CF_LEON,
132 };
133
134 CPUGeneration getCPUGeneration(CPUKind Kind) const;
135
136 CPUFamily getCPUFamily(CPUKind Kind) const;
137
138 CPUKind getCPUKind(StringRef Name) const;
139
140 bool isValidCPUName(StringRef Name) const override {
141 return getCPUKind(Name) != CK_GENERIC;
142 }
143
144 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
145
146 bool setCPU(StringRef Name) override {
147 CPU = getCPUKind(Name);
148 return CPU != CK_GENERIC;
149 }
150
151 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
152 return std::make_pair(x: 32, y: 32);
153 }
154};
155
156// SPARC v8 is the 32-bit mode selected by Triple::sparc.
157class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
158public:
159 SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
160 : SparcTargetInfo(Triple, Opts) {
161 resetDataLayout();
162 // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
163 switch (getTriple().getOS()) {
164 default:
165 SizeType = UnsignedInt;
166 IntPtrType = SignedInt;
167 PtrDiffType = SignedInt;
168 break;
169 case llvm::Triple::NetBSD:
170 case llvm::Triple::OpenBSD:
171 SizeType = UnsignedLong;
172 IntPtrType = SignedLong;
173 PtrDiffType = SignedLong;
174 break;
175 }
176
177 // Base long double format on the triple.
178 if (getTriple().getDefaultLongDoubleFormat() ==
179 llvm::LongDoubleFormat::IEEEdouble) {
180 LongDoubleWidth = 64;
181 LongDoubleAlign = 64;
182 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
183 } else {
184 LongDoubleWidth = 128;
185 LongDoubleAlign = 64;
186 LongDoubleFormat = &llvm::APFloat::IEEEquad();
187 }
188
189 // Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
190 // willing to do atomic ops on up to 64 bits.
191 MaxAtomicPromoteWidth = 64;
192 if (getCPUGeneration(Kind: CPU) == CG_V9)
193 MaxAtomicInlineWidth = 64;
194 else
195 // FIXME: This isn't correct for plain V8 which lacks CAS,
196 // only for LEON 3+ and Myriad.
197 MaxAtomicInlineWidth = 32;
198 }
199
200 void getTargetDefines(const LangOptions &Opts,
201 MacroBuilder &Builder) const override;
202
203 bool hasBitIntType() const override { return true; }
204};
205
206// SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
207class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
208public:
209 SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
210 : SparcV8TargetInfo(Triple, Opts) {
211 resetDataLayout();
212 }
213};
214
215// SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
216class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
217public:
218 SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
219 : SparcTargetInfo(Triple, Opts) {
220 // FIXME: Support Sparc quad-precision long double?
221 resetDataLayout();
222 // This is an LP64 platform.
223 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
224
225 // OpenBSD uses long long for int64_t and intmax_t.
226 if (getTriple().isOSOpenBSD())
227 IntMaxType = SignedLongLong;
228 else
229 IntMaxType = SignedLong;
230 Int64Type = IntMaxType;
231
232 // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
233 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
234 LongDoubleWidth = 128;
235 LongDoubleAlign = 128;
236 SuitableAlign = 128;
237 LongDoubleFormat = &llvm::APFloat::IEEEquad();
238 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
239 }
240
241 void getTargetDefines(const LangOptions &Opts,
242 MacroBuilder &Builder) const override;
243
244 bool isValidCPUName(StringRef Name) const override {
245 return getCPUGeneration(Kind: SparcTargetInfo::getCPUKind(Name)) == CG_V9;
246 }
247
248 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
249
250 bool setCPU(StringRef Name) override {
251 if (!SparcTargetInfo::setCPU(Name))
252 return false;
253 return getCPUGeneration(Kind: CPU) == CG_V9;
254 }
255
256 bool hasBitIntType() const override { return true; }
257};
258} // namespace targets
259} // namespace clang
260#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
261