TargetParser.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements a target parser to recognise hardware features such as
  11. // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_TARGETPARSER_H
  15. #define LLVM_SUPPORT_TARGETPARSER_H
  16. // FIXME: vector is used because that's what clang uses for subtarget feature
  17. // lists, but SmallVector would probably be better
  18. #include <vector>
  19. namespace llvm {
  20. class StringRef;
  21. // Target specific information into their own namespaces. These should be
  22. // generated from TableGen because the information is already there, and there
  23. // is where new information about targets will be added.
  24. // FIXME: To TableGen this we need to make some table generated files available
  25. // even if the back-end is not compiled with LLVM, plus we need to create a new
  26. // back-end to TableGen to create these clean tables.
  27. namespace ARM {
  28. // FPU names.
  29. enum FPUKind {
  30. FK_INVALID = 0,
  31. FK_NONE,
  32. FK_VFP,
  33. FK_VFPV2,
  34. FK_VFPV3,
  35. FK_VFPV3_FP16,
  36. FK_VFPV3_D16,
  37. FK_VFPV3_D16_FP16,
  38. FK_VFPV3XD,
  39. FK_VFPV3XD_FP16,
  40. FK_VFPV4,
  41. FK_VFPV4_D16,
  42. FK_FPV4_SP_D16,
  43. FK_FPV5_D16,
  44. FK_FPV5_SP_D16,
  45. FK_FP_ARMV8,
  46. FK_NEON,
  47. FK_NEON_FP16,
  48. FK_NEON_VFPV4,
  49. FK_NEON_FP_ARMV8,
  50. FK_CRYPTO_NEON_FP_ARMV8,
  51. FK_SOFTVFP,
  52. FK_LAST
  53. };
  54. // FPU Version
  55. enum FPUVersion {
  56. FV_NONE = 0,
  57. FV_VFPV2,
  58. FV_VFPV3,
  59. FV_VFPV3_FP16,
  60. FV_VFPV4,
  61. FV_VFPV5
  62. };
  63. // An FPU name implies one of three levels of Neon support:
  64. enum NeonSupportLevel {
  65. NS_None = 0, ///< No Neon
  66. NS_Neon, ///< Neon
  67. NS_Crypto ///< Neon with Crypto
  68. };
  69. // An FPU name restricts the FPU in one of three ways:
  70. enum FPURestriction {
  71. FR_None = 0, ///< No restriction
  72. FR_D16, ///< Only 16 D registers
  73. FR_SP_D16 ///< Only single-precision instructions, with 16 D registers
  74. };
  75. // Arch names.
  76. enum ArchKind {
  77. AK_INVALID = 0,
  78. AK_ARMV2,
  79. AK_ARMV2A,
  80. AK_ARMV3,
  81. AK_ARMV3M,
  82. AK_ARMV4,
  83. AK_ARMV4T,
  84. AK_ARMV5T,
  85. AK_ARMV5TE,
  86. AK_ARMV5TEJ,
  87. AK_ARMV6,
  88. AK_ARMV6K,
  89. AK_ARMV6T2,
  90. AK_ARMV6Z,
  91. AK_ARMV6ZK,
  92. AK_ARMV6M,
  93. AK_ARMV6SM,
  94. AK_ARMV7A,
  95. AK_ARMV7R,
  96. AK_ARMV7M,
  97. AK_ARMV7EM,
  98. AK_ARMV8A,
  99. AK_ARMV8_1A,
  100. // Non-standard Arch names.
  101. AK_IWMMXT,
  102. AK_IWMMXT2,
  103. AK_XSCALE,
  104. AK_ARMV5,
  105. AK_ARMV5E,
  106. AK_ARMV6J,
  107. AK_ARMV6HL,
  108. AK_ARMV7,
  109. AK_ARMV7L,
  110. AK_ARMV7HL,
  111. AK_ARMV7S,
  112. AK_LAST
  113. };
  114. // Arch extension modifiers for CPUs.
  115. enum ArchExtKind {
  116. AEK_INVALID = 0,
  117. AEK_CRC,
  118. AEK_CRYPTO,
  119. AEK_FP,
  120. AEK_HWDIV,
  121. AEK_MP,
  122. AEK_SIMD,
  123. AEK_SEC,
  124. AEK_VIRT,
  125. // Unsupported extensions.
  126. AEK_OS,
  127. AEK_IWMMXT,
  128. AEK_IWMMXT2,
  129. AEK_MAVERICK,
  130. AEK_XSCALE,
  131. AEK_LAST
  132. };
  133. // ISA kinds.
  134. enum ISAKind {
  135. IK_INVALID = 0,
  136. IK_ARM,
  137. IK_THUMB,
  138. IK_AARCH64
  139. };
  140. // Endianness
  141. // FIXME: BE8 vs. BE32?
  142. enum EndianKind {
  143. EK_INVALID = 0,
  144. EK_LITTLE,
  145. EK_BIG
  146. };
  147. // v6/v7/v8 Profile
  148. enum ProfileKind {
  149. PK_INVALID = 0,
  150. PK_A,
  151. PK_R,
  152. PK_M
  153. };
  154. } // namespace ARM
  155. // Target Parsers, one per architecture.
  156. class ARMTargetParser {
  157. static StringRef getFPUSynonym(StringRef FPU);
  158. static StringRef getArchSynonym(StringRef Arch);
  159. public:
  160. static StringRef getCanonicalArchName(StringRef Arch);
  161. // Information by ID
  162. static const char * getFPUName(unsigned FPUKind);
  163. static unsigned getFPUVersion(unsigned FPUKind);
  164. static unsigned getFPUNeonSupportLevel(unsigned FPUKind);
  165. static unsigned getFPURestriction(unsigned FPUKind);
  166. // FIXME: This should be moved to TargetTuple once it exists
  167. static bool getFPUFeatures(unsigned FPUKind,
  168. std::vector<const char*> &Features);
  169. static const char * getArchName(unsigned ArchKind);
  170. static unsigned getArchAttr(unsigned ArchKind);
  171. static const char * getCPUAttr(unsigned ArchKind);
  172. static const char * getSubArch(unsigned ArchKind);
  173. static const char * getArchExtName(unsigned ArchExtKind);
  174. static const char * getDefaultCPU(StringRef Arch);
  175. // Parser
  176. static unsigned parseFPU(StringRef FPU);
  177. static unsigned parseArch(StringRef Arch);
  178. static unsigned parseArchExt(StringRef ArchExt);
  179. static unsigned parseCPUArch(StringRef CPU);
  180. static unsigned parseArchISA(StringRef Arch);
  181. static unsigned parseArchEndian(StringRef Arch);
  182. static unsigned parseArchProfile(StringRef Arch);
  183. static unsigned parseArchVersion(StringRef Arch);
  184. };
  185. } // namespace llvm
  186. #endif