diff options
Diffstat (limited to 'contrib/llvm/lib/Support/Triple.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/Triple.cpp | 209 |
1 files changed, 157 insertions, 52 deletions
diff --git a/contrib/llvm/lib/Support/Triple.cpp b/contrib/llvm/lib/Support/Triple.cpp index c6646fb..3bb1116 100644 --- a/contrib/llvm/lib/Support/Triple.cpp +++ b/contrib/llvm/lib/Support/Triple.cpp @@ -25,6 +25,7 @@ const char *Triple::getArchTypeName(ArchType Kind) { case aarch64_be: return "aarch64_be"; case arm: return "arm"; case armeb: return "armeb"; + case avr: return "avr"; case bpfel: return "bpfel"; case bpfeb: return "bpfeb"; case hexagon: return "hexagon"; @@ -80,6 +81,8 @@ const char *Triple::getArchTypePrefix(ArchType Kind) { case thumb: case thumbeb: return "arm"; + case avr: return "avr"; + case ppc64: case ppc64le: case ppc: return "ppc"; @@ -124,8 +127,8 @@ const char *Triple::getArchTypePrefix(ArchType Kind) { case spir64: return "spir"; case kalimba: return "kalimba"; case shave: return "shave"; - case wasm32: return "wasm32"; - case wasm64: return "wasm64"; + case wasm32: + case wasm64: return "wasm"; } } @@ -144,6 +147,7 @@ const char *Triple::getVendorTypeName(VendorType Kind) { case MipsTechnologies: return "mti"; case NVIDIA: return "nvidia"; case CSR: return "csr"; + case Myriad: return "myriad"; } llvm_unreachable("Invalid VendorType!"); @@ -177,6 +181,9 @@ const char *Triple::getOSTypeName(OSType Kind) { case NVCL: return "nvcl"; case AMDHSA: return "amdhsa"; case PS4: return "ps4"; + case ELFIAMCU: return "elfiamcu"; + case TvOS: return "tvos"; + case WatchOS: return "watchos"; } llvm_unreachable("Invalid OSType"); @@ -196,6 +203,8 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) { case MSVC: return "msvc"; case Itanium: return "itanium"; case Cygnus: return "cygnus"; + case AMDOpenCL: return "amdopencl"; + case CoreCLR: return "coreclr"; } llvm_unreachable("Invalid EnvironmentType!"); @@ -224,6 +233,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { .Case("arm64", aarch64) // "arm64" is an alias for "aarch64" .Case("arm", arm) .Case("armeb", armeb) + .Case("avr", avr) .StartsWith("bpf", BPFArch) .Case("mips", mips) .Case("mipsel", mipsel) @@ -265,8 +275,8 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { } static Triple::ArchType parseARMArch(StringRef ArchName) { - unsigned ISA = ARMTargetParser::parseArchISA(ArchName); - unsigned ENDIAN = ARMTargetParser::parseArchEndian(ArchName); + unsigned ISA = ARM::parseArchISA(ArchName); + unsigned ENDIAN = ARM::parseArchEndian(ArchName); Triple::ArchType arch = Triple::UnknownArch; switch (ENDIAN) { @@ -300,7 +310,7 @@ static Triple::ArchType parseARMArch(StringRef ArchName) { } } - ArchName = ARMTargetParser::getCanonicalArchName(ArchName); + ArchName = ARM::getCanonicalArchName(ArchName); if (ArchName.empty()) return Triple::UnknownArch; @@ -310,8 +320,8 @@ static Triple::ArchType parseARMArch(StringRef ArchName) { return Triple::UnknownArch; // Thumb only for v6m - unsigned Profile = ARMTargetParser::parseArchProfile(ArchName); - unsigned Version = ARMTargetParser::parseArchVersion(ArchName); + unsigned Profile = ARM::parseArchProfile(ArchName); + unsigned Version = ARM::parseArchVersion(ArchName); if (Profile == ARM::PK_M && Version == 6) { if (ENDIAN == ARM::EK_BIG) return Triple::thumbeb; @@ -323,10 +333,7 @@ static Triple::ArchType parseARMArch(StringRef ArchName) { } static Triple::ArchType parseArch(StringRef ArchName) { - Triple::ArchType ARMArch(parseARMArch(ArchName)); - Triple::ArchType BPFArch(parseBPFArch(ArchName)); - - return StringSwitch<Triple::ArchType>(ArchName) + auto AT = StringSwitch<Triple::ArchType>(ArchName) .Cases("i386", "i486", "i586", "i686", Triple::x86) // FIXME: Do we need to support these? .Cases("i786", "i886", "i986", Triple::x86) @@ -336,9 +343,14 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("powerpc64le", Triple::ppc64le) .Case("xscale", Triple::arm) .Case("xscaleeb", Triple::armeb) - .StartsWith("arm", ARMArch) - .StartsWith("thumb", ARMArch) - .StartsWith("aarch64", ARMArch) + .Case("aarch64", Triple::aarch64) + .Case("aarch64_be", Triple::aarch64_be) + .Case("arm64", Triple::aarch64) + .Case("arm", Triple::arm) + .Case("armeb", Triple::armeb) + .Case("thumb", Triple::thumb) + .Case("thumbeb", Triple::thumbeb) + .Case("avr", Triple::avr) .Case("msp430", Triple::msp430) .Cases("mips", "mipseb", "mipsallegrex", Triple::mips) .Cases("mipsel", "mipsallegrexel", Triple::mipsel) @@ -346,7 +358,6 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("mips64el", Triple::mips64el) .Case("r600", Triple::r600) .Case("amdgcn", Triple::amdgcn) - .StartsWith("bpf", BPFArch) .Case("hexagon", Triple::hexagon) .Case("s390x", Triple::systemz) .Case("sparc", Triple::sparc) @@ -369,6 +380,18 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("wasm32", Triple::wasm32) .Case("wasm64", Triple::wasm64) .Default(Triple::UnknownArch); + + // Some architectures require special parsing logic just to compute the + // ArchType result. + if (AT == Triple::UnknownArch) { + if (ArchName.startswith("arm") || ArchName.startswith("thumb") || + ArchName.startswith("aarch64")) + return parseARMArch(ArchName); + if (ArchName.startswith("bpf")) + return parseBPFArch(ArchName); + } + + return AT; } static Triple::VendorType parseVendor(StringRef VendorName) { @@ -384,6 +407,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { .Case("mti", Triple::MipsTechnologies) .Case("nvidia", Triple::NVIDIA) .Case("csr", Triple::CSR) + .Case("myriad", Triple::Myriad) .Default(Triple::UnknownVendor); } @@ -414,6 +438,9 @@ static Triple::OSType parseOS(StringRef OSName) { .StartsWith("nvcl", Triple::NVCL) .StartsWith("amdhsa", Triple::AMDHSA) .StartsWith("ps4", Triple::PS4) + .StartsWith("elfiamcu", Triple::ELFIAMCU) + .StartsWith("tvos", Triple::TvOS) + .StartsWith("watchos", Triple::WatchOS) .Default(Triple::UnknownOS); } @@ -430,6 +457,8 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { .StartsWith("msvc", Triple::MSVC) .StartsWith("itanium", Triple::Itanium) .StartsWith("cygnus", Triple::Cygnus) + .StartsWith("amdopencl", Triple::AMDOpenCL) + .StartsWith("coreclr", Triple::CoreCLR) .Default(Triple::UnknownEnvironment); } @@ -442,7 +471,7 @@ static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) { } static Triple::SubArchType parseSubArch(StringRef SubArchName) { - StringRef ARMSubArch = ARMTargetParser::getCanonicalArchName(SubArchName); + StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName); // For now, this is the small part. Early return. if (ARMSubArch.empty()) @@ -453,14 +482,12 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) { .Default(Triple::NoSubArch); // ARM sub arch. - switch(ARMTargetParser::parseArch(ARMSubArch)) { + switch(ARM::parseArch(ARMSubArch)) { case ARM::AK_ARMV4: return Triple::NoSubArch; case ARM::AK_ARMV4T: return Triple::ARMSubArch_v4t; - case ARM::AK_ARMV5: case ARM::AK_ARMV5T: - case ARM::AK_ARMV5E: return Triple::ARMSubArch_v5; case ARM::AK_ARMV5TE: case ARM::AK_IWMMXT: @@ -469,24 +496,19 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) { case ARM::AK_ARMV5TEJ: return Triple::ARMSubArch_v5te; case ARM::AK_ARMV6: - case ARM::AK_ARMV6J: - case ARM::AK_ARMV6Z: return Triple::ARMSubArch_v6; case ARM::AK_ARMV6K: - case ARM::AK_ARMV6ZK: - case ARM::AK_ARMV6HL: + case ARM::AK_ARMV6KZ: return Triple::ARMSubArch_v6k; case ARM::AK_ARMV6T2: return Triple::ARMSubArch_v6t2; case ARM::AK_ARMV6M: - case ARM::AK_ARMV6SM: return Triple::ARMSubArch_v6m; - case ARM::AK_ARMV7: case ARM::AK_ARMV7A: case ARM::AK_ARMV7R: - case ARM::AK_ARMV7L: - case ARM::AK_ARMV7HL: return Triple::ARMSubArch_v7; + case ARM::AK_ARMV7K: + return Triple::ARMSubArch_v7k; case ARM::AK_ARMV7M: return Triple::ARMSubArch_v7m; case ARM::AK_ARMV7S: @@ -497,6 +519,8 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) { return Triple::ARMSubArch_v8; case ARM::AK_ARMV8_1A: return Triple::ARMSubArch_v8_1a; + case ARM::AK_ARMV8_2A: + return Triple::ARMSubArch_v8_2a; default: return Triple::NoSubArch; } @@ -514,20 +538,53 @@ static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) { static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { switch (T.getArch()) { - default: - break; + case Triple::UnknownArch: + case Triple::aarch64: + case Triple::arm: + case Triple::thumb: + case Triple::x86: + case Triple::x86_64: + if (T.isOSDarwin()) + return Triple::MachO; + else if (T.isOSWindows()) + return Triple::COFF; + return Triple::ELF; + + case Triple::aarch64_be: + case Triple::amdgcn: + case Triple::amdil: + case Triple::amdil64: + case Triple::armeb: + case Triple::avr: + case Triple::bpfeb: + case Triple::bpfel: case Triple::hexagon: + case Triple::hsail: + case Triple::hsail64: + case Triple::kalimba: + case Triple::le32: + case Triple::le64: case Triple::mips: - case Triple::mipsel: case Triple::mips64: case Triple::mips64el: + case Triple::mipsel: + case Triple::msp430: + case Triple::nvptx: + case Triple::nvptx64: + case Triple::ppc64le: case Triple::r600: - case Triple::amdgcn: + case Triple::shave: case Triple::sparc: + case Triple::sparcel: case Triple::sparcv9: + case Triple::spir: + case Triple::spir64: case Triple::systemz: + case Triple::tce: + case Triple::thumbeb: + case Triple::wasm32: + case Triple::wasm64: case Triple::xcore: - case Triple::ppc64le: return Triple::ELF; case Triple::ppc: @@ -536,12 +593,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { return Triple::MachO; return Triple::ELF; } - - if (T.isOSDarwin()) - return Triple::MachO; - else if (T.isOSWindows()) - return Triple::COFF; - return Triple::ELF; + llvm_unreachable("unknown architecture"); } /// \brief Construct a triple from the string representation provided. @@ -549,14 +601,27 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { /// This stores the string representation and parses the various pieces into /// enum members. Triple::Triple(const Twine &Str) - : Data(Str.str()), - Arch(parseArch(getArchName())), - SubArch(parseSubArch(getArchName())), - Vendor(parseVendor(getVendorName())), - OS(parseOS(getOSName())), - Environment(parseEnvironment(getEnvironmentName())), - ObjectFormat(parseFormat(getEnvironmentName())) { - if (ObjectFormat == Triple::UnknownObjectFormat) + : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch), + Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment), + ObjectFormat(UnknownObjectFormat) { + // Do minimal parsing by hand here. + SmallVector<StringRef, 4> Components; + StringRef(Data).split(Components, '-', /*MaxSplit*/ 3); + if (Components.size() > 0) { + Arch = parseArch(Components[0]); + SubArch = parseSubArch(Components[0]); + if (Components.size() > 1) { + Vendor = parseVendor(Components[1]); + if (Components.size() > 2) { + OS = parseOS(Components[2]); + if (Components.size() > 3) { + Environment = parseEnvironment(Components[3]); + ObjectFormat = parseFormat(Components[3]); + } + } + } + } + if (ObjectFormat == UnknownObjectFormat) ObjectFormat = getDefaultFormat(*this); } @@ -601,7 +666,7 @@ std::string Triple::normalize(StringRef Str) { // Parse into components. SmallVector<StringRef, 4> Components; - Str.split(Components, "-"); + Str.split(Components, '-'); // If the first component corresponds to a known architecture, preferentially // use it for the architecture. If the second component corresponds to a @@ -889,6 +954,8 @@ bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor, return false; break; case IOS: + case TvOS: + case WatchOS: // Ignore the version from the triple. This is only handled because the // the clang driver combines OS X and IOS support into a common Darwin // toolchain that wants to know the OS X version number even when targeting @@ -916,11 +983,38 @@ void Triple::getiOSVersion(unsigned &Major, unsigned &Minor, Micro = 0; break; case IOS: + case TvOS: getOSVersion(Major, Minor, Micro); // Default to 5.0 (or 7.0 for arm64). if (Major == 0) Major = (getArch() == aarch64) ? 7 : 5; break; + case WatchOS: + llvm_unreachable("conflicting triple info"); + } +} + +void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor, + unsigned &Micro) const { + switch (getOS()) { + default: llvm_unreachable("unexpected OS for Darwin triple"); + case Darwin: + case MacOSX: + // Ignore the version from the triple. This is only handled because the + // the clang driver combines OS X and IOS support into a common Darwin + // toolchain that wants to know the iOS version number even when targeting + // OS X. + Major = 2; + Minor = 0; + Micro = 0; + break; + case WatchOS: + getOSVersion(Major, Minor, Micro); + if (Major == 0) + Major = 2; + break; + case IOS: + llvm_unreachable("conflicting triple info"); } } @@ -993,6 +1087,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { case llvm::Triple::UnknownArch: return 0; + case llvm::Triple::avr: case llvm::Triple::msp430: return 16; @@ -1062,6 +1157,7 @@ Triple Triple::get32BitArchVariant() const { case Triple::aarch64: case Triple::aarch64_be: case Triple::amdgcn: + case Triple::avr: case Triple::bpfel: case Triple::bpfeb: case Triple::msp430: @@ -1116,6 +1212,7 @@ Triple Triple::get64BitArchVariant() const { case Triple::UnknownArch: case Triple::arm: case Triple::armeb: + case Triple::avr: case Triple::hexagon: case Triple::kalimba: case Triple::msp430: @@ -1172,6 +1269,7 @@ Triple Triple::getBigEndianArchVariant() const { case Triple::amdgcn: case Triple::amdil64: case Triple::amdil: + case Triple::avr: case Triple::hexagon: case Triple::hsail64: case Triple::hsail: @@ -1244,6 +1342,7 @@ Triple Triple::getLittleEndianArchVariant() const { case Triple::amdil64: case Triple::amdil: case Triple::arm: + case Triple::avr: case Triple::bpfel: case Triple::hexagon: case Triple::hsail64: @@ -1281,10 +1380,10 @@ Triple Triple::getLittleEndianArchVariant() const { return T; } -const char *Triple::getARMCPUForArch(StringRef MArch) const { +StringRef Triple::getARMCPUForArch(StringRef MArch) const { if (MArch.empty()) MArch = getArchName(); - MArch = ARMTargetParser::getCanonicalArchName(MArch); + MArch = ARM::getCanonicalArchName(MArch); // Some defaults are forced. switch (getOS()) { @@ -1296,15 +1395,21 @@ const char *Triple::getARMCPUForArch(StringRef MArch) const { case llvm::Triple::Win32: // FIXME: this is invalid for WindowsCE return "cortex-a9"; + case llvm::Triple::MacOSX: + case llvm::Triple::IOS: + case llvm::Triple::WatchOS: + if (MArch == "v7k") + return "cortex-a7"; + break; default: break; } if (MArch.empty()) - return nullptr; + return StringRef(); - const char *CPU = ARMTargetParser::getDefaultCPU(MArch); - if (CPU) + StringRef CPU = ARM::getDefaultCPU(MArch); + if (!CPU.empty()) return CPU; // If no specific architecture version is requested, return the minimum CPU |