clang 24.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 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(Features, "+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
54 // FIXME: Implement!
55 return {};
56 }
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.
123
128
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(32, 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) {
162 // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
163 switch (getTriple().getOS()) {
164 default:
168 break;
169 case llvm::Triple::NetBSD:
170 case llvm::Triple::OpenBSD:
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.
192 if (getCPUGeneration(CPU) == CG_V9)
194 else
195 // FIXME: This isn't correct for plain V8 which lacks CAS,
196 // only for LEON 3+ and Myriad.
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) {
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?
222 // This is an LP64 platform.
224
225 // OpenBSD uses long long for int64_t and intmax_t.
226 if (getTriple().isOSOpenBSD())
228 else
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();
239 }
240
241 void getTargetDefines(const LangOptions &Opts,
242 MacroBuilder &Builder) const override;
243
244 bool isValidCPUName(StringRef Name) const override {
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(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
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:96
static StringRef getTriple(const Command &Job)
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:241
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:341
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:346
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:254
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:254
Options for controlling the target.
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Sparc.h:140
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition Sparc.h:53
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition Sparc.h:33
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition Sparc.h:57
CPUGeneration getCPUGeneration(CPUKind Kind) const
Definition Sparc.cpp:141
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:41
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition Sparc.h:82
CPUKind getCPUKind(StringRef Name) const
Definition Sparc.cpp:159
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
Definition Sparc.h:151
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition Sparc.h:62
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition Sparc.h:146
enum clang::targets::SparcTargetInfo::CPUKind CPU
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:203
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:159
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:209
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:218
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Sparc.h:244
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition Sparc.h:256
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition Sparc.h:250
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
#define false
Definition stdbool.h:26
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:145