diff options
Diffstat (limited to 'clang/lib/CodeGen/Targets/X86.cpp')
| -rw-r--r-- | clang/lib/CodeGen/Targets/X86.cpp | 99 |
1 files changed, 33 insertions, 66 deletions
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 61b833a9c1b4..7ee8a0dc2a0d 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -352,15 +352,15 @@ bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty, return shouldReturnTypeInRegister(AT->getElementType(), Context); // Otherwise, it must be a record type. - const RecordType *RT = Ty->getAs<RecordType>(); - if (!RT) return false; + const auto *RD = Ty->getAsRecordDecl(); + if (!RD) + return false; // FIXME: Traverse bases here too. // Structure types are passed in register if all fields would be // passed in a register. - for (const auto *FD : - RT->getOriginalDecl()->getDefinitionOrSelf()->fields()) { + for (const auto *FD : RD->fields()) { // Empty fields are ignored. if (isEmptyField(Context, FD, true)) continue; @@ -427,11 +427,10 @@ static bool addBaseAndFieldSizes(ASTContext &Context, const CXXRecordDecl *RD, /// optimizations. bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty) const { // We can only expand structure types. - const RecordType *RT = Ty->getAs<RecordType>(); - if (!RT) + const RecordDecl *RD = Ty->getAsRecordDecl(); + if (!RD) return false; uint64_t Size = 0; - const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf(); if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { if (!IsWin32StructABI) { // On non-Windows, we have to conservatively match our old bitcode @@ -508,13 +507,10 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, } if (isAggregateTypeForABI(RetTy)) { - if (const RecordType *RT = RetTy->getAs<RecordType>()) { + if (const auto *RD = RetTy->getAsRecordDecl(); + RD && RD->hasFlexibleArrayMember()) // Structures with flexible arrays are always indirect. - if (RT->getOriginalDecl() - ->getDefinitionOrSelf() - ->hasFlexibleArrayMember()) - return getIndirectReturnResult(RetTy, State); - } + return getIndirectReturnResult(RetTy, State); // If specified, structs and unions are always indirect. if (!IsRetSmallStructInRegABI && !RetTy->isAnyComplexType()) @@ -556,8 +552,8 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, } // Treat an enum type as its underlying type. - if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) - RetTy = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = RetTy->getAsEnumDecl()) + RetTy = ED->getIntegerType(); if (const auto *EIT = RetTy->getAs<BitIntType>()) if (EIT->getNumBits() > 64) @@ -756,7 +752,7 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState &State, TypeInfo TI = getContext().getTypeInfo(Ty); // Check with the C++ ABI first. - const RecordType *RT = Ty->getAs<RecordType>(); + const RecordType *RT = Ty->getAsCanonical<RecordType>(); if (RT) { CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI()); if (RAA == CGCXXABI::RAA_Indirect) { @@ -885,9 +881,8 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState &State, return ABIArgInfo::getDirect(); } - - if (const EnumType *EnumTy = Ty->getAs<EnumType>()) - Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = Ty->getAsEnumDecl()) + Ty = ED->getIntegerType(); bool InReg = shouldPrimitiveUseInReg(Ty, State); @@ -1538,24 +1533,6 @@ static bool checkAVXParamFeature(DiagnosticsEngine &Diag, return false; } -static bool checkAVX512ParamFeature(DiagnosticsEngine &Diag, - SourceLocation CallLoc, - const llvm::StringMap<bool> &CallerMap, - const llvm::StringMap<bool> &CalleeMap, - QualType Ty, bool IsArgument) { - bool Caller256 = CallerMap.lookup("avx512f") && !CallerMap.lookup("evex512"); - bool Callee256 = CalleeMap.lookup("avx512f") && !CalleeMap.lookup("evex512"); - - // Forbid 512-bit or larger vector pass or return when we disabled ZMM - // instructions. - if (Caller256 || Callee256) - return Diag.Report(CallLoc, diag::err_avx_calling_convention) - << IsArgument << Ty << "evex512"; - - return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, - "avx512f", IsArgument); -} - static bool checkAVXParam(DiagnosticsEngine &Diag, ASTContext &Ctx, SourceLocation CallLoc, const llvm::StringMap<bool> &CallerMap, @@ -1563,8 +1540,8 @@ static bool checkAVXParam(DiagnosticsEngine &Diag, ASTContext &Ctx, bool IsArgument) { uint64_t Size = Ctx.getTypeSize(Ty); if (Size > 256) - return checkAVX512ParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, - IsArgument); + return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, + "avx512f", IsArgument); if (Size > 128) return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx", @@ -1850,10 +1827,9 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, return; } - if (const EnumType *ET = Ty->getAs<EnumType>()) { + if (const auto *ED = Ty->getAsEnumDecl()) { // Classify the underlying integer type. - classify(ET->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(), - OffsetBase, Lo, Hi, isNamedArg); + classify(ED->getIntegerType(), OffsetBase, Lo, Hi, isNamedArg); return; } @@ -2045,7 +2021,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, return; } - if (const RecordType *RT = Ty->getAs<RecordType>()) { + if (const RecordType *RT = Ty->getAsCanonical<RecordType>()) { uint64_t Size = getContext().getTypeSize(Ty); // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger @@ -2075,11 +2051,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, for (const auto &I : CXXRD->bases()) { assert(!I.isVirtual() && !I.getType()->isDependentType() && "Unexpected base class!"); - const auto *Base = - cast<CXXRecordDecl>( - I.getType()->castAs<RecordType>()->getOriginalDecl()) - ->getDefinitionOrSelf(); - + const auto *Base = I.getType()->castAsCXXRecordDecl(); // Classify this field. // // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate exceeds a @@ -2191,8 +2163,8 @@ ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const { // place naturally. if (!isAggregateTypeForABI(Ty)) { // Treat an enum type as its underlying type. - if (const EnumType *EnumTy = Ty->getAs<EnumType>()) - Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = Ty->getAsEnumDecl()) + Ty = ED->getIntegerType(); if (Ty->isBitIntType()) return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace()); @@ -2233,8 +2205,8 @@ ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty, if (!isAggregateTypeForABI(Ty) && !IsIllegalVectorType(Ty) && !Ty->isBitIntType()) { // Treat an enum type as its underlying type. - if (const EnumType *EnumTy = Ty->getAs<EnumType>()) - Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = Ty->getAsEnumDecl()) + Ty = ED->getIntegerType(); return (isPromotableIntegerTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty) : ABIArgInfo::getDirect()); @@ -2354,8 +2326,7 @@ static bool BitsContainNoUserData(QualType Ty, unsigned StartBit, return true; } - if (const RecordType *RT = Ty->getAs<RecordType>()) { - const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf(); + if (const auto *RD = Ty->getAsRecordDecl()) { const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); // If this is a C++ record, check the bases first. @@ -2363,10 +2334,7 @@ static bool BitsContainNoUserData(QualType Ty, unsigned StartBit, for (const auto &I : CXXRD->bases()) { assert(!I.isVirtual() && !I.getType()->isDependentType() && "Unexpected base class!"); - const auto *Base = - cast<CXXRecordDecl>( - I.getType()->castAs<RecordType>()->getOriginalDecl()) - ->getDefinitionOrSelf(); + const auto *Base = I.getType()->castAsCXXRecordDecl(); // If the base is after the span we care about, ignore it. unsigned BaseOffset = Context.toBits(Layout.getBaseClassOffset(Base)); @@ -2646,9 +2614,8 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy) const { // so that the parameter gets the right LLVM IR attributes. if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) { // Treat an enum type as its underlying type. - if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) - RetTy = - EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = RetTy->getAsEnumDecl()) + RetTy = ED->getIntegerType(); if (RetTy->isIntegralOrEnumerationType() && isPromotableIntegerTypeForABI(RetTy)) @@ -2797,8 +2764,8 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned freeIntRegs, // so that the parameter gets the right LLVM IR attributes. if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) { // Treat an enum type as its underlying type. - if (const EnumType *EnumTy = Ty->getAs<EnumType>()) - Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = Ty->getAsEnumDecl()) + Ty = ED->getIntegerType(); if (Ty->isIntegralOrEnumerationType() && isPromotableIntegerTypeForABI(Ty)) @@ -3324,14 +3291,14 @@ ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, unsigned &FreeSSERegs, if (Ty->isVoidType()) return ABIArgInfo::getIgnore(); - if (const EnumType *EnumTy = Ty->getAs<EnumType>()) - Ty = EnumTy->getOriginalDecl()->getDefinitionOrSelf()->getIntegerType(); + if (const auto *ED = Ty->getAsEnumDecl()) + Ty = ED->getIntegerType(); TypeInfo Info = getContext().getTypeInfo(Ty); uint64_t Width = Info.Width; CharUnits Align = getContext().toCharUnitsFromBits(Info.Align); - const RecordType *RT = Ty->getAs<RecordType>(); + const RecordType *RT = Ty->getAsCanonical<RecordType>(); if (RT) { if (!IsReturnType) { if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI())) |
