Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 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 | #include "llvm/Support/ARMBuildAttributes.h" |
| 16 | #include "llvm/Support/TargetParser.h" |
| 17 | #include "llvm/ADT/StringExtras.h" |
| 18 | #include "llvm/ADT/StringSwitch.h" |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 19 | #include <cctype> |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 22 | using namespace ARM; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 23 | |
| 24 | namespace { |
| 25 | |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 26 | // List of canonical FPU names (use getFPUSynonym) and which architectural |
| 27 | // features they correspond to (use getFPUFeatures). |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 28 | // FIXME: TableGen this. |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 29 | // The entries must appear in the order listed in ARM::FPUKind for correct indexing |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 30 | struct { |
| 31 | const char * Name; |
| 32 | ARM::FPUKind ID; |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 33 | ARM::FPUVersion FPUVersion; |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 34 | ARM::NeonSupportLevel NeonSupport; |
| 35 | ARM::FPURestriction Restriction; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 36 | } FPUNames[] = { |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 37 | #define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \ |
| 38 | { NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION }, |
| 39 | #include "llvm/Support/ARMTargetParser.def" |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 40 | }; |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 41 | |
Renato Golin | f7c0d5f | 2015-05-27 18:15:37 +0000 | [diff] [blame] | 42 | // List of canonical arch names (use getArchSynonym). |
| 43 | // This table also provides the build attribute fields for CPU arch |
| 44 | // and Arch ID, according to the Addenda to the ARM ABI, chapters |
| 45 | // 2.4 and 2.3.5.2 respectively. |
Renato Golin | 42dad64 | 2015-05-28 15:05:18 +0000 | [diff] [blame] | 46 | // FIXME: SubArch values were simplified to fit into the expectations |
| 47 | // of the triples and are not conforming with their official names. |
| 48 | // Check to see if the expectation should be changed. |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 49 | // FIXME: TableGen this. |
| 50 | struct { |
| 51 | const char *Name; |
| 52 | ARM::ArchKind ID; |
Renato Golin | f7c0d5f | 2015-05-27 18:15:37 +0000 | [diff] [blame] | 53 | const char *CPUAttr; // CPU class in build attributes. |
Renato Golin | 42dad64 | 2015-05-28 15:05:18 +0000 | [diff] [blame] | 54 | const char *SubArch; // Sub-Arch name. |
Renato Golin | f7c0d5f | 2015-05-27 18:15:37 +0000 | [diff] [blame] | 55 | ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes. |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 56 | } ARCHNames[] = { |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 57 | #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR) \ |
| 58 | { NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR }, |
| 59 | #include "llvm/Support/ARMTargetParser.def" |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 60 | }; |
Renato Golin | e1326ca | 2015-05-28 08:59:03 +0000 | [diff] [blame] | 61 | // List of Arch Extension names. |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 62 | // FIXME: TableGen this. |
| 63 | struct { |
| 64 | const char *Name; |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 65 | unsigned ID; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 66 | } ARCHExtNames[] = { |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 67 | #define ARM_ARCH_EXT_NAME(NAME, ID) { NAME, ID }, |
| 68 | #include "llvm/Support/ARMTargetParser.def" |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 69 | }; |
| 70 | // List of HWDiv names (use getHWDivSynonym) and which architectural |
| 71 | // features they correspond to (use getHWDivFeatures). |
| 72 | // FIXME: TableGen this. |
| 73 | struct { |
| 74 | const char *Name; |
| 75 | unsigned ID; |
| 76 | } HWDivNames[] = { |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 77 | #define ARM_HW_DIV_NAME(NAME, ID) { NAME, ID }, |
| 78 | #include "llvm/Support/ARMTargetParser.def" |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 79 | }; |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 80 | // List of CPU names and their arches. |
| 81 | // The same CPU can have multiple arches and can be default on multiple arches. |
| 82 | // When finding the Arch for a CPU, first-found prevails. Sort them accordingly. |
Renato Golin | 7374fcd | 2015-05-28 12:10:37 +0000 | [diff] [blame] | 83 | // When this becomes table-generated, we'd probably need two tables. |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 84 | // FIXME: TableGen this. |
| 85 | struct { |
| 86 | const char *Name; |
| 87 | ARM::ArchKind ArchID; |
Alexandros Lamprineas | fcd93d5 | 2015-07-15 10:46:21 +0000 | [diff] [blame] | 88 | ARM::FPUKind DefaultFPU; |
| 89 | bool Default; // is $Name the default CPU for $ArchID ? |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 90 | } CPUNames[] = { |
Chandler Carruth | 799e880 | 2015-08-30 05:27:31 +0000 | [diff] [blame^] | 91 | #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT) \ |
| 92 | { NAME, ID, DEFAULT_FPU, IS_DEFAULT }, |
| 93 | #include "llvm/Support/ARMTargetParser.def" |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 94 | }; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 95 | |
| 96 | } // namespace |
| 97 | |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 98 | // ======================================================= // |
| 99 | // Information by ID |
| 100 | // ======================================================= // |
| 101 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 102 | const char *llvm::ARM::getFPUName(unsigned FPUKind) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 103 | if (FPUKind >= ARM::FK_LAST) |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 104 | return nullptr; |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 105 | return FPUNames[FPUKind].Name; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 108 | unsigned llvm::ARM::getFPUVersion(unsigned FPUKind) { |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 109 | if (FPUKind >= ARM::FK_LAST) |
| 110 | return 0; |
| 111 | return FPUNames[FPUKind].FPUVersion; |
| 112 | } |
| 113 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 114 | unsigned llvm::ARM::getFPUNeonSupportLevel(unsigned FPUKind) { |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 115 | if (FPUKind >= ARM::FK_LAST) |
| 116 | return 0; |
| 117 | return FPUNames[FPUKind].NeonSupport; |
| 118 | } |
| 119 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 120 | unsigned llvm::ARM::getFPURestriction(unsigned FPUKind) { |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 121 | if (FPUKind >= ARM::FK_LAST) |
| 122 | return 0; |
| 123 | return FPUNames[FPUKind].Restriction; |
| 124 | } |
| 125 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 126 | unsigned llvm::ARM::getDefaultFPU(StringRef CPU) { |
Alexandros Lamprineas | fcd93d5 | 2015-07-15 10:46:21 +0000 | [diff] [blame] | 127 | for (const auto C : CPUNames) { |
| 128 | if (CPU == C.Name) |
| 129 | return C.DefaultFPU; |
| 130 | } |
| 131 | return ARM::FK_INVALID; |
| 132 | } |
| 133 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 134 | bool llvm::ARM::getHWDivFeatures(unsigned HWDivKind, |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 135 | std::vector<const char *> &Features) { |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 136 | |
| 137 | if (HWDivKind == ARM::AEK_INVALID) |
| 138 | return false; |
| 139 | |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 140 | if (HWDivKind & ARM::AEK_HWDIVARM) |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 141 | Features.push_back("+hwdiv-arm"); |
| 142 | else |
| 143 | Features.push_back("-hwdiv-arm"); |
| 144 | |
| 145 | if (HWDivKind & ARM::AEK_HWDIV) |
| 146 | Features.push_back("+hwdiv"); |
| 147 | else |
| 148 | Features.push_back("-hwdiv"); |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 153 | bool llvm::ARM::getFPUFeatures(unsigned FPUKind, |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 154 | std::vector<const char *> &Features) { |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 155 | |
| 156 | if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID) |
| 157 | return false; |
| 158 | |
| 159 | // fp-only-sp and d16 subtarget features are independent of each other, so we |
| 160 | // must enable/disable both. |
| 161 | switch (FPUNames[FPUKind].Restriction) { |
| 162 | case ARM::FR_SP_D16: |
| 163 | Features.push_back("+fp-only-sp"); |
| 164 | Features.push_back("+d16"); |
| 165 | break; |
| 166 | case ARM::FR_D16: |
| 167 | Features.push_back("-fp-only-sp"); |
| 168 | Features.push_back("+d16"); |
| 169 | break; |
| 170 | case ARM::FR_None: |
| 171 | Features.push_back("-fp-only-sp"); |
| 172 | Features.push_back("-d16"); |
| 173 | break; |
| 174 | } |
| 175 | |
| 176 | // FPU version subtarget features are inclusive of lower-numbered ones, so |
| 177 | // enable the one corresponding to this version and disable all that are |
John Brawn | d9e39d5 | 2015-06-12 09:38:51 +0000 | [diff] [blame] | 178 | // higher. We also have to make sure to disable fp16 when vfp4 is disabled, |
| 179 | // as +vfp4 implies +fp16 but -vfp4 does not imply -fp16. |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 180 | switch (FPUNames[FPUKind].FPUVersion) { |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 181 | case ARM::FV_VFPV5: |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 182 | Features.push_back("+fp-armv8"); |
| 183 | break; |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 184 | case ARM::FV_VFPV4: |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 185 | Features.push_back("+vfp4"); |
| 186 | Features.push_back("-fp-armv8"); |
| 187 | break; |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 188 | case ARM::FV_VFPV3_FP16: |
| 189 | Features.push_back("+vfp3"); |
| 190 | Features.push_back("+fp16"); |
| 191 | Features.push_back("-vfp4"); |
| 192 | Features.push_back("-fp-armv8"); |
| 193 | break; |
| 194 | case ARM::FV_VFPV3: |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 195 | Features.push_back("+vfp3"); |
John Brawn | d9e39d5 | 2015-06-12 09:38:51 +0000 | [diff] [blame] | 196 | Features.push_back("-fp16"); |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 197 | Features.push_back("-vfp4"); |
| 198 | Features.push_back("-fp-armv8"); |
| 199 | break; |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 200 | case ARM::FV_VFPV2: |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 201 | Features.push_back("+vfp2"); |
| 202 | Features.push_back("-vfp3"); |
John Brawn | d9e39d5 | 2015-06-12 09:38:51 +0000 | [diff] [blame] | 203 | Features.push_back("-fp16"); |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 204 | Features.push_back("-vfp4"); |
| 205 | Features.push_back("-fp-armv8"); |
| 206 | break; |
Javed Absar | d552630 | 2015-06-29 09:32:29 +0000 | [diff] [blame] | 207 | case ARM::FV_NONE: |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 208 | Features.push_back("-vfp2"); |
| 209 | Features.push_back("-vfp3"); |
John Brawn | d9e39d5 | 2015-06-12 09:38:51 +0000 | [diff] [blame] | 210 | Features.push_back("-fp16"); |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 211 | Features.push_back("-vfp4"); |
| 212 | Features.push_back("-fp-armv8"); |
| 213 | break; |
| 214 | } |
| 215 | |
| 216 | // crypto includes neon, so we handle this similarly to FPU version. |
| 217 | switch (FPUNames[FPUKind].NeonSupport) { |
| 218 | case ARM::NS_Crypto: |
| 219 | Features.push_back("+crypto"); |
| 220 | break; |
| 221 | case ARM::NS_Neon: |
| 222 | Features.push_back("+neon"); |
| 223 | Features.push_back("-crypto"); |
| 224 | break; |
| 225 | case ARM::NS_None: |
| 226 | Features.push_back("-neon"); |
| 227 | Features.push_back("-crypto"); |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | return true; |
| 232 | } |
| 233 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 234 | const char *llvm::ARM::getArchName(unsigned ArchKind) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 235 | if (ArchKind >= ARM::AK_LAST) |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 236 | return nullptr; |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 237 | return ARCHNames[ArchKind].Name; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 240 | const char *llvm::ARM::getCPUAttr(unsigned ArchKind) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 241 | if (ArchKind >= ARM::AK_LAST) |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 242 | return nullptr; |
Renato Golin | f7c0d5f | 2015-05-27 18:15:37 +0000 | [diff] [blame] | 243 | return ARCHNames[ArchKind].CPUAttr; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 246 | const char *llvm::ARM::getSubArch(unsigned ArchKind) { |
Renato Golin | 42dad64 | 2015-05-28 15:05:18 +0000 | [diff] [blame] | 247 | if (ArchKind >= ARM::AK_LAST) |
| 248 | return nullptr; |
| 249 | return ARCHNames[ArchKind].SubArch; |
| 250 | } |
| 251 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 252 | unsigned llvm::ARM::getArchAttr(unsigned ArchKind) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 253 | if (ArchKind >= ARM::AK_LAST) |
| 254 | return ARMBuildAttrs::CPUArch::Pre_v4; |
Renato Golin | f7c0d5f | 2015-05-27 18:15:37 +0000 | [diff] [blame] | 255 | return ARCHNames[ArchKind].ArchAttr; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 258 | const char *llvm::ARM::getArchExtName(unsigned ArchExtKind) { |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 259 | for (const auto AE : ARCHExtNames) { |
| 260 | if (ArchExtKind == AE.ID) |
| 261 | return AE.Name; |
| 262 | } |
| 263 | return nullptr; |
| 264 | } |
| 265 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 266 | const char *llvm::ARM::getHWDivName(unsigned HWDivKind) { |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 267 | for (const auto D : HWDivNames) { |
| 268 | if (HWDivKind == D.ID) |
| 269 | return D.Name; |
| 270 | } |
| 271 | return nullptr; |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 274 | const char *llvm::ARM::getDefaultCPU(StringRef Arch) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 275 | unsigned AK = parseArch(Arch); |
| 276 | if (AK == ARM::AK_INVALID) |
| 277 | return nullptr; |
| 278 | |
| 279 | // Look for multiple AKs to find the default for pair AK+Name. |
| 280 | for (const auto CPU : CPUNames) { |
| 281 | if (CPU.ArchID == AK && CPU.Default) |
| 282 | return CPU.Name; |
| 283 | } |
| 284 | return nullptr; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // ======================================================= // |
| 288 | // Parsers |
| 289 | // ======================================================= // |
| 290 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 291 | static StringRef getHWDivSynonym(StringRef HWDiv) { |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 292 | return StringSwitch<StringRef>(HWDiv) |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 293 | .Case("thumb,arm", "arm,thumb") |
| 294 | .Default(HWDiv); |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 297 | static StringRef getFPUSynonym(StringRef FPU) { |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 298 | return StringSwitch<StringRef>(FPU) |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 299 | .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported |
| 300 | .Case("vfp2", "vfpv2") |
| 301 | .Case("vfp3", "vfpv3") |
| 302 | .Case("vfp4", "vfpv4") |
| 303 | .Case("vfp3-d16", "vfpv3-d16") |
| 304 | .Case("vfp4-d16", "vfpv4-d16") |
| 305 | .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16") |
| 306 | .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16") |
| 307 | .Case("fp5-sp-d16", "fpv5-sp-d16") |
| 308 | .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16") |
| 309 | // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3. |
| 310 | .Case("neon-vfpv3", "neon") |
| 311 | .Default(FPU); |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 314 | static StringRef getArchSynonym(StringRef Arch) { |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 315 | return StringSwitch<StringRef>(Arch) |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 316 | .Case("v6sm", "v6s-m") |
| 317 | .Case("v6m", "v6-m") |
| 318 | .Case("v7a", "v7-a") |
| 319 | .Case("v7r", "v7-r") |
| 320 | .Case("v7m", "v7-m") |
| 321 | .Case("v7em", "v7e-m") |
| 322 | .Cases("v8", "v8a", "aarch64", "arm64", "v8-a") |
| 323 | .Case("v8.1a", "v8.1-a") |
| 324 | .Default(Arch); |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 327 | // MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but |
| 328 | // (iwmmxt|xscale)(eb)? is also permitted. If the former, return |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 329 | // "v.+", if the latter, return unmodified string, minus 'eb'. |
| 330 | // If invalid, return empty string. |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 331 | StringRef llvm::ARM::getCanonicalArchName(StringRef Arch) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 332 | size_t offset = StringRef::npos; |
| 333 | StringRef A = Arch; |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 334 | StringRef Error = ""; |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 335 | |
| 336 | // Begins with "arm" / "thumb", move past it. |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 337 | if (A.startswith("arm64")) |
| 338 | offset = 5; |
| 339 | else if (A.startswith("arm")) |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 340 | offset = 3; |
| 341 | else if (A.startswith("thumb")) |
| 342 | offset = 5; |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 343 | else if (A.startswith("aarch64")) { |
| 344 | offset = 7; |
| 345 | // AArch64 uses "_be", not "eb" suffix. |
| 346 | if (A.find("eb") != StringRef::npos) |
| 347 | return Error; |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 348 | if (A.substr(offset, 3) == "_be") |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 349 | offset += 3; |
| 350 | } |
| 351 | |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 352 | // Ex. "armebv7", move past the "eb". |
| 353 | if (offset != StringRef::npos && A.substr(offset, 2) == "eb") |
| 354 | offset += 2; |
| 355 | // Or, if it ends with eb ("armv7eb"), chop it off. |
| 356 | else if (A.endswith("eb")) |
| 357 | A = A.substr(0, A.size() - 2); |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 358 | // Trim the head |
| 359 | if (offset != StringRef::npos) |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 360 | A = A.substr(offset); |
| 361 | |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 362 | // Empty string means offset reached the end, which means it's valid. |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 363 | if (A.empty()) |
| 364 | return Arch; |
| 365 | |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 366 | // Only match non-marketing names |
| 367 | if (offset != StringRef::npos) { |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 368 | // Must start with 'vN'. |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 369 | if (A[0] != 'v' || !std::isdigit(A[1])) |
| 370 | return Error; |
| 371 | // Can't have an extra 'eb'. |
| 372 | if (A.find("eb") != StringRef::npos) |
| 373 | return Error; |
| 374 | } |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 375 | |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 376 | // Arch will either be a 'v' name (v7a) or a marketing name (xscale). |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 377 | return A; |
| 378 | } |
| 379 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 380 | unsigned llvm::ARM::parseHWDiv(StringRef HWDiv) { |
Alexandros Lamprineas | 4ea7075 | 2015-07-27 22:26:59 +0000 | [diff] [blame] | 381 | StringRef Syn = getHWDivSynonym(HWDiv); |
| 382 | for (const auto D : HWDivNames) { |
| 383 | if (Syn == D.Name) |
| 384 | return D.ID; |
| 385 | } |
| 386 | return ARM::AEK_INVALID; |
| 387 | } |
| 388 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 389 | unsigned llvm::ARM::parseFPU(StringRef FPU) { |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 390 | StringRef Syn = getFPUSynonym(FPU); |
| 391 | for (const auto F : FPUNames) { |
| 392 | if (Syn == F.Name) |
| 393 | return F.ID; |
| 394 | } |
Renato Golin | 35de35d | 2015-05-12 10:33:58 +0000 | [diff] [blame] | 395 | return ARM::FK_INVALID; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 398 | // Allows partial match, ex. "v7a" matches "armv7a". |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 399 | unsigned llvm::ARM::parseArch(StringRef Arch) { |
Artyom Skrobov | 85aebc8 | 2015-06-04 21:26:58 +0000 | [diff] [blame] | 400 | Arch = getCanonicalArchName(Arch); |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 401 | StringRef Syn = getArchSynonym(Arch); |
| 402 | for (const auto A : ARCHNames) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 403 | if (StringRef(A.Name).endswith(Syn)) |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 404 | return A.ID; |
| 405 | } |
Renato Golin | 35de35d | 2015-05-12 10:33:58 +0000 | [diff] [blame] | 406 | return ARM::AK_INVALID; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 409 | unsigned llvm::ARM::parseArchExt(StringRef ArchExt) { |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 410 | for (const auto A : ARCHExtNames) { |
| 411 | if (ArchExt == A.Name) |
| 412 | return A.ID; |
| 413 | } |
Renato Golin | 35de35d | 2015-05-12 10:33:58 +0000 | [diff] [blame] | 414 | return ARM::AEK_INVALID; |
Renato Golin | f5f373f | 2015-05-08 21:04:27 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 417 | unsigned llvm::ARM::parseCPUArch(StringRef CPU) { |
Renato Golin | e8048f0 | 2015-05-20 15:05:07 +0000 | [diff] [blame] | 418 | for (const auto C : CPUNames) { |
| 419 | if (CPU == C.Name) |
| 420 | return C.ArchID; |
| 421 | } |
| 422 | return ARM::AK_INVALID; |
| 423 | } |
| 424 | |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 425 | // ARM, Thumb, AArch64 |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 426 | unsigned llvm::ARM::parseArchISA(StringRef Arch) { |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 427 | return StringSwitch<unsigned>(Arch) |
| 428 | .StartsWith("aarch64", ARM::IK_AARCH64) |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 429 | .StartsWith("arm64", ARM::IK_AARCH64) |
| 430 | .StartsWith("thumb", ARM::IK_THUMB) |
| 431 | .StartsWith("arm", ARM::IK_ARM) |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 432 | .Default(ARM::EK_INVALID); |
| 433 | } |
| 434 | |
| 435 | // Little/Big endian |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 436 | unsigned llvm::ARM::parseArchEndian(StringRef Arch) { |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 437 | if (Arch.startswith("armeb") || Arch.startswith("thumbeb") || |
Renato Golin | b6b9e05 | 2015-05-21 13:52:20 +0000 | [diff] [blame] | 438 | Arch.startswith("aarch64_be")) |
| 439 | return ARM::EK_BIG; |
| 440 | |
| 441 | if (Arch.startswith("arm") || Arch.startswith("thumb")) { |
| 442 | if (Arch.endswith("eb")) |
| 443 | return ARM::EK_BIG; |
| 444 | else |
| 445 | return ARM::EK_LITTLE; |
| 446 | } |
| 447 | |
| 448 | if (Arch.startswith("aarch64")) |
| 449 | return ARM::EK_LITTLE; |
| 450 | |
| 451 | return ARM::EK_INVALID; |
| 452 | } |
| 453 | |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 454 | // Profile A/R/M |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 455 | unsigned llvm::ARM::parseArchProfile(StringRef Arch) { |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 456 | Arch = getCanonicalArchName(Arch); |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 457 | switch (parseArch(Arch)) { |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 458 | case ARM::AK_ARMV6M: |
| 459 | case ARM::AK_ARMV7M: |
| 460 | case ARM::AK_ARMV6SM: |
| 461 | case ARM::AK_ARMV7EM: |
| 462 | return ARM::PK_M; |
| 463 | case ARM::AK_ARMV7R: |
| 464 | return ARM::PK_R; |
| 465 | case ARM::AK_ARMV7: |
| 466 | case ARM::AK_ARMV7A: |
Alexandros Lamprineas | 0e20b8d | 2015-07-16 14:54:41 +0000 | [diff] [blame] | 467 | case ARM::AK_ARMV7L: |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 468 | case ARM::AK_ARMV8A: |
| 469 | case ARM::AK_ARMV8_1A: |
| 470 | return ARM::PK_A; |
| 471 | } |
| 472 | return ARM::PK_INVALID; |
| 473 | } |
| 474 | |
Renato Golin | ebdd12c | 2015-05-22 20:43:30 +0000 | [diff] [blame] | 475 | // Version number (ex. v7 = 7). |
Chandler Carruth | bb47b9a | 2015-08-30 02:09:48 +0000 | [diff] [blame] | 476 | unsigned llvm::ARM::parseArchVersion(StringRef Arch) { |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 477 | Arch = getCanonicalArchName(Arch); |
Chandler Carruth | 4fc3a98 | 2015-08-30 02:17:15 +0000 | [diff] [blame] | 478 | switch (parseArch(Arch)) { |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 479 | case ARM::AK_ARMV2: |
| 480 | case ARM::AK_ARMV2A: |
| 481 | return 2; |
| 482 | case ARM::AK_ARMV3: |
| 483 | case ARM::AK_ARMV3M: |
| 484 | return 3; |
| 485 | case ARM::AK_ARMV4: |
| 486 | case ARM::AK_ARMV4T: |
| 487 | return 4; |
| 488 | case ARM::AK_ARMV5: |
| 489 | case ARM::AK_ARMV5T: |
| 490 | case ARM::AK_ARMV5TE: |
| 491 | case ARM::AK_IWMMXT: |
| 492 | case ARM::AK_IWMMXT2: |
| 493 | case ARM::AK_XSCALE: |
| 494 | case ARM::AK_ARMV5E: |
| 495 | case ARM::AK_ARMV5TEJ: |
| 496 | return 5; |
| 497 | case ARM::AK_ARMV6: |
| 498 | case ARM::AK_ARMV6J: |
| 499 | case ARM::AK_ARMV6K: |
| 500 | case ARM::AK_ARMV6T2: |
| 501 | case ARM::AK_ARMV6Z: |
| 502 | case ARM::AK_ARMV6ZK: |
| 503 | case ARM::AK_ARMV6M: |
| 504 | case ARM::AK_ARMV6SM: |
| 505 | case ARM::AK_ARMV6HL: |
| 506 | return 6; |
| 507 | case ARM::AK_ARMV7: |
| 508 | case ARM::AK_ARMV7A: |
| 509 | case ARM::AK_ARMV7R: |
| 510 | case ARM::AK_ARMV7M: |
| 511 | case ARM::AK_ARMV7L: |
| 512 | case ARM::AK_ARMV7HL: |
| 513 | case ARM::AK_ARMV7S: |
| 514 | case ARM::AK_ARMV7EM: |
Vedant Kumar | 366dd9fd | 2015-08-21 21:52:48 +0000 | [diff] [blame] | 515 | case ARM::AK_ARMV7K: |
Renato Golin | fadc210 | 2015-05-22 18:17:55 +0000 | [diff] [blame] | 516 | return 7; |
| 517 | case ARM::AK_ARMV8A: |
| 518 | case ARM::AK_ARMV8_1A: |
| 519 | return 8; |
| 520 | } |
| 521 | return 0; |
| 522 | } |