clang 19.0.0git
Sparc.h
Go to the documentation of this file.
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
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
31 int getEHDataRegisterNumber(unsigned RegNo) const override {
32 if (RegNo == 0)
33 return 24;
34 if (RegNo == 1)
35 return 25;
36 return -1;
37 }
38
39 bool handleTargetFeatures(std::vector<std::string> &Features,
40 DiagnosticsEngine &Diags) override {
41 // Check if software floating point is enabled
42 if (llvm::is_contained(Features, "+soft-float"))
43 SoftFloat = true;
44 return true;
45 }
46 void getTargetDefines(const LangOptions &Opts,
47 MacroBuilder &Builder) const override;
48
49 bool hasFeature(StringRef Feature) const override;
50
52 // FIXME: Implement!
53 return std::nullopt;
54 }
56 return TargetInfo::VoidPtrBuiltinVaList;
57 }
58 ArrayRef<const char *> getGCCRegNames() const override;
59 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
60 bool validateAsmConstraint(const char *&Name,
61 TargetInfo::ConstraintInfo &info) const override {
62 // FIXME: Implement!
63 switch (*Name) {
64 case 'I': // Signed 13-bit constant
65 case 'J': // Zero
66 case 'K': // 32-bit constant with the low 12 bits clear
67 case 'L': // A constant in the range supported by movcc (11-bit signed imm)
68 case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
69 case 'N': // Same as 'K' but zext (required for SIMode)
70 case 'O': // The constant 4096
71 return true;
72
73 case 'f':
74 case 'e':
75 info.setAllowsRegister();
76 return true;
77 }
78 return false;
79 }
80 std::string_view getClobbers() const override {
81 // FIXME: Implement!
82 return "";
83 }
84
85 // No Sparc V7 for now, the backend doesn't support it anyway.
86 enum CPUKind {
121 CK_LEON4_GR740
122 } CPU = CK_GENERIC;
123
127 };
128
129 CPUGeneration getCPUGeneration(CPUKind Kind) const;
130
131 CPUKind getCPUKind(StringRef Name) const;
132
133 bool isValidCPUName(StringRef Name) const override {
134 return getCPUKind(Name) != CK_GENERIC;
135 }
136
137 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
138
139 bool setCPU(const std::string &Name) override {
140 CPU = getCPUKind(Name);
141 return CPU != CK_GENERIC;
142 }
143};
144
145// SPARC v8 is the 32-bit mode selected by Triple::sparc.
146class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
147public:
148 SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
149 : SparcTargetInfo(Triple, Opts) {
150 resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
151 // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
152 switch (getTriple().getOS()) {
153 default:
154 SizeType = UnsignedInt;
155 IntPtrType = SignedInt;
156 PtrDiffType = SignedInt;
157 break;
158 case llvm::Triple::NetBSD:
159 case llvm::Triple::OpenBSD:
160 SizeType = UnsignedLong;
161 IntPtrType = SignedLong;
162 PtrDiffType = SignedLong;
163 break;
164 }
165 // Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
166 // willing to do atomic ops on up to 64 bits.
167 MaxAtomicPromoteWidth = 64;
168 if (getCPUGeneration(CPU) == CG_V9)
169 MaxAtomicInlineWidth = 64;
170 else
171 // FIXME: This isn't correct for plain V8 which lacks CAS,
172 // only for LEON 3+ and Myriad.
173 MaxAtomicInlineWidth = 32;
174 }
175
176 void getTargetDefines(const LangOptions &Opts,
177 MacroBuilder &Builder) const override;
178
179 bool hasBitIntType() const override { return true; }
180};
181
182// SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
183class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
184public:
185 SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
186 : SparcV8TargetInfo(Triple, Opts) {
187 resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
188 }
189};
190
191// SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
192class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
193public:
194 SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
195 : SparcTargetInfo(Triple, Opts) {
196 // FIXME: Support Sparc quad-precision long double?
197 resetDataLayout("E-m:e-i64:64-n32:64-S128");
198 // This is an LP64 platform.
199 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
200
201 // OpenBSD uses long long for int64_t and intmax_t.
202 if (getTriple().isOSOpenBSD())
203 IntMaxType = SignedLongLong;
204 else
205 IntMaxType = SignedLong;
206 Int64Type = IntMaxType;
207
208 // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
209 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
210 LongDoubleWidth = 128;
211 LongDoubleAlign = 128;
212 SuitableAlign = 128;
213 LongDoubleFormat = &llvm::APFloat::IEEEquad();
214 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
215 }
216
217 void getTargetDefines(const LangOptions &Opts,
218 MacroBuilder &Builder) const override;
219
220 bool isValidCPUName(StringRef Name) const override {
221 return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
222 }
223
224 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
225
226 bool setCPU(const std::string &Name) override {
227 if (!SparcTargetInfo::setCPU(Name))
228 return false;
229 return getCPUGeneration(CPU) == CG_V9;
230 }
231
232 bool hasBitIntType() const override { return true; }
233};
234} // namespace targets
235} // namespace clang
236#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:100
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:454
Exposes information about the current target.
Definition: TargetInfo.h:213
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:314
Options for controlling the target.
Definition: TargetOptions.h:26
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:133
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: Sparc.h:51
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: Sparc.h:31
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: Sparc.h:55
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:139
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition: Sparc.h:39
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: Sparc.h:80
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: Sparc.h:60
SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: Sparc.h:28
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: Sparc.h:179
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:148
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:185
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:194
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:220
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: Sparc.h:232
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:226
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
#define false
Definition: stdbool.h:22