clang  6.0.0svn
Sparc.h
Go to the documentation of this file.
1 //===--- Sparc.h - Declare Sparc target feature support -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares Sparc TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
16 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 namespace clang {
21 namespace targets {
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[];
26  bool SoftFloat;
27 
28 public:
29  SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
30  : TargetInfo(Triple), SoftFloat(false) {}
31 
32  int getEHDataRegisterNumber(unsigned RegNo) const override {
33  if (RegNo == 0)
34  return 24;
35  if (RegNo == 1)
36  return 25;
37  return -1;
38  }
39 
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()) {
45  SoftFloat = true;
46  }
47  return true;
48  }
49  void getTargetDefines(const LangOptions &Opts,
50  MacroBuilder &Builder) const override;
51 
52  bool hasFeature(StringRef Feature) const override;
53 
54  bool hasSjLjLowering() const override { return true; }
55 
57  // FIXME: Implement!
58  return None;
59  }
62  }
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 {
67  // FIXME: Implement!
68  switch (*Name) {
69  case 'I': // Signed 13-bit constant
70  case 'J': // Zero
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
76  return true;
77 
78  case 'f':
79  case 'e':
80  info.setAllowsRegister();
81  return true;
82  }
83  return false;
84  }
85  const char *getClobbers() const override {
86  // FIXME: Implement!
87  return "";
88  }
89 
90  // No Sparc V7 for now, the backend doesn't support it anyway.
91  enum CPUKind {
126  CK_LEON4_GR740
127  } CPU = CK_GENERIC;
128 
132  };
133 
135  switch (Kind) {
136  case CK_GENERIC:
137  case CK_V8:
138  case CK_SUPERSPARC:
139  case CK_SPARCLITE:
140  case CK_F934:
141  case CK_HYPERSPARC:
142  case CK_SPARCLITE86X:
143  case CK_SPARCLET:
144  case CK_TSC701:
145  case CK_MYRIAD2100:
146  case CK_MYRIAD2150:
147  case CK_MYRIAD2155:
148  case CK_MYRIAD2450:
149  case CK_MYRIAD2455:
150  case CK_MYRIAD2x5x:
151  case CK_MYRIAD2080:
152  case CK_MYRIAD2085:
153  case CK_MYRIAD2480:
154  case CK_MYRIAD2485:
155  case CK_MYRIAD2x8x:
156  case CK_LEON2:
157  case CK_LEON2_AT697E:
158  case CK_LEON2_AT697F:
159  case CK_LEON3:
160  case CK_LEON3_UT699:
161  case CK_LEON3_GR712RC:
162  case CK_LEON4:
163  case CK_LEON4_GR740:
164  return CG_V8;
165  case CK_V9:
166  case CK_ULTRASPARC:
167  case CK_ULTRASPARC3:
168  case CK_NIAGARA:
169  case CK_NIAGARA2:
170  case CK_NIAGARA3:
171  case CK_NIAGARA4:
172  return CG_V9;
173  }
174  llvm_unreachable("Unexpected CPU kind");
175  }
176 
177  CPUKind getCPUKind(StringRef Name) const;
178 
179  bool isValidCPUName(StringRef Name) const override {
180  return getCPUKind(Name) != CK_GENERIC;
181  }
182 
183  bool setCPU(const std::string &Name) override {
184  CPU = getCPUKind(Name);
185  return CPU != CK_GENERIC;
186  }
187 };
188 
189 // SPARC v8 is the 32-bit mode selected by Triple::sparc.
190 class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
191 public:
192  SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
193  : SparcTargetInfo(Triple, Opts) {
194  resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
195  // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
196  switch (getTriple().getOS()) {
197  default:
198  SizeType = UnsignedInt;
199  IntPtrType = SignedInt;
200  PtrDiffType = SignedInt;
201  break;
202  case llvm::Triple::NetBSD:
203  case llvm::Triple::OpenBSD:
204  SizeType = UnsignedLong;
205  IntPtrType = SignedLong;
206  PtrDiffType = SignedLong;
207  break;
208  }
209  // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
210  // on up to 64 bits.
211  MaxAtomicPromoteWidth = 64;
212  MaxAtomicInlineWidth = 32;
213  }
214 
215  void getTargetDefines(const LangOptions &Opts,
216  MacroBuilder &Builder) const override;
217 
218  bool hasSjLjLowering() const override { return true; }
219 };
220 
221 // SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
222 class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
223 public:
224  SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
225  : SparcV8TargetInfo(Triple, Opts) {
226  resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
227  }
228 };
229 
230 // SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
231 class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
232 public:
233  SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
234  : SparcTargetInfo(Triple, Opts) {
235  // FIXME: Support Sparc quad-precision long double?
236  resetDataLayout("E-m:e-i64:64-n32:64-S128");
237  // This is an LP64 platform.
238  LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
239 
240  // OpenBSD uses long long for int64_t and intmax_t.
241  if (getTriple().getOS() == llvm::Triple::OpenBSD)
242  IntMaxType = SignedLongLong;
243  else
244  IntMaxType = SignedLong;
245  Int64Type = IntMaxType;
246 
247  // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
248  // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
249  LongDoubleWidth = 128;
250  LongDoubleAlign = 128;
251  LongDoubleFormat = &llvm::APFloat::IEEEquad();
252  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
253  }
254 
255  void getTargetDefines(const LangOptions &Opts,
256  MacroBuilder &Builder) const override;
257 
258  bool isValidCPUName(StringRef Name) const override {
259  return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
260  }
261 
262  bool setCPU(const std::string &Name) override {
263  if (!SparcTargetInfo::setCPU(Name))
264  return false;
265  return getCPUGeneration(CPU) == CG_V9;
266  }
267 };
268 } // namespace targets
269 } // namespace clang
270 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument...
Definition: Sparc.h:32
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:73
Options for controlling the target.
Definition: TargetOptions.h:26
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:40
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
static const char *const GCCRegNames[]
Definition: X86.cpp:42
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:224
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:183
typedef void* __builtin_va_list;
Definition: TargetInfo.h:157
Exposes information about the current target.
Definition: TargetInfo.h:54
bool hasSjLjLowering() const override
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm...
Definition: Sparc.h:54
#define false
Definition: stdbool.h:33
Kind
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Sparc.h:262
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:233
Defines the clang::TargetOptions class.
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:258
bool hasSjLjLowering() const override
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm...
Definition: Sparc.h:218
SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: Sparc.h:29
Dataflow Directional Tag Classes.
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Sparc.h:179
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: Sparc.h:65
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: Sparc.h:60
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:152
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: Sparc.h:56
CPUGeneration getCPUGeneration(CPUKind Kind) const
Definition: Sparc.h:134
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: Sparc.h:85
Defines the clang::TargetInfo interface.
CPUKind getCPUKind(StringRef Name) const
Definition: Sparc.cpp:54
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: Sparc.h:192