SystemZ.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //===--- SystemZ.cpp - Implement SystemZ target feature support -----------===//
  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 implements SystemZ TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "SystemZ.h"
  13. #include "clang/Basic/Builtins.h"
  14. #include "clang/Basic/LangOptions.h"
  15. #include "clang/Basic/MacroBuilder.h"
  16. #include "clang/Basic/TargetBuiltins.h"
  17. #include "llvm/ADT/StringSwitch.h"
  18. using namespace clang;
  19. using namespace clang::targets;
  20. const Builtin::Info SystemZTargetInfo::BuiltinInfo[] = {
  21. #define BUILTIN(ID, TYPE, ATTRS) \
  22. {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
  23. #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
  24. {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
  25. #include "clang/Basic/BuiltinsSystemZ.def"
  26. };
  27. const char *const SystemZTargetInfo::GCCRegNames[] = {
  28. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  29. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  30. "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
  31. "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
  32. /*ap*/"", "cc", /*fp*/"", /*rp*/"", "a0", "a1",
  33. "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
  34. "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31"
  35. };
  36. const TargetInfo::AddlRegName GCCAddlRegNames[] = {
  37. {{"v0"}, 16}, {{"v2"}, 17}, {{"v4"}, 18}, {{"v6"}, 19},
  38. {{"v1"}, 20}, {{"v3"}, 21}, {{"v5"}, 22}, {{"v7"}, 23},
  39. {{"v8"}, 24}, {{"v10"}, 25}, {{"v12"}, 26}, {{"v14"}, 27},
  40. {{"v9"}, 28}, {{"v11"}, 29}, {{"v13"}, 30}, {{"v15"}, 31}
  41. };
  42. ArrayRef<const char *> SystemZTargetInfo::getGCCRegNames() const {
  43. return llvm::makeArrayRef(GCCRegNames);
  44. }
  45. ArrayRef<TargetInfo::AddlRegName> SystemZTargetInfo::getGCCAddlRegNames() const {
  46. return llvm::makeArrayRef(GCCAddlRegNames);
  47. }
  48. bool SystemZTargetInfo::validateAsmConstraint(
  49. const char *&Name, TargetInfo::ConstraintInfo &Info) const {
  50. switch (*Name) {
  51. default:
  52. return false;
  53. case 'a': // Address register
  54. case 'd': // Data register (equivalent to 'r')
  55. case 'f': // Floating-point register
  56. case 'v': // Vector register
  57. Info.setAllowsRegister();
  58. return true;
  59. case 'I': // Unsigned 8-bit constant
  60. case 'J': // Unsigned 12-bit constant
  61. case 'K': // Signed 16-bit constant
  62. case 'L': // Signed 20-bit displacement (on all targets we support)
  63. case 'M': // 0x7fffffff
  64. return true;
  65. case 'Q': // Memory with base and unsigned 12-bit displacement
  66. case 'R': // Likewise, plus an index
  67. case 'S': // Memory with base and signed 20-bit displacement
  68. case 'T': // Likewise, plus an index
  69. Info.setAllowsMemory();
  70. return true;
  71. }
  72. }
  73. struct ISANameRevision {
  74. llvm::StringLiteral Name;
  75. int ISARevisionID;
  76. };
  77. static constexpr ISANameRevision ISARevisions[] = {
  78. {{"arch8"}, 8}, {{"z10"}, 8},
  79. {{"arch9"}, 9}, {{"z196"}, 9},
  80. {{"arch10"}, 10}, {{"zEC12"}, 10},
  81. {{"arch11"}, 11}, {{"z13"}, 11},
  82. {{"arch12"}, 12}, {{"z14"}, 12},
  83. {{"arch13"}, 13}, {{"z15"}, 13},
  84. {{"arch14"}, 14}
  85. };
  86. int SystemZTargetInfo::getISARevision(StringRef Name) const {
  87. const auto Rev =
  88. llvm::find_if(ISARevisions, [Name](const ISANameRevision &CR) {
  89. return CR.Name == Name;
  90. });
  91. if (Rev == std::end(ISARevisions))
  92. return -1;
  93. return Rev->ISARevisionID;
  94. }
  95. void SystemZTargetInfo::fillValidCPUList(
  96. SmallVectorImpl<StringRef> &Values) const {
  97. for (const ISANameRevision &Rev : ISARevisions)
  98. Values.push_back(Rev.Name);
  99. }
  100. bool SystemZTargetInfo::hasFeature(StringRef Feature) const {
  101. return llvm::StringSwitch<bool>(Feature)
  102. .Case("systemz", true)
  103. .Case("arch8", ISARevision >= 8)
  104. .Case("arch9", ISARevision >= 9)
  105. .Case("arch10", ISARevision >= 10)
  106. .Case("arch11", ISARevision >= 11)
  107. .Case("arch12", ISARevision >= 12)
  108. .Case("arch13", ISARevision >= 13)
  109. .Case("arch14", ISARevision >= 14)
  110. .Case("htm", HasTransactionalExecution)
  111. .Case("vx", HasVector)
  112. .Default(false);
  113. }
  114. void SystemZTargetInfo::getTargetDefines(const LangOptions &Opts,
  115. MacroBuilder &Builder) const {
  116. Builder.defineMacro("__s390__");
  117. Builder.defineMacro("__s390x__");
  118. Builder.defineMacro("__zarch__");
  119. Builder.defineMacro("__LONG_DOUBLE_128__");
  120. Builder.defineMacro("__ARCH__", Twine(ISARevision));
  121. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  122. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  123. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  124. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  125. if (HasTransactionalExecution)
  126. Builder.defineMacro("__HTM__");
  127. if (HasVector)
  128. Builder.defineMacro("__VX__");
  129. if (Opts.ZVector)
  130. Builder.defineMacro("__VEC__", "10304");
  131. }
  132. ArrayRef<Builtin::Info> SystemZTargetInfo::getTargetBuiltins() const {
  133. return llvm::makeArrayRef(BuiltinInfo, clang::SystemZ::LastTSBuiltin -
  134. Builtin::FirstTSBuiltin);
  135. }