1 //===--- Sparc.h - declare sparc target feature support ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares Sparc TargetInfo objects.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
22 // Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
23 class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
24 static const TargetInfo::GCCRegAlias GCCRegAliases[];
25 static const char *const GCCRegNames[];
29 SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
30 : TargetInfo(Triple), SoftFloat(false) {}
32 int getEHDataRegisterNumber(unsigned RegNo) const override {
40 bool handleTargetFeatures(std::vector<std::string> &Features,
41 DiagnosticsEngine &Diags) override {
42 // Check if software floating point is enabled
43 auto Feature = std::find(Features.begin(), Features.end(), "+soft-float");
44 if (Feature != Features.end()) {
49 void getTargetDefines(const LangOptions &Opts,
50 MacroBuilder &Builder) const override;
52 bool hasFeature(StringRef Feature) const override;
54 bool hasSjLjLowering() const override { return true; }
56 ArrayRef<Builtin::Info> getTargetBuiltins() const override {
60 BuiltinVaListKind getBuiltinVaListKind() const override {
61 return TargetInfo::VoidPtrBuiltinVaList;
63 ArrayRef<const char *> getGCCRegNames() const override;
64 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
65 bool validateAsmConstraint(const char *&Name,
66 TargetInfo::ConstraintInfo &info) const override {
69 case 'I': // Signed 13-bit constant
71 case 'K': // 32-bit constant with the low 12 bits clear
72 case 'L': // A constant in the range supported by movcc (11-bit signed imm)
73 case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
74 case 'N': // Same as 'K' but zext (required for SIMode)
75 case 'O': // The constant 4096
80 info.setAllowsRegister();
85 const char *getClobbers() const override {
90 // No Sparc V7 for now, the backend doesn't support it anyway.
134 CPUGeneration getCPUGeneration(CPUKind Kind) const;
136 CPUKind getCPUKind(StringRef Name) const;
138 bool isValidCPUName(StringRef Name) const override {
139 return getCPUKind(Name) != CK_GENERIC;
142 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
144 bool setCPU(const std::string &Name) override {
145 CPU = getCPUKind(Name);
146 return CPU != CK_GENERIC;
150 // SPARC v8 is the 32-bit mode selected by Triple::sparc.
151 class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
153 SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
154 : SparcTargetInfo(Triple, Opts) {
155 resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
156 // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
157 switch (getTriple().getOS()) {
159 SizeType = UnsignedInt;
160 IntPtrType = SignedInt;
161 PtrDiffType = SignedInt;
163 case llvm::Triple::NetBSD:
164 case llvm::Triple::OpenBSD:
165 SizeType = UnsignedLong;
166 IntPtrType = SignedLong;
167 PtrDiffType = SignedLong;
170 // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
172 MaxAtomicPromoteWidth = 64;
173 MaxAtomicInlineWidth = 32;
176 void getTargetDefines(const LangOptions &Opts,
177 MacroBuilder &Builder) const override;
179 bool hasSjLjLowering() const override { return true; }
182 // SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
183 class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
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");
191 // SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
192 class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
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;
201 // OpenBSD uses long long for int64_t and intmax_t.
202 if (getTriple().getOS() == llvm::Triple::OpenBSD)
203 IntMaxType = SignedLongLong;
205 IntMaxType = SignedLong;
206 Int64Type = IntMaxType;
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 LongDoubleFormat = &llvm::APFloat::IEEEquad();
213 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
216 void getTargetDefines(const LangOptions &Opts,
217 MacroBuilder &Builder) const override;
219 bool isValidCPUName(StringRef Name) const override {
220 return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
223 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
225 bool setCPU(const std::string &Name) override {
226 if (!SparcTargetInfo::setCPU(Name))
228 return getCPUGeneration(CPU) == CG_V9;
231 } // namespace targets
233 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H