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/SparcTargetParser.h"
19#include "llvm/TargetParser/Triple.h"
20namespace clang {
21namespace targets {
22// Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
23class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
24 static const TargetInfo::GCCRegAlias GCCRegAliases[];
25 static const char *const GCCRegNames[];
26 bool SoftFloat;
27
28protected:
29 // Features of the CPU and target features, as defined by the backend.
30 bool IsV9 = false;
31 bool IsLeon = false;
32 bool HasLeonCASA = false;
33 bool SoftMulDiv = false;
34
35public:
36 SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
37 : TargetInfo(Triple), SoftFloat(false) {
38 HasStrictFP = true;
39 }
40
41 int getEHDataRegisterNumber(unsigned RegNo) const override {
42 if (RegNo == 0)
43 return 24;
44 if (RegNo == 1)
45 return 25;
46 return -1;
47 }
48
49 bool
50 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
51 StringRef CPU,
52 const std::vector<std::string> &FeaturesVec) const override;
53
54 bool handleTargetFeatures(std::vector<std::string> &Features,
55 DiagnosticsEngine &Diags) override;
56 void getTargetDefines(const LangOptions &Opts,
57 MacroBuilder &Builder) const override;
58
59 bool hasFeature(StringRef Feature) const override;
60
62 // FIXME: Implement!
63 return {};
64 }
68 ArrayRef<const char *> getGCCRegNames() const override;
69 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
70 bool validateAsmConstraint(const char *&Name,
71 TargetInfo::ConstraintInfo &info) const override {
72 // FIXME: Implement!
73 switch (*Name) {
74 case 'I': // Signed 13-bit constant
75 case 'J': // Zero
76 case 'K': // 32-bit constant with the low 12 bits clear
77 case 'L': // A constant in the range supported by movcc (11-bit signed imm)
78 case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
79 case 'N': // Same as 'K' but zext (required for SIMode)
80 case 'O': // The constant 4096
81 return true;
82
83 case 'f':
84 case 'e':
85 info.setAllowsRegister();
86 return true;
87 }
88 return false;
89 }
90 std::string_view getClobbers() const override { return "~{y}"; }
91
92 bool isValidCPUName(StringRef Name) const override;
93
94 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
95
96 bool setCPU(StringRef Name) override { return isValidCPUName(Name); }
97
98 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
99 return std::make_pair(32, 32);
100 }
101};
102
103// SPARC v8 is the 32-bit mode selected by Triple::sparc.
104class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
105 bool V8Plus = false;
106
107public:
108 SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
109 : SparcTargetInfo(Triple, Opts) {
111 // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
112 switch (getTriple().getOS()) {
113 default:
117 break;
118 case llvm::Triple::NetBSD:
119 case llvm::Triple::OpenBSD:
123 break;
124 }
125
126 // Base long double format on the triple.
127 if (getTriple().getDefaultLongDoubleFormat() ==
128 llvm::LongDoubleFormat::IEEEdouble) {
129 LongDoubleWidth = 64;
130 LongDoubleAlign = 64;
131 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
132 } else {
133 LongDoubleWidth = 128;
134 LongDoubleAlign = 64;
135 LongDoubleFormat = &llvm::APFloat::IEEEquad();
136 }
137
138 // We're willing to do atomic ops on up to 64 bits. Which of those are
139 // lock-free is decided in setMaxAtomicWidth.
141 }
142
143 bool handleTargetFeatures(std::vector<std::string> &Features,
144 DiagnosticsEngine &Diags) override {
145 if (!SparcTargetInfo::handleTargetFeatures(Features, Diags))
146 return false;
147 V8Plus = llvm::is_contained(Features, "+v8plus");
148 return true;
149 }
150
151 void setMaxAtomicWidth() override {
152 if (IsV9)
153 // Like GCC, 64-bit atomics in 32-bit code need V8+ mode, where the
154 // %g and %o registers are 64 bits wide.
155 MaxAtomicInlineWidth = V8Plus ? 64 : 32;
156 else
157 // Plain V8 lacks CAS; only the LEON and Myriad 2 CPUs with CASA have it.
159 }
160
161 void getTargetDefines(const LangOptions &Opts,
162 MacroBuilder &Builder) const override;
163
164 bool hasBitIntType() const override { return true; }
165};
166
167// SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
168class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
169public:
170 SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
171 : SparcV8TargetInfo(Triple, Opts) {
173 }
174};
175
176// SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
177class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
178public:
179 SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
180 : SparcTargetInfo(Triple, Opts) {
181 // FIXME: Support Sparc quad-precision long double?
183 // This is an LP64 platform.
185
186 // OpenBSD uses long long for int64_t and intmax_t.
187 if (getTriple().isOSOpenBSD())
189 else
192
193 // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
194 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
195 LongDoubleWidth = 128;
196 LongDoubleAlign = 128;
197 SuitableAlign = 128;
198 LongDoubleFormat = &llvm::APFloat::IEEEquad();
200 }
201
202 void getTargetDefines(const LangOptions &Opts,
203 MacroBuilder &Builder) const override;
204
205 bool isValidCPUName(StringRef Name) const override;
206
207 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
208
209 bool hasBitIntType() const override { return true; }
210};
211} // namespace targets
212} // namespace clang
213#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:240
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 handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition Sparc.cpp:75
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition Sparc.cpp:92
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:61
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition Sparc.h:41
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition Sparc.h:65
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition Sparc.h:90
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:98
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition Sparc.h:70
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition Sparc.h:96
SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition Sparc.h:36
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:143
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition Sparc.h:164
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition Sparc.h:151
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:108
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:170
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition Sparc.h:179
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition Sparc.h:209
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