From 4fa0204309b21d68d594c77bb0485ca2375ff480 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 15 Nov 2025 10:35:39 +0100 Subject: [PATCH 1/2] [CIR][NFC] Fix warnings after rebasing with the upstream --- clang/lib/CIR/CodeGen/CIRGenCXX.cpp | 3 +- clang/lib/CIR/CodeGen/CIRGenCall.cpp | 11 ++- clang/lib/CIR/CodeGen/CIRGenClass.cpp | 43 ++++----- clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 3 +- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 20 ++--- clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp | 16 ++-- clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp | 5 +- clang/lib/CIR/CodeGen/CIRGenExprConst.cpp | 11 ++- clang/lib/CIR/CodeGen/CIRGenFunction.cpp | 7 +- clang/lib/CIR/CodeGen/CIRGenFunction.h | 4 +- clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 28 +++--- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 9 +- clang/lib/CIR/CodeGen/CIRGenTBAA.cpp | 10 +-- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 19 ++-- clang/lib/CIR/CodeGen/TargetInfo.cpp | 4 +- .../Dialect/Transforms/LoweringPrepare.cpp | 5 +- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 46 +++++----- .../ThroughMLIR/LowerCIRLoopToSCF.cpp | 38 ++++---- .../Lowering/ThroughMLIR/LowerCIRToMLIR.cpp | 87 +++++++++---------- 19 files changed, 176 insertions(+), 193 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp index 328602187eb2..4b886ae15b87 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp @@ -77,8 +77,7 @@ bool CIRGenModule::tryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) { continue; // Skip base classes with trivial destructors. - const auto *Base = - cast(I.getType()->castAs()->getOriginalDecl()); + const auto *Base = I.getType()->getAsCXXRecordDecl(); if (Base->hasTrivialDestructor()) continue; diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 63e84a62ee42..3a35f67a4b9b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -790,7 +790,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const Expr *E, // However, we still have to push an EH-only cleanup in case we unwind before // we make it to the call. if (type->isRecordType() && - type->castAs()->getOriginalDecl()->isParamDestroyedInCallee()) { + type->castAs()->getDecl()->isParamDestroyedInCallee()) { llvm_unreachable("Microsoft C++ ABI is NYI"); } @@ -1105,10 +1105,9 @@ const CIRGenFunctionInfo & CIRGenTypes::arrangeFreeFunctionType(CanQual FTNP) { // When translating an unprototyped function type, always use a // variadic type. - return arrangeCIRFunctionInfo(FTNP->getReturnType().getUnqualifiedType(), - cir::FnInfoOpts::None, - llvm::ArrayRef{}, - FTNP->getExtInfo(), {}, RequiredArgs(0)); + return arrangeCIRFunctionInfo( + FTNP->getReturnType().getUnqualifiedType(), cir::FnInfoOpts::None, + llvm::ArrayRef{}, FTNP->getExtInfo(), {}, RequiredArgs(0)); } const CIRGenFunctionInfo & @@ -1218,7 +1217,7 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args, // Deactivate the cleanup for the callee-destructed param that was pushed. if (type->isRecordType() && !CurFuncIsThunk && - type->castAs()->getOriginalDecl()->isParamDestroyedInCallee() && + type->castAs()->getDecl()->isParamDestroyedInCallee() && param->needsDestruction(getContext())) { llvm_unreachable("NYI"); } diff --git a/clang/lib/CIR/CodeGen/CIRGenClass.cpp b/clang/lib/CIR/CodeGen/CIRGenClass.cpp index 6710ec69ae01..ff96febc8ede 100644 --- a/clang/lib/CIR/CodeGen/CIRGenClass.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenClass.cpp @@ -162,8 +162,8 @@ class FieldMemcpyizer { CharUnits memcpySize = getMemcpySize(firstByteOffset); QualType recordTy = CGF.getContext().getTagType( - ElaboratedTypeKeyword::None, /*Qualifier=*/std::nullopt, - ClassDecl, /*OwnsTag=*/false); + ElaboratedTypeKeyword::None, /*Qualifier=*/std::nullopt, ClassDecl, + /*OwnsTag=*/false); Address thisPtr = CGF.LoadCXXThisAddress(); LValue destLv = CGF.makeAddrLValue(thisPtr, recordTy); LValue dest = CGF.emitLValueForFieldInitialization(destLv, FirstField, @@ -521,8 +521,7 @@ class AssignmentMemcpyizer : public FieldMemcpyizer { static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit) { const Type *BaseType = BaseInit->getBaseClass(); - const auto *BaseClassDecl = - cast(BaseType->castAs()->getOriginalDecl()); + const auto *BaseClassDecl = BaseType->castAsCXXRecordDecl(); return BaseClassDecl->isDynamicClass(); } @@ -608,8 +607,7 @@ static void emitBaseInitializer(mlir::Location loc, CIRGenFunction &CGF, Address ThisPtr = CGF.LoadCXXThisAddress(); const Type *BaseType = BaseInit->getBaseClass(); - const auto *BaseClassDecl = - cast(BaseType->castAs()->getOriginalDecl()); + const auto *BaseClassDecl = BaseType->getAsCXXRecordDecl(); bool isBaseVirtual = BaseInit->isBaseVirtual(); @@ -871,8 +869,7 @@ void CIRGenFunction::getVTablePointers(BaseSubobject Base, // Traverse bases. for (const auto &I : RD->bases()) { - auto *BaseDecl = - cast(I.getType()->castAs()->getOriginalDecl()); + auto *BaseDecl = I.getType()->getAsCXXRecordDecl(); // Ignore classes without a vtable. if (!BaseDecl->isDynamicClass()) @@ -1088,7 +1085,7 @@ void CIRGenFunction::emitLambdaStaticInvokeBody(const CXXMethodDecl *MD) { void CIRGenFunction::destroyCXXObject(CIRGenFunction &CGF, Address addr, QualType type) { const RecordType *rtype = type->castAs(); - const CXXRecordDecl *record = cast(rtype->getOriginalDecl()); + const CXXRecordDecl *record = rtype->getAsCXXRecordDecl(); const CXXDestructorDecl *dtor = record->getDestructor(); // TODO(cir): Unlike traditional codegen, CIRGen should actually emit trivial // dtors which shall be removed on later CIR passes. However, only remove this @@ -1123,8 +1120,7 @@ HasTrivialDestructorBody(ASTContext &astContext, if (I.isVirtual()) continue; - const CXXRecordDecl *NonVirtualBase = - cast(I.getType()->castAs()->getOriginalDecl()); + const CXXRecordDecl *NonVirtualBase = I.getType()->getAsCXXRecordDecl(); if (!HasTrivialDestructorBody(astContext, NonVirtualBase, MostDerivedClassDecl)) return false; @@ -1133,8 +1129,7 @@ HasTrivialDestructorBody(ASTContext &astContext, if (BaseClassDecl == MostDerivedClassDecl) { // Check virtual bases. for (const auto &I : BaseClassDecl->vbases()) { - const CXXRecordDecl *VirtualBase = - cast(I.getType()->castAs()->getOriginalDecl()); + const CXXRecordDecl *VirtualBase = I.getType()->getAsCXXRecordDecl(); if (!HasTrivialDestructorBody(astContext, VirtualBase, MostDerivedClassDecl)) return false; @@ -1154,7 +1149,7 @@ static bool FieldHasTrivialDestructorBody(ASTContext &astContext, if (!RT) return true; - CXXRecordDecl *FieldClassDecl = cast(RT->getOriginalDecl()); + CXXRecordDecl *FieldClassDecl = RT->getAsCXXRecordDecl(); // The destructor for an implicit anonymous union member is never invoked. if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion()) @@ -1247,6 +1242,8 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &Args) { // we'd introduce *two* handler blocks. In the Microsoft ABI, we // always delegate because we might not have a definition in this TU. switch (DtorType) { + case Dtor_Unified: + llvm_unreachable("not expecting a unified dtor"); case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT"); case Dtor_Deleting: @@ -1405,8 +1402,7 @@ void CIRGenFunction::EnterDtorCleanups(const CXXDestructorDecl *DD, // We push them in the forward order so that they'll be popped in // the reverse order. for (const auto &Base : ClassDecl->vbases()) { - auto *BaseClassDecl = - cast(Base.getType()->castAs()->getOriginalDecl()); + auto *BaseClassDecl = Base.getType()->getAsCXXRecordDecl(); if (BaseClassDecl->hasTrivialDestructor()) { // Under SanitizeMemoryUseAfterDtor, poison the trivial base class @@ -1466,7 +1462,7 @@ void CIRGenFunction::EnterDtorCleanups(const CXXDestructorDecl *DD, // Anonymous union members do not have their destructors called. const RecordType *RT = type->getAsUnionType(); - if (RT && RT->getOriginalDecl()->isAnonymousStructOrUnion()) + if (RT && RT->getDecl()->isAnonymousStructOrUnion()) continue; CleanupKind cleanupKind = getCleanupKind(dtorKind); @@ -1593,8 +1589,7 @@ Address CIRGenFunction::getAddressOfDerivedClass( CastExpr::path_const_iterator pathEnd, bool nullCheckValue) { assert(pathBegin != pathEnd && "Base path should not be empty!"); - QualType derivedTy = - getContext().getCanonicalTagType(derived); + QualType derivedTy = getContext().getCanonicalTagType(derived); mlir::Type derivedValueTy = convertType(derivedTy); CharUnits nonVirtualOffset = CGM.getNonVirtualBaseClassOffset(derived, pathBegin, pathEnd); @@ -1624,8 +1619,7 @@ CIRGenFunction::getAddressOfBaseClass(Address Value, // *start* with a step down to the correct virtual base subobject, // and hence will not require any further steps. if ((*Start)->isVirtual()) { - VBase = cast( - (*Start)->getType()->castAs()->getOriginalDecl()); + VBase = (*Start)->getType()->getAsCXXRecordDecl(); ++Start; } @@ -1873,8 +1867,8 @@ void CIRGenFunction::emitCXXAggrConstructorCall( // Note that these are complete objects and so we don't need to // use the non-virtual size or alignment. QualType type = getContext().getTypeDeclType(ElaboratedTypeKeyword::None, - /*Qualifier=*/std::nullopt, - ctor->getParent()); + /*Qualifier=*/std::nullopt, + ctor->getParent()); CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement( getContext().getTypeSizeInChars(type)); @@ -1992,7 +1986,8 @@ void CIRGenFunction::emitCXXConstructorCall( if (!NewPointerIsChecked) emitTypeCheck(CIRGenFunction::TCK_ConstructorCall, Loc, This.getPointer(), - getContext().getCanonicalTagType(ClassDecl), CharUnits::Zero()); + getContext().getCanonicalTagType(ClassDecl), + CharUnits::Zero()); // If this is a call to a trivial default constructor: // In LLVM: do nothing. diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index 6b5c942fa193..74971b6796bf 100644 --- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp @@ -116,7 +116,7 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &D, allocaAddr = ReturnValue; if (const RecordType *RecordTy = Ty->getAs()) { - const auto *RD = RecordTy->getOriginalDecl(); + const auto *RD = RecordTy->getDecl(); const auto *CXXRD = dyn_cast(RD); if ((CXXRD && !CXXRD->hasTrivialDestructor()) || RD->isNonTrivialToPrimitiveDestroy()) { @@ -858,6 +858,7 @@ void CIRGenFunction::emitDecl(const Decl &D) { case Decl::MSGuid: // __declspec(uuid("...")) case Decl::TemplateParamObject: case Decl::OMPThreadPrivate: + case Decl::OMPGroupPrivate: case Decl::OMPAllocate: case Decl::OMPCapturedExpr: case Decl::OMPRequires: diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 4980e4ce7d11..cacdd23285a3 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -576,7 +576,7 @@ bool CIRGenFunction::hasBooleanRepresentation(QualType Ty) { return true; if (const EnumType *ET = Ty->getAs()) - return ET->getOriginalDecl()->getIntegerType()->isBooleanType(); + return ET->getDecl()->getIntegerType()->isBooleanType(); if (const AtomicType *AT = Ty->getAs()) return hasBooleanRepresentation(AT->getValueType()); @@ -992,7 +992,8 @@ LValue CIRGenFunction::emitLValueForLambdaField(const FieldDecl *field, if (hasExplicitObjectParameter) { llvm_unreachable("ExplicitObjectMemberFunction NYI"); } else { - QualType lambdaTagType = getContext().getCanonicalTagType(field->getParent()); + QualType lambdaTagType = + getContext().getCanonicalTagType(field->getParent()); lambdaLV = MakeNaturalAlignAddrLValue(thisValue, lambdaTagType); } return emitLValueForField(lambdaLV, field); @@ -1695,7 +1696,7 @@ static bool isPreserveAIArrayBase(CIRGenFunction &CGF, const Expr *ArrayBase) { const auto *PointeeT = PtrT->getPointeeType()->getUnqualifiedDesugaredType(); if (const auto *RecT = dyn_cast(PointeeT)) - return RecT->getOriginalDecl()->hasAttr(); + return RecT->getDecl()->hasAttr(); return false; } @@ -2023,10 +2024,7 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *E) { case CK_UncheckedDerivedToBase: case CK_DerivedToBase: { - const auto *DerivedClassTy = - E->getSubExpr()->getType()->castAs(); - auto *DerivedClassDecl = - cast(DerivedClassTy->getOriginalDecl()); + auto *DerivedClassDecl = E->getSubExpr()->getType()->getAsCXXRecordDecl(); LValue LV = emitLValue(E->getSubExpr()); Address This = LV.getAddress(); @@ -2045,9 +2043,7 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *E) { case CK_ToUnion: assert(0 && "NYI"); case CK_BaseToDerived: { - const auto *derivedClassTy = E->getType()->castAs(); - auto *derivedClassDecl = - cast(derivedClassTy->getOriginalDecl()); + auto *derivedClassDecl = E->getType()->getAsCXXRecordDecl(); LValue lv = emitLValue(E->getSubExpr()); @@ -2315,7 +2311,7 @@ static void pushTemporaryCleanup(CIRGenFunction &CGF, ->getBaseElementTypeUnsafe() ->getAs()) { // Get the destructor for the reference temporary. - if (auto *ClassDecl = dyn_cast(RT->getOriginalDecl())) { + if (auto *ClassDecl = RT->getAsCXXRecordDecl()) { if (!ClassDecl->hasTrivialDestructor()) ReferenceTemporaryDtor = ClassDecl->getDestructor(); } @@ -3191,7 +3187,7 @@ static bool isConstantEmittableObjectType(QualType type) { // Otherwise, all object types satisfy this except C++ classes with // mutable subobjects or non-trivial copy/destroy behavior. if (const auto *RT = dyn_cast(type)) - if (const auto *RD = dyn_cast(RT->getOriginalDecl())) + if (const auto *RD = dyn_cast(RT->getDecl())) if (RD->hasMutableFields() || !RD->isTrivial()) return false; diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp index 2ffe81d2fe4a..514e2af59dd7 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp @@ -589,7 +589,7 @@ bool AggExprEmitter::TypeRequiresGCollection(QualType T) { return false; // Don't mess with non-trivial C++ types. - RecordDecl *Record = RecordTy->getOriginalDecl(); + RecordDecl *Record = RecordTy->getDecl(); if (isa(Record) && (cast(Record)->hasNonTrivialCopyConstructor() || !cast(Record)->hasTrivialDestructor())) @@ -932,7 +932,7 @@ void AggExprEmitter::VisitCXXStdInitializerListExpr( Ctx.getAsConstantArrayType(E->getSubExpr()->getType()); assert(ArrayType && "std::initializer_list constructed from non-array"); - RecordDecl *Record = E->getType()->castAs()->getOriginalDecl(); + RecordDecl *Record = E->getType()->castAs()->getDecl(); RecordDecl::field_iterator Field = Record->field_begin(); assert(Field != Record->field_end() && Ctx.hasSameType(Field->getType()->getPointeeType(), @@ -1297,7 +1297,7 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr( // the disadvantage is that the generated code is more difficult for // the optimizer, especially with bitfields. unsigned NumInitElements = InitExprs.size(); - RecordDecl *record = ExprToVisit->getType()->castAs()->getOriginalDecl(); + RecordDecl *record = ExprToVisit->getType()->castAs()->getDecl(); // We'll need to enter cleanup scopes in case any of the element // initializers throws an exception. @@ -1534,7 +1534,7 @@ static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CIRGenFunction &CGF) { // referencee. InitListExprs for unions and arrays can't have references. if (const RecordType *RT = E->getType()->getAs()) { if (!RT->isUnionType()) { - RecordDecl *SD = RT->getOriginalDecl(); + RecordDecl *SD = RT->getDecl(); CharUnits NumNonZeroBytes = CharUnits::Zero(); unsigned ILEElement = 0; @@ -1586,7 +1586,7 @@ static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E, if (const auto *RT = CGF.getContext() .getBaseElementType(E->getType()) ->getAs()) { - const auto *RD = cast(RT->getOriginalDecl()); + const auto *RD = RT->getAsCXXRecordDecl(); if (RD->hasUserDeclaredConstructor()) return; } @@ -1661,7 +1661,7 @@ void CIRGenFunction::emitAggregateCopy(LValue Dest, LValue Src, QualType Ty, if (getLangOpts().CPlusPlus) { if (const RecordType *RT = Ty->getAs()) { - if (CXXRecordDecl *Record = dyn_cast(RT->getOriginalDecl())) { + if (CXXRecordDecl *Record = dyn_cast(RT->getDecl())) { assert((Record->hasTrivialCopyConstructor() || Record->hasTrivialCopyAssignment() || Record->hasTrivialMoveConstructor() || @@ -1734,14 +1734,14 @@ void CIRGenFunction::emitAggregateCopy(LValue Dest, LValue Src, QualType Ty, if (CGM.getLangOpts().getGC() == LangOptions::NonGC) { // fall through } else if (const RecordType *RecordTy = Ty->getAs()) { - RecordDecl *Record = RecordTy->getOriginalDecl(); + RecordDecl *Record = RecordTy->getDecl(); if (Record->hasObjectMember()) { llvm_unreachable("ObjC is NYI"); } } else if (Ty->isArrayType()) { QualType BaseType = getContext().getBaseElementType(Ty); if (const RecordType *RecordTy = BaseType->getAs()) { - if (RecordTy->getOriginalDecl()->hasObjectMember()) { + if (RecordTy->getDecl()->hasObjectMember()) { llvm_unreachable("ObjC is NYI"); } } diff --git a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp index fd54f8ddfaeb..5f9f2993271a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp @@ -103,8 +103,7 @@ static CXXRecordDecl *getCXXRecord(const Expr *E) { QualType T = E->getType(); if (const PointerType *PTy = T->getAs()) T = PTy->getPointeeType(); - const RecordType *Ty = T->castAs(); - return cast(Ty->getOriginalDecl()); + return T->getAsCXXRecordDecl(); } RValue @@ -1209,7 +1208,7 @@ static bool EmitObjectDelete(CIRGenFunction &CGF, const CXXDeleteExpr *DE, // destructor is virtual, we'll just emit the vcall and return. const CXXDestructorDecl *Dtor = nullptr; if (const RecordType *RT = ElementType->getAs()) { - CXXRecordDecl *RD = cast(RT->getOriginalDecl()); + CXXRecordDecl *RD = RT->getAsCXXRecordDecl(); if (RD->hasDefinition() && !RD->hasTrivialDestructor()) { Dtor = RD->getDestructor(); diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp index 07d96780427a..0e5a403968f2 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp @@ -617,8 +617,7 @@ static bool EmitDesignatedInitUpdater(ConstantEmitter &Emitter, } bool ConstRecordBuilder::Build(InitListExpr *ILE, bool AllowOverwrite) { - RecordDecl *RD = - ILE->getType()->castAs()->getOriginalDecl(); + RecordDecl *RD = ILE->getType()->castAs()->getDecl(); const ASTRecordLayout &Layout = CGM.getASTContext().getASTRecordLayout(RD); unsigned FieldNo = -1; @@ -875,7 +874,7 @@ bool ConstRecordBuilder::ApplyZeroInitPadding(const ASTRecordLayout &Layout, mlir::Attribute ConstRecordBuilder::Finalize(QualType Type) { Type = Type.getNonReferenceType(); - RecordDecl *RD = Type->castAs()->getOriginalDecl(); + RecordDecl *RD = Type->castAs()->getDecl(); mlir::Type ValTy = CGM.convertType(Type); return Builder.build(ValTy, RD->hasFlexibleArrayMember()); } @@ -898,7 +897,7 @@ mlir::Attribute ConstRecordBuilder::BuildRecord(ConstantEmitter &Emitter, ConstantAggregateBuilder Const(Emitter.CGM); ConstRecordBuilder Builder(Emitter, Const, CharUnits::Zero()); - const RecordDecl *RD = ValTy->castAs()->getOriginalDecl(); + const RecordDecl *RD = ValTy->castAs()->getDecl(); const CXXRecordDecl *CD = dyn_cast(RD); if (!Builder.Build(Val, RD, false, CD, CharUnits::Zero())) return nullptr; @@ -1690,7 +1689,7 @@ bool isEmptyRecordForLayout(const ASTContext &ctx, QualType t) { if (!rt) return false; - const RecordDecl *rd = rt->getOriginalDecl(); + const RecordDecl *rd = rt->getDecl(); // If this is a C++ record, check the bases first. if (const CXXRecordDecl *CXXRD = dyn_cast(rd)) { @@ -2097,7 +2096,7 @@ mlir::TypedAttr CIRGenModule::emitNullConstant(QualType T) { } if (const RecordType *rt = T->getAs()) - return ::emitNullConstant(*this, rt->getOriginalDecl(), /*complete object*/ + return ::emitNullConstant(*this, rt->getDecl(), /*complete object*/ true); assert(T->isMemberDataPointerType() && diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index de4c6723a1b7..808fe95af5b2 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -813,9 +813,8 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn, ctorKind = cir::CtorKind::Move; auto cxxCtor = cir::CXXCtorAttr::get( - convertType(getContext().getTypeDeclType(ElaboratedTypeKeyword::None, - std::nullopt, - ctor->getParent())), + convertType(getContext().getTypeDeclType( + ElaboratedTypeKeyword::None, std::nullopt, ctor->getParent())), ctorKind); fn.setCxxSpecialMemberAttr(cxxCtor); @@ -1570,7 +1569,7 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr, // Ignore empty classes in C++. if (getLangOpts().CPlusPlus) { if (const RecordType *rt = ty->getAs()) { - if (cast(rt->getOriginalDecl())->isEmpty()) + if (rt->getAsCXXRecordDecl()->isEmpty()) return; } } diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index a5bf5181db23..2d62cbce0a87 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -1161,10 +1161,8 @@ class CIRGenFunction : public CIRGenTypeCache { /// returns true if aggregate type has a volatile member. /// TODO(cir): this could be a common AST helper between LLVM / CIR. bool hasVolatileMember(QualType T) { - if (const RecordType *RT = T->getAs()) { - const RecordDecl *RD = mlir::cast(RT->getOriginalDecl()); + if (const auto *RD = T->getAsRecordDecl()) return RD->hasVolatileMember(); - } return false; } diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 12b10e9ef28c..8ba9c1501f12 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -143,6 +143,9 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI { case Dtor_Comdat: llvm_unreachable("emitting dtor comdat as function?"); + + case Dtor_Unified: + llvm_unreachable("emitting unified dtor as function?"); } llvm_unreachable("bad dtor kind"); } @@ -160,6 +163,9 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI { case Ctor_Comdat: llvm_unreachable("emitting ctor comdat as function?"); + + case Ctor_Unified: + llvm_unreachable("emitting unified ctor as function?"); } llvm_unreachable("bad dtor kind"); } @@ -1369,7 +1375,7 @@ static bool ShouldUseExternalRTTIDescriptor(CIRGenModule &CGM, QualType Ty) { return false; if (const RecordType *RecordTy = dyn_cast(Ty)) { - const CXXRecordDecl *RD = cast(RecordTy->getOriginalDecl()); + const CXXRecordDecl *RD = RecordTy->getAsCXXRecordDecl(); if (!RD->hasDefinition()) return false; @@ -1404,7 +1410,7 @@ static bool ShouldUseExternalRTTIDescriptor(CIRGenModule &CGM, QualType Ty) { /// Returns whether the given record type is incomplete. /// TODO(cir): this can unified with LLVM codegen static bool IsIncompleteClassType(const RecordType *RecordTy) { - return !RecordTy->getOriginalDecl()->isCompleteDefinition(); + return !RecordTy->getDecl()->isCompleteDefinition(); } /// Returns whether the given type contains an @@ -1432,7 +1438,9 @@ static bool ContainsIncompleteClassType(CIRGenModule &CGM, QualType Ty) { dyn_cast(Ty)) { // Check if the class type is incomplete. const auto *ClassType = cast( - CGM.getASTContext().getCanonicalTagType(MemberPointerTy->getMostRecentCXXRecordDecl()).getTypePtr()); + CGM.getASTContext() + .getCanonicalTagType(MemberPointerTy->getMostRecentCXXRecordDecl()) + .getTypePtr()); if (IsIncompleteClassType(ClassType)) return true; @@ -1464,7 +1472,7 @@ static bool CanUseSingleInheritance(const CXXRecordDecl *RD) { // Check that the class is dynamic iff the base is. auto *BaseDecl = - cast(Base->getType()->castAs()->getOriginalDecl()); + cast(Base->getType()->castAs()->getDecl()); if (!BaseDecl->isEmpty() && BaseDecl->isDynamicClass() != RD->isDynamicClass()) return false; @@ -1503,7 +1511,7 @@ static cir::GlobalLinkageKind getTypeInfoLinkage(CIRGenModule &CGM, return cir::GlobalLinkageKind::LinkOnceODRLinkage; if (const RecordType *Record = dyn_cast(Ty)) { - const CXXRecordDecl *RD = cast(Record->getOriginalDecl()); + const CXXRecordDecl *RD = Record->getAsCXXRecordDecl(); if (RD->hasAttr()) return cir::GlobalLinkageKind::WeakODRLinkage; if (CGM.getTriple().isWindowsItaniumEnvironment()) @@ -1646,7 +1654,7 @@ void CIRGenItaniumRTTIBuilder::BuildVTablePointer(mlir::Location loc, case Type::Record: { const CXXRecordDecl *RD = - cast(cast(Ty)->getOriginalDecl()); + cast(cast(Ty)->getDecl()); if (!RD->hasDefinition() || !RD->getNumBases()) { VTableName = ClassTypeInfo; @@ -2020,8 +2028,7 @@ mlir::Attribute CIRGenItaniumRTTIBuilder::BuildTypeInfo( break; case Type::Record: { - const CXXRecordDecl *RD = - cast(cast(Ty)->getOriginalDecl()); + const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); if (!RD->hasDefinition() || !RD->getNumBases()) { // We don't need to emit any fields. break; @@ -2143,8 +2150,9 @@ void CIRGenItaniumCXXABI::emitVTableDefinitions(CIRGenVTables &CGVT, ItaniumVTableContext &VTContext = CGM.getItaniumVTableContext(); const VTableLayout &VTLayout = VTContext.getVTableLayout(RD); auto Linkage = CGM.getVTableLinkage(RD); - auto RTTI = CGM.getAddrOfRTTIDescriptor( - CGM.getLoc(RD->getBeginLoc()), CGM.getASTContext().getCanonicalTagType(RD)); + auto RTTI = + CGM.getAddrOfRTTIDescriptor(CGM.getLoc(RD->getBeginLoc()), + CGM.getASTContext().getCanonicalTagType(RD)); // Create and set the initializer. ConstantInitBuilder builder(CGM); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 56121a721ae1..d2ce50152cc6 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -2219,7 +2219,7 @@ static bool isVarDeclStrongDefinition(const ASTContext &astContext, return true; if (const auto *rt = varType->getAs()) { - const RecordDecl *rd = rt->getOriginalDecl(); + const RecordDecl *rd = rt->getDecl(); for (const FieldDecl *fd : rd->fields()) { if (fd->isBitField()) continue; @@ -2766,8 +2766,7 @@ void CIRGenModule::setCXXSpecialMemberAttr( if (!funcDecl) return; - auto getConvertedRecordType = - [&](const CXXRecordDecl *record) -> mlir::Type { + auto getConvertedRecordType = [&](const CXXRecordDecl *record) -> mlir::Type { QualType recordTy = getASTContext().getTypeDeclType( ElaboratedTypeKeyword::None, std::nullopt, record); return convertType(recordTy); @@ -4163,9 +4162,7 @@ CharUnits CIRGenModule::computeNonVirtualBaseClassOffset( // Get the layout. const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd); - - const auto *baseDecl = cast( - base->getType()->castAs()->getOriginalDecl()); + const auto *baseDecl = base->getType()->getAsCXXRecordDecl(); // Add the offset. offset += layout.getBaseClassOffset(baseDecl); diff --git a/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp b/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp index 57fb21952c15..b0750a9c77c4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp @@ -51,7 +51,7 @@ static bool typeHasMayAlias(clang::QualType qty) { /// Check if the given type is a valid base type to be used in access tags. static bool isValidBaseType(clang::QualType qty) { if (const clang::RecordType *tty = qty->getAs()) { - const clang::RecordDecl *rd = tty->getOriginalDecl()->getDefinition(); + const clang::RecordDecl *rd = tty->getDecl()->getDefinition(); // Incomplete types are not valid base access types. if (!rd) return false; @@ -216,7 +216,7 @@ cir::TBAAAttr CIRGenTBAA::getTypeInfoHelper(clang::QualType qty) { // This also covers anonymous structs and unions, which have a different // compatibility rule, but it doesn't matter because you can never have a // pointer to an anonymous struct or union. - if (!rt->getOriginalDecl()->getDeclName()) + if (!rt->getDecl()->getDeclName()) return anyPtr; // For non-builtin types use the mangled name of the canonical type. @@ -241,13 +241,13 @@ cir::TBAAAttr CIRGenTBAA::getTypeInfoHelper(clang::QualType qty) { // however they aren't related for TBAA. if (const EnumType *ety = dyn_cast(ty)) { if (!features.CPlusPlus) - return getTypeInfo(ety->getOriginalDecl()->getIntegerType()); + return getTypeInfo(ety->getDecl()->getIntegerType()); // In C++ mode, types have linkage, so we can rely on the ODR and // on their mangled names, if they're external. // TODO: Is there a way to get a program-wide unique name for a // decl with local linkage or no linkage? - if (!ety->getOriginalDecl()->isExternallyVisible()) + if (!ety->getDecl()->isExternallyVisible()) return getChar(); SmallString<256> outName; @@ -361,7 +361,7 @@ cir::TBAAAttr CIRGenTBAA::getValidBaseTypeInfo(clang::QualType qty) { cir::TBAAAttr CIRGenTBAA::getBaseTypeInfoHelper(const clang::Type *ty) { using namespace clang; if (auto *tty = mlir::dyn_cast(ty)) { - const clang::RecordDecl *rd = tty->getOriginalDecl()->getDefinition(); + const clang::RecordDecl *rd = tty->getDecl()->getDefinition(); const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd); SmallVector fields; if (const CXXRecordDecl *cxxrd = dyn_cast(rd)) { diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index f76c885fec7e..4de89fc7081a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -119,7 +119,7 @@ isSafeToConvert(const RecordDecl *RD, CIRGenTypes &CGT, // the class. if (const CXXRecordDecl *CRD = dyn_cast(RD)) { for (const auto &I : CRD->bases()) - if (!isSafeToConvert(I.getType()->castAs()->getOriginalDecl(), CGT, + if (!isSafeToConvert(I.getType()->castAs()->getDecl(), CGT, AlreadyChecked)) return false; } @@ -145,7 +145,7 @@ isSafeToConvert(QualType T, CIRGenTypes &CGT, // If this is a record, check it. if (const auto *RT = T->getAs()) - return isSafeToConvert(RT->getOriginalDecl(), CGT, AlreadyChecked); + return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked); // If this is an array, check the elements, which are embedded inline. if (const auto *AT = CGT.getContext().getAsArrayType(T)) @@ -203,8 +203,7 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *RD) { for (const auto &I : cxxRecordDecl->bases()) { if (I.isVirtual()) continue; - convertRecordDeclType( - I.getType()->castAs()->getOriginalDecl()); + convertRecordDeclType(I.getType()->getAsRecordDecl()); } } @@ -354,7 +353,7 @@ mlir::Type CIRGenTypes::convertType(QualType T) { } if (const auto *recordType = dyn_cast(T)) - return convertRecordDeclType(recordType->getOriginalDecl()); + return convertRecordDeclType(recordType->getDecl()); // See if type is already cached. TypeCacheTy::iterator TCI = TypeCache.find(Ty); @@ -698,7 +697,7 @@ mlir::Type CIRGenTypes::convertType(QualType T) { } case Type::Enum: { - const EnumDecl *ED = cast(Ty)->getOriginalDecl(); + const EnumDecl *ED = cast(Ty)->getDecl(); if (ED->isCompleteDefinition() || ED->isFixed()) return convertType(ED->getIntegerType()); // Return a placeholder 'i32' type. This can be changed later when the @@ -836,9 +835,9 @@ void CIRGenTypes::UpdateCompletedType(const TagDecl *TD) { // a test case that meets that condition. C++ doesn't allow forward // declaration of enums, and C doesn't allow an incomplete forward // declaration with a non-default type. - assert( - !TypeCache.count(astContext.getCanonicalTagType(ED).getTypePtr()) || - (convertType(ED->getIntegerType()) == TypeCache[astContext.getCanonicalTagType(ED).getTypePtr()])); + assert(!TypeCache.count(astContext.getCanonicalTagType(ED).getTypePtr()) || + (convertType(ED->getIntegerType()) == + TypeCache[astContext.getCanonicalTagType(ED).getTypePtr()])); // If necessary, provide the full definition of a type only used with a // declaration so far. assert(!cir::MissingFeatures::generateDebugInfo()); @@ -903,7 +902,7 @@ bool CIRGenTypes::isZeroInitializable(QualType T) { // Records are non-zero-initializable if they contain any // non-zero-initializable subobjects. if (const RecordType *RT = T->getAs()) { - const RecordDecl *RD = RT->getOriginalDecl(); + const RecordDecl *RD = RT->getDecl(); return isZeroInitializable(RD); } diff --git a/clang/lib/CIR/CodeGen/TargetInfo.cpp b/clang/lib/CIR/CodeGen/TargetInfo.cpp index 7230cf5edc7c..d7e57cfc5a87 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.cpp +++ b/clang/lib/CIR/CodeGen/TargetInfo.cpp @@ -31,7 +31,7 @@ bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &Context, if (!RT) return false; - const RecordDecl *RD = RT->getOriginalDecl(); + const RecordDecl *RD = RT->getDecl(); // If this is a C++ record, check the bases first. if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { @@ -625,7 +625,7 @@ cir::ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy) const { if (Hi == Class::NoClass && mlir::isa(ResType)) { // Treat an enum type as its underlying type. if (const auto *EnumTy = RetTy->getAs()) - RetTy = EnumTy->getOriginalDecl()->getIntegerType(); + RetTy = EnumTy->getDecl()->getIntegerType(); if (RetTy->isIntegralOrEnumerationType() && isPromotableIntegerTypeForABI(RetTy)) { diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index f9b9da07be3b..3cf289d56e17 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -1137,8 +1137,7 @@ void LoweringPreparePass::buildCUDAModuleCtor() { mlir::Value nullPtr = builder.getNullPtr(handlePtrTy, loc); auto isNull = builder.createCompare(loc, cir::CmpOpKind::eq, handle, nullPtr); - - builder.create(loc, isNull, ifBlock, exitBlock); + cir::BrCondOp::create(builder, loc, isNull, ifBlock, exitBlock); } { // When handle is null we need to load the fatbin and register it @@ -1152,7 +1151,7 @@ void LoweringPreparePass::buildCUDAModuleCtor() { // Store the value back to the global `__cuda_gpubin_handle`. auto gpuBinaryHandleGlobal = builder.createGetGlobal(gpubinHandle); builder.createStore(loc, gpuBinaryHandle, gpuBinaryHandleGlobal); - builder.create(loc, exitBlock); + cir::BrOp::create(builder, loc, exitBlock); } { // Exit block diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 70c74cd0bab7..ebe7877b303f 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -182,8 +182,7 @@ void getOrCreateLLVMFuncOp(mlir::ConversionPatternRewriter &rewriter, mlir::Operation *srcOp, llvm::StringRef fnName, mlir::Type fnTy) { if (!fnTy) { - srcOp->emitError("failed to materialize LLVM function type for ") - << fnName; + srcOp->emitError("failed to materialize LLVM function type for ") << fnName; return; } auto llvmFnTy = mlir::dyn_cast(fnTy); @@ -194,14 +193,12 @@ void getOrCreateLLVMFuncOp(mlir::ConversionPatternRewriter &rewriter, } auto modOp = srcOp->getParentOfType(); if (!modOp) { - srcOp->emitError("expected parent module when declaring ") - << fnName; + srcOp->emitError("expected parent module when declaring ") << fnName; return; } auto enclosingFnOp = srcOp->getParentOfType(); if (!enclosingFnOp) { - srcOp->emitError("expected parent LLVM function when declaring ") - << fnName; + srcOp->emitError("expected parent LLVM function when declaring ") << fnName; return; } auto *sourceSymbol = mlir::SymbolTable::lookupSymbolIn(modOp, fnName); @@ -1323,20 +1320,20 @@ mlir::LogicalResult CIRToLLVMBrCondOpLowering::matchAndRewrite( i1Condition = adaptor.getCond(); auto *converter = getTypeConverter(); - auto trueBlock = convertSuccessorBlock( - rewriter, converter, brOp, brOp.getDestTrue(), - adaptor.getDestOperandsTrue().getTypes()); + auto trueBlock = + convertSuccessorBlock(rewriter, converter, brOp, brOp.getDestTrue(), + adaptor.getDestOperandsTrue().getTypes()); if (mlir::failed(trueBlock)) return mlir::failure(); - auto falseBlock = convertSuccessorBlock( - rewriter, converter, brOp, brOp.getDestFalse(), - adaptor.getDestOperandsFalse().getTypes()); + auto falseBlock = + convertSuccessorBlock(rewriter, converter, brOp, brOp.getDestFalse(), + adaptor.getDestOperandsFalse().getTypes()); if (mlir::failed(falseBlock)) return mlir::failure(); rewriter.replaceOpWithNewOp( - brOp, i1Condition, *trueBlock, adaptor.getDestOperandsTrue(), - *falseBlock, adaptor.getDestOperandsFalse()); + brOp, i1Condition, *trueBlock, adaptor.getDestOperandsTrue(), *falseBlock, + adaptor.getDestOperandsFalse()); return mlir::success(); } @@ -1828,7 +1825,6 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite( auto resultTy = getTypeConverter()->convertType(op.getType()); // Verification between the CIR alloca AS and the one from data layout. auto allocaAS = [&]() { - auto resPtrTy = mlir::cast(resultTy); auto dlAllocaASAttr = mlir::cast_if_present( dataLayout.getAllocaMemorySpace()); // TODO: The query for the alloca AS should be done through CIRDataLayout @@ -1841,8 +1837,9 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite( auto resPtrTy = mlir::LLVM::LLVMPointerType::get(elementTy.getContext(), allocaAS); - auto llvmAlloca = rewriter.create( - op.getLoc(), resPtrTy, elementTy, size, op.getAlignmentAttr().getInt()); + auto llvmAlloca = + mlir::LLVM::AllocaOp::create(rewriter, op->getLoc(), resPtrTy, elementTy, + size, op.getAlignmentAttr().getInt()); auto expectedPtrTy = mlir::cast( getTypeConverter()->convertType(op.getResult().getType())); @@ -1850,8 +1847,8 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite( mlir::Value finalPtr = llvmAlloca.getResult(); if (expectedPtrTy.getAddressSpace() != allocaAS) { - finalPtr = rewriter.create( - op.getLoc(), expectedPtrTy, finalPtr); + finalPtr = mlir::LLVM::AddrSpaceCastOp::create(rewriter, op.getLoc(), + expectedPtrTy, finalPtr); } // If there are annotations available, copy them out before we destroy the @@ -2703,8 +2700,8 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::lowerInitializer( useInitializerRegion); if (mlir::isa(init)) { + cir::GlobalViewAttr, cir::VTableAttr, cir::TypeInfoAttr>( + init)) { // TODO(cir): once LLVM's dialect has proper equivalent attributes this // should be updated. For now, we use a custom op to initialize globals // to the appropriate value. @@ -3451,8 +3448,8 @@ mlir::LogicalResult CIRToLLVMLLVMIntrinsicCallOpLowering::matchAndRewrite( if (name == "masked.load") { auto operands = adaptor.getOperands(); if (operands.size() == 4) { - if (auto ptrTy = - mlir::dyn_cast(operands[0].getType())) { + if (auto ptrTy = mlir::dyn_cast( + operands[0].getType())) { (void)ptrTy; auto elementTyAttr = mlir::TypeAttr::get(llvmResTy); mlir::IntegerAttr alignAttr; @@ -3522,7 +3519,8 @@ mlir::LogicalResult CIRToLLVMAssumeAlignedOpLowering::matchAndRewrite( auto loc = op.getLoc(); rewriter.setInsertionPoint(op); auto ptrReplacement = adaptor.getPointer(); - auto cond = mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI1Type(), 1); + auto cond = + mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI1Type(), 1); mlir::LLVM::AssumeOp::create(rewriter, loc, cond, "align", opBundleArgs); rewriter.replaceOp(op, ptrReplacement); diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp index e38cb4a8171c..f69e1637c665 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp @@ -229,12 +229,12 @@ cir::CmpOp SCFLoop::findCmpOp() { return cmpOp; } -mlir::Value SCFLoop::plusConstant(mlir::Value V, mlir::Location loc, +mlir::Value SCFLoop::plusConstant(mlir::Value v, mlir::Location loc, int addend) { - auto type = V.getType(); - auto c1 = rewriter->create( - loc, mlir::IntegerAttr::get(type, addend)); - return rewriter->create(loc, V, c1); + auto type = v.getType(); + auto c1 = mlir::arith::ConstantOp::create( + *rewriter, loc, mlir::IntegerAttr::get(type, addend)); + return mlir::arith::AddIOp::create(*rewriter, loc, v, c1); } // Return IV initial value by searching the store before the loop. @@ -313,9 +313,9 @@ void SCFLoop::transferToSCFForOp() { auto lb = getLowerBound(); auto loc = forOp.getLoc(); auto type = lb.getType(); - auto step = rewriter->create( - loc, mlir::IntegerAttr::get(type, getStep())); - auto scfForOp = rewriter->create(loc, lb, ub, step); + auto step = mlir::arith::ConstantOp::create( + *rewriter, loc, mlir::IntegerAttr::get(type, getStep())); + auto scfForOp = mlir::scf::ForOp::create(*rewriter, loc, lb, ub, step); SmallVector bbArg; rewriter->eraseOp(&scfForOp.getBody()->back()); rewriter->inlineBlockBefore(&forOp.getBody().front(), scfForOp.getBody(), @@ -347,8 +347,8 @@ void SCFLoop::transferToSCFForOp() { } void SCFLoop::transformToSCFWhileOp() { - auto scfWhileOp = rewriter->create( - forOp->getLoc(), forOp->getResultTypes(), mlir::ValueRange()); + auto scfWhileOp = mlir::scf::WhileOp::create( + *rewriter, forOp->getLoc(), forOp->getResultTypes(), mlir::ValueRange()); rewriter->createBlock(&scfWhileOp.getBefore()); rewriter->createBlock(&scfWhileOp.getAfter()); @@ -369,8 +369,8 @@ void SCFLoop::transformToSCFWhileOp() { } void SCFLoop::transformToCIRWhileOp() { - auto cirWhileOp = rewriter->create( - forOp->getLoc(), forOp->getResultTypes(), mlir::ValueRange()); + auto cirWhileOp = cir::WhileOp::create( + *rewriter, forOp->getLoc(), forOp->getResultTypes(), mlir::ValueRange()); rewriter->createBlock(&cirWhileOp.getCond()); rewriter->createBlock(&cirWhileOp.getBody()); @@ -393,8 +393,9 @@ void SCFLoop::transformToCIRWhileOp() { } mlir::scf::WhileOp SCFWhileLoop::transferToSCFWhileOp() { - auto scfWhileOp = rewriter->create( - whileOp->getLoc(), whileOp->getResultTypes(), adaptor.getOperands()); + auto scfWhileOp = mlir::scf::WhileOp::create(*rewriter, whileOp->getLoc(), + whileOp->getResultTypes(), + adaptor.getOperands()); rewriter->createBlock(&scfWhileOp.getBefore()); rewriter->createBlock(&scfWhileOp.getAfter()); rewriter->inlineBlockBefore(&whileOp.getCond().front(), @@ -417,14 +418,15 @@ void SCFDoLoop::transferToSCFWhileOp() { yieldOp->getResults()); rewriter->eraseOp(yieldOp); }; + auto afterBuilder = [&](mlir::OpBuilder &builder, mlir::Location loc, mlir::ValueRange args) { - rewriter->create(loc, args); + mlir::scf::YieldOp::create(*rewriter, loc, args); }; - rewriter->create(DoOp.getLoc(), DoOp->getResultTypes(), - adaptor.getOperands(), beforeBuilder, - afterBuilder); + mlir::scf::WhileOp::create(*rewriter, DoOp.getLoc(), DoOp->getResultTypes(), + adaptor.getOperands(), beforeBuilder, + afterBuilder); } class CIRForOpLowering : public mlir::OpConversionPattern { diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index 585a7004cf2f..5b4ec9c5cf16 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -33,8 +33,8 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Operation.h" -#include "mlir/IR/Region.h" #include "mlir/IR/PatternMatch.h" +#include "mlir/IR/Region.h" #include "mlir/IR/TypeRange.h" #include "mlir/IR/Value.h" #include "mlir/IR/ValueRange.h" @@ -370,11 +370,12 @@ static void eraseIfSafe(mlir::Value oldAddr, mlir::Value newAddr, } } -static mlir::LogicalResult prepareReinterpretMetadata( - mlir::MemRefType type, mlir::ConversionPatternRewriter &rewriter, - llvm::SmallVectorImpl &sizes, - llvm::SmallVectorImpl &strides, - mlir::Operation *anchorOp) { +static mlir::LogicalResult +prepareReinterpretMetadata(mlir::MemRefType type, + mlir::ConversionPatternRewriter &rewriter, + llvm::SmallVectorImpl &sizes, + llvm::SmallVectorImpl &strides, + mlir::Operation *anchorOp) { sizes.clear(); strides.clear(); @@ -744,7 +745,7 @@ class CIRFuncOpLowering : public mlir::OpConversionPattern { // TODO: once the func dialect supports variadic functions rewrite this // For now only insert special handling of printf via the llvmir dialect if (op.getSymName().equals_insensitive("printf")) { - auto context = rewriter.getContext(); + auto *context = rewriter.getContext(); // Create a llvmir dialect function declaration for printf, the // signature is: i32 (!llvm.ptr, ...) auto llvmI32Ty = mlir::IntegerType::get(context, 32); @@ -859,8 +860,8 @@ class CIRBinOpLowering : public mlir::OpConversionPattern { "operand type not supported yet"); auto type = op.getLhs().getType(); - if (auto VecType = mlir::dyn_cast(type)) { - type = VecType.getElementType(); + if (auto vecType = mlir::dyn_cast(type)) { + type = vecType.getElementType(); } switch (op.getKind()) { @@ -1146,9 +1147,8 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern { llvm_unreachable("GlobalOp lowering array with initial value fail"); } else if (auto constComplex = mlir::dyn_cast(init.value())) { - if (auto lowered = - cir::direct::lowerConstComplexAttr(constComplex, - getTypeConverter()); + if (auto lowered = cir::direct::lowerConstComplexAttr( + constComplex, getTypeConverter()); lowered.has_value()) initialValue = lowered.value(); else @@ -1163,8 +1163,7 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern { if (mlir::isa(elementType)) initialValue = mlir::DenseIntElementsAttr::get(rtt, 0); else if (mlir::isa(elementType)) { - auto floatZero = - mlir::FloatAttr::get(elementType, 0.0).getValue(); + auto floatZero = mlir::FloatAttr::get(elementType, 0.0).getValue(); initialValue = mlir::DenseFPElementsAttr::get(rtt, floatZero); } else initialValue = mlir::Attribute(); @@ -1239,22 +1238,19 @@ class CIRComplexCreateOpLowering matchAndRewrite(cir::ComplexCreateOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto loc = op.getLoc(); - auto vecType = - mlir::cast(getTypeConverter()->convertType( - op.getType())); + auto vecType = mlir::cast( + getTypeConverter()->convertType(op.getType())); auto zeroAttr = rewriter.getZeroAttr(vecType); mlir::Value result = - rewriter.create(loc, vecType, zeroAttr) + mlir::arith::ConstantOp::create(rewriter, loc, vecType, zeroAttr) .getResult(); SmallVector realIdx{0}; SmallVector imagIdx{1}; - result = rewriter - .create(loc, adaptor.getReal(), result, - realIdx) + result = mlir::vector::InsertOp::create(rewriter, loc, adaptor.getReal(), + result, realIdx) .getResult(); - result = rewriter - .create(loc, adaptor.getImag(), result, - imagIdx) + result = mlir::vector::InsertOp::create(rewriter, loc, adaptor.getImag(), + result, imagIdx) .getResult(); rewriter.replaceOp(op, result); return mlir::success(); @@ -1312,9 +1308,9 @@ class CIRVectorCreateLowering "cir.vec.create op count doesn't match vector type elements count"); for (uint64_t i = 0; i < vecTy.getSize(); ++i) { SmallVector position{static_cast(i)}; - vectorVal = mlir::vector::InsertOp::create( - rewriter, loc, adaptor.getElements()[i], - vectorVal, position) + vectorVal = mlir::vector::InsertOp::create(rewriter, loc, + adaptor.getElements()[i], + vectorVal, position) .getResult(); } rewriter.replaceOp(op, vectorVal); @@ -1332,11 +1328,11 @@ class CIRVectorInsertLowering mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value index = adaptor.getIndex(); if (!mlir::isa(index.getType())) - index = rewriter.create( - op.getLoc(), rewriter.getIndexType(), index); + index = mlir::arith::IndexCastOp::create(rewriter, op.getLoc(), + rewriter.getIndexType(), index); SmallVector position{index}; - auto newVec = rewriter.create( - op.getLoc(), adaptor.getValue(), adaptor.getVec(), position); + auto newVec = mlir::vector::InsertOp::create( + rewriter, op.getLoc(), adaptor.getValue(), adaptor.getVec(), position); rewriter.replaceOp(op, newVec.getResult()); return mlir::success(); } @@ -1352,11 +1348,11 @@ class CIRVectorExtractLowering mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value index = adaptor.getIndex(); if (!mlir::isa(index.getType())) - index = rewriter.create( - op.getLoc(), rewriter.getIndexType(), index); + index = mlir::arith::IndexCastOp::create(rewriter, op.getLoc(), + rewriter.getIndexType(), index); SmallVector position{index}; - auto extracted = rewriter.create( - op.getLoc(), adaptor.getVec(), position); + auto extracted = mlir::vector::ExtractOp::create( + rewriter, op.getLoc(), adaptor.getVec(), position); rewriter.replaceOp(op, extracted.getResult()); return mlir::success(); } @@ -1690,17 +1686,16 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns, CIRGetGlobalOpLowering, CIRComplexCreateOpLowering, CIRComplexRealOpLowering, CIRComplexImagOpLowering, CIRCastOpLowering, CIRPtrStrideOpLowering, CIRGetElementOpLowering, CIRSqrtOpLowering, - CIRCeilOpLowering, CIRExp2OpLowering, CIRExpOpLowering, - CIRFAbsOpLowering, CIRAbsOpLowering, CIRFloorOpLowering, - CIRLog10OpLowering, CIRLog2OpLowering, CIRLogOpLowering, - CIRRoundOpLowering, CIRSinOpLowering, CIRTanOpLowering, CIRShiftOpLowering, - CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering, - CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering, - CIRIfOpLowering, CIRScopeOpLowering, CIRVectorCreateLowering, - CIRVectorInsertLowering, CIRVectorExtractLowering, - CIRVectorCmpOpLowering, CIRACosOpLowering, CIRASinOpLowering, - CIRUnreachableOpLowering, CIRTrapOpLowering>(converter, - patterns.getContext()); + CIRCeilOpLowering, CIRExp2OpLowering, CIRExpOpLowering, CIRFAbsOpLowering, + CIRAbsOpLowering, CIRFloorOpLowering, CIRLog10OpLowering, + CIRLog2OpLowering, CIRLogOpLowering, CIRRoundOpLowering, CIRSinOpLowering, + CIRTanOpLowering, CIRShiftOpLowering, CIRBitClzOpLowering, + CIRBitCtzOpLowering, CIRBitPopcountOpLowering, CIRBitClrsbOpLowering, + CIRBitFfsOpLowering, CIRBitParityOpLowering, CIRIfOpLowering, + CIRScopeOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering, + CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering, + CIRASinOpLowering, CIRUnreachableOpLowering, CIRTrapOpLowering>( + converter, patterns.getContext()); } static mlir::TypeConverter prepareTypeConverter() { From 00bf20d93bab34e140ed80f2de8c0a490f522eb1 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Mon, 17 Nov 2025 19:50:49 +0100 Subject: [PATCH 2/2] Add change --- clang/lib/CIR/CodeGen/CIRGenCall.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 3a35f67a4b9b..20a596e1fe9c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -790,7 +790,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const Expr *E, // However, we still have to push an EH-only cleanup in case we unwind before // we make it to the call. if (type->isRecordType() && - type->castAs()->getDecl()->isParamDestroyedInCallee()) { + type->getAsRecordDecl()->isParamDestroyedInCallee()) { llvm_unreachable("Microsoft C++ ABI is NYI"); }