diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp | 126 |
1 files changed, 115 insertions, 11 deletions
diff --git a/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp b/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp index 188ffb5f2f78..96b3ad9ba2f2 100644 --- a/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp +++ b/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// This file implements the TargetInfo and TargetInfoImpl interfaces. +// This file implements the TargetInfo interface. // //===----------------------------------------------------------------------===// @@ -14,15 +14,41 @@ #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/DiagnosticFrontend.h" #include "clang/Basic/LangOptions.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/TargetParser.h" +#include "llvm/TargetParser/TargetParser.h" #include <cstdlib> using namespace clang; static const LangASMap DefaultAddrSpaceMap = {0}; +// The fake address space map must have a distinct entry for each +// language-specific address space. +static const LangASMap FakeAddrSpaceMap = { + 0, // Default + 1, // opencl_global + 3, // opencl_local + 2, // opencl_constant + 0, // opencl_private + 4, // opencl_generic + 5, // opencl_global_device + 6, // opencl_global_host + 7, // cuda_device + 8, // cuda_constant + 9, // cuda_shared + 1, // sycl_global + 5, // sycl_global_device + 6, // sycl_global_host + 3, // sycl_local + 0, // sycl_private + 10, // ptr32_sptr + 11, // ptr32_uptr + 12, // ptr64 + 13, // hlsl_groupshared + 20, // wasm_funcref +}; // TargetInfo Constructor. TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { @@ -33,10 +59,12 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { VLASupported = true; NoAsmVariants = false; HasLegalHalfType = false; + HalfArgsAndReturns = false; HasFloat128 = false; HasIbm128 = false; HasFloat16 = false; HasBFloat16 = false; + HasFullBFloat16 = false; HasLongDouble = true; HasFPReturn = true; HasStrictFP = false; @@ -45,6 +73,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { IntWidth = IntAlign = 32; LongWidth = LongAlign = 32; LongLongWidth = LongLongAlign = 64; + Int128Align = 128; // Fixed point default bit widths ShortAccumWidth = ShortAccumAlign = 16; @@ -71,7 +100,8 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html. // This alignment guarantee also applies to Windows and Android. On Darwin // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems. - if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid()) + if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid() || + T.isOHOSFamily()) NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0; else if (T.isOSDarwin() || T.isOSOpenBSD()) NewAlign = 128; @@ -92,7 +122,6 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0; MaxVectorAlign = 0; MaxTLSAlign = 0; - SimdDefaultAlign = 0; SizeType = UnsignedLong; PtrDiffType = SignedLong; IntMaxType = SignedLongLong; @@ -131,7 +160,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { ARMCDECoprocMask = 0; // Default to no types using fpret. - RealTypeUsesObjCFPRet = 0; + RealTypeUsesObjCFPRetMask = 0; // Default to not using fp2ret for __Complex long double ComplexLongDoubleUsesFP2Ret = false; @@ -150,7 +179,8 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { PlatformMinVersion = VersionTuple(); MaxOpenCLWorkGroupSize = 1024; - ProgramAddrSpace = 0; + + MaxBitIntWidth.reset(); } // Out of line virtual dtor for TargetInfo. @@ -204,11 +234,11 @@ const char *TargetInfo::getTypeConstantSuffix(IntType T) const { case UnsignedChar: if (getCharWidth() < getIntWidth()) return ""; - LLVM_FALLTHROUGH; + [[fallthrough]]; case UnsignedShort: if (getShortWidth() < getIntWidth()) return ""; - LLVM_FALLTHROUGH; + [[fallthrough]]; case UnsignedInt: return "U"; case UnsignedLong: return "UL"; case UnsignedLongLong: return "ULL"; @@ -284,6 +314,8 @@ TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth, FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth, FloatModeKind ExplicitType) const { + if (getHalfWidth() == BitWidth) + return FloatModeKind::Half; if (getFloatWidth() == BitWidth) return FloatModeKind::Float; if (getDoubleWidth() == BitWidth) @@ -449,6 +481,20 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { } else if (Opts.LongDoubleSize == 128) { LongDoubleWidth = LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::IEEEquad(); + } else if (Opts.LongDoubleSize == 80) { + LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); + if (getTriple().isWindowsMSVCEnvironment()) { + LongDoubleWidth = 128; + LongDoubleAlign = 128; + } else { // Linux + if (getTriple().getArch() == llvm::Triple::x86) { + LongDoubleWidth = 96; + LongDoubleAlign = 32; + } else { + LongDoubleWidth = 128; + LongDoubleAlign = 128; + } + } } } @@ -464,6 +510,12 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens"; Opts.ProtectParens = false; } + + if (Opts.MaxBitIntWidth) + MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth); + + if (Opts.FakeAddressSpaceMap) + AddrSpaceMap = &FakeAddrSpaceMap; } bool TargetInfo::initFeatureMap( @@ -471,21 +523,73 @@ bool TargetInfo::initFeatureMap( const std::vector<std::string> &FeatureVec) const { for (const auto &F : FeatureVec) { StringRef Name = F; + if (Name.empty()) + continue; // Apply the feature via the target. - bool Enabled = Name[0] == '+'; - setFeatureEnabled(Features, Name.substr(1), Enabled); + if (Name[0] != '+' && Name[0] != '-') + Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name; + else + setFeatureEnabled(Features, Name.substr(1), Name[0] == '+'); } return true; } +ParsedTargetAttr TargetInfo::parseTargetAttr(StringRef Features) const { + ParsedTargetAttr Ret; + if (Features == "default") + return Ret; + SmallVector<StringRef, 1> AttrFeatures; + Features.split(AttrFeatures, ","); + + // Grab the various features and prepend a "+" to turn on the feature to + // the backend and add them to our existing set of features. + for (auto &Feature : AttrFeatures) { + // Go ahead and trim whitespace rather than either erroring or + // accepting it weirdly. + Feature = Feature.trim(); + + // TODO: Support the fpmath option. It will require checking + // overall feature validity for the function with the rest of the + // attributes on the function. + if (Feature.starts_with("fpmath=")) + continue; + + if (Feature.starts_with("branch-protection=")) { + Ret.BranchProtection = Feature.split('=').second.trim(); + continue; + } + + // While we're here iterating check for a different target cpu. + if (Feature.starts_with("arch=")) { + if (!Ret.CPU.empty()) + Ret.Duplicate = "arch="; + else + Ret.CPU = Feature.split("=").second.trim(); + } else if (Feature.starts_with("tune=")) { + if (!Ret.Tune.empty()) + Ret.Duplicate = "tune="; + else + Ret.Tune = Feature.split("=").second.trim(); + } else if (Feature.starts_with("no-")) + Ret.Features.push_back("-" + Feature.split("-").second.str()); + else + Ret.Features.push_back("+" + Feature.str()); + } + return Ret; +} + TargetInfo::CallingConvKind TargetInfo::getCallingConvKind(bool ClangABICompat4) const { if (getCXXABI() != TargetCXXABI::Microsoft && - (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4)) + (ClangABICompat4 || getTriple().isPS4())) return CCK_ClangABI4OrPS4; return CCK_Default; } +bool TargetInfo::areDefaultedSMFStillPOD(const LangOptions &LangOpts) const { + return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15; +} + LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const { switch (TK) { case OCLTK_Image: |