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 15 #ifndef LLVM_SUPPORT_TARGETPARSER_H 16 #define LLVM_SUPPORT_TARGETPARSER_H 17 18 // FIXME: vector is used because that's what clang uses for subtarget feature 19 // lists, but SmallVector would probably be better 20 #include <vector> 21 22 namespace llvm { 23 class StringRef; 24 25 // Target specific information into their own namespaces. These should be 26 // generated from TableGen because the information is already there, and there 27 // is where new information about targets will be added. 28 // FIXME: To TableGen this we need to make some table generated files available 29 // even if the back-end is not compiled with LLVM, plus we need to create a new 30 // back-end to TableGen to create these clean tables. 31 namespace ARM { 32 33 // FPU names. 34 enum FPUKind { 35 #define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) KIND, 36 #include "ARMTargetParser.def" 37 FK_LAST 38 }; 39 40 // FPU Version 41 enum FPUVersion { 42 FV_NONE = 0, 43 FV_VFPV2, 44 FV_VFPV3, 45 FV_VFPV3_FP16, 46 FV_VFPV4, 47 FV_VFPV5 48 }; 49 50 // An FPU name implies one of three levels of Neon support: 51 enum NeonSupportLevel { 52 NS_None = 0, ///< No Neon 53 NS_Neon, ///< Neon 54 NS_Crypto ///< Neon with Crypto 55 }; 56 57 // An FPU name restricts the FPU in one of three ways: 58 enum FPURestriction { 59 FR_None = 0, ///< No restriction 60 FR_D16, ///< Only 16 D registers 61 FR_SP_D16 ///< Only single-precision instructions, with 16 D registers 62 }; 63 64 // Arch names. 65 enum ArchKind { 66 #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID, 67 #include "ARMTargetParser.def" 68 AK_LAST 69 }; 70 71 // Arch extension modifiers for CPUs. 72 enum ArchExtKind : unsigned { 73 AEK_INVALID = 0x0, 74 AEK_NONE = 0x1, 75 AEK_CRC = 0x2, 76 AEK_CRYPTO = 0x4, 77 AEK_FP = 0x8, 78 AEK_HWDIV = 0x10, 79 AEK_HWDIVARM = 0x20, 80 AEK_MP = 0x40, 81 AEK_SIMD = 0x80, 82 AEK_SEC = 0x100, 83 AEK_VIRT = 0x200, 84 AEK_DSP = 0x400, 85 AEK_FP16 = 0x800, 86 AEK_RAS = 0x1000, 87 // Unsupported extensions. 88 AEK_OS = 0x8000000, 89 AEK_IWMMXT = 0x10000000, 90 AEK_IWMMXT2 = 0x20000000, 91 AEK_MAVERICK = 0x40000000, 92 AEK_XSCALE = 0x80000000, 93 }; 94 95 // ISA kinds. 96 enum ISAKind { IK_INVALID = 0, IK_ARM, IK_THUMB, IK_AARCH64 }; 97 98 // Endianness 99 // FIXME: BE8 vs. BE32? 100 enum EndianKind { EK_INVALID = 0, EK_LITTLE, EK_BIG }; 101 102 // v6/v7/v8 Profile 103 enum ProfileKind { PK_INVALID = 0, PK_A, PK_R, PK_M }; 104 105 StringRef getCanonicalArchName(StringRef Arch); 106 107 // Information by ID 108 StringRef getFPUName(unsigned FPUKind); 109 unsigned getFPUVersion(unsigned FPUKind); 110 unsigned getFPUNeonSupportLevel(unsigned FPUKind); 111 unsigned getFPURestriction(unsigned FPUKind); 112 113 // FIXME: These should be moved to TargetTuple once it exists 114 bool getFPUFeatures(unsigned FPUKind, std::vector<const char *> &Features); 115 bool getHWDivFeatures(unsigned HWDivKind, std::vector<const char *> &Features); 116 bool getExtensionFeatures(unsigned Extensions, 117 std::vector<const char*> &Features); 118 119 StringRef getArchName(unsigned ArchKind); 120 unsigned getArchAttr(unsigned ArchKind); 121 StringRef getCPUAttr(unsigned ArchKind); 122 StringRef getSubArch(unsigned ArchKind); 123 StringRef getArchExtName(unsigned ArchExtKind); 124 const char *getArchExtFeature(StringRef ArchExt); 125 StringRef getHWDivName(unsigned HWDivKind); 126 127 // Information by Name 128 unsigned getDefaultFPU(StringRef CPU, unsigned ArchKind); 129 unsigned getDefaultExtensions(StringRef CPU, unsigned ArchKind); 130 StringRef getDefaultCPU(StringRef Arch); 131 132 // Parser 133 unsigned parseHWDiv(StringRef HWDiv); 134 unsigned parseFPU(StringRef FPU); 135 unsigned parseArch(StringRef Arch); 136 unsigned parseArchExt(StringRef ArchExt); 137 unsigned parseCPUArch(StringRef CPU); 138 unsigned parseArchISA(StringRef Arch); 139 unsigned parseArchEndian(StringRef Arch); 140 unsigned parseArchProfile(StringRef Arch); 141 unsigned parseArchVersion(StringRef Arch); 142 143 } // namespace ARM 144 145 // FIXME:This should be made into class design,to avoid dupplication. 146 namespace AArch64 { 147 148 // Arch names. 149 enum class ArchKind { 150 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID, 151 #include "AArch64TargetParser.def" 152 AK_LAST 153 }; 154 155 // Arch extension modifiers for CPUs. 156 enum ArchExtKind : unsigned { 157 AEK_INVALID = 0x0, 158 AEK_NONE = 0x1, 159 AEK_CRC = 0x2, 160 AEK_CRYPTO = 0x4, 161 AEK_FP = 0x8, 162 AEK_SIMD = 0x10, 163 AEK_FP16 = 0x20, 164 AEK_PROFILE = 0x40, 165 AEK_RAS = 0x80 166 }; 167 168 StringRef getCanonicalArchName(StringRef Arch); 169 170 // Information by ID 171 StringRef getFPUName(unsigned FPUKind); 172 unsigned getFPUVersion(unsigned FPUKind); 173 unsigned getFPUNeonSupportLevel(unsigned FPUKind); 174 unsigned getFPURestriction(unsigned FPUKind); 175 176 // FIXME: These should be moved to TargetTuple once it exists 177 bool getFPUFeatures(unsigned FPUKind, std::vector<const char *> &Features); 178 bool getExtensionFeatures(unsigned Extensions, 179 std::vector<const char*> &Features); 180 bool getArchFeatures(unsigned ArchKind, std::vector<const char *> &Features); 181 182 StringRef getArchName(unsigned ArchKind); 183 unsigned getArchAttr(unsigned ArchKind); 184 StringRef getCPUAttr(unsigned ArchKind); 185 StringRef getSubArch(unsigned ArchKind); 186 StringRef getArchExtName(unsigned ArchExtKind); 187 const char *getArchExtFeature(StringRef ArchExt); 188 unsigned checkArchVersion(StringRef Arch); 189 190 // Information by Name 191 unsigned getDefaultFPU(StringRef CPU, unsigned ArchKind); 192 unsigned getDefaultExtensions(StringRef CPU, unsigned ArchKind); 193 StringRef getDefaultCPU(StringRef Arch); 194 195 // Parser 196 unsigned parseFPU(StringRef FPU); 197 unsigned parseArch(StringRef Arch); 198 unsigned parseArchExt(StringRef ArchExt); 199 unsigned parseCPUArch(StringRef CPU); 200 unsigned parseArchISA(StringRef Arch); 201 unsigned parseArchEndian(StringRef Arch); 202 unsigned parseArchProfile(StringRef Arch); 203 unsigned parseArchVersion(StringRef Arch); 204 205 } // namespace AArch64 206 } // namespace llvm 207 208 #endif 209