clang  14.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
15 #include "clang/Basic/TargetInfo.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/Compiler.h"
19 namespace clang {
20 namespace targets {
21 // Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
22 class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
23  static const TargetInfo::GCCRegAlias GCCRegAliases[];
24  static const char *const GCCRegNames[];
25  bool SoftFloat;
26 
27 public:
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 
51  bool hasSjLjLowering() const override { return true; }
52 
54  // FIXME: Implement!
55  return None;
56  }
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  const char *getClobbers() const override {
83  // FIXME: Implement!
84  return "";
85  }
86 
87  // No Sparc V7 for now, the backend doesn't support it anyway.
88  enum CPUKind {
123  CK_LEON4_GR740
124  } CPU = CK_GENERIC;
125 
129  };
130 
131  CPUGeneration getCPUGeneration(CPUKind Kind) const;
132 
133  CPUKind getCPUKind(StringRef Name) const;
134 
135  bool isValidCPUName(StringRef Name) const override {
136  return getCPUKind(Name) != CK_GENERIC;
137  }
138 
139  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
140 
141  bool setCPU(const std::string &Name) override {
142  CPU = getCPUKind(Name);
143  return CPU != CK_GENERIC;
144  }
145 };
146 
147 // SPARC v8 is the 32-bit mode selected by Triple::sparc.
148 class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
149 public:
150  SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
151  : SparcTargetInfo(Triple, Opts) {
152  resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
153  // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
154  switch (getTriple().getOS()) {
155  default:
156  SizeType = UnsignedInt;
157  IntPtrType = SignedInt;
158  PtrDiffType = SignedInt;
159  break;
160  case llvm::Triple::NetBSD:
161  case llvm::Triple::OpenBSD:
162  SizeType = UnsignedLong;
163  IntPtrType = SignedLong;
164  PtrDiffType = SignedLong;
165  break;
166  }
167  // Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
168  // willing to do atomic ops on up to 64 bits.
169  MaxAtomicPromoteWidth = 64;
170  if (getCPUGeneration(CPU) == CG_V9)
171  MaxAtomicInlineWidth = 64;
172  else
173  // FIXME: This isn't correct for plain V8 which lacks CAS,
174  // only for LEON 3+ and Myriad.
175  MaxAtomicInlineWidth = 32;
176  }
177 
178  void getTargetDefines(const LangOptions &Opts,
179  MacroBuilder &Builder) const override;
180 
181  bool hasSjLjLowering() const override { return true; }
182  bool hasExtIntType() const override { return true; }
183 };
184 
185 // SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
186 class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
187 public:
188  SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
189  : SparcV8TargetInfo(Triple, Opts) {
190  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
191  }
192 };
193 
194 // SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
195 class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
196 public:
197  SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
198  : SparcTargetInfo(Triple, Opts) {
199  // FIXME: Support Sparc quad-precision long double?
200  resetDataLayout("E-m:e-i64:64-n32:64-S128");
201  // This is an LP64 platform.
202  LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
203 
204  // OpenBSD uses long long for int64_t and intmax_t.
205  if (getTriple().isOSOpenBSD())
206  IntMaxType = SignedLongLong;
207  else
208  IntMaxType = SignedLong;
209  Int64Type = IntMaxType;
210 
211  // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
212  // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
213  LongDoubleWidth = 128;
214  LongDoubleAlign = 128;
215  SuitableAlign = 128;
216  LongDoubleFormat = &llvm::APFloat::IEEEquad();
217  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
218  }
219 
220  void getTargetDefines(const LangOptions &Opts,
221  MacroBuilder &Builder) const override;
222 
223  bool isValidCPUName(StringRef Name) const override {
224  return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
225  }
226 
227  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
228 
229  bool setCPU(const std::string &Name) override {
230  if (!SparcTargetInfo::setCPU(Name))
231  return false;
232  return getCPUGeneration(CPU) == CG_V9;
233  }
234 
235  bool hasExtIntType() const override { return true; }
236 };
237 } // namespace targets
238 } // namespace clang
239 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
clang::targets::SparcTargetInfo::CK_ULTRASPARC
@ CK_ULTRASPARC
Definition: Sparc.h:99
clang::targets::SparcTargetInfo::CK_MYRIAD2x5x
@ CK_MYRIAD2x5x
Definition: Sparc.h:110
clang::targets::SparcV9TargetInfo::SparcV9TargetInfo
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:197
clang::targets::SparcTargetInfo
Definition: Sparc.h:22
clang::targets::SparcTargetInfo::CK_NIAGARA
@ CK_NIAGARA
Definition: Sparc.h:101
clang::targets::SparcTargetInfo::getEHDataRegisterNumber
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
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::targets::SparcTargetInfo::CK_MYRIAD2450
@ CK_MYRIAD2450
Definition: Sparc.h:108
clang::targets::SparcV8TargetInfo
Definition: Sparc.h:148
clang::targets::SparcTargetInfo::CK_MYRIAD2485
@ CK_MYRIAD2485
Definition: Sparc.h:114
TargetInfo.h
clang::targets::SparcV9TargetInfo::hasExtIntType
bool hasExtIntType() const override
Determine whether the _ExtInt type is supported on this target.
Definition: Sparc.h:235
clang::targets::SparcTargetInfo::CK_MYRIAD2085
@ CK_MYRIAD2085
Definition: Sparc.h:112
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::targets::SparcTargetInfo::CK_MYRIAD2x8x
@ CK_MYRIAD2x8x
Definition: Sparc.h:115
clang::targets::SparcTargetInfo::CK_LEON2_AT697F
@ CK_LEON2_AT697F
Definition: Sparc.h:118
clang::TargetInfo::VoidPtrBuiltinVaList
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition: TargetInfo.h:270
clang::targets::SparcTargetInfo::CK_TSC701
@ CK_TSC701
Definition: Sparc.h:97
clang::targets::SparcTargetInfo::handleTargetFeatures
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
clang::targets::SparcTargetInfo::CG_V9
@ CG_V9
Definition: Sparc.h:128
clang::targets::SparcTargetInfo::CK_LEON2
@ CK_LEON2
Definition: Sparc.h:116
clang::targets::SparcTargetInfo::CK_SPARCLITE
@ CK_SPARCLITE
Definition: Sparc.h:92
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:265
clang::targets::SparcTargetInfo::CK_SPARCLET
@ CK_SPARCLET
Definition: Sparc.h:96
clang::TargetInfo::ConstraintInfo::setAllowsRegister
void setAllowsRegister()
Definition: TargetInfo.h:1025
clang::targets::SparcTargetInfo::CK_MYRIAD2155
@ CK_MYRIAD2155
Definition: Sparc.h:107
clang::targets::SparcTargetInfo::CK_MYRIAD2455
@ CK_MYRIAD2455
Definition: Sparc.h:109
clang::targets::SparcV9TargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:229
clang::targets::SparcTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:141
clang::targets::GCCRegNames
static const char *const GCCRegNames[]
Definition: X86.cpp:43
clang::targets::SparcV8elTargetInfo::SparcV8elTargetInfo
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:188
clang::targets::SparcTargetInfo::CPUKind
CPUKind
Definition: Sparc.h:88
clang::targets::SparcV9TargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:223
clang::targets::SparcTargetInfo::CK_V8
@ CK_V8
Definition: Sparc.h:90
clang::targets::SparcTargetInfo::CK_LEON3_GR712RC
@ CK_LEON3_GR712RC
Definition: Sparc.h:121
clang::targets::SparcTargetInfo::hasSjLjLowering
bool hasSjLjLowering() const override
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm....
Definition: Sparc.h:51
clang::targets::SparcTargetInfo::CG_V8
@ CG_V8
Definition: Sparc.h:127
clang::targets::SparcV8elTargetInfo
Definition: Sparc.h:186
clang::TargetInfo::GCCRegAlias
Definition: TargetInfo.h:1142
clang::targets::SparcTargetInfo::CK_SPARCLITE86X
@ CK_SPARCLITE86X
Definition: Sparc.h:95
clang::targets::SparcTargetInfo::CK_MYRIAD2100
@ CK_MYRIAD2100
Definition: Sparc.h:105
clang::targets::SparcV9TargetInfo
Definition: Sparc.h:195
clang::targets::SparcTargetInfo::CK_LEON4
@ CK_LEON4
Definition: Sparc.h:122
clang::targets::SparcTargetInfo::CK_NIAGARA4
@ CK_NIAGARA4
Definition: Sparc.h:104
clang::targets::SparcV8TargetInfo::SparcV8TargetInfo
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:150
clang::targets::SparcTargetInfo::CK_LEON2_AT697E
@ CK_LEON2_AT697E
Definition: Sparc.h:117
clang::targets::SparcTargetInfo::CK_SUPERSPARC
@ CK_SUPERSPARC
Definition: Sparc.h:91
false
#define false
Definition: stdbool.h:17
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::targets::SparcTargetInfo::CK_NIAGARA2
@ CK_NIAGARA2
Definition: Sparc.h:102
clang::targets::SparcTargetInfo::CK_MYRIAD2080
@ CK_MYRIAD2080
Definition: Sparc.h:111
clang::targets::SparcTargetInfo::CK_GENERIC
@ CK_GENERIC
Definition: Sparc.h:89
clang::targets::SparcTargetInfo::CK_LEON3_UT699
@ CK_LEON3_UT699
Definition: Sparc.h:120
clang::targets::SparcTargetInfo::CK_NIAGARA3
@ CK_NIAGARA3
Definition: Sparc.h:103
clang::targets::SparcTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:135
clang::targets::SparcTargetInfo::CK_LEON3
@ CK_LEON3
Definition: Sparc.h:119
clang::targets::SparcTargetInfo::CK_MYRIAD2480
@ CK_MYRIAD2480
Definition: Sparc.h:113
clang::targets::SparcTargetInfo::SparcTargetInfo
SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: Sparc.h:28
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:960
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::targets::SparcTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: Sparc.h:62
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::targets::SparcTargetInfo::CK_MYRIAD2150
@ CK_MYRIAD2150
Definition: Sparc.h:106
clang::targets::SparcTargetInfo::CPUGeneration
CPUGeneration
Definition: Sparc.h:126
clang::targets::SparcTargetInfo::CK_V9
@ CK_V9
Definition: Sparc.h:98
clang
Definition: CalledOnceCheck.h:17
clang::targets::SparcTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: Sparc.h:57
clang::targets::SparcTargetInfo::CK_ULTRASPARC3
@ CK_ULTRASPARC3
Definition: Sparc.h:100
clang::targets::SparcTargetInfo::getTargetBuiltins
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: Sparc.h:53
clang::targets::SparcTargetInfo::CK_HYPERSPARC
@ CK_HYPERSPARC
Definition: Sparc.h:94
clang::targets::SparcV8TargetInfo::hasSjLjLowering
bool hasSjLjLowering() const override
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm....
Definition: Sparc.h:181
clang::targets::SparcV8TargetInfo::hasExtIntType
bool hasExtIntType() const override
Determine whether the _ExtInt type is supported on this target.
Definition: Sparc.h:182
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::SparcTargetInfo::getCPUKind
CPUKind getCPUKind(StringRef Name) const
Definition: Sparc.cpp:123
clang::targets::SparcTargetInfo::CK_F934
@ CK_F934
Definition: Sparc.h:93
hasFeature
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:101
clang::targets::SparcTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: Sparc.h:82