Sparc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H
  14. #include "clang/Basic/TargetInfo.h"
  15. #include "clang/Basic/TargetOptions.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/Support/Compiler.h"
  18. namespace clang {
  19. namespace targets {
  20. // Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
  21. class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo {
  22. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  23. static const char *const GCCRegNames[];
  24. bool SoftFloat;
  25. public:
  26. SparcTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  27. : TargetInfo(Triple), SoftFloat(false) {}
  28. int getEHDataRegisterNumber(unsigned RegNo) const override {
  29. if (RegNo == 0)
  30. return 24;
  31. if (RegNo == 1)
  32. return 25;
  33. return -1;
  34. }
  35. bool handleTargetFeatures(std::vector<std::string> &Features,
  36. DiagnosticsEngine &Diags) override {
  37. // Check if software floating point is enabled
  38. auto Feature = llvm::find(Features, "+soft-float");
  39. if (Feature != Features.end()) {
  40. SoftFloat = true;
  41. }
  42. return true;
  43. }
  44. void getTargetDefines(const LangOptions &Opts,
  45. MacroBuilder &Builder) const override;
  46. bool hasFeature(StringRef Feature) const override;
  47. bool hasSjLjLowering() const override { return true; }
  48. ArrayRef<Builtin::Info> getTargetBuiltins() const override {
  49. // FIXME: Implement!
  50. return None;
  51. }
  52. BuiltinVaListKind getBuiltinVaListKind() const override {
  53. return TargetInfo::VoidPtrBuiltinVaList;
  54. }
  55. ArrayRef<const char *> getGCCRegNames() const override;
  56. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  57. bool validateAsmConstraint(const char *&Name,
  58. TargetInfo::ConstraintInfo &info) const override {
  59. // FIXME: Implement!
  60. switch (*Name) {
  61. case 'I': // Signed 13-bit constant
  62. case 'J': // Zero
  63. case 'K': // 32-bit constant with the low 12 bits clear
  64. case 'L': // A constant in the range supported by movcc (11-bit signed imm)
  65. case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
  66. case 'N': // Same as 'K' but zext (required for SIMode)
  67. case 'O': // The constant 4096
  68. return true;
  69. case 'f':
  70. case 'e':
  71. info.setAllowsRegister();
  72. return true;
  73. }
  74. return false;
  75. }
  76. const char *getClobbers() const override {
  77. // FIXME: Implement!
  78. return "";
  79. }
  80. // No Sparc V7 for now, the backend doesn't support it anyway.
  81. enum CPUKind {
  82. CK_GENERIC,
  83. CK_V8,
  84. CK_SUPERSPARC,
  85. CK_SPARCLITE,
  86. CK_F934,
  87. CK_HYPERSPARC,
  88. CK_SPARCLITE86X,
  89. CK_SPARCLET,
  90. CK_TSC701,
  91. CK_V9,
  92. CK_ULTRASPARC,
  93. CK_ULTRASPARC3,
  94. CK_NIAGARA,
  95. CK_NIAGARA2,
  96. CK_NIAGARA3,
  97. CK_NIAGARA4,
  98. CK_MYRIAD2100,
  99. CK_MYRIAD2150,
  100. CK_MYRIAD2155,
  101. CK_MYRIAD2450,
  102. CK_MYRIAD2455,
  103. CK_MYRIAD2x5x,
  104. CK_MYRIAD2080,
  105. CK_MYRIAD2085,
  106. CK_MYRIAD2480,
  107. CK_MYRIAD2485,
  108. CK_MYRIAD2x8x,
  109. CK_LEON2,
  110. CK_LEON2_AT697E,
  111. CK_LEON2_AT697F,
  112. CK_LEON3,
  113. CK_LEON3_UT699,
  114. CK_LEON3_GR712RC,
  115. CK_LEON4,
  116. CK_LEON4_GR740
  117. } CPU = CK_GENERIC;
  118. enum CPUGeneration {
  119. CG_V8,
  120. CG_V9,
  121. };
  122. CPUGeneration getCPUGeneration(CPUKind Kind) const;
  123. CPUKind getCPUKind(StringRef Name) const;
  124. bool isValidCPUName(StringRef Name) const override {
  125. return getCPUKind(Name) != CK_GENERIC;
  126. }
  127. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  128. bool setCPU(const std::string &Name) override {
  129. CPU = getCPUKind(Name);
  130. return CPU != CK_GENERIC;
  131. }
  132. };
  133. // SPARC v8 is the 32-bit mode selected by Triple::sparc.
  134. class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
  135. public:
  136. SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  137. : SparcTargetInfo(Triple, Opts) {
  138. resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
  139. // NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
  140. switch (getTriple().getOS()) {
  141. default:
  142. SizeType = UnsignedInt;
  143. IntPtrType = SignedInt;
  144. PtrDiffType = SignedInt;
  145. break;
  146. case llvm::Triple::NetBSD:
  147. case llvm::Triple::OpenBSD:
  148. SizeType = UnsignedLong;
  149. IntPtrType = SignedLong;
  150. PtrDiffType = SignedLong;
  151. break;
  152. }
  153. // Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
  154. // on up to 64 bits.
  155. MaxAtomicPromoteWidth = 64;
  156. MaxAtomicInlineWidth = 32;
  157. }
  158. void getTargetDefines(const LangOptions &Opts,
  159. MacroBuilder &Builder) const override;
  160. bool hasSjLjLowering() const override { return true; }
  161. };
  162. // SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
  163. class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
  164. public:
  165. SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  166. : SparcV8TargetInfo(Triple, Opts) {
  167. resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
  168. }
  169. };
  170. // SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
  171. class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
  172. public:
  173. SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  174. : SparcTargetInfo(Triple, Opts) {
  175. // FIXME: Support Sparc quad-precision long double?
  176. resetDataLayout("E-m:e-i64:64-n32:64-S128");
  177. // This is an LP64 platform.
  178. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  179. // OpenBSD uses long long for int64_t and intmax_t.
  180. if (getTriple().isOSOpenBSD())
  181. IntMaxType = SignedLongLong;
  182. else
  183. IntMaxType = SignedLong;
  184. Int64Type = IntMaxType;
  185. // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
  186. // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
  187. LongDoubleWidth = 128;
  188. LongDoubleAlign = 128;
  189. SuitableAlign = 128;
  190. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  191. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  192. }
  193. void getTargetDefines(const LangOptions &Opts,
  194. MacroBuilder &Builder) const override;
  195. bool isValidCPUName(StringRef Name) const override {
  196. return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9;
  197. }
  198. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  199. bool setCPU(const std::string &Name) override {
  200. if (!SparcTargetInfo::setCPU(Name))
  201. return false;
  202. return getCPUGeneration(CPU) == CG_V9;
  203. }
  204. };
  205. } // namespace targets
  206. } // namespace clang
  207. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPARC_H