Index: include/llvm/ADT/Triple.h =================================================================== --- include/llvm/ADT/Triple.h +++ include/llvm/ADT/Triple.h @@ -621,6 +621,30 @@ /// Tests whether the target is Android bool isAndroid() const { return getEnvironment() == Triple::Android; } + /// Tests whether the target is an EABI variant + bool isEABI() const { + return getEnvironment() == Triple::GNUEABI || + getEnvironment() == Triple::GNUEABIHF || + getEnvironment() == Triple::EABI || + getEnvironment() == Triple::EABIHF || + getEnvironment() == Triple::MuslEABI || + getEnvironment() == Triple::MuslEABIHF; + } + + /// Tests whether the target is a hard-float EABI variant + bool isHardFloatEABI() const { + return getEnvironment() == Triple::GNUEABIHF || + getEnvironment() == Triple::EABIHF || + getEnvironment() == Triple::MuslEABIHF; + } + + /// Tests whether the target is a soft-float EABI variant + bool isSoftFloatEABI() const { + return getEnvironment() == Triple::GNUEABI || + getEnvironment() == Triple::EABI || + getEnvironment() == Triple::MuslEABI; + } + bool isAndroidVersionLT(unsigned Major) const { assert(isAndroid() && "Not an Android triple!"); @@ -752,6 +776,24 @@ /// architecture if no such variant can be found. llvm::Triple get64BitArchVariant() const; + /// Form a triple with a hard-float variant of the current architecture. + /// + /// This can be used to move across "families" of architectures where useful. + /// + /// \returns A new triple with a hard float variant of the current + /// architecture or an unknown architecture if no such variant + /// can be found. + llvm::Triple getHardFloatArchVariant() const; + + /// Form a triple with a soft-float variant of the current architecture. + /// + /// This can be used to move across "families" of architectures where useful. + /// + /// \returns A new triple with a soft float variant of the current + /// architecture or an unknown architecture if no such variant + /// can be found. + llvm::Triple getSoftFloatArchVariant() const; + /// Form a triple with a big endian variant of the current architecture. /// /// This can be used to move across "families" of architectures where useful. Index: lib/Support/Triple.cpp =================================================================== --- lib/Support/Triple.cpp +++ lib/Support/Triple.cpp @@ -1390,6 +1390,65 @@ return T; } +Triple Triple::getHardFloatArchVariant() const { + Triple T(*this); + // A few architectures are guaranteed to *always* be hard-float. + switch (getArch()) { + case Triple::aarch64: + case Triple::aarch64_be: + case Triple::sparcv9: + case Triple::x86_64: + // Always hard-float + return T; + } + + // Hard-float vs soft-float triples are normally distinguished by + // environment rather than architecture (i.e. GNUEABI vs GNUEABIHF). + switch (getEnvironment()) { + case Triple::EABIHF: + case Triple::GNUEABIHF: + case Triple::MuslEABIHF: + // Already hard-float. + break; + case Triple::EABI: T.setEnvironment(Triple::EABIHF); break; + case Triple::GNUEABI: T.setEnvironment(Triple::GNUEABIHF); break; + case Triple::MuslEABI: T.setEnvironment(Triple::MuslEABIHF); break; + default: + T.setArch(UnknownArch); + } + return T; +} + +Triple Triple::getSoftFloatArchVariant() const { + Triple T(*this); + // A few architectures are guaranteed to *always* be hard-float. + switch (getArch()) { + case Triple::aarch64: + case Triple::aarch64_be: + case Triple::sparcv9: + case Triple::x86_64: + // No soft-float variant. + T.setArch(UnknownArch); + return T; + } + + // Hard-float vs soft-float triples are normally distinguished by + // environment rather than architecture (i.e. GNUEABI vs GNUEABIHF). + switch (getEnvironment()) { + case Triple::EABI: + case Triple::GNUEABI: + case Triple::MuslEABI: + // Already soft-float. + break; + case Triple::EABIHF: T.setEnvironment(Triple::EABI); break; + case Triple::GNUEABIHF: T.setEnvironment(Triple::GNUEABI); break; + case Triple::MuslEABIHF: T.setEnvironment(Triple::MuslEABI); break; + default: + T.setArch(UnknownArch); + } + return T; +} + Triple Triple::getBigEndianArchVariant() const { Triple T(*this); // Already big endian.