From d83ce0c5da0361baa968ace63e4e79690e57381c Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Wed, 10 Jan 2024 02:33:39 +0100 Subject: [PATCH] [CIR][NFC] Enable the formatting workflow for llvm/clangir and format the files (#390) Fixes #345 --- .github/workflows/pr-code-format.yml | 2 +- .../include/clang/CIR/Dialect/IR/CIRDialect.h | 2 +- .../clang/CIR/Dialect/IR/CIRTypesDetails.h | 2 +- clang/lib/CIR/CodeGen/CIRAsm.cpp | 4 +- clang/lib/CIR/CodeGen/CIRGenBuilder.h | 4 +- clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp | 10 +- clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 2 +- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 8 +- clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp | 71 ++++++------ clang/lib/CIR/CodeGen/CIRGenExprConst.cpp | 7 +- clang/lib/CIR/CodeGen/CIRGenFunction.h | 8 +- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 8 +- clang/lib/CIR/CodeGen/CIRGenModule.h | 6 +- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 2 +- clang/lib/CIR/CodeGen/CIRGenVTables.cpp | 3 +- .../CIR/CodeGen/CIRRecordLayoutBuilder.cpp | 6 +- clang/lib/CIR/CodeGen/EHScopeStack.h | 21 ++-- clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 4 +- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 8 +- .../Dialect/Transforms/LoweringPrepare.cpp | 21 ++-- .../lib/CIR/Dialect/Transforms/StdHelpers.cpp | 2 +- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 101 +++++++++--------- 22 files changed, 143 insertions(+), 159 deletions(-) diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml index 1d1fa2483b65..d47efe586dc8 100644 --- a/.github/workflows/pr-code-format.yml +++ b/.github/workflows/pr-code-format.yml @@ -10,7 +10,7 @@ permissions: jobs: code_formatter: runs-on: ubuntu-latest - if: github.repository == 'llvm/llvm-project' + if: github.repository == 'llvm/clangir' steps: - name: Fetch LLVM sources uses: actions/checkout@v4 diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h index 191910c2749b..47f80cc8a635 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h +++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h @@ -18,9 +18,9 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" +#include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/LoopLikeInterface.h" #include "mlir/Interfaces/SideEffectInterfaces.h" diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h b/clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h index ae9e97ce3cab..5eba4ac460a7 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h @@ -1,4 +1,4 @@ -//===- CIRTypesDetails.h - Details of CIR dialect types -----------*- C++ -*-===// +//===- CIRTypesDetails.h - Details of CIR dialect types ---------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/clang/lib/CIR/CodeGen/CIRAsm.cpp b/clang/lib/CIR/CodeGen/CIRAsm.cpp index 91d3f5420a77..bf184a3d4f07 100644 --- a/clang/lib/CIR/CodeGen/CIRAsm.cpp +++ b/clang/lib/CIR/CodeGen/CIRAsm.cpp @@ -41,8 +41,8 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) { AsmDialect AsmDialect = inferDialect(CGM, S); - builder.create( - getLoc(S.getAsmLoc()), ResultType, AsmString, AsmDialect); + builder.create(getLoc(S.getAsmLoc()), ResultType, + AsmString, AsmDialect); return mlir::success(); } \ No newline at end of file diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 7b2b87bdf4fd..49a0fa276832 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -787,10 +787,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy { return create(loc, ty); } - mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v) { + mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc, + mlir::Value v) { return create(loc, v); } - }; } // namespace cir diff --git a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp index 98e1f9281a33..1c05018b535d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp @@ -194,10 +194,9 @@ CIRGenFunction::buildCoroAllocBuiltinCall(mlir::Location loc) { mlir::cir::FuncOp fnOp; if (!builtin) { - fnOp = CGM.createCIRFunction( - loc, CGM.builtinCoroAlloc, - mlir::cir::FuncType::get({int32Ty}, boolTy), - /*FD=*/nullptr); + fnOp = CGM.createCIRFunction(loc, CGM.builtinCoroAlloc, + mlir::cir::FuncType::get({int32Ty}, boolTy), + /*FD=*/nullptr); assert(fnOp && "should always succeed"); fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext())); } else @@ -217,8 +216,7 @@ CIRGenFunction::buildCoroBeginBuiltinCall(mlir::Location loc, if (!builtin) { fnOp = CGM.createCIRFunction( loc, CGM.builtinCoroBegin, - mlir::cir::FuncType::get({int32Ty, VoidPtrTy}, - VoidPtrTy), + mlir::cir::FuncType::get({int32Ty, VoidPtrTy}, VoidPtrTy), /*FD=*/nullptr); assert(fnOp && "should always succeed"); fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext())); diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index 77dae8cfb878..662d24cd63a9 100644 --- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp @@ -892,7 +892,7 @@ struct CallCleanupFunction final : EHScopeStack::Cleanup { /// Push the standard destructor for the given type as /// at least a normal cleanup. void CIRGenFunction::pushDestroy(QualType::DestructionKind dtorKind, - Address addr, QualType type) { + Address addr, QualType type) { assert(dtorKind && "cannot push destructor for trivial type"); CleanupKind cleanupKind = getCleanupKind(dtorKind); diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 6499305ab0d9..08eb18301824 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -234,8 +234,8 @@ Address CIRGenFunction::getAddrOfBitFieldStorage(LValue base, auto fieldPtr = mlir::cir::PointerType::get(getBuilder().getContext(), fieldType); - auto sea = getBuilder().createGetMember( - loc, fieldPtr, base.getPointer(), field->getName(), index); + auto sea = getBuilder().createGetMember(loc, fieldPtr, base.getPointer(), + field->getName(), index); return Address(sea, CharUnits::One()); } @@ -341,7 +341,7 @@ LValue CIRGenFunction::buildLValueForField(LValue base, if (!IsInPreservedAIRegion && (!getDebugInfo() || !rec->hasAttr())) { llvm::StringRef fieldName = field->getName(); - auto& layout = CGM.getTypes().getCIRGenRecordLayout(field->getParent()); + auto &layout = CGM.getTypes().getCIRGenRecordLayout(field->getParent()); unsigned fieldIndex = layout.getCIRFieldNo(field); if (CGM.LambdaFieldToName.count(field)) @@ -396,7 +396,7 @@ LValue CIRGenFunction::buildLValueForFieldInitialization( if (!FieldType->isReferenceType()) return buildLValueForField(Base, Field); - auto& layout = CGM.getTypes().getCIRGenRecordLayout(Field->getParent()); + auto &layout = CGM.getTypes().getCIRGenRecordLayout(Field->getParent()); unsigned FieldIndex = layout.getCIRFieldNo(Field); Address V = buildAddrOfFieldStorage(*this, Base.getAddress(), Field, diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp index 199a0345c11e..d1abc8cdc73e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp @@ -60,37 +60,36 @@ static bool isBlockVarRef(const Expr *E) { // FIXME: pointer arithmetic? return false; - // Check both sides of a conditional operator. - } else if (const AbstractConditionalOperator *op - = dyn_cast(E)) { - return isBlockVarRef(op->getTrueExpr()) - || isBlockVarRef(op->getFalseExpr()); - - // OVEs are required to support BinaryConditionalOperators. - } else if (const OpaqueValueExpr *op - = dyn_cast(E)) { + // Check both sides of a conditional operator. + } else if (const AbstractConditionalOperator *op = + dyn_cast(E)) { + return isBlockVarRef(op->getTrueExpr()) || + isBlockVarRef(op->getFalseExpr()); + + // OVEs are required to support BinaryConditionalOperators. + } else if (const OpaqueValueExpr *op = dyn_cast(E)) { if (const Expr *src = op->getSourceExpr()) return isBlockVarRef(src); - // Casts are necessary to get things like (*(int*)&var) = foo(). - // We don't really care about the kind of cast here, except - // we don't want to look through l2r casts, because it's okay - // to get the *value* in a __block variable. + // Casts are necessary to get things like (*(int*)&var) = foo(). + // We don't really care about the kind of cast here, except + // we don't want to look through l2r casts, because it's okay + // to get the *value* in a __block variable. } else if (const CastExpr *cast = dyn_cast(E)) { if (cast->getCastKind() == CK_LValueToRValue) return false; return isBlockVarRef(cast->getSubExpr()); - // Handle unary operators. Again, just aggressively look through - // it, ignoring the operation. + // Handle unary operators. Again, just aggressively look through + // it, ignoring the operation. } else if (const UnaryOperator *uop = dyn_cast(E)) { return isBlockVarRef(uop->getSubExpr()); - // Look into the base of a field access. + // Look into the base of a field access. } else if (const MemberExpr *mem = dyn_cast(E)) { return isBlockVarRef(mem->getBase()); - // Look into the base of a subscript. + // Look into the base of a subscript. } else if (const ArraySubscriptExpr *sub = dyn_cast(E)) { return isBlockVarRef(sub->getBase()); } @@ -113,7 +112,8 @@ class AggExprEmitter : public StmtVisitor { llvm::function_ref Fn); AggValueSlot EnsureSlot(mlir::Location loc, QualType T) { - if (!Dest.isIgnored()) return Dest; + if (!Dest.isIgnored()) + return Dest; return CGF.CreateAggTemp(T, loc, "agg.tmp.ensured"); } @@ -213,11 +213,11 @@ class AggExprEmitter : public StmtVisitor { // For an assignment to work, the value on the right has // to be compatible with the value on the left. assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(), - E->getRHS()->getType()) - && "Invalid assignment"); + E->getRHS()->getType()) && + "Invalid assignment"); if (isBlockVarRef(E->getLHS()) && - E->getRHS()->HasSideEffects(CGF.getContext())) { + E->getRHS()->HasSideEffects(CGF.getContext())) { llvm_unreachable("NYI"); } @@ -233,12 +233,11 @@ class AggExprEmitter : public StmtVisitor { // Codegen the RHS so that it stores directly into the LHS. AggValueSlot lhsSlot = AggValueSlot::forLValue( - lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers, - AggValueSlot::IsAliased, AggValueSlot::MayOverlap); + lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers, + AggValueSlot::IsAliased, AggValueSlot::MayOverlap); // A non-volatile aggregate destination might have volatile member. - if (!lhsSlot.isVolatile() && - CGF.hasVolatileMember(E->getLHS()->getType())) + if (!lhsSlot.isVolatile() && CGF.hasVolatileMember(E->getLHS()->getType())) assert(!UnimplementedFeature::atomicTypes()); CGF.buildAggExpr(E->getRHS(), lhsSlot); @@ -247,10 +246,10 @@ class AggExprEmitter : public StmtVisitor { buildFinalDestCopy(E->getType(), lhs); if (!Dest.isIgnored() && !Dest.isExternallyDestructed() && - E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) + E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(), - E->getType()); - } + E->getType()); + } void VisitBinComma(const BinaryOperator *E) { llvm_unreachable("NYI"); } void VisitBinCmp(const BinaryOperator *E) { llvm_unreachable("NYI"); } @@ -356,8 +355,8 @@ void AggExprEmitter::buildFinalDestCopy(QualType type, const LValue &src, assert(!UnimplementedFeature::volatileTypes()); if (SrcValueKind == EVK_RValue) { - if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) { - llvm_unreachable("move assignment/move ctor for rvalue is NYI"); + if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) { + llvm_unreachable("move assignment/move ctor for rvalue is NYI"); } } else { if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) @@ -674,8 +673,8 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) { } // Emit initialization - LValue LV = CGF.buildLValueForFieldInitialization( - SlotLV, *CurField, fieldName); + LValue LV = + CGF.buildLValueForFieldInitialization(SlotLV, *CurField, fieldName); if (CurField->hasCapturedVLAType()) { llvm_unreachable("NYI"); } @@ -822,8 +821,8 @@ void AggExprEmitter::withReturnValueSlot( if (!UseTemp) { RetAddr = Dest.getAddress(); } else { - RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()), - "tmp", &RetAddr); + RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()), "tmp", + &RetAddr); assert(!UnimplementedFeature::shouldEmitLifetimeMarkers() && "NYI"); } @@ -942,8 +941,8 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr( if (curInitIndex == NumInitElements && Dest.isZeroed() && CGF.getTypes().isZeroInitializable(ExprToVisit->getType())) break; - LValue LV = CGF.buildLValueForFieldInitialization( - DestLV, field, field->getName()); + LValue LV = + CGF.buildLValueForFieldInitialization(DestLV, field, field->getName()); // We never generate write-barries for initialized fields. assert(!UnimplementedFeature::setNonGC()); diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp index 7ab02d691a5a..6b5ad352551a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp @@ -908,7 +908,7 @@ class ConstExprEmitter // Look through the temporary; it's just converting the value to an lvalue // to pass it to the constructor. if (auto *MTE = dyn_cast(Arg)) - return Visit(MTE->getSubExpr(), Ty); + return Visit(MTE->getSubExpr(), Ty); // Don't try to support arbitrary lvalue-to-rvalue conversions for now. return nullptr; } @@ -1075,8 +1075,7 @@ class ConstantLValueEmitter ConstantLValue applyOffset(ConstantLValue &C) { // Handle attribute constant LValues. - if (auto Attr = - C.Value.dyn_cast()) { + if (auto Attr = C.Value.dyn_cast()) { if (auto GV = Attr.dyn_cast()) { auto baseTy = GV.getType().cast().getPointee(); auto destTy = CGM.getTypes().convertTypeForMem(DestType); @@ -1339,7 +1338,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) { } InConstantContext = D.hasConstantInitialization(); - const Expr * E = D.getInit(); + const Expr *E = D.getInit(); assert(E && "No initializer to emit"); QualType destType = D.getType(); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index 7b8ce358f301..024ec494bc5b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -771,7 +771,7 @@ class CIRGenFunction : public CIRGenTypeCache { /// Create a check for a function parameter that may potentially be /// declared as non-null. void buildNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, - AbstractCallee AC, unsigned ParmNum); + AbstractCallee AC, unsigned ParmNum); void buildCallArg(CallArgList &args, const clang::Expr *E, clang::QualType ArgType); @@ -1362,7 +1362,7 @@ class CIRGenFunction : public CIRGenTypeCache { AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD); LValue buildLValueForField(LValue Base, const clang::FieldDecl *Field); LValue buildLValueForBitField(LValue base, const FieldDecl *field); - + /// Like buildLValueForField, excpet that if the Field is a reference, this /// will return the address of the reference and not the address of the value /// stored in the reference. @@ -1520,8 +1520,8 @@ class CIRGenFunction : public CIRGenTypeCache { static Destroyer destroyCXXObject; - void pushDestroy(QualType::DestructionKind dtorKind, - Address addr, QualType type); + void pushDestroy(QualType::DestructionKind dtorKind, Address addr, + QualType type); void pushDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 0013adb582b1..c811b0f6d76f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -100,10 +100,10 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context, const clang::CodeGenOptions &CGO, DiagnosticsEngine &Diags) : builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()), - codeGenOpts(CGO), theModule{mlir::ModuleOp::create( - builder.getUnknownLoc())}, - Diags(Diags), target(astCtx.getTargetInfo()), - ABI(createCXXABI(*this)), genTypes{*this}, VTables{*this} { + codeGenOpts(CGO), + theModule{mlir::ModuleOp::create(builder.getUnknownLoc())}, Diags(Diags), + target(astCtx.getTargetInfo()), ABI(createCXXABI(*this)), genTypes{*this}, + VTables{*this} { // Initialize CIR signed integer types cache. SInt8Ty = diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index a0b30e7464ab..e468c53e58d4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -196,7 +196,7 @@ class CIRGenModule : public CIRGenTypeCache { mlir::cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &D, - mlir::cir::GlobalLinkageKind Linkage); + mlir::cir::GlobalLinkageKind Linkage); mlir::cir::GlobalOp buildGlobal(const VarDecl *D, mlir::Type Ty, ForDefinition_t IsForDefinition); @@ -239,7 +239,7 @@ class CIRGenModule : public CIRGenTypeCache { ForDefinition_t IsForDefinition = NotForDefinition); /// Get a reference to the target of VD. - mlir::Operation* getWeakRefReference(const ValueDecl *VD); + mlir::Operation *getWeakRefReference(const ValueDecl *VD); CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, @@ -509,7 +509,7 @@ class CIRGenModule : public CIRGenTypeCache { /// Emit the function that initializes the specified global void buildGlobalVarDeclInit(const VarDecl *D, mlir::cir::GlobalOp Addr, - bool PerformInit); + bool PerformInit); void addDeferredVTable(const CXXRecordDecl *RD) { DeferredVTables.push_back(RD); diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 07535d459d34..1513b7003fb6 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -631,7 +631,7 @@ mlir::Type CIRGenTypes::ConvertType(QualType T) { SkippedLayout = true; ResultType = Builder.getUInt8Ty(); } - ResultType = Builder.getArrayType(ResultType, 0); + ResultType = Builder.getArrayType(ResultType, 0); break; } case Type::ConstantArray: { diff --git a/clang/lib/CIR/CodeGen/CIRGenVTables.cpp b/clang/lib/CIR/CodeGen/CIRGenVTables.cpp index 4add04e56ccb..673f5feec48c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenVTables.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenVTables.cpp @@ -434,8 +434,7 @@ getAddrOfVTTVTable(CIRGenVTables &CGVT, CIRGenModule &CGM, llvm_unreachable("generateConstructionVTable NYI"); } -mlir::cir::GlobalOp CIRGenVTables::getAddrOfVTT(const CXXRecordDecl *RD) -{ +mlir::cir::GlobalOp CIRGenVTables::getAddrOfVTT(const CXXRecordDecl *RD) { assert(RD->getNumVBases() && "Only classes with virtual bases need a VTT"); SmallString<256> OutName; diff --git a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp index effad38412a5..066906c1adc4 100644 --- a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp @@ -215,8 +215,8 @@ CIRRecordLowering::CIRRecordLowering(CIRGenTypes &cirGenTypes, cxxRecordDecl{llvm::dyn_cast(recordDecl)}, astRecordLayout{cirGenTypes.getContext().getASTRecordLayout(recordDecl)}, dataLayout{cirGenTypes.getModule().getModule()}, - IsZeroInitializable(true), - IsZeroInitializableAsBase(true), isPacked{isPacked} {} + IsZeroInitializable(true), IsZeroInitializableAsBase(true), + isPacked{isPacked} {} void CIRRecordLowering::setBitFieldInfo(const FieldDecl *FD, CharUnits StartOffset, @@ -227,7 +227,7 @@ void CIRRecordLowering::setBitFieldInfo(const FieldDecl *FD, (unsigned)(getFieldBitOffset(FD) - astContext.toBits(StartOffset)); Info.Size = FD->getBitWidthValue(astContext); Info.StorageSize = getSizeInBits(StorageType).getQuantity(); - Info.StorageOffset = StartOffset; + Info.StorageOffset = StartOffset; Info.Name = FD->getName(); if (Info.Size > Info.StorageSize) diff --git a/clang/lib/CIR/CodeGen/EHScopeStack.h b/clang/lib/CIR/CodeGen/EHScopeStack.h index 8711cd3c232e..5ab356df319f 100644 --- a/clang/lib/CIR/CodeGen/EHScopeStack.h +++ b/clang/lib/CIR/CodeGen/EHScopeStack.h @@ -73,7 +73,7 @@ struct DominatingPointer; template struct DominatingPointer : InvariantValue {}; // template struct DominatingPointer at end of file -template struct DominatingValue : DominatingPointer {}; +template struct DominatingValue : DominatingPointer {}; enum CleanupKind : unsigned { /// Denotes a cleanup that should run when a scope is exited using exceptional @@ -268,9 +268,9 @@ class EHScopeStack { public: EHScopeStack() - : StartOfBuffer(nullptr), EndOfBuffer(nullptr), StartOfData(nullptr), - InnermostNormalCleanup(stable_end()), InnermostEHScope(stable_end()), - CGF(nullptr) {} + : StartOfBuffer(nullptr), EndOfBuffer(nullptr), StartOfData(nullptr), + InnermostNormalCleanup(stable_end()), InnermostEHScope(stable_end()), + CGF(nullptr) {} ~EHScopeStack() { delete[] StartOfBuffer; } /// Push a lazily-created cleanup on the stack. @@ -279,7 +279,7 @@ class EHScopeStack { "Cleanup's alignment is too large."); void *Buffer = pushCleanup(Kind, sizeof(T)); Cleanup *Obj = new (Buffer) T(A...); - (void) Obj; + (void)Obj; } /// Push a lazily-created cleanup on the stack. Tuple version. @@ -289,7 +289,7 @@ class EHScopeStack { "Cleanup's alignment is too large."); void *Buffer = pushCleanup(Kind, sizeof(T)); Cleanup *Obj = new (Buffer) T(std::move(A)); - (void) Obj; + (void)Obj; } // Feel free to add more variants of the following: @@ -364,10 +364,7 @@ class EHScopeStack { } stable_iterator getInnermostActiveNormalCleanup() const; - stable_iterator getInnermostEHScope() const { - return InnermostEHScope; - } - + stable_iterator getInnermostEHScope() const { return InnermostEHScope; } /// An unstable reference to a scope-stack depth. Invalidated by /// pushes but not pops. @@ -387,9 +384,7 @@ class EHScopeStack { } /// Create a stable reference to the bottom of the EH stack. - static stable_iterator stable_end() { - return stable_iterator(0); - } + static stable_iterator stable_end() { return stable_iterator(0); } /// Translates an iterator into a stable_iterator. stable_iterator stabilize(iterator it) const; diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index b4794921165b..e6362b34b24c 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -221,9 +221,9 @@ Attribute ConstPtrAttr::parse(AsmParser &parser, Type odsType) { void ConstPtrAttr::print(AsmPrinter &printer) const { printer << '<'; if (isNullValue()) - printer << "null"; + printer << "null"; else - printer << getValue(); + printer << getValue(); printer << '>'; } diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index af6b0b85f3f5..cab294012cd7 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -189,8 +189,8 @@ bool omitRegionTerm(mlir::Region &r) { // CIR Custom Parsers/Printers //===----------------------------------------------------------------------===// -static mlir::ParseResult -parseOmittedTerminatorRegion(mlir::OpAsmParser &parser, mlir::Region ®ion) { +static mlir::ParseResult parseOmittedTerminatorRegion(mlir::OpAsmParser &parser, + mlir::Region ®ion) { auto regionLoc = parser.getCurrentLocation(); if (parser.parseRegion(region)) return failure(); @@ -200,8 +200,8 @@ parseOmittedTerminatorRegion(mlir::OpAsmParser &parser, mlir::Region ®ion) { } static void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer, - mlir::cir::ScopeOp &op, - mlir::Region ®ion) { + mlir::cir::ScopeOp &op, + mlir::Region ®ion) { printer.printRegion(region, /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/!omitRegionTerm(region)); diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index 63148b74c4ca..611a35eacc2a 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -109,9 +109,8 @@ struct LoweringPreparePass : public LoweringPrepareBase { GlobalOp LoweringPreparePass::buildRuntimeVariable( mlir::OpBuilder &builder, llvm::StringRef name, mlir::Location loc, mlir::Type type, mlir::cir::GlobalLinkageKind linkage) { - GlobalOp g = - dyn_cast_or_null(SymbolTable::lookupNearestSymbolFrom( - theModule, StringAttr::get(theModule->getContext(), name))); + GlobalOp g = dyn_cast_or_null(SymbolTable::lookupNearestSymbolFrom( + theModule, StringAttr::get(theModule->getContext(), name))); if (!g) { g = builder.create(loc, name, type); g.setLinkageAttr( @@ -125,9 +124,8 @@ GlobalOp LoweringPreparePass::buildRuntimeVariable( FuncOp LoweringPreparePass::buildRuntimeFunction( mlir::OpBuilder &builder, llvm::StringRef name, mlir::Location loc, mlir::cir::FuncType type, mlir::cir::GlobalLinkageKind linkage) { - FuncOp f = - dyn_cast_or_null(SymbolTable::lookupNearestSymbolFrom( - theModule, StringAttr::get(theModule->getContext(), name))); + FuncOp f = dyn_cast_or_null(SymbolTable::lookupNearestSymbolFrom( + theModule, StringAttr::get(theModule->getContext(), name))); if (!f) { f = builder.create(loc, name, type); f.setLinkageAttr( @@ -342,8 +340,8 @@ void LoweringPreparePass::lowerGetBitfieldOp(GetBitfieldOp op) { } val = builder.createIntCast(val, resultTy); - op.replaceAllUsesWith(val); - op.erase(); + op.replaceAllUsesWith(val); + op.erase(); } void LoweringPreparePass::lowerSetBitfieldOp(SetBitfieldOp op) { @@ -369,8 +367,7 @@ void LoweringPreparePass::lowerSetBitfieldOp(SetBitfieldOp op) { if (storageSize != size) { assert(storageSize > size && "Invalid bitfield size."); - mlir::Value val = - builder.create(loc, storageType, addr); + mlir::Value val = builder.create(loc, storageType, addr); srcVal = builder.createAnd(srcVal, llvm::APInt::getLowBitsSet(srcWidth, size)); @@ -380,8 +377,8 @@ void LoweringPreparePass::lowerSetBitfieldOp(SetBitfieldOp op) { srcVal = builder.createShiftLeft(srcVal, offset); // Mask out the original value. - val = builder.createAnd(val, - ~llvm::APInt::getBitsSet(srcWidth, offset, offset + size)); + val = builder.createAnd( + val, ~llvm::APInt::getBitsSet(srcWidth, offset, offset + size)); // Or together the unchanged values and the source value. srcVal = builder.createOr(val, srcVal); diff --git a/clang/lib/CIR/Dialect/Transforms/StdHelpers.cpp b/clang/lib/CIR/Dialect/Transforms/StdHelpers.cpp index e6beada09786..93e19294feec 100644 --- a/clang/lib/CIR/Dialect/Transforms/StdHelpers.cpp +++ b/clang/lib/CIR/Dialect/Transforms/StdHelpers.cpp @@ -29,4 +29,4 @@ bool isStdArrayType(mlir::Type t) { } } // namespace cir -} // namespace mlir \ No newline at end of file +} // namespace mlir diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 786cca9425a6..09f9170ca570 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -326,33 +326,30 @@ mlir::LLVM::Linkage convertLinkage(mlir::cir::GlobalLinkageKind linkage) { static void lowerNestedYield(mlir::cir::YieldOpKind targetKind, mlir::ConversionPatternRewriter &rewriter, - mlir::Region &body, - mlir::Block *dst) { + mlir::Region &body, mlir::Block *dst) { // top-level yields are lowered in matchAndRewrite of the parent operations auto isNested = [&](mlir::Operation *op) { return op->getParentRegion() != &body; }; - body.walk( - [&](mlir::Operation *op) { - if (!isNested(op)) - return mlir::WalkResult::advance(); + body.walk([&](mlir::Operation *op) { + if (!isNested(op)) + return mlir::WalkResult::advance(); - // don't process breaks/continues in nested loops and switches - if (isa(*op)) - return mlir::WalkResult::skip(); + // don't process breaks/continues in nested loops and switches + if (isa(*op)) + return mlir::WalkResult::skip(); - auto yield = dyn_cast(*op); - if (yield && yield.getKind() == targetKind) { - rewriter.setInsertionPoint(op); - rewriter.replaceOpWithNewOp(op, yield.getArgs(), dst); - } + auto yield = dyn_cast(*op); + if (yield && yield.getKind() == targetKind) { + rewriter.setInsertionPoint(op); + rewriter.replaceOpWithNewOp(op, yield.getArgs(), dst); + } - return mlir::WalkResult::advance(); - }); + return mlir::WalkResult::advance(); + }); } - class CIRCopyOpLowering : public mlir::OpConversionPattern { public: using mlir::OpConversionPattern::OpConversionPattern; @@ -456,10 +453,10 @@ class CIRLoopOpLowering : public mlir::OpConversionPattern { dyn_cast(stepRegion.back().getTerminator()); auto &stepBlock = (kind == LoopKind::For ? stepFrontBlock : condFrontBlock); - lowerNestedYield(mlir::cir::YieldOpKind::Break, - rewriter, bodyRegion, continueBlock); - lowerNestedYield(mlir::cir::YieldOpKind::Continue, - rewriter, bodyRegion, &stepBlock); + lowerNestedYield(mlir::cir::YieldOpKind::Break, rewriter, bodyRegion, + continueBlock); + lowerNestedYield(mlir::cir::YieldOpKind::Continue, rewriter, bodyRegion, + &stepBlock); // Move loop op region contents to current CFG. rewriter.inlineRegionBefore(condRegion, continueBlock); @@ -758,8 +755,8 @@ class CIRIfLowering : public mlir::OpConversionPattern { rewriter.setInsertionPointToEnd(elseAfterBody); if (auto elseYieldOp = dyn_cast(elseAfterBody->getTerminator())) { - if (!isBreakOrContinue(elseYieldOp)) // lowering of parent loop yields is - // deferred to loop lowering + if (!isBreakOrContinue(elseYieldOp)) // lowering of parent loop yields + // is deferred to loop lowering rewriter.replaceOpWithNewOp( elseYieldOp, elseYieldOp.getArgs(), continueBlock); } else if (!dyn_cast( @@ -873,23 +870,23 @@ class CIRCallLowering : public mlir::OpConversionPattern { mlir::ConversionPatternRewriter &rewriter) const override { llvm::SmallVector llvmResults; auto cirResults = op.getResultTypes(); - auto* converter = getTypeConverter(); + auto *converter = getTypeConverter(); if (converter->convertTypes(cirResults, llvmResults).failed()) return mlir::failure(); - if (auto callee = op.getCalleeAttr()) { // direct call + if (auto callee = op.getCalleeAttr()) { // direct call rewriter.replaceOpWithNewOp( - op, llvmResults, op.getCalleeAttr(), adaptor.getOperands()); + op, llvmResults, op.getCalleeAttr(), adaptor.getOperands()); } else { // indirect call - assert(op.getOperands().size() - && "operands list must no be empty for the indirect call"); - auto typ = op.getOperands().front().getType(); + assert(op.getOperands().size() && + "operands list must no be empty for the indirect call"); + auto typ = op.getOperands().front().getType(); assert(isa(typ) && "expected pointer type"); auto ptyp = dyn_cast(typ); auto ftyp = dyn_cast(ptyp.getPointee()); assert(ftyp && "expected a pointer to a function as the first operand"); - + rewriter.replaceOpWithNewOp( op, dyn_cast(converter->convertType(ftyp)), @@ -1391,7 +1388,7 @@ class CIRSwitchOpLowering fallthroughYieldOp = nullptr; } - for (auto& blk : region.getBlocks()) { + for (auto &blk : region.getBlocks()) { if (blk.getNumSuccessors()) continue; @@ -1412,7 +1409,7 @@ class CIRSwitchOpLowering rewriteYieldOp(rewriter, yieldOp, exitBlock); break; case mlir::cir::YieldOpKind::Continue: // Continue is handled only in - // loop lowering + // loop lowering break; default: return op->emitError("invalid yield kind in case statement"); @@ -1420,8 +1417,8 @@ class CIRSwitchOpLowering } } - lowerNestedYield(mlir::cir::YieldOpKind::Break, - rewriter, region, exitBlock); + lowerNestedYield(mlir::cir::YieldOpKind::Break, rewriter, region, + exitBlock); // Extract region contents before erasing the switch op. rewriter.inlineRegionBefore(region, exitBlock); @@ -2044,7 +2041,8 @@ class CIRVTableAddrPointOpLowering } }; -class CIRStackSaveLowering : public mlir::OpConversionPattern { +class CIRStackSaveLowering + : public mlir::OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; @@ -2057,16 +2055,16 @@ class CIRStackSaveLowering : public mlir::OpConversionPattern { +class CIRStackRestoreLowering + : public mlir::OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; mlir::LogicalResult matchAndRewrite(mlir::cir::StackRestoreOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOpWithNewOp( - op, - adaptor.getPtr()); + rewriter.replaceOpWithNewOp(op, + adaptor.getPtr()); return mlir::success(); } }; @@ -2074,19 +2072,18 @@ class CIRStackRestoreLowering : public mlir::OpConversionPattern(patterns.getContext()); - patterns.add( + patterns.add< + CIRCmpOpLowering, CIRLoopOpLowering, CIRBrCondOpLowering, + CIRPtrStrideOpLowering, CIRCallLowering, CIRUnaryOpLowering, + CIRBinOpLowering, CIRShiftOpLowering, CIRLoadLowering, + CIRConstantLowering, CIRStoreLowering, CIRAllocaLowering, CIRFuncLowering, + CIRScopeOpLowering, CIRCastOpLowering, CIRIfLowering, CIRGlobalOpLowering, + CIRGetGlobalOpLowering, CIRVAStartLowering, CIRVAEndLowering, + CIRVACopyLowering, CIRVAArgLowering, CIRBrOpLowering, + CIRTernaryOpLowering, CIRGetMemberOpLowering, CIRSwitchOpLowering, + CIRPtrDiffOpLowering, CIRCopyOpLowering, CIRMemCpyOpLowering, + CIRFAbsOpLowering, CIRVTableAddrPointOpLowering, CIRVectorCreateLowering, + CIRVectorExtractLowering, CIRStackSaveLowering, CIRStackRestoreLowering>( converter, patterns.getContext()); }