SystemZ.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 Builtin::Info BuiltinInfo[];
  22. static const char *const GCCRegNames[];
  23. std::string CPU;
  24. int ISARevision;
  25. bool HasTransactionalExecution;
  26. bool HasVector;
  27. bool SoftFloat;
  28. public:
  29. SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  30. : TargetInfo(Triple), CPU("z10"), ISARevision(8),
  31. HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
  32. IntMaxType = SignedLong;
  33. Int64Type = SignedLong;
  34. TLSSupported = true;
  35. IntWidth = IntAlign = 32;
  36. LongWidth = LongLongWidth = LongAlign = LongLongAlign = 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 some details:
  48. // - name mangling is GOFF
  49. // - 128 bit vector types are 64 bit aligned
  50. resetDataLayout(
  51. "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
  52. } else
  53. resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128: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 None;
  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. const char *getClobbers() const override {
  72. // FIXME: Is this really right?
  73. return "";
  74. }
  75. BuiltinVaListKind getBuiltinVaListKind() const override {
  76. return TargetInfo::SystemZBuiltinVaList;
  77. }
  78. int getISARevision(StringRef Name) const;
  79. bool isValidCPUName(StringRef Name) const override {
  80. return getISARevision(Name) != -1;
  81. }
  82. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  83. bool setCPU(const std::string &Name) override {
  84. CPU = Name;
  85. ISARevision = getISARevision(CPU);
  86. return ISARevision != -1;
  87. }
  88. bool
  89. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  90. StringRef CPU,
  91. const std::vector<std::string> &FeaturesVec) const override {
  92. int ISARevision = getISARevision(CPU);
  93. if (ISARevision >= 10)
  94. Features["transactional-execution"] = true;
  95. if (ISARevision >= 11)
  96. Features["vector"] = true;
  97. if (ISARevision >= 12)
  98. Features["vector-enhancements-1"] = true;
  99. if (ISARevision >= 13)
  100. Features["vector-enhancements-2"] = true;
  101. if (ISARevision >= 14)
  102. Features["nnp-assist"] = true;
  103. return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
  104. }
  105. bool handleTargetFeatures(std::vector<std::string> &Features,
  106. DiagnosticsEngine &Diags) override {
  107. HasTransactionalExecution = false;
  108. HasVector = false;
  109. SoftFloat = false;
  110. for (const auto &Feature : Features) {
  111. if (Feature == "+transactional-execution")
  112. HasTransactionalExecution = true;
  113. else if (Feature == "+vector")
  114. HasVector = true;
  115. else if (Feature == "+soft-float")
  116. SoftFloat = true;
  117. }
  118. HasVector &= !SoftFloat;
  119. // If we use the vector ABI, vector types are 64-bit aligned.
  120. if (HasVector && !getTriple().isOSzOS()) {
  121. MaxVectorAlign = 64;
  122. resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
  123. "-v128:64-a:8:16-n32:64");
  124. }
  125. return true;
  126. }
  127. bool hasFeature(StringRef Feature) const override;
  128. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  129. switch (CC) {
  130. case CC_C:
  131. case CC_Swift:
  132. case CC_OpenCLKernel:
  133. return CCCR_OK;
  134. case CC_SwiftAsync:
  135. return CCCR_Error;
  136. default:
  137. return CCCR_Warning;
  138. }
  139. }
  140. StringRef getABI() const override {
  141. if (HasVector)
  142. return "vector";
  143. return "";
  144. }
  145. const char *getLongDoubleMangling() const override { return "g"; }
  146. bool hasBitIntType() const override { return true; }
  147. int getEHDataRegisterNumber(unsigned RegNo) const override {
  148. return RegNo < 4 ? 6 + RegNo : -1;
  149. }
  150. };
  151. } // namespace targets
  152. } // namespace clang
  153. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H