SystemZ.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //===--- SystemZ.h - Declare SystemZ 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 SystemZ TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_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. class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
  21. static const char *const GCCRegNames[];
  22. std::string CPU;
  23. int ISARevision;
  24. bool HasTransactionalExecution;
  25. bool HasVector;
  26. bool SoftFloat;
  27. public:
  28. SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  29. : TargetInfo(Triple), CPU("z10"), ISARevision(8),
  30. HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
  31. IntMaxType = SignedLong;
  32. Int64Type = SignedLong;
  33. TLSSupported = true;
  34. IntWidth = IntAlign = 32;
  35. LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
  36. Int128Align = 64;
  37. PointerWidth = PointerAlign = 64;
  38. LongDoubleWidth = 128;
  39. LongDoubleAlign = 64;
  40. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  41. DefaultAlignForAttributeAligned = 64;
  42. MinGlobalAlign = 16;
  43. if (Triple.isOSzOS()) {
  44. // All vector types are default aligned on an 8-byte boundary, even if the
  45. // vector facility is not available. That is different from Linux.
  46. MaxVectorAlign = 64;
  47. // Compared to Linux/ELF, the data layout differs only in that name
  48. // mangling is GOFF.
  49. resetDataLayout(
  50. "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
  51. } else
  52. resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
  53. "-v128:64-a:8:16-n32:64");
  54. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  55. HasStrictFP = true;
  56. }
  57. void getTargetDefines(const LangOptions &Opts,
  58. MacroBuilder &Builder) const override;
  59. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  60. ArrayRef<const char *> getGCCRegNames() const override;
  61. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
  62. // No aliases.
  63. return std::nullopt;
  64. }
  65. ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
  66. bool isSPRegName(StringRef RegName) const override {
  67. return RegName.equals("r15");
  68. }
  69. bool validateAsmConstraint(const char *&Name,
  70. TargetInfo::ConstraintInfo &info) const override;
  71. std::string convertConstraint(const char *&Constraint) const override {
  72. switch (Constraint[0]) {
  73. case 'p': // Keep 'p' constraint.
  74. return std::string("p");
  75. case 'Z':
  76. switch (Constraint[1]) {
  77. case 'Q': // Address with base and unsigned 12-bit displacement
  78. case 'R': // Likewise, plus an index
  79. case 'S': // Address with base and signed 20-bit displacement
  80. case 'T': // Likewise, plus an index
  81. // "^" hints llvm that this is a 2 letter constraint.
  82. // "Constraint++" is used to promote the string iterator
  83. // to the next constraint.
  84. return std::string("^") + std::string(Constraint++, 2);
  85. default:
  86. break;
  87. }
  88. break;
  89. default:
  90. break;
  91. }
  92. return TargetInfo::convertConstraint(Constraint);
  93. }
  94. const char *getClobbers() const override {
  95. // FIXME: Is this really right?
  96. return "";
  97. }
  98. BuiltinVaListKind getBuiltinVaListKind() const override {
  99. return TargetInfo::SystemZBuiltinVaList;
  100. }
  101. int getISARevision(StringRef Name) const;
  102. bool isValidCPUName(StringRef Name) const override {
  103. return getISARevision(Name) != -1;
  104. }
  105. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  106. bool isValidTuneCPUName(StringRef Name) const override {
  107. return isValidCPUName(Name);
  108. }
  109. void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override {
  110. fillValidCPUList(Values);
  111. }
  112. bool setCPU(const std::string &Name) override {
  113. CPU = Name;
  114. ISARevision = getISARevision(CPU);
  115. return ISARevision != -1;
  116. }
  117. bool
  118. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  119. StringRef CPU,
  120. const std::vector<std::string> &FeaturesVec) const override {
  121. int ISARevision = getISARevision(CPU);
  122. if (ISARevision >= 10)
  123. Features["transactional-execution"] = true;
  124. if (ISARevision >= 11)
  125. Features["vector"] = true;
  126. if (ISARevision >= 12)
  127. Features["vector-enhancements-1"] = true;
  128. if (ISARevision >= 13)
  129. Features["vector-enhancements-2"] = true;
  130. if (ISARevision >= 14)
  131. Features["nnp-assist"] = true;
  132. return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
  133. }
  134. bool handleTargetFeatures(std::vector<std::string> &Features,
  135. DiagnosticsEngine &Diags) override {
  136. HasTransactionalExecution = false;
  137. HasVector = false;
  138. SoftFloat = false;
  139. for (const auto &Feature : Features) {
  140. if (Feature == "+transactional-execution")
  141. HasTransactionalExecution = true;
  142. else if (Feature == "+vector")
  143. HasVector = true;
  144. else if (Feature == "+soft-float")
  145. SoftFloat = true;
  146. }
  147. HasVector &= !SoftFloat;
  148. // If we use the vector ABI, vector types are 64-bit aligned. The
  149. // DataLayout string is always set to this alignment as it is not a
  150. // requirement that it follows the alignment emitted by the front end. It
  151. // is assumed generally that the Datalayout should reflect only the
  152. // target triple and not any specific feature.
  153. if (HasVector && !getTriple().isOSzOS())
  154. MaxVectorAlign = 64;
  155. return true;
  156. }
  157. bool hasFeature(StringRef Feature) const override;
  158. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  159. switch (CC) {
  160. case CC_C:
  161. case CC_Swift:
  162. case CC_OpenCLKernel:
  163. return CCCR_OK;
  164. case CC_SwiftAsync:
  165. return CCCR_Error;
  166. default:
  167. return CCCR_Warning;
  168. }
  169. }
  170. StringRef getABI() const override {
  171. if (HasVector)
  172. return "vector";
  173. return "";
  174. }
  175. const char *getLongDoubleMangling() const override { return "g"; }
  176. bool hasBitIntType() const override { return true; }
  177. int getEHDataRegisterNumber(unsigned RegNo) const override {
  178. return RegNo < 4 ? 6 + RegNo : -1;
  179. }
  180. };
  181. } // namespace targets
  182. } // namespace clang
  183. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H