diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -828,19 +828,18 @@ // This is a very simple ABI that relies a lot on DefaultABIInfo. //===----------------------------------------------------------------------===// -class WebAssemblyABIInfo final : public ABIInfo { -public: - enum ABIKind { - MVP = 0, - ExperimentalMV = 1, - }; +enum class WebAssemblyABIKind { + MVP = 0, + ExperimentalMV = 1, +}; -private: +class WebAssemblyABIInfo final : public ABIInfo { DefaultABIInfo defaultInfo; - ABIKind Kind; + WebAssemblyABIKind Kind; public: - explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind) + explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, + WebAssemblyABIKind Kind) : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {} private: @@ -864,7 +863,7 @@ class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo { public: explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, - WebAssemblyABIInfo::ABIKind K) + WebAssemblyABIKind K) : TargetCodeGenInfo(std::make_unique(CGT, K)) { SwiftInfo = std::make_unique(CGT, /*SwiftErrorInRegister=*/false); @@ -929,7 +928,7 @@ if (const Type *SeltTy = isSingleElementStruct(Ty, getContext())) return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); // For the experimental multivalue ABI, fully expand all other aggregates - if (Kind == ABIKind::ExperimentalMV) { + if (Kind == WebAssemblyABIKind::ExperimentalMV) { const RecordType *RT = Ty->getAs(); assert(RT); bool HasBitField = false; @@ -962,7 +961,7 @@ if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); // For the experimental multivalue ABI, return all other aggregates - if (Kind == ABIKind::ExperimentalMV) + if (Kind == WebAssemblyABIKind::ExperimentalMV) return ABIArgInfo::getDirect(); } } @@ -4989,21 +4988,19 @@ // PowerPC-64 namespace { +enum class PPC64_SVR4_ABIKind { + ELFv1 = 0, + ELFv2, +}; + /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information. class PPC64_SVR4_ABIInfo : public ABIInfo { -public: - enum ABIKind { - ELFv1 = 0, - ELFv2 - }; - -private: static const unsigned GPRBits = 64; - ABIKind Kind; + PPC64_SVR4_ABIKind Kind; bool IsSoftFloatABI; public: - PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind, + PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind, bool SoftFloatABI) : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {} @@ -5051,8 +5048,7 @@ class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo { public: - PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, - PPC64_SVR4_ABIInfo::ABIKind Kind, + PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind, bool SoftFloatABI) : TargetCodeGenInfo( std::make_unique(CGT, Kind, SoftFloatABI)) { @@ -5151,7 +5147,7 @@ // Likewise for ELFv2 homogeneous aggregates. const Type *Base = nullptr; uint64_t Members = 0; - if (!AlignAsType && Kind == ELFv2 && + if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 && isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members)) AlignAsType = Base; @@ -5345,7 +5341,7 @@ // ELFv2 homogeneous aggregates are passed as array types. const Type *Base = nullptr; uint64_t Members = 0; - if (Kind == ELFv2 && + if (Kind == PPC64_SVR4_ABIKind::ELFv2 && isHomogeneousAggregate(Ty, Base, Members)) { llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0)); llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members); @@ -5415,7 +5411,7 @@ // ELFv2 homogeneous aggregates are returned as array types. const Type *Base = nullptr; uint64_t Members = 0; - if (Kind == ELFv2 && + if (Kind == PPC64_SVR4_ABIKind::ELFv2 && isHomogeneousAggregate(RetTy, Base, Members)) { llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0)); llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members); @@ -5424,7 +5420,7 @@ // ELFv2 small aggregates are returned in up to two registers. uint64_t Bits = getContext().getTypeSize(RetTy); - if (Kind == ELFv2 && Bits <= 2 * GPRBits) { + if (Kind == PPC64_SVR4_ABIKind::ELFv2 && Bits <= 2 * GPRBits) { if (Bits == 0) return ABIArgInfo::getIgnore(); @@ -5505,23 +5501,22 @@ namespace { -class AArch64ABIInfo : public ABIInfo { -public: - enum ABIKind { - AAPCS = 0, - DarwinPCS, - Win64 - }; +enum class AArch64ABIKind { + AAPCS = 0, + DarwinPCS, + Win64, +}; -private: - ABIKind Kind; +class AArch64ABIInfo : public ABIInfo { + AArch64ABIKind Kind; public: - AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind) : ABIInfo(CGT), Kind(Kind) {} + AArch64ABIInfo(CodeGenTypes &CGT, AArch64ABIKind Kind) + : ABIInfo(CGT), Kind(Kind) {} private: - ABIKind getABIKind() const { return Kind; } - bool isDarwinPCS() const { return Kind == DarwinPCS; } + AArch64ABIKind getABIKind() const { return Kind; } + bool isDarwinPCS() const { return Kind == AArch64ABIKind::DarwinPCS; } ABIArgInfo classifyReturnType(QualType RetTy, bool IsVariadic) const; ABIArgInfo classifyArgumentType(QualType RetTy, bool IsVariadic, @@ -5557,8 +5552,8 @@ llvm::report_fatal_error("Passing SVE types to variadic functions is " "currently not supported"); - return Kind == Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty) - : isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF) + return Kind == AArch64ABIKind::Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty) + : isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF) : EmitAAPCSVAArg(VAListAddr, Ty, CGF); } @@ -5581,7 +5576,7 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo { public: - AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind) + AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIKind Kind) : TargetCodeGenInfo(std::make_unique(CGT, Kind)) { SwiftInfo = std::make_unique(CGT); } @@ -5649,7 +5644,7 @@ class WindowsAArch64TargetCodeGenInfo : public AArch64TargetCodeGenInfo { public: - WindowsAArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind K) + WindowsAArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIKind K) : AArch64TargetCodeGenInfo(CGT, K) {} void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, @@ -5807,12 +5802,13 @@ // Homogeneous Floating-point Aggregates (HFAs) need to be expanded. const Type *Base = nullptr; uint64_t Members = 0; - bool IsWin64 = Kind == Win64 || CallingConvention == llvm::CallingConv::Win64; + bool IsWin64 = Kind == AArch64ABIKind::Win64 || + CallingConvention == llvm::CallingConv::Win64; bool IsWinVariadic = IsWin64 && IsVariadic; // In variadic functions on Windows, all composite types are treated alike, // no special handling of HFAs/HVAs. if (!IsWinVariadic && isHomogeneousAggregate(Ty, Base, Members)) { - if (Kind != AArch64ABIInfo::AAPCS) + if (Kind != AArch64ABIKind::AAPCS) return ABIArgInfo::getDirect( llvm::ArrayType::get(CGT.ConvertType(QualType(Base, 0)), Members)); @@ -5835,7 +5831,7 @@ return coerceToIntArray(Ty, getContext(), getVMContext()); } unsigned Alignment; - if (Kind == AArch64ABIInfo::AAPCS) { + if (Kind == AArch64ABIKind::AAPCS) { Alignment = getContext().getTypeUnadjustedAlign(Ty); Alignment = Alignment < 128 ? 64 : 128; } else { @@ -6314,21 +6310,19 @@ namespace { -class ARMABIInfo : public ABIInfo { -public: - enum ABIKind { - APCS = 0, - AAPCS = 1, - AAPCS_VFP = 2, - AAPCS16_VFP = 3, - }; +enum class ARMABIKind { + APCS = 0, + AAPCS = 1, + AAPCS_VFP = 2, + AAPCS16_VFP = 3, +}; -private: - ABIKind Kind; +class ARMABIInfo : public ABIInfo { + ARMABIKind Kind; bool IsFloatABISoftFP; public: - ARMABIInfo(CodeGenTypes &CGT, ABIKind Kind) : ABIInfo(CGT), Kind(Kind) { + ARMABIInfo(CodeGenTypes &CGT, ARMABIKind Kind) : ABIInfo(CGT), Kind(Kind) { setCCs(); IsFloatABISoftFP = CGT.getCodeGenOpts().FloatABI == "softfp" || CGT.getCodeGenOpts().FloatABI == ""; // default @@ -6360,7 +6354,7 @@ } } - ABIKind getABIKind() const { return Kind; } + ARMABIKind getABIKind() const { return Kind; } bool allowBFloatArgsAndRet() const override { return !IsFloatABISoftFP && getTarget().hasBFloat16Type(); @@ -6405,7 +6399,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo { public: - ARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIInfo::ABIKind K) + ARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIKind K) : TargetCodeGenInfo(std::make_unique(CGT, K)) { SwiftInfo = std::make_unique(CGT); } @@ -6499,8 +6493,8 @@ Fn->addFnAttr("interrupt", Kind); - ARMABIInfo::ABIKind ABI = cast(getABIInfo()).getABIKind(); - if (ABI == ARMABIInfo::APCS) + ARMABIKind ABI = cast(getABIInfo()).getABIKind(); + if (ABI == ARMABIKind::APCS) return; // AAPCS guarantees that sp will be 8-byte aligned on any public interface, @@ -6514,7 +6508,7 @@ class WindowsARMTargetCodeGenInfo : public ARMTargetCodeGenInfo { public: - WindowsARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIInfo::ABIKind K) + WindowsARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIKind K) : ARMTargetCodeGenInfo(CGT, K) {} void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, @@ -6574,10 +6568,14 @@ /// as the C calling convention. llvm::CallingConv::ID ARMABIInfo::getABIDefaultCC() const { switch (getABIKind()) { - case APCS: return llvm::CallingConv::ARM_APCS; - case AAPCS: return llvm::CallingConv::ARM_AAPCS; - case AAPCS_VFP: return llvm::CallingConv::ARM_AAPCS_VFP; - case AAPCS16_VFP: return llvm::CallingConv::ARM_AAPCS_VFP; + case ARMABIKind::APCS: + return llvm::CallingConv::ARM_APCS; + case ARMABIKind::AAPCS: + return llvm::CallingConv::ARM_AAPCS; + case ARMABIKind::AAPCS_VFP: + return llvm::CallingConv::ARM_AAPCS_VFP; + case ARMABIKind::AAPCS16_VFP: + return llvm::CallingConv::ARM_AAPCS_VFP; } llvm_unreachable("bad ABI kind"); } @@ -6623,8 +6621,8 @@ } } unsigned Align = 0; - if (getABIKind() == ARMABIInfo::AAPCS || - getABIKind() == ARMABIInfo::AAPCS_VFP) { + if (getABIKind() == ARMABIKind::AAPCS || + getABIKind() == ARMABIKind::AAPCS_VFP) { // For alignment adjusted HFAs, cap the argument alignment to 8, leave it // default otherwise. Align = getContext().getTypeUnadjustedAlignInChars(Ty).getQuantity(); @@ -6682,7 +6680,7 @@ uint64_t Members = 0; if (isHomogeneousAggregate(Ty, Base, Members)) return classifyHomogeneousAggregate(Ty, Base, Members); - } else if (getABIKind() == ARMABIInfo::AAPCS16_VFP) { + } else if (getABIKind() == ARMABIKind::AAPCS16_VFP) { // WatchOS does have homogeneous aggregates. Note that we intentionally use // this convention even for a variadic function: the backend will use GPRs // if needed. @@ -6696,7 +6694,7 @@ } } - if (getABIKind() == ARMABIInfo::AAPCS16_VFP && + if (getABIKind() == ARMABIKind::AAPCS16_VFP && getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(16)) { // WatchOS is adopting the 64-bit AAPCS rule on composite types: if they're // bigger than 128-bits, they get placed in space allocated by the caller, @@ -6711,15 +6709,15 @@ // than ABI alignment. uint64_t ABIAlign = 4; uint64_t TyAlign; - if (getABIKind() == ARMABIInfo::AAPCS_VFP || - getABIKind() == ARMABIInfo::AAPCS) { + if (getABIKind() == ARMABIKind::AAPCS_VFP || + getABIKind() == ARMABIKind::AAPCS) { TyAlign = getContext().getTypeUnadjustedAlignInChars(Ty).getQuantity(); ABIAlign = std::clamp(TyAlign, (uint64_t)4, (uint64_t)8); } else { TyAlign = getContext().getTypeAlignInChars(Ty).getQuantity(); } if (getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(64)) { - assert(getABIKind() != ARMABIInfo::AAPCS16_VFP && "unexpected byval"); + assert(getABIKind() != ARMABIKind::AAPCS16_VFP && "unexpected byval"); return ABIArgInfo::getIndirect(CharUnits::fromQuantity(ABIAlign), /*ByVal=*/true, /*Realign=*/TyAlign > ABIAlign); @@ -6870,7 +6868,7 @@ } // Are we following APCS? - if (getABIKind() == APCS) { + if (getABIKind() == ARMABIKind::APCS) { if (isEmptyRecord(getContext(), RetTy, false)) return ABIArgInfo::getIgnore(); @@ -6929,7 +6927,7 @@ if (Size <= 16) return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext())); return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext())); - } else if (Size <= 128 && getABIKind() == AAPCS16_VFP) { + } else if (Size <= 128 && getABIKind() == ARMABIKind::AAPCS16_VFP) { llvm::Type *Int32Ty = llvm::Type::getInt32Ty(getVMContext()); llvm::Type *CoerceTy = llvm::ArrayType::get(Int32Ty, llvm::alignTo(Size, 32) / 32); @@ -7059,8 +7057,8 @@ if (callConvention != llvm::CallingConv::C) return (callConvention == llvm::CallingConv::ARM_AAPCS_VFP); else - return (getABIKind() == AAPCS_VFP) || - (acceptHalf && (getABIKind() == AAPCS16_VFP)); + return (getABIKind() == ARMABIKind::AAPCS_VFP) || + (acceptHalf && (getABIKind() == ARMABIKind::AAPCS16_VFP)); } Address ARMABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, @@ -7088,7 +7086,7 @@ // ARMv7k passes structs bigger than 16 bytes indirectly, in space // allocated by the caller. } else if (TySize > CharUnits::fromQuantity(16) && - getABIKind() == ARMABIInfo::AAPCS16_VFP && + getABIKind() == ARMABIKind::AAPCS16_VFP && !isHomogeneousAggregate(Ty, Base, Members)) { IsIndirect = true; @@ -7096,11 +7094,11 @@ // The ABI alignment for 64-bit or 128-bit vectors is 8 for AAPCS and 4 for // APCS. For AAPCS, the ABI alignment is at least 4-byte and at most 8-byte. // Our callers should be prepared to handle an under-aligned address. - } else if (getABIKind() == ARMABIInfo::AAPCS_VFP || - getABIKind() == ARMABIInfo::AAPCS) { + } else if (getABIKind() == ARMABIKind::AAPCS_VFP || + getABIKind() == ARMABIKind::AAPCS) { TyAlignForABI = std::max(TyAlignForABI, CharUnits::fromQuantity(4)); TyAlignForABI = std::min(TyAlignForABI, CharUnits::fromQuantity(8)); - } else if (getABIKind() == ARMABIInfo::AAPCS16_VFP) { + } else if (getABIKind() == ARMABIKind::AAPCS16_VFP) { // ARMv7k allows type alignment up to 16 bytes. TyAlignForABI = std::max(TyAlignForABI, CharUnits::fromQuantity(4)); TyAlignForABI = std::min(TyAlignForABI, CharUnits::fromQuantity(16)); @@ -12348,21 +12346,21 @@ case llvm::Triple::aarch64: case llvm::Triple::aarch64_32: case llvm::Triple::aarch64_be: { - AArch64ABIInfo::ABIKind Kind = AArch64ABIInfo::AAPCS; + AArch64ABIKind Kind = AArch64ABIKind::AAPCS; if (getTarget().getABI() == "darwinpcs") - Kind = AArch64ABIInfo::DarwinPCS; + Kind = AArch64ABIKind::DarwinPCS; else if (Triple.isOSWindows()) return SetCGInfo( - new WindowsAArch64TargetCodeGenInfo(Types, AArch64ABIInfo::Win64)); + new WindowsAArch64TargetCodeGenInfo(Types, AArch64ABIKind::Win64)); return SetCGInfo(new AArch64TargetCodeGenInfo(Types, Kind)); } case llvm::Triple::wasm32: case llvm::Triple::wasm64: { - WebAssemblyABIInfo::ABIKind Kind = WebAssemblyABIInfo::MVP; + WebAssemblyABIKind Kind = WebAssemblyABIKind::MVP; if (getTarget().getABI() == "experimental-mv") - Kind = WebAssemblyABIInfo::ExperimentalMV; + Kind = WebAssemblyABIKind::ExperimentalMV; return SetCGInfo(new WebAssemblyTargetCodeGenInfo(Types, Kind)); } @@ -12372,21 +12370,21 @@ case llvm::Triple::thumbeb: { if (Triple.getOS() == llvm::Triple::Win32) { return SetCGInfo( - new WindowsARMTargetCodeGenInfo(Types, ARMABIInfo::AAPCS_VFP)); + new WindowsARMTargetCodeGenInfo(Types, ARMABIKind::AAPCS_VFP)); } - ARMABIInfo::ABIKind Kind = ARMABIInfo::AAPCS; + ARMABIKind Kind = ARMABIKind::AAPCS; StringRef ABIStr = getTarget().getABI(); if (ABIStr == "apcs-gnu") - Kind = ARMABIInfo::APCS; + Kind = ARMABIKind::APCS; else if (ABIStr == "aapcs16") - Kind = ARMABIInfo::AAPCS16_VFP; + Kind = ARMABIKind::AAPCS16_VFP; else if (CodeGenOpts.FloatABI == "hard" || (CodeGenOpts.FloatABI != "soft" && (Triple.getEnvironment() == llvm::Triple::GNUEABIHF || Triple.getEnvironment() == llvm::Triple::MuslEABIHF || Triple.getEnvironment() == llvm::Triple::EABIHF))) - Kind = ARMABIInfo::AAPCS_VFP; + Kind = ARMABIKind::AAPCS_VFP; return SetCGInfo(new ARMTargetCodeGenInfo(Types, Kind)); } @@ -12414,9 +12412,9 @@ return SetCGInfo(new AIXTargetCodeGenInfo(Types, /*Is64Bit*/ true)); if (Triple.isOSBinFormatELF()) { - PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv1; + PPC64_SVR4_ABIKind Kind = PPC64_SVR4_ABIKind::ELFv1; if (getTarget().getABI() == "elfv2") - Kind = PPC64_SVR4_ABIInfo::ELFv2; + Kind = PPC64_SVR4_ABIKind::ELFv2; bool IsSoftFloat = CodeGenOpts.FloatABI == "soft"; return SetCGInfo( @@ -12425,9 +12423,9 @@ return SetCGInfo(new PPC64TargetCodeGenInfo(Types)); case llvm::Triple::ppc64le: { assert(Triple.isOSBinFormatELF() && "PPC64 LE non-ELF not supported!"); - PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv2; + PPC64_SVR4_ABIKind Kind = PPC64_SVR4_ABIKind::ELFv2; if (getTarget().getABI() == "elfv1") - Kind = PPC64_SVR4_ABIInfo::ELFv1; + Kind = PPC64_SVR4_ABIKind::ELFv1; bool IsSoftFloat = CodeGenOpts.FloatABI == "soft"; return SetCGInfo(