ARMTargetParser.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //===-- ARMTargetParser - Parser for ARM target features --------*- 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 implements a target parser to recognise ARM hardware features
  10. // such as FPU/CPU/ARCH/extensions and specific support such as HWDIV.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_ARMTARGETPARSER_H
  14. #define LLVM_SUPPORT_ARMTARGETPARSER_H
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/Support/ARMBuildAttributes.h"
  18. #include <vector>
  19. namespace llvm {
  20. class Triple;
  21. namespace ARM {
  22. // Arch extension modifiers for CPUs.
  23. // Note that this is not the same as the AArch64 list
  24. enum ArchExtKind : uint64_t {
  25. AEK_INVALID = 0,
  26. AEK_NONE = 1,
  27. AEK_CRC = 1 << 1,
  28. AEK_CRYPTO = 1 << 2,
  29. AEK_FP = 1 << 3,
  30. AEK_HWDIVTHUMB = 1 << 4,
  31. AEK_HWDIVARM = 1 << 5,
  32. AEK_MP = 1 << 6,
  33. AEK_SIMD = 1 << 7,
  34. AEK_SEC = 1 << 8,
  35. AEK_VIRT = 1 << 9,
  36. AEK_DSP = 1 << 10,
  37. AEK_FP16 = 1 << 11,
  38. AEK_RAS = 1 << 12,
  39. AEK_DOTPROD = 1 << 13,
  40. AEK_SHA2 = 1 << 14,
  41. AEK_AES = 1 << 15,
  42. AEK_FP16FML = 1 << 16,
  43. AEK_SB = 1 << 17,
  44. AEK_FP_DP = 1 << 18,
  45. AEK_LOB = 1 << 19,
  46. AEK_BF16 = 1 << 20,
  47. AEK_I8MM = 1 << 21,
  48. AEK_CDECP0 = 1 << 22,
  49. AEK_CDECP1 = 1 << 23,
  50. AEK_CDECP2 = 1 << 24,
  51. AEK_CDECP3 = 1 << 25,
  52. AEK_CDECP4 = 1 << 26,
  53. AEK_CDECP5 = 1 << 27,
  54. AEK_CDECP6 = 1 << 28,
  55. AEK_CDECP7 = 1 << 29,
  56. // Unsupported extensions.
  57. AEK_OS = 1ULL << 59,
  58. AEK_IWMMXT = 1ULL << 60,
  59. AEK_IWMMXT2 = 1ULL << 61,
  60. AEK_MAVERICK = 1ULL << 62,
  61. AEK_XSCALE = 1ULL << 63,
  62. };
  63. // List of Arch Extension names.
  64. // FIXME: TableGen this.
  65. struct ExtName {
  66. const char *NameCStr;
  67. size_t NameLength;
  68. uint64_t ID;
  69. const char *Feature;
  70. const char *NegFeature;
  71. StringRef getName() const { return StringRef(NameCStr, NameLength); }
  72. };
  73. const ExtName ARCHExtNames[] = {
  74. #define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
  75. {NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE},
  76. #include "ARMTargetParser.def"
  77. };
  78. // List of HWDiv names (use getHWDivSynonym) and which architectural
  79. // features they correspond to (use getHWDivFeatures).
  80. // FIXME: TableGen this.
  81. const struct {
  82. const char *NameCStr;
  83. size_t NameLength;
  84. uint64_t ID;
  85. StringRef getName() const { return StringRef(NameCStr, NameLength); }
  86. } HWDivNames[] = {
  87. #define ARM_HW_DIV_NAME(NAME, ID) {NAME, sizeof(NAME) - 1, ID},
  88. #include "ARMTargetParser.def"
  89. };
  90. // Arch names.
  91. enum class ArchKind {
  92. #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID,
  93. #include "ARMTargetParser.def"
  94. };
  95. // List of CPU names and their arches.
  96. // The same CPU can have multiple arches and can be default on multiple arches.
  97. // When finding the Arch for a CPU, first-found prevails. Sort them accordingly.
  98. // When this becomes table-generated, we'd probably need two tables.
  99. // FIXME: TableGen this.
  100. template <typename T> struct CpuNames {
  101. const char *NameCStr;
  102. size_t NameLength;
  103. T ArchID;
  104. bool Default; // is $Name the default CPU for $ArchID ?
  105. uint64_t DefaultExtensions;
  106. StringRef getName() const { return StringRef(NameCStr, NameLength); }
  107. };
  108. const CpuNames<ArchKind> CPUNames[] = {
  109. #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
  110. {NAME, sizeof(NAME) - 1, ARM::ArchKind::ID, IS_DEFAULT, DEFAULT_EXT},
  111. #include "ARMTargetParser.def"
  112. };
  113. // FPU names.
  114. enum FPUKind {
  115. #define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) KIND,
  116. #include "ARMTargetParser.def"
  117. FK_LAST
  118. };
  119. // FPU Version
  120. enum class FPUVersion {
  121. NONE,
  122. VFPV2,
  123. VFPV3,
  124. VFPV3_FP16,
  125. VFPV4,
  126. VFPV5,
  127. VFPV5_FULLFP16,
  128. };
  129. // An FPU name restricts the FPU in one of three ways:
  130. enum class FPURestriction {
  131. None = 0, ///< No restriction
  132. D16, ///< Only 16 D registers
  133. SP_D16 ///< Only single-precision instructions, with 16 D registers
  134. };
  135. // An FPU name implies one of three levels of Neon support:
  136. enum class NeonSupportLevel {
  137. None = 0, ///< No Neon
  138. Neon, ///< Neon
  139. Crypto ///< Neon with Crypto
  140. };
  141. // ISA kinds.
  142. enum class ISAKind { INVALID = 0, ARM, THUMB, AARCH64 };
  143. // Endianness
  144. // FIXME: BE8 vs. BE32?
  145. enum class EndianKind { INVALID = 0, LITTLE, BIG };
  146. // v6/v7/v8 Profile
  147. enum class ProfileKind { INVALID = 0, A, R, M };
  148. // List of canonical FPU names (use getFPUSynonym) and which architectural
  149. // features they correspond to (use getFPUFeatures).
  150. // FIXME: TableGen this.
  151. // The entries must appear in the order listed in ARM::FPUKind for correct
  152. // indexing
  153. struct FPUName {
  154. const char *NameCStr;
  155. size_t NameLength;
  156. FPUKind ID;
  157. FPUVersion FPUVer;
  158. NeonSupportLevel NeonSupport;
  159. FPURestriction Restriction;
  160. StringRef getName() const { return StringRef(NameCStr, NameLength); }
  161. };
  162. static const FPUName FPUNames[] = {
  163. #define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
  164. {NAME, sizeof(NAME) - 1, KIND, VERSION, NEON_SUPPORT, RESTRICTION},
  165. #include "llvm/Support/ARMTargetParser.def"
  166. };
  167. // List of canonical arch names (use getArchSynonym).
  168. // This table also provides the build attribute fields for CPU arch
  169. // and Arch ID, according to the Addenda to the ARM ABI, chapters
  170. // 2.4 and 2.3.5.2 respectively.
  171. // FIXME: SubArch values were simplified to fit into the expectations
  172. // of the triples and are not conforming with their official names.
  173. // Check to see if the expectation should be changed.
  174. // FIXME: TableGen this.
  175. template <typename T> struct ArchNames {
  176. const char *NameCStr;
  177. size_t NameLength;
  178. const char *CPUAttrCStr;
  179. size_t CPUAttrLength;
  180. const char *SubArchCStr;
  181. size_t SubArchLength;
  182. unsigned DefaultFPU;
  183. uint64_t ArchBaseExtensions;
  184. T ID;
  185. ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes.
  186. StringRef getName() const { return StringRef(NameCStr, NameLength); }
  187. // CPU class in build attributes.
  188. StringRef getCPUAttr() const { return StringRef(CPUAttrCStr, CPUAttrLength); }
  189. // Sub-Arch name.
  190. StringRef getSubArch() const { return StringRef(SubArchCStr, SubArchLength); }
  191. };
  192. static const ArchNames<ArchKind> ARCHNames[] = {
  193. #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, \
  194. ARCH_BASE_EXT) \
  195. {NAME, sizeof(NAME) - 1, \
  196. CPU_ATTR, sizeof(CPU_ATTR) - 1, \
  197. SUB_ARCH, sizeof(SUB_ARCH) - 1, \
  198. ARCH_FPU, ARCH_BASE_EXT, \
  199. ArchKind::ID, ARCH_ATTR},
  200. #include "llvm/Support/ARMTargetParser.def"
  201. };
  202. // Information by ID
  203. StringRef getFPUName(unsigned FPUKind);
  204. FPUVersion getFPUVersion(unsigned FPUKind);
  205. NeonSupportLevel getFPUNeonSupportLevel(unsigned FPUKind);
  206. FPURestriction getFPURestriction(unsigned FPUKind);
  207. // FIXME: These should be moved to TargetTuple once it exists
  208. bool getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features);
  209. bool getHWDivFeatures(uint64_t HWDivKind, std::vector<StringRef> &Features);
  210. bool getExtensionFeatures(uint64_t Extensions,
  211. std::vector<StringRef> &Features);
  212. StringRef getArchName(ArchKind AK);
  213. unsigned getArchAttr(ArchKind AK);
  214. StringRef getCPUAttr(ArchKind AK);
  215. StringRef getSubArch(ArchKind AK);
  216. StringRef getArchExtName(uint64_t ArchExtKind);
  217. StringRef getArchExtFeature(StringRef ArchExt);
  218. bool appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK, StringRef ArchExt,
  219. std::vector<StringRef> &Features,
  220. unsigned &ArgFPUKind);
  221. StringRef getHWDivName(uint64_t HWDivKind);
  222. // Information by Name
  223. unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
  224. uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
  225. StringRef getDefaultCPU(StringRef Arch);
  226. StringRef getCanonicalArchName(StringRef Arch);
  227. StringRef getFPUSynonym(StringRef FPU);
  228. StringRef getArchSynonym(StringRef Arch);
  229. // Parser
  230. uint64_t parseHWDiv(StringRef HWDiv);
  231. unsigned parseFPU(StringRef FPU);
  232. ArchKind parseArch(StringRef Arch);
  233. uint64_t parseArchExt(StringRef ArchExt);
  234. ArchKind parseCPUArch(StringRef CPU);
  235. ISAKind parseArchISA(StringRef Arch);
  236. EndianKind parseArchEndian(StringRef Arch);
  237. ProfileKind parseArchProfile(StringRef Arch);
  238. unsigned parseArchVersion(StringRef Arch);
  239. void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
  240. StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
  241. } // namespace ARM
  242. } // namespace llvm
  243. #endif