diff options
Diffstat (limited to 'contrib/llvm/lib/Support/TargetParser.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/TargetParser.cpp | 130 |
1 files changed, 68 insertions, 62 deletions
diff --git a/contrib/llvm/lib/Support/TargetParser.cpp b/contrib/llvm/lib/Support/TargetParser.cpp index c3f8613..42fab67 100644 --- a/contrib/llvm/lib/Support/TargetParser.cpp +++ b/contrib/llvm/lib/Support/TargetParser.cpp @@ -52,7 +52,7 @@ static const struct { // of the triples and are not conforming with their official names. // Check to see if the expectation should be changed. // FIXME: TableGen this. -static const struct { +template <typename T> struct ArchNames { const char *NameCStr; size_t NameLength; const char *CPUAttrCStr; @@ -61,7 +61,7 @@ static const struct { size_t SubArchLength; unsigned DefaultFPU; unsigned ArchBaseExtensions; - ARM::ArchKind ID; + T ID; ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes. StringRef getName() const { return StringRef(NameCStr, NameLength); } @@ -71,18 +71,22 @@ static const struct { // Sub-Arch name. StringRef getSubArch() const { return StringRef(SubArchCStr, SubArchLength); } -} ARCHNames[] = { +}; +ArchNames<ARM::ArchKind> ARCHNames[] = { #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \ {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH, \ sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR}, #include "llvm/Support/ARMTargetParser.def" -},AArch64ARCHNames[] = { -#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \ - {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH, \ - sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR}, -#include "llvm/Support/AArch64TargetParser.def" }; +ArchNames<AArch64::ArchKind> AArch64ARCHNames[] = { + #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \ + {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH, \ + sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, AArch64::ArchKind::ID, ARCH_ATTR}, + #include "llvm/Support/AArch64TargetParser.def" + }; + + // List of Arch Extension names. // FIXME: TableGen this. static const struct { @@ -122,24 +126,27 @@ static const struct { // When finding the Arch for a CPU, first-found prevails. Sort them accordingly. // When this becomes table-generated, we'd probably need two tables. // FIXME: TableGen this. -static const struct { +template <typename T> struct CpuNames { const char *NameCStr; size_t NameLength; - ARM::ArchKind ArchID; + T ArchID; bool Default; // is $Name the default CPU for $ArchID ? unsigned DefaultExtensions; StringRef getName() const { return StringRef(NameCStr, NameLength); } -} CPUNames[] = { +}; +CpuNames<ARM::ArchKind> CPUNames[] = { #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT }, #include "llvm/Support/ARMTargetParser.def" -},AArch64CPUNames[] = { -#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ - { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT }, -#include "llvm/Support/AArch64TargetParser.def" }; +CpuNames<AArch64::ArchKind> AArch64CPUNames[] = { + #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ + { NAME, sizeof(NAME) - 1, AArch64::ArchKind::ID, IS_DEFAULT, DEFAULT_EXT }, + #include "llvm/Support/AArch64TargetParser.def" + }; + } // namespace // ======================================================= // @@ -193,7 +200,7 @@ unsigned llvm::ARM::getDefaultExtensions(StringRef CPU, unsigned ArchKind) { } bool llvm::ARM::getHWDivFeatures(unsigned HWDivKind, - std::vector<const char *> &Features) { + std::vector<StringRef> &Features) { if (HWDivKind == ARM::AEK_INVALID) return false; @@ -212,7 +219,7 @@ bool llvm::ARM::getHWDivFeatures(unsigned HWDivKind, } bool llvm::ARM::getExtensionFeatures(unsigned Extensions, - std::vector<const char *> &Features) { + std::vector<StringRef> &Features) { if (Extensions == ARM::AEK_INVALID) return false; @@ -231,7 +238,7 @@ bool llvm::ARM::getExtensionFeatures(unsigned Extensions, } bool llvm::ARM::getFPUFeatures(unsigned FPUKind, - std::vector<const char *> &Features) { + std::vector<StringRef> &Features) { if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID) return false; @@ -344,20 +351,20 @@ StringRef llvm::ARM::getArchExtName(unsigned ArchExtKind) { return StringRef(); } -const char *llvm::ARM::getArchExtFeature(StringRef ArchExt) { +StringRef llvm::ARM::getArchExtFeature(StringRef ArchExt) { if (ArchExt.startswith("no")) { StringRef ArchExtBase(ArchExt.substr(2)); for (const auto AE : ARCHExtNames) { if (AE.NegFeature && ArchExtBase == AE.getName()) - return AE.NegFeature; + return StringRef(AE.NegFeature); } } for (const auto AE : ARCHExtNames) { if (AE.Feature && ArchExt == AE.getName()) - return AE.Feature; + return StringRef(AE.Feature); } - return nullptr; + return StringRef(); } StringRef llvm::ARM::getHWDivName(unsigned HWDivKind) { @@ -416,13 +423,13 @@ unsigned llvm::AArch64::getDefaultExtensions(StringRef CPU, unsigned ArchKind) { return StringSwitch<unsigned>(CPU) #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ - .Case(NAME, AArch64ARCHNames[ID].ArchBaseExtensions | DEFAULT_EXT) + .Case(NAME, DEFAULT_EXT) #include "llvm/Support/AArch64TargetParser.def" .Default(AArch64::AEK_INVALID); } bool llvm::AArch64::getExtensionFeatures(unsigned Extensions, - std::vector<const char *> &Features) { + std::vector<StringRef> &Features) { if (Extensions == AArch64::AEK_INVALID) return false; @@ -446,81 +453,77 @@ bool llvm::AArch64::getExtensionFeatures(unsigned Extensions, } bool llvm::AArch64::getFPUFeatures(unsigned FPUKind, - std::vector<const char *> &Features) { + std::vector<StringRef> &Features) { return ARM::getFPUFeatures(FPUKind, Features); } bool llvm::AArch64::getArchFeatures(unsigned ArchKind, - std::vector<const char *> &Features) { - if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST) - return false; - - if (ArchKind == ARM::AK_ARMV8_1A) + std::vector<StringRef> &Features) { + if (ArchKind == static_cast<unsigned>(AArch64::ArchKind::AK_ARMV8_1A)) Features.push_back("+v8.1a"); - if (ArchKind == ARM::AK_ARMV8_2A) + if (ArchKind == static_cast<unsigned>(AArch64::ArchKind::AK_ARMV8_2A)) Features.push_back("+v8.2a"); - return true; + return ArchKind > static_cast<unsigned>(AArch64::ArchKind::AK_INVALID) && + ArchKind < static_cast<unsigned>(AArch64::ArchKind::AK_LAST); } StringRef llvm::AArch64::getArchName(unsigned ArchKind) { - for (const auto &AI : AArch64ARCHNames) - if (AI.ID == ArchKind) - return AI.getName(); - return StringRef(); + if (ArchKind >= static_cast<unsigned>(AArch64::ArchKind::AK_LAST)) + return StringRef(); + return AArch64ARCHNames[ArchKind].getName(); } StringRef llvm::AArch64::getCPUAttr(unsigned ArchKind) { - for (const auto &AI : AArch64ARCHNames) - if (AI.ID == ArchKind) - return AI.getCPUAttr(); - return StringRef(); + if (ArchKind == static_cast<unsigned>(AArch64::ArchKind::AK_INVALID) || + ArchKind >= static_cast<unsigned>(AArch64::ArchKind::AK_LAST)) + return StringRef(); + return AArch64ARCHNames[ArchKind].getCPUAttr(); } StringRef llvm::AArch64::getSubArch(unsigned ArchKind) { - for (const auto &AI : AArch64ARCHNames) - if (AI.ID == ArchKind) - return AI.getSubArch(); - return StringRef(); + if (ArchKind == static_cast<unsigned>(AArch64::ArchKind::AK_INVALID) || + ArchKind >= static_cast<unsigned>(AArch64::ArchKind::AK_LAST)) + return StringRef(); + return AArch64ARCHNames[ArchKind].getSubArch(); } unsigned llvm::AArch64::getArchAttr(unsigned ArchKind) { - for (const auto &AI : AArch64ARCHNames) - if (AI.ID == ArchKind) - return AI.ArchAttr; - return ARMBuildAttrs::CPUArch::v8_A; + if (ArchKind >= static_cast<unsigned>(AArch64::ArchKind::AK_LAST)) + return ARMBuildAttrs::CPUArch::v8_A; + return AArch64ARCHNames[ArchKind].ArchAttr; } -StringRef llvm::AArch64::getArchExtName(unsigned AArchExtKind) { +StringRef llvm::AArch64::getArchExtName(unsigned ArchExtKind) { for (const auto &AE : AArch64ARCHExtNames) - if (AArchExtKind == AE.ID) + if (ArchExtKind == AE.ID) return AE.getName(); return StringRef(); } -const char *llvm::AArch64::getArchExtFeature(StringRef ArchExt) { +StringRef llvm::AArch64::getArchExtFeature(StringRef ArchExt) { if (ArchExt.startswith("no")) { StringRef ArchExtBase(ArchExt.substr(2)); for (const auto &AE : AArch64ARCHExtNames) { if (AE.NegFeature && ArchExtBase == AE.getName()) - return AE.NegFeature; + return StringRef(AE.NegFeature); } } for (const auto &AE : AArch64ARCHExtNames) if (AE.Feature && ArchExt == AE.getName()) - return AE.Feature; - return nullptr; + return StringRef(AE.Feature); + return StringRef(); } StringRef llvm::AArch64::getDefaultCPU(StringRef Arch) { unsigned AK = parseArch(Arch); - if (AK == ARM::AK_INVALID) + if (AK == static_cast<unsigned>(AArch64::ArchKind::AK_INVALID)) return StringRef(); // Look for multiple AKs to find the default for pair AK+Name. for (const auto &CPU : AArch64CPUNames) - if (CPU.ArchID == AK && CPU.Default) + if (static_cast<unsigned>(CPU.ArchID) == AK && CPU.Default) return CPU.getName(); // If we can't find a default then target the architecture instead @@ -575,6 +578,7 @@ static StringRef getArchSynonym(StringRef Arch) { .Cases("v8", "v8a", "aarch64", "arm64", "v8-a") .Case("v8.1a", "v8.1-a") .Case("v8.2a", "v8.2-a") + .Case("v8r", "v8-r") .Case("v8m.base", "v8-m.base") .Case("v8m.main", "v8-m.main") .Default(Arch); @@ -685,7 +689,7 @@ unsigned llvm::ARM::parseArchISA(StringRef Arch) { .StartsWith("arm64", ARM::IK_AARCH64) .StartsWith("thumb", ARM::IK_THUMB) .StartsWith("arm", ARM::IK_ARM) - .Default(ARM::EK_INVALID); + .Default(ARM::IK_INVALID); } // Little/Big endian @@ -718,6 +722,7 @@ unsigned llvm::ARM::parseArchProfile(StringRef Arch) { case ARM::AK_ARMV8MBaseline: return ARM::PK_M; case ARM::AK_ARMV7R: + case ARM::AK_ARMV8R: return ARM::PK_R; case ARM::AK_ARMV7A: case ARM::AK_ARMV7K: @@ -765,6 +770,7 @@ unsigned llvm::ARM::parseArchVersion(StringRef Arch) { case ARM::AK_ARMV8A: case ARM::AK_ARMV8_1A: case ARM::AK_ARMV8_2A: + case ARM::AK_ARMV8R: case ARM::AK_ARMV8MBaseline: case ARM::AK_ARMV8MMainline: return 8; @@ -784,14 +790,14 @@ unsigned llvm::AArch64::parseFPU(StringRef FPU) { unsigned llvm::AArch64::parseArch(StringRef Arch) { Arch = getCanonicalArchName(Arch); if (checkArchVersion(Arch) < 8) - return ARM::AK_INVALID; + return static_cast<unsigned>(AArch64::ArchKind::AK_INVALID); StringRef Syn = getArchSynonym(Arch); for (const auto A : AArch64ARCHNames) { if (A.getName().endswith(Syn)) - return A.ID; + return static_cast<unsigned>(A.ID); } - return ARM::AK_INVALID; + return static_cast<unsigned>(AArch64::ArchKind::AK_INVALID); } unsigned llvm::AArch64::parseArchExt(StringRef ArchExt) { @@ -805,9 +811,9 @@ unsigned llvm::AArch64::parseArchExt(StringRef ArchExt) { unsigned llvm::AArch64::parseCPUArch(StringRef CPU) { for (const auto C : AArch64CPUNames) { if (CPU == C.getName()) - return C.ArchID; + return static_cast<unsigned>(C.ArchID); } - return ARM::AK_INVALID; + return static_cast<unsigned>(AArch64::ArchKind::AK_INVALID); } // ARM, Thumb, AArch64 |