From 76b79211daf1d88e263259d7645500fc70b256bb Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 28 Nov 2025 09:44:37 +0100 Subject: [PATCH] [CIR] Fix various build warnings --- clang/lib/CIR/CodeGen/CIRGenBuilder.cpp | 18 +++++++++--------- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 7 +------ clang/lib/CIR/CodeGen/CIRGenStmt.cpp | 1 + .../CIR/Dialect/Transforms/LoweringPrepare.cpp | 4 ++-- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 2 -- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 1 - 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp index 5322865b9474..22c8ce5d8375 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp @@ -19,8 +19,8 @@ mlir::Value CIRGenBuilderTy::maybeBuildArrayDecay(mlir::Location loc, if (arrayTy) { cir::PointerType flatPtrTy = getPointerTo(arrayTy.getElementType(), arrayPtrTy.getAddrSpace()); - return create(loc, flatPtrTy, cir::CastKind::array_to_ptrdecay, - arrayPtr); + return cir::CastOp::create(*this, loc, flatPtrTy, + cir::CastKind::array_to_ptrdecay, arrayPtr); } assert(arrayPtrTy.getPointee() == eltTy && @@ -37,15 +37,15 @@ mlir::Value CIRGenBuilderTy::promoteArrayIndex(const clang::TargetInfo &ti, // If this is a boolean, zero-extend it to the array index type. if (auto boolTy = mlir::dyn_cast(index.getType())) - return create(loc, arrayIndexType, cir::CastKind::bool_to_int, - index); + return cir::CastOp::create(*this, loc, arrayIndexType, + cir::CastKind::bool_to_int, index); // If this an integer, ensure that it is at least as width as the array index // type. if (auto intTy = mlir::dyn_cast(index.getType())) { if (intTy.getWidth() < arrayIndexWidth) - return create(loc, arrayIndexType, cir::CastKind::integral, - index); + return cir::CastOp::create(*this, loc, arrayIndexType, + cir::CastKind::integral, index); } return index; @@ -65,7 +65,7 @@ mlir::Value CIRGenBuilderTy::getArrayElement(const clang::TargetInfo &ti, if (shouldDecay && arrayTy && arrayTy == eltTy) { auto eltPtrTy = getPointerTo(arrayTy.getElementType(), arrayPtrTy.getAddrSpace()); - return create(arrayLocEnd, eltPtrTy, arrayPtr, + return cir::GetElementOp::create(*this, arrayLocEnd, eltPtrTy, arrayPtr, promoteArrayIndex(ti, arrayLocBegin, idx)); } @@ -74,7 +74,7 @@ mlir::Value CIRGenBuilderTy::getArrayElement(const clang::TargetInfo &ti, if (shouldDecay) basePtr = maybeBuildArrayDecay(arrayLocBegin, arrayPtr, eltTy); mlir::Type flatPtrTy = basePtr.getType(); - return create(arrayLocEnd, flatPtrTy, basePtr, idx); + return cir::PtrStrideOp::create(*this, arrayLocEnd, flatPtrTy, basePtr, idx); } cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, @@ -96,7 +96,7 @@ cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, mlir::Type t, uint64_t c) { assert(mlir::isa(t) && "expected cir::IntType"); - return create(loc, cir::IntAttr::get(t, c)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(t, c)); } void CIRGenBuilderTy::computeGlobalViewIndicesFromFlatOffset( diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 359176574200..38d995c8103c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -1637,14 +1637,9 @@ mlir::Value ScalarExprEmitter::emitSub(const BinOpInfo &Ops) { divisor = vlaSize.NumElts; CharUnits eltSize = CGF.getContext().getTypeSizeInChars(elementType); - if (!eltSize.isOne()) { - cir::IntType cirIntTy = llvm::cast(CGF.PtrDiffTy); - cir::IntAttr eltSizeAttr = - cir::IntAttr::get(cirIntTy, eltSize.getQuantity()); - + if (!eltSize.isOne()) if (divisor.getType() != CGF.PtrDiffTy) divisor = Builder.createIntCast(divisor, CGF.PtrDiffTy); - } } else { // cir::ptrdiff correctly computes the ABI difference of 2 pointers. We // do not need to compute anything else here. We just return it. diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp index 8f2bd4f49873..0e3b3d33719b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp @@ -211,6 +211,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *S, case Stmt::OMPUnrollDirectiveClass: case Stmt::OMPForDirectiveClass: case Stmt::OMPForSimdDirectiveClass: + case Stmt::OMPFuseDirectiveClass: case Stmt::OMPSectionsDirectiveClass: case Stmt::OMPSectionDirectiveClass: case Stmt::OMPSingleDirectiveClass: diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index 4c5befec0147..d7359bf960e4 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -1393,14 +1393,14 @@ std::optional LoweringPreparePass::buildHIPModuleDtor() { auto handlePtrTy = llvm::cast(handle.getType()); mlir::Value nullPtr = builder.getNullPtr(handlePtrTy, loc); auto isNull = builder.createCompare(loc, cir::CmpOpKind::ne, handle, nullPtr); - builder.create(loc, isNull, ifBlock, exitBlock); + cir::BrCondOp::create(builder, loc, isNull, ifBlock, exitBlock); { // When handle is not null we need to unregister it and store null to handle mlir::OpBuilder::InsertionGuard guard(builder); builder.setInsertionPointToStart(ifBlock); builder.createCallOp(loc, unregisterFunc, handle); builder.createStore(loc, nullPtr, builder.createGetGlobal(gpuBinGlobal)); - builder.create(loc, exitBlock); + cir::BrOp::create(builder, loc, exitBlock); } { // Exit block diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index b723fa64e258..6064cebb8e73 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -367,8 +367,6 @@ class CIRGenConsumer : public clang::ASTConsumer { case CIRGenAction::OutputType::EmitBC: case CIRGenAction::OutputType::EmitObj: case CIRGenAction::OutputType::EmitAssembly: { - auto &CGOpts = CI.getCodeGenOpts(); - llvm::LLVMContext LlvmCtx; LlvmCtx.setDefaultTargetCPU(TargetOpts.CPU); LlvmCtx.setDefaultTargetFeatures(llvm::join(TargetOpts.Features, ",")); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index c94ae0f34bec..8b615efde058 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -1822,7 +1822,6 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite( rewriter.getIntegerAttr(rewriter.getIndexType(), 1)); auto elementTy = convertTypeForMemory(*getTypeConverter(), dataLayout, op.getAllocaType()); - auto resultTy = getTypeConverter()->convertType(op.getType()); // Verification between the CIR alloca AS and the one from data layout. auto allocaAS = [&]() { auto dlAllocaASAttr = mlir::cast_if_present(