TargetParser.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file implements a target parser to recognise hardware features such as
  15. // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_TARGETPARSER_H
  19. #define LLVM_SUPPORT_TARGETPARSER_H
  20. // FIXME: vector is used because that's what clang uses for subtarget feature
  21. // lists, but SmallVector would probably be better
  22. #include "llvm/Support/RISCVISAInfo.h"
  23. #include <vector>
  24. namespace llvm {
  25. class StringRef;
  26. template <typename T> class SmallVectorImpl;
  27. class Triple;
  28. // Target specific information in their own namespaces.
  29. // (ARM/AArch64/X86 are declared in ARM/AArch64/X86TargetParser.h)
  30. // These should be generated from TableGen because the information is already
  31. // there, and there is where new information about targets will be added.
  32. // FIXME: To TableGen this we need to make some table generated files available
  33. // even if the back-end is not compiled with LLVM, plus we need to create a new
  34. // back-end to TableGen to create these clean tables.
  35. namespace AMDGPU {
  36. /// GPU kinds supported by the AMDGPU target.
  37. enum GPUKind : uint32_t {
  38. // Not specified processor.
  39. GK_NONE = 0,
  40. // R600-based processors.
  41. GK_R600 = 1,
  42. GK_R630 = 2,
  43. GK_RS880 = 3,
  44. GK_RV670 = 4,
  45. GK_RV710 = 5,
  46. GK_RV730 = 6,
  47. GK_RV770 = 7,
  48. GK_CEDAR = 8,
  49. GK_CYPRESS = 9,
  50. GK_JUNIPER = 10,
  51. GK_REDWOOD = 11,
  52. GK_SUMO = 12,
  53. GK_BARTS = 13,
  54. GK_CAICOS = 14,
  55. GK_CAYMAN = 15,
  56. GK_TURKS = 16,
  57. GK_R600_FIRST = GK_R600,
  58. GK_R600_LAST = GK_TURKS,
  59. // AMDGCN-based processors.
  60. GK_GFX600 = 32,
  61. GK_GFX601 = 33,
  62. GK_GFX602 = 34,
  63. GK_GFX700 = 40,
  64. GK_GFX701 = 41,
  65. GK_GFX702 = 42,
  66. GK_GFX703 = 43,
  67. GK_GFX704 = 44,
  68. GK_GFX705 = 45,
  69. GK_GFX801 = 50,
  70. GK_GFX802 = 51,
  71. GK_GFX803 = 52,
  72. GK_GFX805 = 53,
  73. GK_GFX810 = 54,
  74. GK_GFX900 = 60,
  75. GK_GFX902 = 61,
  76. GK_GFX904 = 62,
  77. GK_GFX906 = 63,
  78. GK_GFX908 = 64,
  79. GK_GFX909 = 65,
  80. GK_GFX90A = 66,
  81. GK_GFX90C = 67,
  82. GK_GFX1010 = 71,
  83. GK_GFX1011 = 72,
  84. GK_GFX1012 = 73,
  85. GK_GFX1013 = 74,
  86. GK_GFX1030 = 75,
  87. GK_GFX1031 = 76,
  88. GK_GFX1032 = 77,
  89. GK_GFX1033 = 78,
  90. GK_GFX1034 = 79,
  91. GK_GFX1035 = 80,
  92. GK_AMDGCN_FIRST = GK_GFX600,
  93. GK_AMDGCN_LAST = GK_GFX1035,
  94. };
  95. /// Instruction set architecture version.
  96. struct IsaVersion {
  97. unsigned Major;
  98. unsigned Minor;
  99. unsigned Stepping;
  100. };
  101. // This isn't comprehensive for now, just things that are needed from the
  102. // frontend driver.
  103. enum ArchFeatureKind : uint32_t {
  104. FEATURE_NONE = 0,
  105. // These features only exist for r600, and are implied true for amdgcn.
  106. FEATURE_FMA = 1 << 1,
  107. FEATURE_LDEXP = 1 << 2,
  108. FEATURE_FP64 = 1 << 3,
  109. // Common features.
  110. FEATURE_FAST_FMA_F32 = 1 << 4,
  111. FEATURE_FAST_DENORMAL_F32 = 1 << 5,
  112. // Wavefront 32 is available.
  113. FEATURE_WAVE32 = 1 << 6,
  114. // Xnack is available.
  115. FEATURE_XNACK = 1 << 7,
  116. // Sram-ecc is available.
  117. FEATURE_SRAMECC = 1 << 8,
  118. };
  119. StringRef getArchNameAMDGCN(GPUKind AK);
  120. StringRef getArchNameR600(GPUKind AK);
  121. StringRef getCanonicalArchName(const Triple &T, StringRef Arch);
  122. GPUKind parseArchAMDGCN(StringRef CPU);
  123. GPUKind parseArchR600(StringRef CPU);
  124. unsigned getArchAttrAMDGCN(GPUKind AK);
  125. unsigned getArchAttrR600(GPUKind AK);
  126. void fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values);
  127. void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
  128. IsaVersion getIsaVersion(StringRef GPU);
  129. } // namespace AMDGPU
  130. namespace RISCV {
  131. enum CPUKind : unsigned {
  132. #define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) CK_##ENUM,
  133. #include "RISCVTargetParser.def"
  134. };
  135. enum FeatureKind : unsigned {
  136. FK_INVALID = 0,
  137. FK_NONE = 1,
  138. FK_64BIT = 1 << 2,
  139. };
  140. bool checkCPUKind(CPUKind Kind, bool IsRV64);
  141. bool checkTuneCPUKind(CPUKind Kind, bool IsRV64);
  142. CPUKind parseCPUKind(StringRef CPU);
  143. CPUKind parseTuneCPUKind(StringRef CPU, bool IsRV64);
  144. StringRef getMArchFromMcpu(StringRef CPU);
  145. void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64);
  146. void fillValidTuneCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64);
  147. bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector<StringRef> &Features);
  148. StringRef resolveTuneCPUAlias(StringRef TuneCPU, bool IsRV64);
  149. StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo &ISAInfo);
  150. } // namespace RISCV
  151. namespace ARM {
  152. struct ParsedBranchProtection {
  153. StringRef Scope;
  154. StringRef Key;
  155. bool BranchTargetEnforcement;
  156. };
  157. bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
  158. StringRef &Err);
  159. } // namespace ARM
  160. } // namespace llvm
  161. #endif
  162. #ifdef __GNUC__
  163. #pragma GCC diagnostic pop
  164. #endif