diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index 8b4c2f73a84e8..d8b6a9f87ab19 100644 --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -549,8 +549,9 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { } mlir::Value genNot(mlir::Location loc, mlir::Value boolean) { - return create(loc, mlir::arith::CmpIPredicate::eq, - boolean, createBool(loc, false)); + return mlir::arith::CmpIOp::create(*this, loc, + mlir::arith::CmpIPredicate::eq, boolean, + createBool(loc, false)); } /// Generate code testing \p addr is not a null address. @@ -641,7 +642,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right) { if (!resultType.isIntOrFloat()) - return create(loc, resultType, left, right); + return OpTy::create(*this, loc, resultType, left, right); mlir::Type signlessType = mlir::IntegerType::get( getContext(), resultType.getIntOrFloatBitWidth(), mlir::IntegerType::SignednessSemantics::Signless); @@ -654,7 +655,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { right = createConvert(loc, signlessType, right); opResType = signlessType; } - mlir::Value result = create(loc, opResType, left, right); + mlir::Value result = OpTy::create(*this, loc, opResType, left, right); if (resultType.isUnsignedInteger()) result = createConvert(loc, resultType, result); return result; @@ -666,7 +667,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { mlir::Value ptr1, mlir::Value ptr2) { ptr1 = createConvert(loc, getIndexType(), ptr1); ptr2 = createConvert(loc, getIndexType(), ptr2); - return create(loc, predicate, ptr1, ptr2); + return mlir::arith::CmpIOp::create(*this, loc, predicate, ptr1, ptr2); } private: diff --git a/flang/include/flang/Optimizer/Builder/Factory.h b/flang/include/flang/Optimizer/Builder/Factory.h index e67ef457c8b4c..fd9f33c340fa9 100644 --- a/flang/include/flang/Optimizer/Builder/Factory.h +++ b/flang/include/flang/Optimizer/Builder/Factory.h @@ -53,8 +53,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, fir::StoreOp::create(builder, loc, load, dst); return; } - auto zero = builder.template create(loc, 0); - auto one = builder.template create(loc, 1); + auto zero = mlir::arith::ConstantIndexOp::create(builder, loc, 0); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); auto toArrayTy = [&](fir::CharacterType ty) { return fir::ReferenceType::get(fir::SequenceType::get( fir::SequenceType::ShapeRef{fir::SequenceType::getUnknownExtent()}, @@ -68,8 +68,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, return fir::ReferenceType::get(toEleTy(ty)); }; if (!srcLen && !dstLen && srcTy.getLen() >= dstTy.getLen()) { - auto upper = builder.template create( - loc, dstTy.getLen() - 1); + auto upper = + mlir::arith::ConstantIndexOp::create(builder, loc, dstTy.getLen() - 1); auto loop = fir::DoLoopOp::create(builder, loc, zero, upper, one); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(loop.getBody()); @@ -92,26 +92,26 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst, return; } auto minusOne = [&](mlir::Value v) -> mlir::Value { - return builder.template create( - loc, fir::ConvertOp::create(builder, loc, one.getType(), v), one); + return mlir::arith::SubIOp::create( + builder, loc, fir::ConvertOp::create(builder, loc, one.getType(), v), + one); }; mlir::Value len = dstLen ? minusOne(dstLen) - : builder - .template create( - loc, dstTy.getLen() - 1) + : mlir::arith::ConstantIndexOp::create( + builder, loc, dstTy.getLen() - 1) .getResult(); auto loop = fir::DoLoopOp::create(builder, loc, zero, len, one); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(loop.getBody()); mlir::Value slen = - srcLen ? fir::ConvertOp::create(builder, loc, one.getType(), srcLen) - .getResult() - : builder - .template create( - loc, srcTy.getLen()) - .getResult(); - auto cond = builder.template create( - loc, mlir::arith::CmpIPredicate::slt, loop.getInductionVar(), slen); + srcLen + ? fir::ConvertOp::create(builder, loc, one.getType(), srcLen) + .getResult() + : mlir::arith::ConstantIndexOp::create(builder, loc, srcTy.getLen()) + .getResult(); + auto cond = + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::slt, + loop.getInductionVar(), slen); auto ifOp = fir::IfOp::create(builder, loc, cond, /*withElse=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); auto csrcTy = toArrayTy(srcTy); @@ -189,7 +189,7 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy, auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy); assert(ty && mlir::isa(ty)); auto seqTy = mlir::cast(ty); - auto one = builder.template create(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); const auto dimension = seqTy.getDimension(); if (shapeVal) { assert(dimension == mlir::cast(shapeVal.getDefiningOp()) @@ -200,7 +200,7 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy, if (i.index() < dimension) { assert(fir::isa_integer(i.value().getType())); result.push_back( - builder.template create(loc, i.value(), one)); + mlir::arith::AddIOp::create(builder, loc, i.value(), one)); } else { result.push_back(i.value()); } @@ -211,8 +211,8 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy, unsigned origOff = 0; for (auto i : llvm::enumerate(indices)) { if (i.index() < dimension) - result.push_back(builder.template create( - loc, i.value(), origins[origOff++])); + result.push_back(mlir::arith::AddIOp::create(builder, loc, i.value(), + origins[origOff++])); else result.push_back(i.value()); } diff --git a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td index 2414de496d45b..8341720d34c1e 100644 --- a/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td +++ b/flang/include/flang/Optimizer/Dialect/CanonicalizationPatterns.td @@ -105,8 +105,8 @@ def CombineConvertTruncOptPattern (IntPred $arg, $irm), (SmallerWidthPred $arg, $irm)]>; def createConstantOp - : NativeCodeCall<"$_builder.create" - "($_loc, $_builder.getIndexType(), " + : NativeCodeCall<"mlir::arith::ConstantOp::create" + "($_builder, $_loc, $_builder.getIndexType(), " "rewriter.getIndexAttr(" "mlir::dyn_cast($1).getInt()))">; diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 61476efbee1fc..c56de2d4d1e1f 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -1458,7 +1458,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { void genBranch(mlir::Block *targetBlock) { assert(targetBlock && "missing unconditional target block"); - builder->create(toLocation(), targetBlock); + mlir::cf::BranchOp::create(*builder, toLocation(), targetBlock); } void genConditionalBranch(mlir::Value cond, mlir::Block *trueTarget, @@ -1467,9 +1467,9 @@ class FirConverter : public Fortran::lower::AbstractConverter { assert(falseTarget && "missing conditional branch false block"); mlir::Location loc = toLocation(); mlir::Value bcc = builder->createConvert(loc, builder->getI1Type(), cond); - builder->create(loc, bcc, trueTarget, - mlir::ValueRange{}, falseTarget, - mlir::ValueRange{}); + mlir::cf::CondBranchOp::create(*builder, loc, bcc, trueTarget, + mlir::ValueRange{}, falseTarget, + mlir::ValueRange{}); } void genConditionalBranch(mlir::Value cond, Fortran::lower::pft::Evaluation *trueTarget, @@ -1637,28 +1637,28 @@ class FirConverter : public Fortran::lower::AbstractConverter { assert((inArithmeticIfContext || !realSelector) && "invalid selector type"); mlir::Value zero; if (inArithmeticIfContext) - zero = - realSelector - ? builder->create( - loc, selectorType, builder->getFloatAttr(selectorType, 0.0)) - : builder->createIntegerConstant(loc, selectorType, 0); + zero = realSelector + ? mlir::arith::ConstantOp::create( + *builder, loc, selectorType, + builder->getFloatAttr(selectorType, 0.0)) + : builder->createIntegerConstant(loc, selectorType, 0); for (auto label : llvm::enumerate(labelList)) { mlir::Value cond; if (realSelector) // inArithmeticIfContext - cond = builder->create( - loc, + cond = mlir::arith::CmpFOp::create( + *builder, loc, label.index() == 0 ? mlir::arith::CmpFPredicate::OLT : mlir::arith::CmpFPredicate::OGT, selector, zero); else if (inArithmeticIfContext) // INTEGER selector - cond = builder->create( - loc, + cond = mlir::arith::CmpIOp::create( + *builder, loc, label.index() == 0 ? mlir::arith::CmpIPredicate::slt : mlir::arith::CmpIPredicate::sgt, selector, zero); else // A value of 0 is an IO ERR branch: invert comparison. - cond = builder->create( - loc, + cond = mlir::arith::CmpIOp::create( + *builder, loc, valueList[label.index()] == 0 ? mlir::arith::CmpIPredicate::ne : mlir::arith::CmpIPredicate::eq, selector, @@ -1715,7 +1715,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { if (blockIsUnterminated()) { bridge.openAccCtx().finalizeAndKeep(); bridge.fctCtx().finalizeAndKeep(); - builder->create(toLocation(), retval); + mlir::func::ReturnOp::create(*builder, toLocation(), retval); } if (!earlyReturn) { bridge.openAccCtx().pop(); @@ -1795,7 +1795,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { if (mlir::Block *finalBlock = funit.finalBlock) { // The current block must end with a terminator. if (blockIsUnterminated()) - builder->create(toLocation(), finalBlock); + mlir::cf::BranchOp::create(*builder, toLocation(), finalBlock); // Set insertion point to final block. builder->setInsertionPoint(finalBlock, finalBlock->end()); } @@ -1828,8 +1828,9 @@ class FirConverter : public Fortran::lower::AbstractConverter { mlir::Value cond = builder->createConvert(loc, builder->getI1Type(), condExpr); if (negate) - cond = builder->create( - loc, cond, builder->createIntegerConstant(loc, cond.getType(), 1)); + cond = mlir::arith::XOrIOp::create( + *builder, loc, cond, + builder->createIntegerConstant(loc, cond.getType(), 1)); return cond; } @@ -1912,7 +1913,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { stmtCtx.finalizeAndReset(); // Raise an exception if REAL expr is a NaN. if (mlir::isa(expr.getType())) - expr = builder->create(toLocation(), expr, expr); + expr = mlir::arith::AddFOp::create(*builder, toLocation(), expr, expr); // An empty valueList indicates to genMultiwayBranch that the branch is // an ArithmeticIfStmt that has two branches on value 0 or 0.0. llvm::SmallVector valueList; @@ -2517,27 +2518,28 @@ class FirConverter : public Fortran::lower::AbstractConverter { mlir::Value tripCount; if (info.hasRealControl) { auto diff1 = - builder->create(loc, upperValue, lowerValue); + mlir::arith::SubFOp::create(*builder, loc, upperValue, lowerValue); auto diff2 = - builder->create(loc, diff1, stepValue); - tripCount = builder->create(loc, diff2, stepValue); + mlir::arith::AddFOp::create(*builder, loc, diff1, stepValue); + tripCount = + mlir::arith::DivFOp::create(*builder, loc, diff2, stepValue); tripCount = builder->createConvert(loc, builder->getIndexType(), tripCount); } else { auto diff1 = - builder->create(loc, upperValue, lowerValue); + mlir::arith::SubIOp::create(*builder, loc, upperValue, lowerValue); auto diff2 = - builder->create(loc, diff1, stepValue); + mlir::arith::AddIOp::create(*builder, loc, diff1, stepValue); tripCount = - builder->create(loc, diff2, stepValue); + mlir::arith::DivSIOp::create(*builder, loc, diff2, stepValue); } if (forceLoopToExecuteOnce) { // minimum tripCount is 1 mlir::Value one = builder->createIntegerConstant(loc, tripCount.getType(), 1); - auto cond = builder->create( - loc, mlir::arith::CmpIPredicate::slt, tripCount, one); + auto cond = mlir::arith::CmpIOp::create( + *builder, loc, mlir::arith::CmpIPredicate::slt, tripCount, one); tripCount = - builder->create(loc, cond, one, tripCount); + mlir::arith::SelectOp::create(*builder, loc, cond, one, tripCount); } info.tripVariable = builder->createTemporary(loc, tripCount.getType()); fir::StoreOp::create(*builder, loc, tripCount, info.tripVariable); @@ -2549,8 +2551,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { tripCount = fir::LoadOp::create(*builder, loc, info.tripVariable); mlir::Value zero = builder->createIntegerConstant(loc, tripCount.getType(), 0); - auto cond = builder->create( - loc, mlir::arith::CmpIPredicate::sgt, tripCount, zero); + auto cond = mlir::arith::CmpIOp::create( + *builder, loc, mlir::arith::CmpIPredicate::sgt, tripCount, zero); if (info.maskExpr) { genConditionalBranch(cond, info.maskBlock, info.exitBlock); startBlock(info.maskBlock); @@ -2653,8 +2655,9 @@ class FirConverter : public Fortran::lower::AbstractConverter { auto doLoopOp = mlir::cast(info.loopOp); builder->setInsertionPointToEnd(doLoopOp.getBody()); llvm::SmallVector results; - results.push_back(builder->create( - loc, doLoopOp.getInductionVar(), doLoopOp.getStep(), iofAttr)); + results.push_back(mlir::arith::AddIOp::create( + *builder, loc, doLoopOp.getInductionVar(), doLoopOp.getStep(), + iofAttr)); // Step loopVariable to help optimizations such as vectorization. // Induction variable elimination will clean up as necessary. mlir::Value step = builder->createConvert( @@ -2662,7 +2665,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { mlir::Value loopVar = fir::LoadOp::create(*builder, loc, info.loopVariable); results.push_back( - builder->create(loc, loopVar, step, iofAttr)); + mlir::arith::AddIOp::create(*builder, loc, loopVar, step, iofAttr)); fir::ResultOp::create(*builder, loc, results); builder->setInsertionPointAfter(doLoopOp); // The loop control variable may be used after the loop. @@ -2676,7 +2679,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { fir::LoadOp::create(*builder, loc, info.tripVariable); mlir::Value one = builder->createIntegerConstant(loc, tripCount.getType(), 1); - tripCount = builder->create(loc, tripCount, one); + tripCount = mlir::arith::SubIOp::create(*builder, loc, tripCount, one); fir::StoreOp::create(*builder, loc, tripCount, info.tripVariable); mlir::Value value = fir::LoadOp::create(*builder, loc, info.loopVariable); mlir::Value step; @@ -2685,9 +2688,10 @@ class FirConverter : public Fortran::lower::AbstractConverter { else step = genControlValue(info.stepExpr, info); if (info.hasRealControl) - value = builder->create(loc, value, step); + value = mlir::arith::AddFOp::create(*builder, loc, value, step); else - value = builder->create(loc, value, step, iofAttr); + value = + mlir::arith::AddIOp::create(*builder, loc, value, step, iofAttr); fir::StoreOp::create(*builder, loc, value, info.loopVariable); genBranch(info.headerBlock); @@ -3184,8 +3188,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { assert(funit && "not inside main program, function or subroutine"); mlir::Block *continueBlock = builder->getBlock()->splitBlock(builder->getBlock()->end()); - builder->create(toLocation(), exitCond, - funit->finalBlock, continueBlock); + mlir::cf::CondBranchOp::create(*builder, toLocation(), exitCond, + funit->finalBlock, continueBlock); builder->setInsertionPointToEnd(continueBlock); } } @@ -3353,8 +3357,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { step = fir::getBase( genExprValue(*Fortran::semantics::GetExpr(*expr), stmtCtx)); else - step = builder->create( - loc, 1); // Use index type directly + step = mlir::arith::ConstantIndexOp::create( + *builder, loc, 1); // Use index type directly // Ensure lb, ub, and step are of index type using fir.convert lb = fir::ConvertOp::create(*builder, loc, idxTy, lb); @@ -3625,7 +3629,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { auto genCond = [&](mlir::Value rhs, mlir::arith::CmpIPredicate pred) -> mlir::Value { if (!isCharSelector) - return builder->create(loc, pred, selector, rhs); + return mlir::arith::CmpIOp::create(*builder, loc, pred, selector, + rhs); fir::factory::CharacterExprHelper charHelper{*builder, loc}; std::pair lhsVal = charHelper.createUnboxChar(selector); @@ -3840,9 +3845,9 @@ class FirConverter : public Fortran::lower::AbstractConverter { mlir::Block *selectCaseBlock = insertBlock(blockList[0]); mlir::Block *assumedSizeBlock = rankStarBlock ? rankStarBlock : defaultBlock; - builder->create( - loc, isAssumedSize, assumedSizeBlock, mlir::ValueRange{}, - selectCaseBlock, mlir::ValueRange{}); + mlir::cf::CondBranchOp::create(*builder, loc, isAssumedSize, + assumedSizeBlock, mlir::ValueRange{}, + selectCaseBlock, mlir::ValueRange{}); startBlock(selectCaseBlock); } // Create fir.select_case for the other rank cases. @@ -5631,7 +5636,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { if (Fortran::lower::isInOpenACCLoop(*builder)) Fortran::lower::genEarlyReturnInOpenACCLoop(*builder, loc); else - builder->create(loc, funit->finalBlock); + mlir::cf::BranchOp::create(*builder, loc, funit->finalBlock); } void genFIR(const Fortran::parser::CycleStmt &) { diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index d1efd8e8d2ca7..0a06d0a09727c 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -1566,8 +1566,8 @@ template static OpTy genOpWithBody(const OpWithBodyGenInfo &info, const ConstructQueue &queue, ConstructQueue::const_iterator item, Args &&...args) { - auto op = info.converter.getFirOpBuilder().create( - info.loc, std::forward(args)...); + auto op = OpTy::create(info.converter.getFirOpBuilder(), info.loc, + std::forward(args)...); createBodyOfOp(*op, info, queue, item); return op; } @@ -1948,7 +1948,7 @@ genBarrierOp(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, mlir::Location loc, const ConstructQueue &queue, ConstructQueue::const_iterator item) { - return converter.getFirOpBuilder().create(loc); + return mlir::omp::BarrierOp::create(converter.getFirOpBuilder(), loc); } static mlir::omp::CancelOp genCancelOp(lower::AbstractConverter &converter, @@ -1960,8 +1960,8 @@ static mlir::omp::CancelOp genCancelOp(lower::AbstractConverter &converter, mlir::omp::CancelOperands clauseOps; genCancelClauses(converter, semaCtx, item->clauses, loc, clauseOps); - return converter.getFirOpBuilder().create(loc, - clauseOps); + return mlir::omp::CancelOp::create(converter.getFirOpBuilder(), loc, + clauseOps); } static mlir::omp::CancellationPointOp genCancellationPointOp( @@ -1972,8 +1972,8 @@ static mlir::omp::CancellationPointOp genCancellationPointOp( genCancellationPointClauses(converter, semaCtx, item->clauses, loc, clauseOps); - return converter.getFirOpBuilder().create( - loc, clauseOps); + return mlir::omp::CancellationPointOp::create(converter.getFirOpBuilder(), + loc, clauseOps); } static mlir::omp::CriticalOp @@ -2016,8 +2016,9 @@ genFlushOp(lower::AbstractConverter &converter, lower::SymMap &symTable, genFlushClauses(converter, semaCtx, objects, item->clauses, loc, operandRange); - return converter.getFirOpBuilder().create( - converter.getCurrentLocation(), operandRange); + return mlir::omp::FlushOp::create(converter.getFirOpBuilder(), + converter.getCurrentLocation(), + operandRange); } static mlir::omp::LoopNestOp genLoopNestOp( @@ -2135,36 +2136,37 @@ genCanonicalLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable, // Start lowering mlir::Value zero = firOpBuilder.createIntegerConstant(loc, loopVarType, 0); mlir::Value one = firOpBuilder.createIntegerConstant(loc, loopVarType, 1); - mlir::Value isDownwards = firOpBuilder.create( - loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero); + mlir::Value isDownwards = mlir::arith::CmpIOp::create( + firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero); // Ensure we are counting upwards. If not, negate step and swap lb and ub. mlir::Value negStep = - firOpBuilder.create(loc, zero, loopStepVar); - mlir::Value incr = firOpBuilder.create( - loc, isDownwards, negStep, loopStepVar); - mlir::Value lb = firOpBuilder.create( - loc, isDownwards, loopUBVar, loopLBVar); - mlir::Value ub = firOpBuilder.create( - loc, isDownwards, loopLBVar, loopUBVar); + mlir::arith::SubIOp::create(firOpBuilder, loc, zero, loopStepVar); + mlir::Value incr = mlir::arith::SelectOp::create( + firOpBuilder, loc, isDownwards, negStep, loopStepVar); + mlir::Value lb = mlir::arith::SelectOp::create(firOpBuilder, loc, isDownwards, + loopUBVar, loopLBVar); + mlir::Value ub = mlir::arith::SelectOp::create(firOpBuilder, loc, isDownwards, + loopLBVar, loopUBVar); // Compute the trip count assuming lb <= ub. This guarantees that the result // is non-negative and we can use unsigned arithmetic. - mlir::Value span = firOpBuilder.create( - loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw); + mlir::Value span = mlir::arith::SubIOp::create( + firOpBuilder, loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw); mlir::Value tcMinusOne = - firOpBuilder.create(loc, span, incr); - mlir::Value tcIfLooping = firOpBuilder.create( - loc, tcMinusOne, one, ::mlir::arith::IntegerOverflowFlags::nuw); + mlir::arith::DivUIOp::create(firOpBuilder, loc, span, incr); + mlir::Value tcIfLooping = + mlir::arith::AddIOp::create(firOpBuilder, loc, tcMinusOne, one, + ::mlir::arith::IntegerOverflowFlags::nuw); // Fall back to 0 if lb > ub - mlir::Value isZeroTC = firOpBuilder.create( - loc, mlir::arith::CmpIPredicate::slt, ub, lb); - mlir::Value tripcount = firOpBuilder.create( - loc, isZeroTC, zero, tcIfLooping); + mlir::Value isZeroTC = mlir::arith::CmpIOp::create( + firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, ub, lb); + mlir::Value tripcount = mlir::arith::SelectOp::create( + firOpBuilder, loc, isZeroTC, zero, tcIfLooping); // Create the CLI handle. - auto newcli = firOpBuilder.create(loc); + auto newcli = mlir::omp::NewCliOp::create(firOpBuilder, loc); mlir::Value cli = newcli.getResult(); auto ivCallback = [&](mlir::Operation *op) @@ -2177,9 +2179,9 @@ genCanonicalLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable, // Compute the value of the loop variable from the logical iteration number. mlir::Value natIterNum = fir::getBase(region.front().getArgument(0)); mlir::Value scaled = - firOpBuilder.create(loc, natIterNum, loopStepVar); + mlir::arith::MulIOp::create(firOpBuilder, loc, natIterNum, loopStepVar); mlir::Value userVal = - firOpBuilder.create(loc, loopLBVar, scaled); + mlir::arith::AddIOp::create(firOpBuilder, loc, loopLBVar, scaled); // Write loop value to loop variable mlir::Operation *storeOp = setLoopVar(converter, loc, userVal, iv); @@ -2226,7 +2228,7 @@ static void genUnrollOp(Fortran::lower::AbstractConverter &converter, // Apply unrolling to it auto cli = canonLoop.getCli(); - firOpBuilder.create(loc, cli); + mlir::omp::UnrollHeuristicOp::create(firOpBuilder, loc, cli); } static mlir::omp::MaskedOp @@ -2310,8 +2312,8 @@ genScanOp(lower::AbstractConverter &converter, lower::SymMap &symTable, const ConstructQueue &queue, ConstructQueue::const_iterator item) { mlir::omp::ScanOperands clauseOps; genScanClauses(converter, semaCtx, item->clauses, loc, clauseOps); - return converter.getFirOpBuilder().create( - converter.getCurrentLocation(), clauseOps); + return mlir::omp::ScanOp::create(converter.getFirOpBuilder(), + converter.getCurrentLocation(), clauseOps); } static mlir::omp::SectionsOp @@ -2625,9 +2627,8 @@ static mlir::omp::TargetDataOp genTargetDataOp( genTargetDataClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps, useDeviceAddrSyms, useDevicePtrSyms); - auto targetDataOp = - converter.getFirOpBuilder().create(loc, - clauseOps); + auto targetDataOp = mlir::omp::TargetDataOp::create( + converter.getFirOpBuilder(), loc, clauseOps); llvm::SmallVector useDeviceAddrBaseValues, useDevicePtrBaseValues; @@ -2741,8 +2742,8 @@ genTaskwaitOp(lower::AbstractConverter &converter, lower::SymMap &symTable, ConstructQueue::const_iterator item) { mlir::omp::TaskwaitOperands clauseOps; genTaskwaitClauses(converter, semaCtx, item->clauses, loc, clauseOps); - return converter.getFirOpBuilder().create(loc, - clauseOps); + return mlir::omp::TaskwaitOp::create(converter.getFirOpBuilder(), loc, + clauseOps); } static mlir::omp::TaskyieldOp @@ -2751,7 +2752,7 @@ genTaskyieldOp(lower::AbstractConverter &converter, lower::SymMap &symTable, lower::pft::Evaluation &eval, mlir::Location loc, const ConstructQueue &queue, ConstructQueue::const_iterator item) { - return converter.getFirOpBuilder().create(loc); + return mlir::omp::TaskyieldOp::create(converter.getFirOpBuilder(), loc); } static mlir::omp::WorkshareOp genWorkshareOp( diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index d1925c3602848..87a52ffc339f4 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -147,7 +147,8 @@ mlir::Value fir::FirOpBuilder::createIntegerConstant(mlir::Location loc, assert((cst >= 0 || mlir::isa(ty) || mlir::cast(ty).getWidth() <= 64) && "must use APint"); - return create(loc, ty, getIntegerAttr(ty, cst)); + return mlir::arith::ConstantOp::create(*this, loc, ty, + getIntegerAttr(ty, cst)); } mlir::Value fir::FirOpBuilder::createAllOnesInteger(mlir::Location loc, @@ -156,7 +157,8 @@ mlir::Value fir::FirOpBuilder::createAllOnesInteger(mlir::Location loc, return createIntegerConstant(loc, ty, -1); llvm::APInt allOnes = llvm::APInt::getAllOnes(mlir::cast(ty).getWidth()); - return create(loc, ty, getIntegerAttr(ty, allOnes)); + return mlir::arith::ConstantOp::create(*this, loc, ty, + getIntegerAttr(ty, allOnes)); } mlir::Value @@ -185,7 +187,7 @@ mlir::Value fir::FirOpBuilder::createRealConstant(mlir::Location loc, const llvm::APFloat &value) { if (mlir::isa(fltTy)) { auto attr = getFloatAttr(fltTy, value); - return create(loc, fltTy, attr); + return mlir::arith::ConstantOp::create(*this, loc, fltTy, attr); } llvm_unreachable("should use builtin floating-point type"); } @@ -418,12 +420,12 @@ mlir::Value fir::FirOpBuilder::genTempDeclareOp( mlir::Value fir::FirOpBuilder::genStackSave(mlir::Location loc) { mlir::Type voidPtr = mlir::LLVM::LLVMPointerType::get( getContext(), fir::factory::getAllocaAddressSpace(&getDataLayout())); - return create(loc, voidPtr); + return mlir::LLVM::StackSaveOp::create(*this, loc, voidPtr); } void fir::FirOpBuilder::genStackRestore(mlir::Location loc, mlir::Value stackPointer) { - create(loc, stackPointer); + mlir::LLVM::StackRestoreOp::create(*this, loc, stackPointer); } /// Create a global variable in the (read-only) data section. A global variable @@ -701,8 +703,8 @@ mlir::Value fir::FirOpBuilder::createSlice(mlir::Location loc, for (auto [lbnd, extent] : llvm::zip(lbounds, extents)) { auto lb = createConvert(loc, idxTy, lbnd); auto ext = createConvert(loc, idxTy, extent); - auto shift = create(loc, lb, one); - auto ub = create(loc, ext, shift); + auto shift = mlir::arith::SubIOp::create(*this, loc, lb, one); + auto ub = mlir::arith::AddIOp::create(*this, loc, ext, shift); trips.push_back(lb); trips.push_back(ub); trips.push_back(one); @@ -852,12 +854,12 @@ mlir::Value fir::FirOpBuilder::genExtentFromTriplet(mlir::Location loc, lb = createConvert(loc, type, lb); ub = createConvert(loc, type, ub); step = createConvert(loc, type, step); - auto diff = create(loc, ub, lb); - auto add = create(loc, diff, step); - auto div = create(loc, add, step); - auto cmp = create(loc, mlir::arith::CmpIPredicate::sgt, - div, zero); - return create(loc, cmp, div, zero); + auto diff = mlir::arith::SubIOp::create(*this, loc, ub, lb); + auto add = mlir::arith::AddIOp::create(*this, loc, diff, step); + auto div = mlir::arith::DivSIOp::create(*this, loc, add, step); + auto cmp = mlir::arith::CmpIOp::create( + *this, loc, mlir::arith::CmpIPredicate::sgt, div, zero); + return mlir::arith::SelectOp::create(*this, loc, cmp, div, zero); } mlir::Value fir::FirOpBuilder::genAbsentOp(mlir::Location loc, diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index dec59ef159b76..bfa470dd5690d 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -2413,14 +2413,14 @@ mlir::func::FuncOp IntrinsicLibrary::getWrapper(GeneratorType generator, if constexpr (std::is_same_v) { localLib.invokeGenerator(generator, localArguments); - localBuilder->create(localLoc); + mlir::func::ReturnOp::create(*localBuilder, localLoc); } else { assert(funcType.getNumResults() == 1 && "expect one result for intrinsic function wrapper type"); mlir::Type resultType = funcType.getResult(0); auto result = localLib.invokeGenerator(generator, resultType, localArguments); - localBuilder->create(localLoc, result); + mlir::func::ReturnOp::create(*localBuilder, localLoc, result); } } else { // Wrapper was already built, ensure it has the sought type @@ -6662,9 +6662,8 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, mlir::Type retTy = mlir::LLVM::LLVMStructType::getLiteral(context, {resultType, i1Ty}); auto match = - builder - .create(loc, retTy, args[0], arg1, - mlir::NVVM::MatchSyncKind::all) + mlir::NVVM::MatchSyncOp::create(builder, loc, retTy, args[0], arg1, + mlir::NVVM::MatchSyncKind::all) .getResult(); auto value = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 0); auto pred = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 1); @@ -6701,9 +6700,8 @@ IntrinsicLibrary::genMatchAnySync(mlir::Type resultType, arg1 = fir::ConvertOp::create( builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); - return builder - .create(loc, resultType, args[0], arg1, - mlir::NVVM::MatchSyncKind::any) + return mlir::NVVM::MatchSyncOp::create(builder, loc, resultType, args[0], + arg1, mlir::NVVM::MatchSyncKind::any) .getResult(); } @@ -8142,7 +8140,7 @@ mlir::Value IntrinsicLibrary::genSinpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); } @@ -8239,7 +8237,7 @@ mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); } diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 1362a9f2bfdfd..1b289ae690cbe 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -1335,19 +1335,19 @@ genCUFAllocDescriptor(mlir::Location loc, RTNAME_STRING(CUFAllocDescriptor)); auto funcFunc = mod.lookupSymbol(RTNAME_STRING(CUFAllocDescriptor)); - if (!llvmFunc && !funcFunc) - mlir::OpBuilder::atBlockEnd(mod.getBody()) - .create(loc, RTNAME_STRING(CUFAllocDescriptor), - fctTy); + if (!llvmFunc && !funcFunc) { + auto builder = mlir::OpBuilder::atBlockEnd(mod.getBody()); + mlir::LLVM::LLVMFuncOp::create(builder, loc, + RTNAME_STRING(CUFAllocDescriptor), fctTy); + } mlir::Type structTy = typeConverter.convertBoxTypeAsStruct(boxTy); std::size_t boxSize = dl->getTypeSizeInBits(structTy) / 8; mlir::Value sizeInBytes = genConstantIndex(loc, llvmIntPtrType, rewriter, boxSize); llvm::SmallVector args = {sizeInBytes, sourceFile, sourceLine}; - return rewriter - .create(loc, fctTy, RTNAME_STRING(CUFAllocDescriptor), - args) + return mlir::LLVM::CallOp::create(rewriter, loc, fctTy, + RTNAME_STRING(CUFAllocDescriptor), args) .getResult(); } diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index 68f9d4115a981..fa935542d40f7 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -520,10 +520,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { llvm::SmallVector newCallResults; // TODO propagate/update call argument and result attributes. if constexpr (std::is_same_v, mlir::gpu::LaunchFuncOp>) { - auto newCall = rewriter->create( - loc, callOp.getKernel(), callOp.getGridSizeOperandValues(), - callOp.getBlockSizeOperandValues(), - callOp.getDynamicSharedMemorySize(), newOpers); + auto newCall = A::create(*rewriter, loc, callOp.getKernel(), + callOp.getGridSizeOperandValues(), + callOp.getBlockSizeOperandValues(), + callOp.getDynamicSharedMemorySize(), newOpers); if (callOp.getClusterSizeX()) newCall.getClusterSizeXMutable().assign(callOp.getClusterSizeX()); if (callOp.getClusterSizeY()) @@ -585,9 +585,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { else newCallResults.append(newCall.result_begin(), newCall.result_end()); } else { - fir::DispatchOp dispatchOp = rewriter->create( - loc, newResTys, rewriter->getStringAttr(callOp.getMethod()), - callOp.getOperands()[0], newOpers, + fir::DispatchOp dispatchOp = A::create( + *rewriter, loc, newResTys, + rewriter->getStringAttr(callOp.getMethod()), callOp.getOperands()[0], + newOpers, rewriter->getI32IntegerAttr(*callOp.getPassArgPos() + passArgShift), /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, callOp.getProcedureAttrsAttr()); @@ -1056,7 +1057,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { auto cast = fir::ConvertOp::create(*rewriter, loc, oldOperTy, newArg); fir::StoreOp::create(*rewriter, loc, oldOper, cast); - rewriter->create(loc); + ReturnOpTy::create(*rewriter, loc); ret.erase(); }); } break; @@ -1069,7 +1070,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { mlir::Value bitcast = convertValueInMemory(loc, oldOper, newResTys[fixup.index], /*inputMayBeBigger=*/false); - rewriter->create(loc, bitcast); + ReturnOpTy::create(*rewriter, loc, bitcast); ret.erase(); }); } break; diff --git a/flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp b/flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp index df1411a894373..95f01e0a9ab6f 100644 --- a/flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp +++ b/flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp @@ -43,8 +43,8 @@ struct HLFIRToolsTest : public testing::Test { mlir::Value createConstant(std::int64_t cst) { mlir::Type indexType = firBuilder->getIndexType(); - return firBuilder->create( - getLoc(), indexType, firBuilder->getIntegerAttr(indexType, cst)); + return mlir::arith::ConstantOp::create(*firBuilder, getLoc(), indexType, + firBuilder->getIntegerAttr(indexType, cst)); } mlir::Location getLoc() { return firBuilder->getUnknownLoc(); } diff --git a/flang/unittests/Optimizer/FortranVariableTest.cpp b/flang/unittests/Optimizer/FortranVariableTest.cpp index 94537edc6082a..f194eb7489df4 100644 --- a/flang/unittests/Optimizer/FortranVariableTest.cpp +++ b/flang/unittests/Optimizer/FortranVariableTest.cpp @@ -19,10 +19,10 @@ struct FortranVariableTest : public testing::Test { // Set up a Module with a dummy function operation inside. // Set the insertion point in the function entry block. - moduleOp = builder->create(loc); + moduleOp = mlir::ModuleOp::create(*builder, loc); builder->setInsertionPointToStart(moduleOp->getBody()); - mlir::func::FuncOp func = builder->create( - loc, "fortran_variable_tests", builder->getFunctionType({}, {})); + mlir::func::FuncOp func = mlir::func::FuncOp::create(*builder, loc, + "fortran_variable_tests", builder->getFunctionType({}, {})); auto *entryBlock = func.addEntryBlock(); builder->setInsertionPointToStart(entryBlock); } @@ -30,8 +30,8 @@ struct FortranVariableTest : public testing::Test { mlir::Location getLoc() { return builder->getUnknownLoc(); } mlir::Value createConstant(std::int64_t cst) { mlir::Type indexType = builder->getIndexType(); - return builder->create( - getLoc(), indexType, builder->getIntegerAttr(indexType, cst)); + return mlir::arith::ConstantOp::create( + *builder, getLoc(), indexType, builder->getIntegerAttr(indexType, cst)); } mlir::Value createShape(llvm::ArrayRef extents) {