diff --git a/clang/lib/AST/MicrosoftCXXABI.cpp b/clang/lib/AST/MicrosoftCXXABI.cpp --- a/clang/lib/AST/MicrosoftCXXABI.cpp +++ b/clang/lib/AST/MicrosoftCXXABI.cpp @@ -21,6 +21,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/AST/Type.h" #include "clang/Basic/TargetInfo.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace clang; @@ -315,7 +316,7 @@ // When MSVC does x86_32 record layout, it aligns aggregate member pointers to // 8 bytes. However, __alignof usually returns 4 for data memptrs and 8 for // function memptrs. - if (Ptrs + Ints > 1 && Target.getTriple().isArch32Bit()) + if (Ptrs + Ints > 1 && llvm::TripleUtils::isArch32Bit(Target.getTriple())) MPI.Align = 64; else if (Ptrs) MPI.Align = Target.getPointerAlign(LangAS::Default); diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -14,12 +14,13 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" -#include "clang/AST/VTableBuilder.h" #include "clang/AST/RecordLayout.h" +#include "clang/AST/VTableBuilder.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallSet.h" #include "llvm/Support/Format.h" #include "llvm/Support/MathExtras.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace clang; @@ -1624,7 +1625,8 @@ // as [unsigned]. StorageUnitSize = Context.getTypeSize(Context.UnsignedIntTy); } else if (StorageUnitSize > Context.getTypeSize(Context.UnsignedIntTy) && - Context.getTargetInfo().getTriple().isArch32Bit() && + llvm::TripleUtils::isArch32Bit( + Context.getTargetInfo().getTriple()) && FieldSize <= 32) { // Under 32-bit compile mode, the bitcontainer is 32 bits if a single // long long bitfield has length no greater than 32 bits. diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/TargetParser/TargetParser.h" +#include "llvm/TargetParser/TripleUtils.h" #include using namespace clang; @@ -102,7 +103,9 @@ // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems. if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid() || T.isOHOSFamily()) - NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0; + NewAlign = Triple.isArch64Bit() ? 128 + : llvm::TripleUtils::isArch32Bit(Triple) ? 64 + : 0; else if (T.isOSDarwin() || T.isOSOpenBSD()) NewAlign = 128; else diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/TargetParser/AArch64TargetParser.h" #include "llvm/TargetParser/ARMTargetParserCommon.h" +#include "llvm/TargetParser/TripleUtils.h" #include using namespace clang; @@ -1374,7 +1375,7 @@ void AArch64leTargetInfo::setDataLayout() { if (getTriple().isOSBinFormatMachO()) { - if(getTriple().isArch32Bit()) + if (llvm::TripleUtils::isArch32Bit(getTriple())) resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_"); else resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_"); @@ -1500,7 +1501,7 @@ const TargetOptions &Opts) : DarwinTargetInfo(Triple, Opts) { Int64Type = SignedLongLong; - if (getTriple().isArch32Bit()) + if (llvm::TripleUtils::isArch32Bit(getTriple())) IntMaxType = SignedLongLong; WCharType = SignedInt; @@ -1511,7 +1512,7 @@ UseZeroLengthBitfieldAlignment = false; - if (getTriple().isArch32Bit()) { + if (llvm::TripleUtils::isArch32Bit(getTriple())) { UseBitFieldTypeAlignment = false; ZeroLengthBitfieldBoundary = 32; UseZeroLengthBitfieldAlignment = true; @@ -1524,7 +1525,7 @@ const llvm::Triple &Triple, MacroBuilder &Builder) const { Builder.defineMacro("__AARCH64_SIMD__"); - if (Triple.isArch32Bit()) + if (llvm::TripleUtils::isArch32Bit(Triple)) Builder.defineMacro("__ARM64_ARCH_8_32__"); else Builder.defineMacro("__ARM64_ARCH_8__"); diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -13,6 +13,7 @@ #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H #include "Targets.h" +#include "llvm/TargetParser/TripleUtils.h" namespace clang { namespace targets { @@ -91,7 +92,7 @@ // 32-bit simulator from 10 onwards. if (Triple.isArch64Bit()) this->TLSSupported = !Triple.isOSVersionLT(8); - else if (Triple.isArch32Bit()) { + else if (llvm::TripleUtils::isArch32Bit(Triple)) { if (!Triple.isSimulatorEnvironment()) this->TLSSupported = !Triple.isOSVersionLT(9); else diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -16,6 +16,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/Path.h" +#include "llvm/TargetParser/TripleUtils.h" using AIX = clang::driver::toolchains::AIX; using namespace clang::driver; @@ -32,7 +33,8 @@ const char *LinkingOutput) const { ArgStringList CmdArgs; - const bool IsArch32Bit = getToolChain().getTriple().isArch32Bit(); + const bool IsArch32Bit = + llvm::TripleUtils::isArch32Bit(getToolChain().getTriple()); const bool IsArch64Bit = getToolChain().getTriple().isArch64Bit(); // Only support 32 and 64 bit. if (!IsArch32Bit && !IsArch64Bit) @@ -107,7 +109,8 @@ const Driver &D = ToolChain.getDriver(); ArgStringList CmdArgs; - const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit(); + const bool IsArch32Bit = + llvm::TripleUtils::isArch32Bit(ToolChain.getTriple()); const bool IsArch64Bit = ToolChain.getTriple().isArch64Bit(); // Only support 32 and 64 bit. if (!(IsArch32Bit || IsArch64Bit)) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/TargetParser/TargetParser.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include // ::getenv using namespace clang::driver; @@ -2285,7 +2286,7 @@ } // For 32-bit targets, the deployment target for iOS has to be earlier than // iOS 11. - if (getTriple().isArch32Bit() && Major >= 11) { + if (llvm::TripleUtils::isArch32Bit(getTriple()) && Major >= 11) { // If the deployment target is explicitly specified, print a diagnostic. if (OSTarget->isExplicitlySpecified()) { if (OSTarget->getEnvironment() == MacCatalyst) diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -18,6 +18,7 @@ #include "clang/Driver/SanitizerArgs.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -376,7 +377,7 @@ // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall // back to '/usr/lib' if it doesn't exist. - if (Triple.isArch32Bit() && + if (llvm::TripleUtils::isArch32Bit(Triple) && D.getVFS().exists(concat(getDriver().SysRoot, "/usr/lib32/crt1.o"))) getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib32")); else diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h --- a/clang/lib/Driver/ToolChains/Gnu.h +++ b/clang/lib/Driver/ToolChains/Gnu.h @@ -14,6 +14,7 @@ #include "ROCm.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" +#include "llvm/TargetParser/TripleUtils.h" #include namespace clang { @@ -319,7 +320,9 @@ bool isTarget64Bit() const { return getTriple().isArch64Bit(); } /// Check whether the target triple's architecture is 32-bits. - bool isTarget32Bit() const { return getTriple().isArch32Bit(); } + bool isTarget32Bit() const { + return llvm::TripleUtils::isArch32Bit(getTriple()); + } void PushPPaths(ToolChain::path_list &PPaths); void AddMultilibPaths(const Driver &D, const std::string &SysRoot, diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -1889,9 +1889,9 @@ // Also handle cases such as 64 on 32, 32 on 64, etc. enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; const bool IsX32 = TargetTriple.isX32(); - if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) + if (llvm::TripleUtils::isArch32Bit(TargetTriple) && !NonExistent(Alt32)) Want = WANT64; - if (TargetTriple.isArch32Bit() && !NonExistent(Alt32sparc)) + if (llvm::TripleUtils::isArch32Bit(TargetTriple) && !NonExistent(Alt32sparc)) Want = WANT64; else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) Want = WANT64; @@ -1900,7 +1900,7 @@ else if (TargetTriple.isArch64Bit() && !NonExistent(Alt32sparc)) Want = WANT64; else { - if (TargetTriple.isArch32Bit()) + if (llvm::TripleUtils::isArch32Bit(TargetTriple)) Want = NeedsBiarchSuffix ? WANT64 : WANT32; else if (IsX32) Want = NeedsBiarchSuffix ? WANT64 : WANTX32; @@ -1935,7 +1935,7 @@ Multilib::flags_list Flags; addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "-m64", Flags); - addMultilibFlag(TargetTriple.isArch32Bit(), "-m32", Flags); + addMultilibFlag(llvm::TripleUtils::isArch32Bit(TargetTriple), "-m32", Flags); addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "-mx32", Flags); if (!Result.Multilibs.select(Flags, Result.SelectedMultilibs)) @@ -2073,9 +2073,10 @@ void Generic_GCC::GCCInstallationDetector::init( const llvm::Triple &TargetTriple, const ArgList &Args, ArrayRef ExtraTripleAliases) { - llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() - ? TargetTriple.get64BitArchVariant() - : TargetTriple.get32BitArchVariant(); + llvm::Triple BiarchVariantTriple = + llvm::TripleUtils::isArch32Bit(TargetTriple) + ? TargetTriple.get64BitArchVariant() + : TargetTriple.get32BitArchVariant(); // The library directories which may contain GCC installations. SmallVector CandidateLibDirs, CandidateBiarchLibDirs; // The compatible GCC triples for this particular architecture. diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp --- a/clang/lib/Driver/ToolChains/Hurd.cpp +++ b/clang/lib/Driver/ToolChains/Hurd.cpp @@ -13,6 +13,7 @@ #include "clang/Driver/Options.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,7 +59,7 @@ if (Triple.getArch() == llvm::Triple::x86) return "lib32"; - return Triple.isArch32Bit() ? "lib" : "lib64"; + return llvm::TripleUtils::isArch32Bit(Triple) ? "lib" : "lib64"; } Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/TripleUtils.h" #include using namespace clang::driver; @@ -184,7 +185,7 @@ // code for N32 ABI only. if (tools::mips::hasMipsAbiArg(Args, "n32")) return "lib32"; - return Triple.isArch32Bit() ? "lib" : "lib64"; + return llvm::TripleUtils::isArch32Bit(Triple) ? "lib" : "lib64"; } // It happens that only x86, PPC and SPARC use the 'lib32' variant of @@ -206,7 +207,7 @@ if (Triple.getArch() == llvm::Triple::riscv32) return "lib32"; - return Triple.isArch32Bit() ? "lib" : "lib64"; + return llvm::TripleUtils::isArch32Bit(Triple) ? "lib" : "lib64"; } Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -173,7 +174,7 @@ const llvm::opt::ArgList &Args) : ToolChain(D, Triple, Args) { - assert(Triple.isArch32Bit() != Triple.isArch64Bit()); + assert(llvm::TripleUtils::isArch32Bit(Triple) != Triple.isArch64Bit()); getProgramPaths().push_back(getDriver().getInstalledDir()); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -87,6 +87,7 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include #include #include @@ -3843,9 +3844,9 @@ if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) { enum ArchPtrSize { Arch16Bit, Arch32Bit, Arch64Bit }; auto getArchPtrSize = [](const llvm::Triple &T) { - if (T.isArch16Bit()) + if (llvm::TripleUtils::isArch16Bit(T)) return Arch16Bit; - if (T.isArch32Bit()) + if (llvm::TripleUtils::isArch32Bit(T)) return Arch32Bit; assert(T.isArch64Bit() && "Expected 64-bit architecture"); return Arch64Bit; diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -453,12 +453,16 @@ /// Test whether the architecture is 32-bit /// /// Note that this tests for 32-bit pointer width, and nothing else. - bool isArch32Bit() const; + [[deprecated("Use TripleUtils::isArch32Bit(const llvm::Triple& tripleImpl) " + "instead.")]] bool + isArch32Bit() const; /// Test whether the architecture is 16-bit /// /// Note that this tests for 16-bit pointer width, and nothing else. - bool isArch16Bit() const; + [[deprecated("Use TripleUtils::isArch16Bit(const llvm::Triple& tripleImpl) " + "instead.")]] bool + isArch16Bit() const; /// Helper function for doing comparisons against version numbers included in /// the target triple. diff --git a/llvm/include/llvm/TargetParser/TripleUtils.h b/llvm/include/llvm/TargetParser/TripleUtils.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/TargetParser/TripleUtils.h @@ -0,0 +1,30 @@ +//===-- llvm/TargetParser/TripleUtils.h - Triple Utils class--*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TARGETPARSER_TRIPLE_UTILS_H +#define LLVM_TARGETPARSER_TRIPLE_UTILS_H + +#include "llvm/TargetParser/Triple.h" +#include + +namespace llvm { + +class TripleUtils { +public: + /// Test whether the architecture is 16-bit + /// + /// Note that this tests for 16-bit pointer width, and nothing else. + + static bool isArch16Bit(const llvm::Triple &tripleImpl); + + static bool isArch32Bit(const llvm::Triple &tripleImpl); +}; + +} // namespace llvm + +#endif \ No newline at end of file diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -15,6 +15,7 @@ #include "llvm/InitializePasses.h" #include "llvm/Support/CommandLine.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace llvm; static cl::opt ClVectorLibrary( @@ -184,7 +185,7 @@ // Let's assume by default that the size of int is 32 bits, unless the target // is a 16-bit architecture because then it most likely is 16 bits. If that // isn't true for a target those defaults should be overridden below. - TLI.setIntSize(T.isArch16Bit() ? 16 : 32); + TLI.setIntSize(llvm::TripleUtils::isArch16Bit(T) ? 16 : 32); // There is really no runtime library on AMDGPU, apart from // __kmpc_alloc/free_shared. diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp --- a/llvm/lib/BinaryFormat/MachO.cpp +++ b/llvm/lib/BinaryFormat/MachO.cpp @@ -9,12 +9,13 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/TargetParser/ARMTargetParser.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace llvm; static MachO::CPUSubTypeX86 getX86SubType(const Triple &T) { assert(T.isX86()); - if (T.isArch32Bit()) + if (TripleUtils::isArch32Bit(T)) return MachO::CPU_SUBTYPE_I386_ALL; assert(T.isArch64Bit()); @@ -56,7 +57,7 @@ static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T) { assert(T.isAArch64()); - if (T.isArch32Bit()) + if (TripleUtils::isArch32Bit(T)) return (MachO::CPUSubTypeARM64)MachO::CPU_SUBTYPE_ARM64_32_V8; if (T.isArm64e()) return MachO::CPU_SUBTYPE_ARM64E; @@ -77,14 +78,15 @@ Expected MachO::getCPUType(const Triple &T) { if (!T.isOSBinFormatMachO()) return unsupported("type", T); - if (T.isX86() && T.isArch32Bit()) + if (T.isX86() && TripleUtils::isArch32Bit(T)) return MachO::CPU_TYPE_X86; if (T.isX86() && T.isArch64Bit()) return MachO::CPU_TYPE_X86_64; if (T.isARM() || T.isThumb()) return MachO::CPU_TYPE_ARM; if (T.isAArch64()) - return T.isArch32Bit() ? MachO::CPU_TYPE_ARM64_32 : MachO::CPU_TYPE_ARM64; + return TripleUtils::isArch32Bit(T) ? MachO::CPU_TYPE_ARM64_32 + : MachO::CPU_TYPE_ARM64; if (T.getArch() == Triple::ppc) return MachO::CPU_TYPE_POWERPC; if (T.getArch() == Triple::ppc64) diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -65,6 +65,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include #include @@ -2535,10 +2536,10 @@ void TargetLoweringObjectFileXCOFF::Initialize(MCContext &Ctx, const TargetMachine &TgtM) { TargetLoweringObjectFile::Initialize(Ctx, TgtM); - TTypeEncoding = - dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_datarel | - (TgtM.getTargetTriple().isArch32Bit() ? dwarf::DW_EH_PE_sdata4 - : dwarf::DW_EH_PE_sdata8); + TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_datarel | + (llvm::TripleUtils::isArch32Bit(TgtM.getTargetTriple()) + ? dwarf::DW_EH_PE_sdata4 + : dwarf::DW_EH_PE_sdata8); PersonalityEncoding = 0; LSDAEncoding = 0; CallSiteEncoding = dwarf::DW_EH_PE_udata4; diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp --- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp +++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp @@ -16,6 +16,7 @@ #include "llvm/DebugInfo/DWARF/DWARFUnit.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Debug.h" +#include "llvm/TargetParser/TripleUtils.h" #include #define DEBUG_TYPE "correlator" @@ -87,7 +88,7 @@ auto T = Obj->makeTriple(); if (T.isArch64Bit()) return InstrProfCorrelatorImpl::get(std::move(*CtxOrErr), *Obj); - if (T.isArch32Bit()) + if (TripleUtils::isArch32Bit(T)) return InstrProfCorrelatorImpl::get(std::move(*CtxOrErr), *Obj); } return make_error( diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.h b/llvm/lib/Target/AArch64/AArch64Subtarget.h --- a/llvm/lib/Target/AArch64/AArch64Subtarget.h +++ b/llvm/lib/Target/AArch64/AArch64Subtarget.h @@ -25,6 +25,7 @@ #include "llvm/CodeGen/RegisterBankInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/DataLayout.h" +#include "llvm/TargetParser/TripleUtils.h" #include #define GET_SUBTARGETINFO_HEADER @@ -285,7 +286,7 @@ bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } bool isTargetILP32() const { - return TargetTriple.isArch32Bit() || + return llvm::TripleUtils::isArch32Bit(TargetTriple) || TargetTriple.getEnvironment() == Triple::GNUILP32; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace llvm; namespace { @@ -561,7 +562,7 @@ uint32_t CPUType = cantFail(MachO::getCPUType(TheTriple)); uint32_t CPUSubType = cantFail(MachO::getCPUSubType(TheTriple)); return createAArch64MachObjectWriter(CPUType, CPUSubType, - TheTriple.isArch32Bit()); + TripleUtils::isArch32Bit(TheTriple)); } /// Generate the compact unwind encoding from the CFI directives. diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp --- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp @@ -22,6 +22,7 @@ #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/CodeGen.h" +#include "llvm/TargetParser/TripleUtils.h" #include "llvm/Transforms/Scalar.h" #include @@ -46,7 +47,8 @@ static std::string computeDataLayout(const Triple &TT) { if (TT.isArch64Bit()) return "e-m:e-p:64:64-i64:64-i128:128-n64-S128"; - assert(TT.isArch32Bit() && "only LA32 and LA64 are currently supported"); + assert(llvm::TripleUtils::isArch32Bit(TT) && + "only LA32 and LA64 are currently supported"); return "e-m:e-p:32:32-i64:64-n32-S128"; } diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -43,6 +43,7 @@ #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetOptions.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include "llvm/Transforms/Scalar.h" #include #include @@ -291,7 +292,7 @@ assert(TT.isOSBinFormatELF() && "All remaining PPC OSes are ELF based."); - if (TT.isArch32Bit()) + if (TripleUtils::isArch32Bit(TT)) return CodeModel::Small; assert(TT.isArch64Bit() && "Unsupported PPC architecture."); diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -33,6 +33,7 @@ #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/TargetParser/TripleUtils.h" #include "llvm/Transforms/IPO.h" #include using namespace llvm; @@ -95,7 +96,8 @@ static StringRef computeDataLayout(const Triple &TT) { if (TT.isArch64Bit()) return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"; - assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported"); + assert(llvm::TripleUtils::isArch32Bit(TT) && + "only RV32 and RV64 are currently supported"); return "e-m:e-p:32:32-i64:64-n32-S128"; } diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -44,6 +44,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace llvm; @@ -766,7 +767,7 @@ if (FeatureFlagsAnd) { // Emit a .note.gnu.property section with the flags. - if (!TT.isArch32Bit() && !TT.isArch64Bit()) + if (!TripleUtils::isArch32Bit(TT) && !TT.isArch64Bit()) llvm_unreachable("CFProtection used on invalid architecture!"); MCSection *Cur = OutStreamer->getCurrentSectionOnly(); MCSection *Nt = MMI->getContext().getELFSection( diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt --- a/llvm/lib/TargetParser/CMakeLists.txt +++ b/llvm/lib/TargetParser/CMakeLists.txt @@ -19,6 +19,7 @@ SubtargetFeature.cpp TargetParser.cpp Triple.cpp + TripleUtils.cpp X86TargetParser.cpp ADDITIONAL_HEADER_DIRS diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include "llvm/TargetParser/X86TargetParser.h" #include @@ -1950,7 +1951,7 @@ PT = withHostArch(PT); #endif - if (sizeof(void *) == 8 && PT.isArch32Bit()) + if (sizeof(void *) == 8 && llvm::TripleUtils::isArch32Bit(PT)) PT = PT.get64BitArchVariant(); if (sizeof(void *) == 4 && PT.isArch64Bit()) PT = PT.get32BitArchVariant(); diff --git a/llvm/lib/TargetParser/TripleUtils.cpp b/llvm/lib/TargetParser/TripleUtils.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/TargetParser/TripleUtils.cpp @@ -0,0 +1,93 @@ +//===--- TripleUtils.cpp - Triple Utils class --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/TargetParser/TripleUtils.h" +#include "llvm/Support/ErrorHandling.h" +using namespace llvm; + +static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { + switch (Arch) { + case llvm::Triple::UnknownArch: + return 0; + + case llvm::Triple::avr: + case llvm::Triple::msp430: + return 16; + + case llvm::Triple::aarch64_32: + case llvm::Triple::amdil: + case llvm::Triple::arc: + case llvm::Triple::arm: + case llvm::Triple::armeb: + case llvm::Triple::csky: + case llvm::Triple::dxil: + case llvm::Triple::hexagon: + case llvm::Triple::hsail: + case llvm::Triple::kalimba: + case llvm::Triple::lanai: + case llvm::Triple::le32: + case llvm::Triple::loongarch32: + case llvm::Triple::m68k: + case llvm::Triple::mips: + case llvm::Triple::mipsel: + case llvm::Triple::nvptx: + case llvm::Triple::ppc: + case llvm::Triple::ppcle: + case llvm::Triple::r600: + case llvm::Triple::renderscript32: + case llvm::Triple::riscv32: + case llvm::Triple::shave: + case llvm::Triple::sparc: + case llvm::Triple::sparcel: + case llvm::Triple::spir: + case llvm::Triple::spirv32: + case llvm::Triple::tce: + case llvm::Triple::tcele: + case llvm::Triple::thumb: + case llvm::Triple::thumbeb: + case llvm::Triple::wasm32: + case llvm::Triple::x86: + case llvm::Triple::xcore: + case llvm::Triple::xtensa: + return 32; + + case llvm::Triple::aarch64: + case llvm::Triple::aarch64_be: + case llvm::Triple::amdgcn: + case llvm::Triple::amdil64: + case llvm::Triple::bpfeb: + case llvm::Triple::bpfel: + case llvm::Triple::hsail64: + case llvm::Triple::le64: + case llvm::Triple::loongarch64: + case llvm::Triple::mips64: + case llvm::Triple::mips64el: + case llvm::Triple::nvptx64: + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + case llvm::Triple::renderscript64: + case llvm::Triple::riscv64: + case llvm::Triple::sparcv9: + case llvm::Triple::spir64: + case llvm::Triple::spirv64: + case llvm::Triple::systemz: + case llvm::Triple::ve: + case llvm::Triple::wasm64: + case llvm::Triple::x86_64: + return 64; + } + llvm_unreachable("Invalid architecture value"); +} + +bool TripleUtils::isArch16Bit(const llvm::Triple &tripleImpl) { + return getArchPointerBitWidth(tripleImpl.getArch()) == 16; +} + +bool TripleUtils::isArch32Bit(const llvm::Triple &tripleImpl) { + return getArchPointerBitWidth(tripleImpl.getArch()) == 32; +} \ No newline at end of file diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp --- a/llvm/lib/XRay/InstrumentationMap.cpp +++ b/llvm/lib/XRay/InstrumentationMap.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" #include #include #include @@ -144,7 +145,7 @@ // Copy the instrumentation map data into the Sleds data structure. auto C = Contents.bytes_begin(); - bool Is32Bit = ObjFile.getBinary()->makeTriple().isArch32Bit(); + bool Is32Bit = TripleUtils::isArch32Bit(ObjFile.getBinary()->makeTriple()); size_t ELFSledEntrySize = Is32Bit ? 16 : 32; if ((C - Contents.bytes_end()) % ELFSledEntrySize != 0) diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -43,6 +43,7 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/WithColor.h" #include "llvm/TargetParser/Host.h" +#include "llvm/TargetParser/TripleUtils.h" #include #include @@ -275,7 +276,7 @@ const std::string &TripleName = TheTriple.getTriple(); bool SafeSEH = InputArgs.hasArg(OPT_safeseh); - if (SafeSEH && !(TheTriple.isArch32Bit() && TheTriple.isX86())) { + if (SafeSEH && !(TripleUtils::isArch32Bit(TheTriple) && TheTriple.isX86())) { WithColor::warning() << "/safeseh applies only to 32-bit X86 platforms; ignoring.\n"; SafeSEH = false; diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -37,7 +37,7 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" - +#include "llvm/TargetParser/TripleUtils.h" #include #include @@ -728,9 +728,9 @@ // If the -target-addr-end option wasn't explicitly passed, then set it to a // sensible default based on the target triple. if (TargetAddrEnd.getNumOccurrences() == 0) { - if (TargetTriple.isArch16Bit()) + if (llvm::TripleUtils::isArch16Bit(TargetTriple)) TargetAddrEnd = (1ULL << 16) - 1; - else if (TargetTriple.isArch32Bit()) + else if (llvm::TripleUtils::isArch32Bit(TargetTriple)) TargetAddrEnd = (1ULL << 32) - 1; // TargetAddrEnd already has a sensible default for 64-bit systems, so // there's nothing to do in the 64-bit case. diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp --- a/llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp @@ -12,6 +12,7 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/TargetParser/TripleUtils.h" using namespace llvm; @@ -40,7 +41,7 @@ // If a 32-bit/64-bit address size was specified, try to convert the triple // if it is for the wrong variant. - if (AddrSize == 8 && T.isArch32Bit()) + if (AddrSize == 8 && TripleUtils::isArch32Bit(T)) return T.get64BitArchVariant(); if (AddrSize == 4 && T.isArch64Bit()) return T.get32BitArchVariant(); diff --git a/llvm/unittests/TargetParser/CMakeLists.txt b/llvm/unittests/TargetParser/CMakeLists.txt --- a/llvm/unittests/TargetParser/CMakeLists.txt +++ b/llvm/unittests/TargetParser/CMakeLists.txt @@ -8,6 +8,7 @@ Host.cpp TargetParserTest.cpp TripleTest.cpp + TripleUtilsTest.cpp ) target_link_libraries(TargetParserTests PRIVATE LLVMTestingSupport) diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp --- a/llvm/unittests/TargetParser/TripleTest.cpp +++ b/llvm/unittests/TargetParser/TripleTest.cpp @@ -763,7 +763,6 @@ EXPECT_EQ(Triple::aarch64_32, T.getArch()); EXPECT_EQ(Triple::IOS, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); - EXPECT_TRUE(T.isArch32Bit()); T = Triple("dxil-unknown-shadermodel-pixel"); EXPECT_EQ(Triple::dxil, T.getArch()); @@ -1094,173 +1093,109 @@ TEST(TripleTest, BitWidthPredicates) { Triple T; - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::arm); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::hexagon); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::mips); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::mips64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::msp430); - EXPECT_TRUE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::ppc); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::ppc64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::x86); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::x86_64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::amdil); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::amdil64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::hsail); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::hsail64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::spir); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::spir64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::spirv32); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); EXPECT_TRUE(T.isSPIRV()); T.setArch(Triple::spirv64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); EXPECT_TRUE(T.isSPIRV()); T.setArch(Triple::sparc); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::sparcel); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::sparcv9); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::wasm32); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::wasm64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.setArch(Triple::avr); - EXPECT_TRUE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::lanai); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.setArch(Triple::riscv32); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); EXPECT_TRUE(T.isRISCV()); T.setArch(Triple::riscv64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); EXPECT_TRUE(T.isRISCV()); T.setArch(Triple::csky); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); EXPECT_TRUE(T.isCSKY()); T.setArch(Triple::loongarch32); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); EXPECT_TRUE(T.isLoongArch()); EXPECT_TRUE(T.isLoongArch32()); T.setArch(Triple::loongarch64); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); EXPECT_TRUE(T.isLoongArch()); EXPECT_TRUE(T.isLoongArch64()); T.setArch(Triple::dxil); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); EXPECT_TRUE(T.isDXIL()); T.setArch(Triple::xtensa); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); } @@ -1622,8 +1557,6 @@ T = Triple("i386-apple-darwin9"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 5), Version); @@ -1633,8 +1566,6 @@ T = Triple("x86_64-apple-darwin9"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 5), Version); @@ -1644,8 +1575,6 @@ T = Triple("x86_64-apple-macosx"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 4), Version); @@ -1655,8 +1584,6 @@ T = Triple("x86_64-apple-macosx10.7"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 7), Version); @@ -1666,8 +1593,6 @@ T = Triple("x86_64-apple-macos11.0"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(11, 0), Version); @@ -1675,8 +1600,6 @@ T = Triple("arm64-apple-macosx11.5.8"); EXPECT_TRUE(T.isMacOSX()); EXPECT_FALSE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(11, 5, 8), Version); @@ -1702,8 +1625,6 @@ T = Triple("armv7-apple-ios"); EXPECT_FALSE(T.isMacOSX()); EXPECT_TRUE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 4), Version); @@ -1713,8 +1634,6 @@ T = Triple("armv7-apple-ios7.0"); EXPECT_FALSE(T.isMacOSX()); EXPECT_TRUE(T.isiOS()); - EXPECT_FALSE(T.isArch16Bit()); - EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); T.getMacOSXVersion(Version); EXPECT_EQ(VersionTuple(10, 4), Version); diff --git a/llvm/unittests/TargetParser/TripleUtilsTest.cpp b/llvm/unittests/TargetParser/TripleUtilsTest.cpp new file mode 100644 --- /dev/null +++ b/llvm/unittests/TargetParser/TripleUtilsTest.cpp @@ -0,0 +1,179 @@ +//===----------- TripleUtils.cpp - TripleUtils unit tests +//---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/TargetParser/TripleUtils.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(TripleUtilsTest, CheckArchBitWidth) { + Triple T; + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::arm); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::hexagon); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::mips); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::mips64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::msp430); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_TRUE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::ppc); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::ppc64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::x86); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::x86_64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::amdil); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::amdil64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::hsail); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::hsail64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::spir); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::spir64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::spirv32); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::spirv64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::sparc); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::sparcel); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::sparcv9); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::wasm32); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::wasm64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::avr); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_TRUE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::lanai); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::riscv32); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::riscv64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::csky); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::loongarch32); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::loongarch64); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::dxil); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); + + T.setArch(Triple::xtensa); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + EXPECT_FALSE(llvm::TripleUtils::isArch16Bit(T)); +} + +TEST(TripleUtilsTest, CheckArchBitWidthUsingOSVersion) { + Triple T; + VersionTuple Version; + + T = Triple("i386-apple-darwin9"); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("x86_64-apple-darwin9"); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("x86_64-apple-macosx"); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("x86_64-apple-macosx10.7"); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("x86_64-apple-macos11.0"); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("arm64-apple-macosx11.5.8"); + EXPECT_FALSE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("armv7-apple-ios"); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("armv7-apple-ios7.0"); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); + + T = Triple("arm64_32-apple-ios"); + EXPECT_TRUE(llvm::TripleUtils::isArch32Bit(T)); +} + +} // namespace \ No newline at end of file