diff options
Diffstat (limited to 'flang/lib')
98 files changed, 4182 insertions, 3572 deletions
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp index 9957010..9c6d49d 100644 --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -957,6 +957,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ {"sin", {{"x", SameFloating}}, SameFloating}, {"sind", {{"x", SameFloating}}, SameFloating}, {"sinh", {{"x", SameFloating}}, SameFloating}, + {"sinpi", {{"x", SameFloating}}, SameFloating}, {"size", {{"array", AnyData, Rank::arrayOrAssumedRank}, OptionalDIM, // unless array is assumed-size @@ -988,6 +989,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ {"tan", {{"x", SameFloating}}, SameFloating}, {"tand", {{"x", SameFloating}}, SameFloating}, {"tanh", {{"x", SameFloating}}, SameFloating}, + {"tanpi", {{"x", SameFloating}}, SameFloating}, {"team_number", {OptionalTEAM}, DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, {"this_image", diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp index 5536bfe..15cd977 100644 --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -78,8 +78,8 @@ struct ErrorManager { statExpr && errMsgExpr ? builder.createBox(loc, converter.genExprAddr(loc, errMsgExpr, stmtCtx)) - : builder.create<fir::AbsentOp>( - loc, + : fir::AbsentOp::create( + builder, loc, fir::BoxType::get(mlir::NoneType::get(builder.getContext()))); sourceFile = fir::factory::locationToFilename(builder, loc); sourceLine = fir::factory::locationToLineNo(builder, loc, @@ -92,10 +92,10 @@ struct ErrorManager { if (statValue) { mlir::Value zero = builder.createIntegerConstant(loc, statValue.getType(), 0); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, statValue, zero); - auto ifOp = builder.create<fir::IfOp>(loc, cmp, - /*withElseRegion=*/false); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, statValue, zero); + auto ifOp = fir::IfOp::create(builder, loc, cmp, + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } } @@ -106,7 +106,7 @@ struct ErrorManager { assert(stat && "missing stat value"); mlir::Value castStat = builder.createConvert( loc, fir::dyn_cast_ptrEleTy(statAddr.getType()), stat); - builder.create<fir::StoreOp>(loc, castStat, statAddr); + fir::StoreOp::create(builder, loc, castStat, statAddr); statValue = stat; } } @@ -141,7 +141,7 @@ static void genRuntimeSetBounds(fir::FirOpBuilder &builder, mlir::Location loc, const auto args = fir::runtime::createArguments( builder, loc, callee.getFunctionType(), box.getAddr(), dimIndex, lowerBound, upperBound); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } /// Generate runtime call to set the lengths of a character allocatable or @@ -171,7 +171,7 @@ static void genRuntimeInitCharacter(fir::FirOpBuilder &builder, args.push_back(builder.createIntegerConstant(loc, inputTypes[4], corank)); const auto convertedArgs = fir::runtime::createArguments( builder, loc, callee.getFunctionType(), args); - builder.create<fir::CallOp>(loc, callee, convertedArgs); + fir::CallOp::create(builder, loc, callee, convertedArgs); } /// Generate a sequence of runtime calls to allocate memory. @@ -194,7 +194,7 @@ static mlir::Value genRuntimeAllocate(fir::FirOpBuilder &builder, args.push_back(errorManager.sourceLine); const auto convertedArgs = fir::runtime::createArguments( builder, loc, callee.getFunctionType(), args); - return builder.create<fir::CallOp>(loc, callee, convertedArgs).getResult(0); + return fir::CallOp::create(builder, loc, callee, convertedArgs).getResult(0); } /// Generate a sequence of runtime calls to allocate memory and assign with the @@ -214,7 +214,7 @@ static mlir::Value genRuntimeAllocateSource(fir::FirOpBuilder &builder, builder, loc, callee.getFunctionType(), box.getAddr(), fir::getBase(source), errorManager.hasStat, errorManager.errMsgAddr, errorManager.sourceFile, errorManager.sourceLine); - return builder.create<fir::CallOp>(loc, callee, args).getResult(0); + return fir::CallOp::create(builder, loc, callee, args).getResult(0); } /// Generate runtime call to apply mold to the descriptor. @@ -233,7 +233,7 @@ static void genRuntimeAllocateApplyMold(fir::FirOpBuilder &builder, fir::factory::getMutableIRBox(builder, loc, box), fir::getBase(mold), builder.createIntegerConstant( loc, callee.getFunctionType().getInputs()[2], rank)); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } /// Generate a runtime call to deallocate memory. @@ -270,7 +270,7 @@ static mlir::Value genRuntimeDeallocate(fir::FirOpBuilder &builder, errorManager.hasStat, errorManager.errMsgAddr, errorManager.sourceFile, errorManager.sourceLine); } - return builder.create<fir::CallOp>(loc, callee, operands).getResult(0); + return fir::CallOp::create(builder, loc, callee, operands).getResult(0); } //===----------------------------------------------------------------------===// @@ -433,9 +433,9 @@ private: loc, Fortran::semantics::GetExpr(std::get<1>(shapeSpec.t)), stmtCtx)); ub = builder.createConvert(loc, idxTy, ub); if (lb) { - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, ub, lb); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, ub, lb); extents.emplace_back( - builder.create<mlir::arith::AddIOp>(loc, diff, one)); + mlir::arith::AddIOp::create(builder, loc, diff, one)); } else { extents.emplace_back(ub); } @@ -461,7 +461,7 @@ private: mlir::Value falseValue = builder.createBool(loc, false); mlir::Value falseConv = builder.createConvert( loc, fir::unwrapRefType(pinned.getType()), falseValue); - builder.create<fir::StoreOp>(loc, falseConv, pinned); + fir::StoreOp::create(builder, loc, falseConv, pinned); } void genSimpleAllocation(const Allocation &alloc, @@ -557,7 +557,7 @@ private: mlir::Value nullPointer = fir::factory::createUnallocatedBox( builder, loc, box.getBoxTy(), box.nonDeferredLenParams(), /*typeSourceBox=*/{}, allocatorIdx); - builder.create<fir::StoreOp>(loc, nullPointer, box.getAddr()); + fir::StoreOp::create(builder, loc, nullPointer, box.getAddr()); } else { assert(box.isAllocatable() && "must be an allocatable"); // For allocatables, sync the MutableBoxValue and descriptor before the @@ -597,13 +597,14 @@ private: assert(sourceBox && "source expression should be lowered to one box"); for (int i = 0; i < sourceExpr->Rank(); ++i) { auto dimVal = builder.createIntegerConstant(loc, idxTy, i); - auto dimInfo = builder.create<fir::BoxDimsOp>( - loc, idxTy, idxTy, idxTy, sourceBox->getAddr(), dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + sourceBox->getAddr(), dimVal); mlir::Value lb = fir::factory::readLowerBound(builder, loc, sourceExv, i, one); mlir::Value extent = dimInfo.getResult(1); - mlir::Value ub = builder.create<mlir::arith::SubIOp>( - loc, builder.create<mlir::arith::AddIOp>(loc, extent, lb), one); + mlir::Value ub = mlir::arith::SubIOp::create( + builder, loc, mlir::arith::AddIOp::create(builder, loc, extent, lb), + one); mlir::Value dimIndex = builder.createIntegerConstant(loc, i32Ty, i); genRuntimeSetBounds(builder, loc, box, dimIndex, lb, ub); } @@ -668,7 +669,7 @@ private: const auto args = fir::runtime::createArguments( builder, loc, callee.getFunctionType(), box.getAddr(), typeDescAddr, rankValue, corankValue); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } /// Generate call to PointerNullifyIntrinsic or AllocatableInitIntrinsic to @@ -697,7 +698,7 @@ private: const auto args = fir::runtime::createArguments( builder, loc, callee.getFunctionType(), box.getAddr(), categoryValue, kindValue, rankValue, corankValue); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } /// Generate call to the AllocatableInitDerived to set up the type descriptor @@ -909,8 +910,8 @@ void Fortran::lower::genDeallocateIfAllocated( .genThen([&]() { if (mlir::Type eleType = box.getEleTy(); mlir::isa<fir::RecordType>(eleType) && box.isPolymorphic()) { - mlir::Value declaredTypeDesc = builder.create<fir::TypeDescOp>( - loc, mlir::TypeAttr::get(eleType)); + mlir::Value declaredTypeDesc = fir::TypeDescOp::create( + builder, loc, mlir::TypeAttr::get(eleType)); genDeallocateBox(converter, box, loc, sym, declaredTypeDesc); } else { genDeallocateBox(converter, box, loc, sym); @@ -1151,7 +1152,7 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen( // here). auto readLength = [&]() { fir::BoxValue boxLoad = - builder.create<fir::LoadOp>(loc, fir::getBase(box)).getResult(); + fir::LoadOp::create(builder, loc, fir::getBase(box)).getResult(); return fir::factory::readCharLen(builder, loc, boxLoad); }; if (Fortran::semantics::IsOptional(sym)) { @@ -1160,15 +1161,15 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen( // they are absents. According to 15.5.2.12 3 (9), it is illegal to // inquire the length of absent optional, even if non deferred, so // it's fine to use undefOp in this case. - auto isPresent = builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(box)); + auto isPresent = fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(box)); mlir::Value len = builder.genIfOp(loc, {idxTy}, isPresent, true) .genThen( - [&]() { builder.create<fir::ResultOp>(loc, readLength()); }) + [&]() { fir::ResultOp::create(builder, loc, readLength()); }) .genElse([&]() { - auto undef = builder.create<fir::UndefOp>(loc, idxTy); - builder.create<fir::ResultOp>(loc, undef.getResult()); + auto undef = fir::UndefOp::create(builder, loc, idxTy); + fir::ResultOp::create(builder, loc, undef.getResult()); }) .getResults()[0]; return len; @@ -1183,5 +1184,5 @@ mlir::Value Fortran::lower::getTypeDescAddr( mlir::Type typeDesc = Fortran::lower::translateDerivedTypeToFIRType(converter, typeSpec); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - return builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(typeDesc)); + return fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(typeDesc)); } diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 4241d12..13420f3 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -333,11 +333,12 @@ private: if (details.numPrivatesNotOverridden() > 0) tbpName += "."s + std::to_string(details.numPrivatesNotOverridden()); std::string bindingName = converter.mangleName(details.symbol()); - builder.create<fir::DTEntryOp>( - info.loc, mlir::StringAttr::get(builder.getContext(), tbpName), + fir::DTEntryOp::create( + builder, info.loc, + mlir::StringAttr::get(builder.getContext(), tbpName), mlir::SymbolRefAttr::get(builder.getContext(), bindingName)); } - builder.create<fir::FirEndOp>(info.loc); + fir::FirEndOp::create(builder, info.loc); } // Gather info about components that is not reflected in fir.type and may be // needed later: component initial values and array component non default @@ -360,11 +361,11 @@ private: componentInfo = builder.createBlock(&dt.getComponentInfo()); auto compName = mlir::StringAttr::get(builder.getContext(), toStringRef(component.name())); - builder.create<fir::DTComponentOp>(info.loc, compName, lbs, init_val); + fir::DTComponentOp::create(builder, info.loc, compName, lbs, init_val); } } if (componentInfo) - builder.create<fir::FirEndOp>(info.loc); + fir::FirEndOp::create(builder, info.loc); builder.restoreInsertionPoint(insertPointIfCreated); } @@ -1466,8 +1467,9 @@ private: assert(falseTarget && "missing conditional branch false block"); mlir::Location loc = toLocation(); mlir::Value bcc = builder->createConvert(loc, builder->getI1Type(), cond); - builder->create<mlir::cf::CondBranchOp>(loc, bcc, trueTarget, std::nullopt, - falseTarget, std::nullopt); + builder->create<mlir::cf::CondBranchOp>(loc, bcc, trueTarget, + mlir::ValueRange{}, falseTarget, + mlir::ValueRange{}); } void genConditionalBranch(mlir::Value cond, Fortran::lower::pft::Evaluation *trueTarget, @@ -2123,9 +2125,10 @@ private: llvm::SmallVector<mlir::Value> reduceVars; Fortran::lower::omp::ReductionProcessor rp; - rp.processReductionArguments<fir::DeclareReductionOp>( + bool result = rp.processReductionArguments<fir::DeclareReductionOp>( toLocation(), *this, info.reduceOperatorList, reduceVars, reduceVarByRef, reductionDeclSymbols, info.reduceSymList); + assert(result && "Failed to process `do concurrent` reductions"); doConcurrentLoopOp.getReduceVarsMutable().assign(reduceVars); doConcurrentLoopOp.setReduceSymsAttr( @@ -2556,8 +2559,8 @@ private: builder->setInsertionPointToEnd(loopWrapperOp.getBody()); auto loopOp = builder->create<fir::DoConcurrentLoopOp>( loc, nestLBs, nestUBs, nestSts, /*loopAnnotation=*/nullptr, - /*local_vars=*/std::nullopt, - /*local_syms=*/nullptr, /*reduce_vars=*/std::nullopt, + /*local_vars=*/mlir::ValueRange{}, + /*local_syms=*/nullptr, /*reduce_vars=*/mlir::ValueRange{}, /*reduce_byref=*/nullptr, /*reduce_syms=*/nullptr, /*reduce_attrs=*/nullptr); @@ -3810,9 +3813,9 @@ private: mlir::Block *selectCaseBlock = insertBlock(blockList[0]); mlir::Block *assumedSizeBlock = rankStarBlock ? rankStarBlock : defaultBlock; - builder->create<mlir::cf::CondBranchOp>(loc, isAssumedSize, - assumedSizeBlock, std::nullopt, - selectCaseBlock, std::nullopt); + builder->create<mlir::cf::CondBranchOp>( + loc, isAssumedSize, assumedSizeBlock, mlir::ValueRange{}, + selectCaseBlock, mlir::ValueRange{}); startBlock(selectCaseBlock); } // Create fir.select_case for the other rank cases. @@ -4702,8 +4705,10 @@ private: mlir::Value lhs = lhsMutableBox.getAddr(); mlir::Value rhs = fir::getBase(genExprBox(loc, assign.rhs, stmtCtx)); mlir::Value boundsDesc = createBoundArray(lbounds, ubounds, loc); - Fortran::lower::genPointerAssociateRemapping(*builder, loc, lhs, rhs, - boundsDesc); + Fortran::lower::genPointerAssociateRemapping( + *builder, loc, lhs, rhs, boundsDesc, + lhsType && rhsType && !lhsType->IsPolymorphic() && + rhsType->IsPolymorphic()); return; } if (!lowerToHighLevelFIR() && explicitIterationSpace()) { @@ -4826,18 +4831,18 @@ private: base = convertOp.getValue(); // Special case if the rhs is a constant. if (matchPattern(base.getDefiningOp(), mlir::m_Constant())) { - builder.create<cuf::DataTransferOp>(loc, base, lhsVal, shape, - transferKindAttr); + cuf::DataTransferOp::create(builder, loc, base, lhsVal, shape, + transferKindAttr); } else { auto associate = hlfir::genAssociateExpr( loc, builder, rhs, rhs.getType(), ".cuf_host_tmp"); - builder.create<cuf::DataTransferOp>(loc, associate.getBase(), lhsVal, - shape, transferKindAttr); - builder.create<hlfir::EndAssociateOp>(loc, associate); + cuf::DataTransferOp::create(builder, loc, associate.getBase(), lhsVal, + shape, transferKindAttr); + hlfir::EndAssociateOp::create(builder, loc, associate); } } else { - builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape, - transferKindAttr); + cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape, + transferKindAttr); } return; } @@ -4846,8 +4851,8 @@ private: if (!lhsIsDevice && rhsIsDevice) { auto transferKindAttr = cuf::DataTransferKindAttr::get( builder.getContext(), cuf::DataTransferKind::DeviceHost); - builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape, - transferKindAttr); + cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape, + transferKindAttr); return; } @@ -4856,8 +4861,8 @@ private: assert(rhs.isVariable() && "CUDA Fortran assignment rhs is not legal"); auto transferKindAttr = cuf::DataTransferKindAttr::get( builder.getContext(), cuf::DataTransferKind::DeviceDevice); - builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape, - transferKindAttr); + cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape, + transferKindAttr); return; } llvm_unreachable("Unhandled CUDA data transfer"); @@ -4903,8 +4908,9 @@ private: addSymbol(sym, hlfir::translateToExtendedValue(loc, builder, temp).first, /*forced=*/true); - builder.create<cuf::DataTransferOp>( - loc, addr, temp, /*shape=*/mlir::Value{}, transferKindAttr); + cuf::DataTransferOp::create(builder, loc, addr, temp, + /*shape=*/mlir::Value{}, + transferKindAttr); ++nbDeviceResidentObject; } } @@ -4993,13 +4999,13 @@ private: if (isCUDATransfer && !hasCUDAImplicitTransfer) genCUDADataTransfer(builder, loc, assign, lhs, rhs); else - builder.create<hlfir::AssignOp>(loc, rhs, lhs, - isWholeAllocatableAssignment, - keepLhsLengthInAllocatableAssignment); + hlfir::AssignOp::create(builder, loc, rhs, lhs, + isWholeAllocatableAssignment, + keepLhsLengthInAllocatableAssignment); if (hasCUDAImplicitTransfer && !isInDeviceContext) { localSymbols.popScope(); for (mlir::Value temp : implicitTemps) - builder.create<fir::FreeMemOp>(loc, temp); + fir::FreeMemOp::create(builder, loc, temp); } return; } @@ -5007,13 +5013,13 @@ private: // left-hand side requires using an hlfir.region_assign in HLFIR. The // right-hand side and left-hand side must be evaluated inside the // hlfir.region_assign regions. - auto regionAssignOp = builder.create<hlfir::RegionAssignOp>(loc); + auto regionAssignOp = hlfir::RegionAssignOp::create(builder, loc); // Lower RHS in its own region. builder.createBlock(®ionAssignOp.getRhsRegion()); Fortran::lower::StatementContext rhsContext; hlfir::Entity rhs = evaluateRhs(rhsContext); - auto rhsYieldOp = builder.create<hlfir::YieldOp>(loc, rhs); + auto rhsYieldOp = hlfir::YieldOp::create(builder, loc, rhs); Fortran::lower::genCleanUpInRegionIfAny( loc, builder, rhsYieldOp.getCleanup(), rhsContext); // Lower LHS in its own region. @@ -5022,7 +5028,7 @@ private: mlir::Value lhsYield = nullptr; if (!lhsHasVectorSubscripts) { hlfir::Entity lhs = evaluateLhs(lhsContext); - auto lhsYieldOp = builder.create<hlfir::YieldOp>(loc, lhs); + auto lhsYieldOp = hlfir::YieldOp::create(builder, loc, lhs); Fortran::lower::genCleanUpInRegionIfAny( loc, builder, lhsYieldOp.getCleanup(), lhsContext); lhsYield = lhs; @@ -5051,7 +5057,7 @@ private: builder.createBlock(®ionAssignOp.getUserDefinedAssignment(), mlir::Region::iterator{}, {rhsType, lhsType}, {loc, loc}); - auto end = builder.create<fir::FirEndOp>(loc); + auto end = fir::FirEndOp::create(builder, loc); builder.setInsertionPoint(end); hlfir::Entity lhsBlockArg{regionAssignOp.getUserAssignmentLhs()}; hlfir::Entity rhsBlockArg{regionAssignOp.getUserAssignmentRhs()}; diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp index 7e21426..55c4b45 100644 --- a/flang/lib/Lower/ConvertArrayConstructor.cpp +++ b/flang/lib/Lower/ConvertArrayConstructor.cpp @@ -137,9 +137,9 @@ public: mlir::Value stride) { if constexpr (!hasLoops) fir::emitFatalError(loc, "array constructor lowering is inconsistent"); - auto loop = builder.create<fir::DoLoopOp>(loc, lower, upper, stride, - /*unordered=*/false, - /*finalCount=*/false); + auto loop = fir::DoLoopOp::create(builder, loc, lower, upper, stride, + /*unordered=*/false, + /*finalCount=*/false); builder.setInsertionPointToStart(loop.getBody()); return loop.getInductionVar(); } @@ -213,15 +213,15 @@ public: assert(!elementalOp && "expected only one implied-do"); mlir::Value one = builder.createIntegerConstant(loc, builder.getIndexType(), 1); - elementalOp = builder.create<hlfir::ElementalOp>( - loc, exprType, shape, - /*mold=*/nullptr, lengthParams, /*isUnordered=*/true); + elementalOp = hlfir::ElementalOp::create(builder, loc, exprType, shape, + /*mold=*/nullptr, lengthParams, + /*isUnordered=*/true); builder.setInsertionPointToStart(elementalOp.getBody()); // implied-do-index = lower+((i-1)*stride) - mlir::Value diff = builder.create<mlir::arith::SubIOp>( - loc, elementalOp.getIndices()[0], one); - mlir::Value mul = builder.create<mlir::arith::MulIOp>(loc, diff, stride); - mlir::Value add = builder.create<mlir::arith::AddIOp>(loc, lower, mul); + mlir::Value diff = mlir::arith::SubIOp::create( + builder, loc, elementalOp.getIndices()[0], one); + mlir::Value mul = mlir::arith::MulIOp::create(builder, loc, diff, stride); + mlir::Value add = mlir::arith::AddIOp::create(builder, loc, lower, mul); return add; } @@ -260,7 +260,7 @@ public: if (destroyOp) destroyOp->erase(); - builder.create<hlfir::YieldElementOp>(loc, elementResult); + hlfir::YieldElementOp::create(builder, loc, elementResult); } // Override the default, because the context scope must be popped in @@ -315,8 +315,8 @@ public: mlir::Value tempStorage = builder.createHeapTemporary( loc, declaredType, tempName, extents, lengths); mlir::Value shape = builder.genShape(loc, extents); - declare = builder.create<hlfir::DeclareOp>( - loc, tempStorage, tempName, shape, lengths, + declare = hlfir::DeclareOp::create( + builder, loc, tempStorage, tempName, shape, lengths, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); initialBoxValue = builder.createBox(loc, boxType, declare->getOriginalBase(), shape, @@ -347,7 +347,7 @@ public: /*slice=*/mlir::Value{}, emboxLengths, /*tdesc=*/{}); } - builder.create<fir::StoreOp>(loc, initialBoxValue, allocatableTemp); + fir::StoreOp::create(builder, loc, initialBoxValue, allocatableTemp); arrayConstructorVector = fir::runtime::genInitArrayConstructorVector( loc, builder, allocatableTemp, builder.createBool(loc, missingLengthParameters)); @@ -369,7 +369,7 @@ public: loc, builder, value, arrayConstructorElementType); mlir::Value addr = fir::getBase(addrExv); if (mlir::isa<fir::BaseBoxType>(addr.getType())) - addr = builder.create<fir::BoxAddrOp>(loc, addr); + addr = fir::BoxAddrOp::create(builder, loc, addr); fir::runtime::genPushArrayConstructorSimpleScalar( loc, builder, arrayConstructorVector, addr); if (cleanUp) @@ -389,9 +389,9 @@ public: mlir::Value startImpliedDo(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value lower, mlir::Value upper, mlir::Value stride) { - auto loop = builder.create<fir::DoLoopOp>(loc, lower, upper, stride, - /*unordered=*/false, - /*finalCount=*/false); + auto loop = fir::DoLoopOp::create(builder, loc, lower, upper, stride, + /*unordered=*/false, + /*finalCount=*/false); builder.setInsertionPointToStart(loop.getBody()); return loop.getInductionVar(); } @@ -409,7 +409,7 @@ public: else temp = hlfir::derefPointersAndAllocatables( loc, builder, hlfir::Entity{allocatableTemp}); - auto hlfirExpr = builder.create<hlfir::AsExprOp>(loc, temp, mustFree); + auto hlfirExpr = hlfir::AsExprOp::create(builder, loc, temp, mustFree); return hlfir::Entity{hlfirExpr}; } diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index 0715133..8c3648b 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -85,7 +85,7 @@ static mlir::Value genRecordCPtrValueArg(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec, mlir::Type ty) { mlir::Value cAddr = fir::factory::genCPtrOrCFunptrAddr(builder, loc, rec, ty); - mlir::Value cVal = builder.create<fir::LoadOp>(loc, cAddr); + mlir::Value cVal = fir::LoadOp::create(builder, loc, cAddr); return builder.createConvert(loc, cAddr.getType(), cVal); } @@ -159,8 +159,8 @@ static mlir::Value readDim3Value(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type refI32Ty = fir::ReferenceType::get(i32Ty); llvm::SmallVector<mlir::Value> lenParams; - mlir::Value designate = builder.create<hlfir::DesignateOp>( - loc, refI32Ty, dim3Addr, /*component=*/comp, + mlir::Value designate = hlfir::DesignateOp::create( + builder, loc, refI32Ty, dim3Addr, /*component=*/comp, /*componentShape=*/mlir::Value{}, hlfir::DesignateOp::Subscripts{}, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, mlir::Value{}, lenParams); @@ -229,8 +229,8 @@ static mlir::Value remapActualToDummyDescriptor( if (fir::isPolymorphicType(dummyBoxType)) mold = explicitArgument; mlir::Value remapped = - builder.create<fir::EmboxOp>(loc, dummyBoxType, baseAddr, shape, - /*slice=*/mlir::Value{}, lengths, mold); + fir::EmboxOp::create(builder, loc, dummyBoxType, baseAddr, shape, + /*slice=*/mlir::Value{}, lengths, mold); if (mapSymbols) symMap.popScope(); return remapped; @@ -273,12 +273,12 @@ static void remapActualToDummyDescriptors( mlir::Value newBox = remapActualToDummyDescriptor( loc, converter, symMap, argLambdaCapture, caller, isBindcCall); - builder.create<fir::ResultOp>(loc, newBox); + fir::ResultOp::create(builder, loc, newBox); }) .genElse([&]() { mlir::Value absent = - builder.create<fir::AbsentOp>(loc, dummyType); - builder.create<fir::ResultOp>(loc, absent); + fir::AbsentOp::create(builder, loc, dummyType); + fir::ResultOp::create(builder, loc, absent); }) .getResults()[0]; caller.placeInput(arg, remapped); @@ -381,8 +381,8 @@ Fortran::lower::genCallOpAndResult( if (isExprCall) { mlir::Type exprType = hlfir::getExprType(type); - evaluateInMemory = builder.create<hlfir::EvaluateInMemoryOp>( - loc, exprType, arrayResultShape, resultLengths); + evaluateInMemory = hlfir::EvaluateInMemoryOp::create( + builder, loc, exprType, arrayResultShape, resultLengths); builder.setInsertionPointToStart(&evaluateInMemory.getBody().front()); return toExtendedValue(loc, evaluateInMemory.getMemory(), extents, lengths); @@ -454,7 +454,7 @@ Fortran::lower::genCallOpAndResult( if (!addHostAssociations && mustCastFuncOpToCopeWithImplicitInterfaceMismatch( loc, converter, callSiteType, funcOpType)) - funcPointer = builder.create<fir::AddrOfOp>(loc, funcOpType, symbolAttr); + funcPointer = fir::AddrOfOp::create(builder, loc, funcOpType, symbolAttr); else funcSymbolAttr = symbolAttr; @@ -482,7 +482,7 @@ Fortran::lower::genCallOpAndResult( if (funcPointer) { operands.push_back( mlir::isa<fir::BoxProcType>(funcPointer.getType()) - ? builder.create<fir::BoxAddrOp>(loc, funcType, funcPointer) + ? fir::BoxAddrOp::create(builder, loc, funcType, funcPointer) : builder.createConvert(loc, funcType, funcPointer)); } @@ -499,10 +499,10 @@ Fortran::lower::genCallOpAndResult( auto funcTy = mlir::FunctionType::get(context, {}, {}); auto boxProcTy = builder.getBoxProcType(funcTy); if (mlir::Value host = argumentHostAssocs(converter, fst)) { - cast = builder.create<fir::EmboxProcOp>( - loc, boxProcTy, llvm::ArrayRef<mlir::Value>{fst, host}); + cast = fir::EmboxProcOp::create(builder, loc, boxProcTy, + llvm::ArrayRef<mlir::Value>{fst, host}); } else { - cast = builder.create<fir::EmboxProcOp>(loc, boxProcTy, fst); + cast = fir::EmboxProcOp::create(builder, loc, boxProcTy, fst); } } else { mlir::Type fromTy = fir::unwrapRefType(fst.getType()); @@ -613,10 +613,10 @@ Fortran::lower::genCallOpAndResult( stream = fir::getBase(converter.genExprAddr( caller.getCallDescription().chevrons()[3], stmtCtx)); - builder.create<cuf::KernelLaunchOp>( - loc, funcType.getResults(), funcSymbolAttr, grid_x, grid_y, grid_z, - block_x, block_y, block_z, bytes, stream, operands, - /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr); + cuf::KernelLaunchOp::create(builder, loc, funcType.getResults(), + funcSymbolAttr, grid_x, grid_y, grid_z, block_x, + block_y, block_z, bytes, stream, operands, + /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr); callNumResults = 0; } else if (caller.requireDispatchCall()) { // Procedure call requiring a dynamic dispatch. Call is created with @@ -640,8 +640,8 @@ Fortran::lower::genCallOpAndResult( // passed object because interface mismatch issues may have inserted a // cast to the operand with a different declared type, which would break // later type bound call resolution in the FIR to FIR pass. - dispatch = builder.create<fir::DispatchOp>( - loc, funcType.getResults(), builder.getStringAttr(procName), + dispatch = fir::DispatchOp::create( + builder, loc, funcType.getResults(), builder.getStringAttr(procName), caller.getInputs()[*passArg], operands, builder.getI32IntegerAttr(*passArg), /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, procAttrs); @@ -656,9 +656,9 @@ Fortran::lower::genCallOpAndResult( mlir::Value passObject = fir::getBase(dataRefValue); if (fir::isa_ref_type(passObject.getType())) - passObject = builder.create<fir::LoadOp>(loc, passObject); - dispatch = builder.create<fir::DispatchOp>( - loc, funcType.getResults(), builder.getStringAttr(procName), + passObject = fir::LoadOp::create(builder, loc, passObject); + dispatch = fir::DispatchOp::create( + builder, loc, funcType.getResults(), builder.getStringAttr(procName), passObject, operands, nullptr, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, procAttrs); } @@ -667,8 +667,8 @@ Fortran::lower::genCallOpAndResult( callResult = dispatch.getResult(0); } else { // Standard procedure call with fir.call. - auto call = builder.create<fir::CallOp>( - loc, funcType.getResults(), funcSymbolAttr, operands, + auto call = fir::CallOp::create( + builder, loc, funcType.getResults(), funcSymbolAttr, operands, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, procAttrs); callNumResults = call.getNumResults(); @@ -691,9 +691,9 @@ Fortran::lower::genCallOpAndResult( if (caller.mustSaveResult()) { assert(allocatedResult.has_value()); - builder.create<fir::SaveResultOp>(loc, callResult, - fir::getBase(*allocatedResult), - arrayResultShape, resultLengths); + fir::SaveResultOp::create(builder, loc, callResult, + fir::getBase(*allocatedResult), arrayResultShape, + resultLengths); } if (evaluateInMemory) { @@ -864,9 +864,9 @@ static hlfir::EntityWithAttributes genStmtFunctionRef( // The result must not be a variable. result = hlfir::loadTrivialScalar(loc, builder, result); if (result.isVariable()) - result = hlfir::Entity{builder.create<hlfir::AsExprOp>(loc, result)}; + result = hlfir::Entity{hlfir::AsExprOp::create(builder, loc, result)}; for (auto associate : exprAssociations) - builder.create<hlfir::EndAssociateOp>(loc, associate); + hlfir::EndAssociateOp::create(builder, loc, associate); return hlfir::EntityWithAttributes{result}; } @@ -951,9 +951,9 @@ extendedValueToHlfirEntity(mlir::Location loc, fir::FirOpBuilder &builder, // rid of the memory indirection in a = char(b), so there is // little incentive to increase the compiler complexity. hlfir::Entity storage{builder.createTemporary(loc, charTy)}; - builder.create<fir::StoreOp>(loc, firBase, storage); - auto asExpr = builder.create<hlfir::AsExprOp>( - loc, storage, /*mustFree=*/builder.createBool(loc, false)); + fir::StoreOp::create(builder, loc, firBase, storage); + auto asExpr = hlfir::AsExprOp::create( + builder, loc, storage, /*mustFree=*/builder.createBool(loc, false)); return hlfir::EntityWithAttributes{asExpr.getResult()}; } return hlfir::genDeclare(loc, builder, exv, name, @@ -965,7 +965,7 @@ namespace { struct CallCleanUp { struct CopyIn { void genCleanUp(mlir::Location loc, fir::FirOpBuilder &builder) { - builder.create<hlfir::CopyOutOp>(loc, tempBox, wasCopied, copyBackVar); + hlfir::CopyOutOp::create(builder, loc, tempBox, wasCopied, copyBackVar); } // address of the descriptor holding the temp if a temp was created. mlir::Value tempBox; @@ -976,7 +976,7 @@ struct CallCleanUp { }; struct ExprAssociate { void genCleanUp(mlir::Location loc, fir::FirOpBuilder &builder) { - builder.create<hlfir::EndAssociateOp>(loc, tempVar, mustFree); + hlfir::EndAssociateOp::create(builder, loc, tempVar, mustFree); } mlir::Value tempVar; mlir::Value mustFree; @@ -1074,7 +1074,7 @@ struct ConditionallyPreparedDummy { /// Generate the "fir.result %preparedDummy" in the then branch of the /// wrapping fir.if. void genThenResult(mlir::Location loc, fir::FirOpBuilder &builder) const { - builder.create<fir::ResultOp>(loc, thenResultValues); + fir::ResultOp::create(builder, loc, thenResultValues); } /// Generate the "fir.result %absent" in the else branch of the @@ -1089,7 +1089,7 @@ struct ConditionallyPreparedDummy { else elseResultValues.push_back(builder.genAbsentOp(loc, type)); } - builder.create<fir::ResultOp>(loc, elseResultValues); + fir::ResultOp::create(builder, loc, elseResultValues); } /// Once the fir.if has been created, get the resulting %conditionallyPrepared @@ -1134,7 +1134,7 @@ static hlfir::Entity fixProcedureDummyMismatch(mlir::Location loc, if (mlir::isa<fir::BoxProcType>(actual.getType()) && fir::isCharacterProcedureTuple(dummyType)) { mlir::Value length = - builder.create<fir::UndefOp>(loc, builder.getCharacterLengthType()); + fir::UndefOp::create(builder, loc, builder.getCharacterLengthType()); mlir::Value tuple = fir::factory::createCharacterProcedureTuple( builder, loc, dummyType, actual, length); return hlfir::Entity{tuple}; @@ -1317,8 +1317,8 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( mlir::Type tempBoxType = baseBoxTy.getBoxTypeWithNewAttr( fir::BaseBoxType::Attribute::Allocatable); mlir::Value tempBox = builder.createTemporary(loc, tempBoxType); - auto copyIn = builder.create<hlfir::CopyInOp>( - loc, var, tempBox, /*var_is_present=*/mlir::Value{}); + auto copyIn = hlfir::CopyInOp::create(builder, loc, var, tempBox, + /*var_is_present=*/mlir::Value{}); // Register the copy-out after the call. preparedDummy.pushCopyInCleanUp(copyIn.getTempBox(), copyIn.getWasCopied(), doCopyOut ? copyIn.getVar() @@ -1330,16 +1330,17 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( fir::BaseBoxType boxType = fir::BoxType::get( hlfir::getFortranElementOrSequenceType(dummyTypeWithActualRank)); if (actualIsAssumedRank) - return hlfir::Entity{builder.create<fir::ReboxAssumedRankOp>( - loc, boxType, var, fir::LowerBoundModifierAttribute::SetToOnes)}; + return hlfir::Entity{fir::ReboxAssumedRankOp::create( + builder, loc, boxType, var, + fir::LowerBoundModifierAttribute::SetToOnes)}; // Use actual shape when creating descriptor with dummy type, the dummy // shape may be unknown in case of sequence association. mlir::Type actualTy = hlfir::getFortranElementOrSequenceType(actual.getType()); boxType = boxType.getBoxTypeWithNewShape(actualTy); - return hlfir::Entity{builder.create<fir::ReboxOp>(loc, boxType, var, - /*shape=*/mlir::Value{}, - /*slice=*/mlir::Value{})}; + return hlfir::Entity{fir::ReboxOp::create(builder, loc, boxType, var, + /*shape=*/mlir::Value{}, + /*slice=*/mlir::Value{})}; }; // Step 2: prepare the storage for the dummy arguments, ensuring that it @@ -1361,7 +1362,7 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( // generated writes in copy-out. isParameterObjectOrSubObject(entity)) { // Make a copy in a temporary. - auto copy = builder.create<hlfir::AsExprOp>(loc, entity); + auto copy = hlfir::AsExprOp::create(builder, loc, entity); mlir::Type storageType = entity.getType(); mlir::NamedAttribute byRefAttr = fir::getAdaptToByRefAttr(builder); hlfir::AssociateOp associate = hlfir::genAssociateExpr( @@ -1441,14 +1442,14 @@ static PreparedDummyArgument preparePresentUserCallActualArgument( auto lbModifier = needsZeroLowerBounds ? fir::LowerBoundModifierAttribute::SetToZeroes : fir::LowerBoundModifierAttribute::SetToOnes; - entity = hlfir::Entity{builder.create<fir::ReboxAssumedRankOp>( - loc, dummyTypeWithActualRank, entity, lbModifier)}; + entity = hlfir::Entity{fir::ReboxAssumedRankOp::create( + builder, loc, dummyTypeWithActualRank, entity, lbModifier)}; } else { mlir::Value shift{}; if (needsZeroLowerBounds) shift = getZeroLowerBounds(loc, builder, entity); - entity = hlfir::Entity{builder.create<fir::ReboxOp>( - loc, dummyTypeWithActualRank, entity, /*shape=*/shift, + entity = hlfir::Entity{fir::ReboxOp::create( + builder, loc, dummyTypeWithActualRank, entity, /*shape=*/shift, /*slice=*/mlir::Value{})}; } } @@ -1501,8 +1502,8 @@ static PreparedDummyArgument prepareUserCallActualArgument( // for this unusual if/then/else generation is that the number // and types of the if results will depend on how the argument // is prepared, and forecasting that here would be brittle. - auto badIfOp = builder.create<fir::IfOp>(loc, dummyType, isPresent, - /*withElseRegion=*/false); + auto badIfOp = fir::IfOp::create(builder, loc, dummyType, isPresent, + /*withElseRegion=*/false); mlir::Block *preparationBlock = &badIfOp.getThenRegion().front(); builder.setInsertionPointToStart(preparationBlock); PreparedDummyArgument unconditionalDummy = @@ -1520,9 +1521,9 @@ static PreparedDummyArgument prepareUserCallActualArgument( // badIfOp cannot be modified and used here). llvm::SmallVector<mlir::Type> ifOpResultTypes; ConditionallyPreparedDummy conditionalDummy(unconditionalDummy); - auto ifOp = builder.create<fir::IfOp>(loc, conditionalDummy.getIfResulTypes(), - isPresent, - /*withElseRegion=*/true); + auto ifOp = fir::IfOp::create(builder, loc, + conditionalDummy.getIfResulTypes(), isPresent, + /*withElseRegion=*/true); // Move "preparationBlock" into the "then" of the new // fir.if operation and create fir.result propagating // unconditionalDummy. @@ -1559,7 +1560,7 @@ static PreparedDummyArgument prepareProcedurePointerActualArgument( auto tempBoxProc{builder.createTemporary(loc, boxTy)}; hlfir::Entity nullBoxProc( fir::factory::createNullBoxProc(builder, loc, boxTy)); - builder.create<fir::StoreOp>(loc, nullBoxProc, tempBoxProc); + fir::StoreOp::create(builder, loc, nullBoxProc, tempBoxProc); return PreparedDummyArgument{tempBoxProc, /*cleanups=*/{}}; } hlfir::Entity actual = preparedActual.getActual(loc, builder); @@ -1568,7 +1569,7 @@ static PreparedDummyArgument prepareProcedurePointerActualArgument( assert(actual.isProcedure()); // Procedure actual to procedure pointer dummy. auto tempBoxProc{builder.createTemporary(loc, actual.getType())}; - builder.create<fir::StoreOp>(loc, actual, tempBoxProc); + fir::StoreOp::create(builder, loc, actual, tempBoxProc); return PreparedDummyArgument{tempBoxProc, /*cleanups=*/{}}; } @@ -1607,7 +1608,7 @@ void prepareUserCallArguments( "adapt.cptrbyval"); value = hlfir::Entity{genRecordCPtrValueArg( builder, loc, associate.getFirBase(), eleTy)}; - builder.create<hlfir::EndAssociateOp>(loc, associate); + hlfir::EndAssociateOp::create(builder, loc, associate); } else { value = hlfir::Entity{genRecordCPtrValueArg(builder, loc, value, eleTy)}; @@ -1626,7 +1627,7 @@ void prepareUserCallArguments( loadedValue = builder.createConvert( loc, fir::ReferenceType::get(argTy), loadedValue); if (fir::isa_ref_type(loadedValue.getType())) - loadedValue = builder.create<fir::LoadOp>(loc, loadedValue); + loadedValue = fir::LoadOp::create(builder, loc, loadedValue); caller.placeInput(arg, loadedValue); if (cleanup) (*cleanup)(); @@ -1811,8 +1812,9 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals, // In such case, the expression should not be freed after its use since // the result is stack allocated or deallocation (for allocatable results) // was already inserted in genCallOpAndResult. - auto asExpr = builder.create<hlfir::AsExprOp>( - loc, resultEntity, /*mustFree=*/builder.createBool(loc, false)); + auto asExpr = + hlfir::AsExprOp::create(builder, loc, resultEntity, + /*mustFree=*/builder.createBool(loc, false)); return hlfir::EntityWithAttributes{asExpr.getResult()}; } return hlfir::EntityWithAttributes{resultEntity}; @@ -1860,12 +1862,12 @@ static ExvAndCleanup genOptionalValue(fir::FirOpBuilder &builder, "must be a numerical or logical scalar"); mlir::Value val = hlfir::loadTrivialScalar(loc, builder, entity); - builder.create<fir::ResultOp>(loc, val); + fir::ResultOp::create(builder, loc, val); }) .genElse([&]() { mlir::Value zero = fir::factory::createZeroValue(builder, loc, eleType); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0], std::nullopt}; @@ -1912,9 +1914,9 @@ static ExvAndCleanup genOptionalBox(fir::FirOpBuilder &builder, // ensures it won't be. mlir::Value box = builder.createBox(loc, newExv); mlir::Type boxType = box.getType(); - auto absent = builder.create<fir::AbsentOp>(loc, boxType); - auto boxOrAbsent = builder.create<mlir::arith::SelectOp>( - loc, boxType, isPresent, box, absent); + auto absent = fir::AbsentOp::create(builder, loc, boxType); + auto boxOrAbsent = mlir::arith::SelectOp::create(builder, loc, boxType, + isPresent, box, absent); return {fir::BoxValue(boxOrAbsent), cleanup}; } @@ -2142,10 +2144,10 @@ genIntrinsicRefCore(Fortran::lower::PreparedActualArguments &loweredActuals, // ownership of this address cannot be taken here since it may not be a // temp. if (intrinsicName == "merge") - asExpr = builder.create<hlfir::AsExprOp>(loc, resultEntity); + asExpr = hlfir::AsExprOp::create(builder, loc, resultEntity); else - asExpr = builder.create<hlfir::AsExprOp>( - loc, resultEntity, builder.createBool(loc, mustBeFreed)); + asExpr = hlfir::AsExprOp::create(builder, loc, resultEntity, + builder.createBool(loc, mustBeFreed)); resultEntity = hlfir::EntityWithAttributes{asExpr.getResult()}; } return resultEntity; @@ -2525,7 +2527,7 @@ genIsPresentIfArgMaybeAbsent(mlir::Location loc, hlfir::Entity actual, // May fall into the category above if the allocatable is not optional. // Passing an optional to an optional. - return builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), actual) + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), actual) .getResult(); } @@ -2813,9 +2815,9 @@ genProcedureRef(CallContext &callContext) { // TYPE(*) cannot be ALLOCATABLE/POINTER (C709) so there is no // need to cover the case of passing an ALLOCATABLE/POINTER to an // OPTIONAL. - isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), actual) - .getResult(); + isPresent = fir::IsPresentOp::create(builder, loc, + builder.getI1Type(), actual) + .getResult(); } loweredActuals.push_back(Fortran::lower::PreparedActualArgument{ hlfir::Entity{*var}, isPresent}); @@ -2931,7 +2933,7 @@ std::optional<hlfir::EntityWithAttributes> Fortran::lower::convertCallToHLFIR( // this can be enforced whenscheduling forall/where expression evaluations. Fortran::lower::StatementContext localStmtCtx; mlir::Type bogusType = builder.getIndexType(); - auto exactlyOnce = builder.create<hlfir::ExactlyOnceOp>(loc, bogusType); + auto exactlyOnce = hlfir::ExactlyOnceOp::create(builder, loc, bogusType); mlir::Block *block = builder.createBlock(&exactlyOnce.getBody()); builder.setInsertionPointToStart(block); CallContext callContext(procRef, resultType, loc, converter, symMap, @@ -2939,7 +2941,7 @@ std::optional<hlfir::EntityWithAttributes> Fortran::lower::convertCallToHLFIR( std::optional<hlfir::EntityWithAttributes> res = genProcedureRef(callContext); assert(res.has_value() && "must be a function"); - auto yield = builder.create<hlfir::YieldOp>(loc, *res); + auto yield = hlfir::YieldOp::create(builder, loc, *res); Fortran::lower::genCleanUpInRegionIfAny(loc, builder, yield.getCleanup(), localStmtCtx); builder.setInsertionPointAfter(exactlyOnce); diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp index 1850b67..768a237 100644 --- a/flang/lib/Lower/ConvertConstant.cpp +++ b/flang/lib/Lower/ConvertConstant.cpp @@ -237,8 +237,8 @@ static mlir::Value genScalarLit( ? value.UnsignedDecimal() : value.SignedDecimal(), 10); - return builder.create<mlir::arith::ConstantOp>( - loc, ty, mlir::IntegerAttr::get(ty, bigInt)); + return mlir::arith::ConstantOp::create( + builder, loc, ty, mlir::IntegerAttr::get(ty, bigInt)); } return builder.createIntegerConstant(loc, ty, value.ToInt64()); } else if constexpr (TC == Fortran::common::TypeCategory::Logical) { @@ -302,8 +302,9 @@ createStringLitOp(fir::FirOpBuilder &builder, mlir::Location loc, auto sizeTag = mlir::StringAttr::get(context, fir::StringLitOp::size()); mlir::NamedAttribute sizeAttr(sizeTag, builder.getI64IntegerAttr(len)); llvm::SmallVector<mlir::NamedAttribute> attrs = {dataAttr, sizeAttr}; - return builder.create<fir::StringLitOp>( - loc, llvm::ArrayRef<mlir::Type>{type}, std::nullopt, attrs); + return fir::StringLitOp::create(builder, loc, + llvm::ArrayRef<mlir::Type>{type}, + mlir::ValueRange{}, attrs); } } @@ -340,11 +341,11 @@ genScalarLit(fir::FirOpBuilder &builder, mlir::Location loc, [&](fir::FirOpBuilder &builder) { fir::StringLitOp str = createStringLitOp<KIND>(builder, loc, value, len); - builder.create<fir::HasValueOp>(loc, str); + fir::HasValueOp::create(builder, loc, str); }, builder.createLinkOnceLinkage()); - return builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + return fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); } // Helper to generate StructureConstructor component values. @@ -364,9 +365,9 @@ static mlir::Value genStructureComponentInit( auto fieldTy = fir::FieldType::get(recTy.getContext()); assert(componentTy && "failed to retrieve component"); // FIXME: type parameters must come from the derived-type-spec - auto field = builder.create<fir::FieldIndexOp>( - loc, fieldTy, name, recTy, - /*typeParams=*/mlir::ValueRange{} /*TODO*/); + auto field = + fir::FieldIndexOp::create(builder, loc, fieldTy, name, recTy, + /*typeParams=*/mlir::ValueRange{} /*TODO*/); if (Fortran::semantics::IsAllocatable(sym)) { if (!Fortran::evaluate::IsNullPointerOrAllocatable(&expr)) { @@ -378,8 +379,8 @@ static mlir::Value genStructureComponentInit( fir::factory::createUnallocatedBox(builder, loc, componentTy, {})}; componentValue = builder.createConvert(loc, componentTy, componentValue); - return builder.create<fir::InsertValueOp>( - loc, recTy, res, componentValue, + return fir::InsertValueOp::create( + builder, loc, recTy, res, componentValue, builder.getArrayAttr(field.getAttributes())); } } @@ -400,9 +401,9 @@ static mlir::Value genStructureComponentInit( } else initialTarget = Fortran::lower::genInitialDataTarget(converter, loc, componentTy, expr); - res = builder.create<fir::InsertValueOp>( - loc, recTy, res, initialTarget, - builder.getArrayAttr(field.getAttributes())); + res = + fir::InsertValueOp::create(builder, loc, recTy, res, initialTarget, + builder.getArrayAttr(field.getAttributes())); return res; } @@ -426,7 +427,7 @@ static mlir::Value genStructureComponentInit( mlir::Value addr = fir::getBase( Fortran::lower::genExtAddrInInitializer(converter, loc, expr)); if (mlir::isa<fir::BoxProcType>(addr.getType())) - addr = builder.create<fir::BoxAddrOp>(loc, addr); + addr = fir::BoxAddrOp::create(builder, loc, addr); assert((fir::isa_ref_type(addr.getType()) || mlir::isa<mlir::FunctionType>(addr.getType())) && "expect reference type for address field"); @@ -435,24 +436,25 @@ static mlir::Value genStructureComponentInit( auto cPtrRecTy = mlir::cast<fir::RecordType>(componentTy); llvm::StringRef addrFieldName = Fortran::lower::builtin::cptrFieldName; mlir::Type addrFieldTy = cPtrRecTy.getType(addrFieldName); - auto addrField = builder.create<fir::FieldIndexOp>( - loc, fieldTy, addrFieldName, componentTy, + auto addrField = fir::FieldIndexOp::create( + builder, loc, fieldTy, addrFieldName, componentTy, /*typeParams=*/mlir::ValueRange{}); mlir::Value castAddr = builder.createConvert(loc, addrFieldTy, addr); - auto undef = builder.create<fir::UndefOp>(loc, componentTy); - addr = builder.create<fir::InsertValueOp>( - loc, componentTy, undef, castAddr, + auto undef = fir::UndefOp::create(builder, loc, componentTy); + addr = fir::InsertValueOp::create( + builder, loc, componentTy, undef, castAddr, builder.getArrayAttr(addrField.getAttributes())); - res = builder.create<fir::InsertValueOp>( - loc, recTy, res, addr, builder.getArrayAttr(field.getAttributes())); + res = + fir::InsertValueOp::create(builder, loc, recTy, res, addr, + builder.getArrayAttr(field.getAttributes())); return res; } mlir::Value val = fir::getBase(genConstantValue(converter, loc, expr)); assert(!fir::isa_ref_type(val.getType()) && "expecting a constant value"); mlir::Value castVal = builder.createConvert(loc, componentTy, val); - res = builder.create<fir::InsertValueOp>( - loc, recTy, res, castVal, builder.getArrayAttr(field.getAttributes())); + res = fir::InsertValueOp::create(builder, loc, recTy, res, castVal, + builder.getArrayAttr(field.getAttributes())); return res; } @@ -465,7 +467,7 @@ static mlir::Value genInlinedStructureCtorLitImpl( auto recTy = mlir::cast<fir::RecordType>(type); if (!converter.getLoweringOptions().getLowerToHighLevelFIR()) { - mlir::Value res = builder.create<fir::UndefOp>(loc, recTy); + mlir::Value res = fir::UndefOp::create(builder, loc, recTy); for (const auto &[sym, expr] : ctor.values()) { // Parent components need more work because they do not appear in the // fir.rec type. @@ -495,13 +497,13 @@ static mlir::Value genInlinedStructureCtorLitImpl( break; } for (mlir::Type parentType : llvm::reverse(parentTypes)) { - auto undef = builder.create<fir::UndefOp>(loc, parentType); + auto undef = fir::UndefOp::create(builder, loc, parentType); fir::RecordType parentRecTy = mlir::cast<fir::RecordType>(parentType); - auto field = builder.create<fir::FieldIndexOp>( - loc, fieldTy, parentRecTy.getTypeList()[0].first, parentType, + auto field = fir::FieldIndexOp::create( + builder, loc, fieldTy, parentRecTy.getTypeList()[0].first, parentType, /*typeParams=*/mlir::ValueRange{} /*TODO*/); - res = builder.create<fir::InsertValueOp>( - loc, parentRecTy, undef, res, + res = fir::InsertValueOp::create( + builder, loc, parentRecTy, undef, res, builder.getArrayAttr(field.getAttributes())); } }; @@ -514,7 +516,7 @@ static mlir::Value genInlinedStructureCtorLitImpl( if (!res) { mlir::Type parentType = converter.genType(*componentParentType); curentType = componentParentType; - res = builder.create<fir::UndefOp>(loc, parentType); + res = fir::UndefOp::create(builder, loc, parentType); } else if (*componentParentType != *curentType) { mlir::Type parentType = converter.genType(*componentParentType); insertParentValueIntoExtension(parentType); @@ -524,7 +526,7 @@ static mlir::Value genInlinedStructureCtorLitImpl( } if (!res) // structure constructor for empty type. - return builder.create<fir::UndefOp>(loc, recTy); + return fir::UndefOp::create(builder, loc, recTy); // The last component may belong to a parent type. if (res.getType() != recTy) @@ -550,12 +552,12 @@ static mlir::Value genScalarLit( [&](fir::FirOpBuilder &builder) { mlir::Value result = genInlinedStructureCtorLitImpl(converter, loc, value, eleTy); - builder.create<fir::HasValueOp>(loc, result); + fir::HasValueOp::create(builder, loc, result); }, builder.createInternalLinkage()); } - return builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + return fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); } /// Create an evaluate::Constant<T> array to a fir.array<> value @@ -576,7 +578,7 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, builder.getIntegerAttr(idxTy, subscripts[i] - con.lbounds()[i])); return idx; }; - mlir::Value array = builder.create<fir::UndefOp>(loc, arrayTy); + mlir::Value array = fir::UndefOp::create(builder, loc, arrayTy); if (Fortran::evaluate::GetSize(con.shape()) == 0) return array; if constexpr (T::category == Fortran::common::TypeCategory::Character) { @@ -584,8 +586,9 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, mlir::Value elementVal = genScalarLit<T::kind>(builder, loc, con.At(subscripts), con.LEN(), /*outlineInReadOnlyMemory=*/false); - array = builder.create<fir::InsertValueOp>( - loc, arrayTy, array, elementVal, builder.getArrayAttr(createIdx())); + array = + fir::InsertValueOp::create(builder, loc, arrayTy, array, elementVal, + builder.getArrayAttr(createIdx())); } while (con.IncrementSubscripts(subscripts)); } else if constexpr (T::category == Fortran::common::TypeCategory::Derived) { do { @@ -594,8 +597,9 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, mlir::Value elementVal = genScalarLit(converter, loc, con.At(subscripts), eleTy, /*outlineInReadOnlyMemory=*/false); - array = builder.create<fir::InsertValueOp>( - loc, arrayTy, array, elementVal, builder.getArrayAttr(createIdx())); + array = + fir::InsertValueOp::create(builder, loc, arrayTy, array, elementVal, + builder.getArrayAttr(createIdx())); } while (con.IncrementSubscripts(subscripts)); } else { llvm::SmallVector<mlir::Attribute> rangeStartIdx; @@ -611,9 +615,9 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, bool nextIsSame = con.IncrementSubscripts(nextSubscripts) && con.At(subscripts) == con.At(nextSubscripts); if (!rangeSize && !nextIsSame) { // single (non-range) value - array = builder.create<fir::InsertValueOp>( - loc, arrayTy, array, getElementVal(), - builder.getArrayAttr(createIdx())); + array = fir::InsertValueOp::create(builder, loc, arrayTy, array, + getElementVal(), + builder.getArrayAttr(createIdx())); } else if (!rangeSize) { // start a range rangeStartIdx = createIdx(); rangeSize = 1; @@ -629,8 +633,8 @@ genInlinedArrayLit(Fortran::lower::AbstractConverter &converter, rangeBounds.push_back( mlir::cast<mlir::IntegerAttr>(idx[i]).getValue().getSExtValue()); } - array = builder.create<fir::InsertOnRangeOp>( - loc, arrayTy, array, getElementVal(), + array = fir::InsertOnRangeOp::create( + builder, loc, arrayTy, array, getElementVal(), builder.getIndexVectorAttr(rangeBounds)); rangeSize = 0; } @@ -679,12 +683,12 @@ genOutlineArrayLit(Fortran::lower::AbstractConverter &converter, [&](fir::FirOpBuilder &builder) { mlir::Value result = genInlinedArrayLit(converter, loc, arrayTy, constant); - builder.create<fir::HasValueOp>(loc, result); + fir::HasValueOp::create(builder, loc, result); }, builder.createInternalLinkage()); } - return builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + return fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); } /// Convert an evaluate::Constant<T> array into an fir::ExtendedValue. diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index 0a1cd67..3578f94 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -267,8 +267,8 @@ static mlir::Value genActualIsPresentTest(fir::FirOpBuilder &builder, // Optional case (not that optional allocatable/pointer cannot be absent // when passed to CMPLX as per 15.5.2.12 point 3 (7) and (8)). It is // therefore possible to catch them in the `then` case above. - return builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(actual)); + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(actual)); } /// Convert the array_load, `load`, to an extended value. If `path` is not @@ -345,8 +345,8 @@ arrayLoadExtValue(fir::FirOpBuilder &builder, mlir::Location loc, auto origins = fir::factory::getNonDefaultLowerBounds(builder, loc, exv); if (shapeVal) { // shapeVal is a ShiftOp and load.memref() is a boxed value. - newBase = builder.create<fir::ReboxOp>(loc, oldBox.getType(), oldBox, - shapeVal, /*slice=*/mlir::Value{}); + newBase = fir::ReboxOp::create(builder, loc, oldBox.getType(), oldBox, + shapeVal, /*slice=*/mlir::Value{}); origins = fir::factory::getOrigins(shapeVal); } return fir::substBase(arrayToExtendedValue(extents, origins), newBase); @@ -378,7 +378,7 @@ placeScalarValueInMemory(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value temp = builder.createTemporary( loc, storageType, llvm::ArrayRef<mlir::NamedAttribute>{fir::getAdaptToByRefAttr(builder)}); - builder.create<fir::StoreOp>(loc, val, temp); + fir::StoreOp::create(builder, loc, val, temp); return fir::substBase(exv, temp); } @@ -434,14 +434,14 @@ static fir::ExtendedValue genLoad(fir::FirOpBuilder &builder, if (mlir::isa<fir::RecordType>( fir::unwrapRefType(fir::getBase(p).getType()))) return p; - mlir::Value load = builder.create<fir::LoadOp>(loc, fir::getBase(p)); + mlir::Value load = fir::LoadOp::create(builder, loc, fir::getBase(p)); return fir::PolymorphicValue(load, p.getSourceBox()); }, [&](const fir::UnboxedValue &v) -> fir::ExtendedValue { if (mlir::isa<fir::RecordType>( fir::unwrapRefType(fir::getBase(v).getType()))) return v; - return builder.create<fir::LoadOp>(loc, fir::getBase(v)); + return fir::LoadOp::create(builder, loc, fir::getBase(v)); }, [&](const fir::MutableBoxValue &box) -> fir::ExtendedValue { return genLoad(builder, loc, @@ -473,11 +473,11 @@ static fir::ExtendedValue genOptionalValue(fir::FirOpBuilder &builder, /*withElseRegion=*/true) .genThen([&]() { mlir::Value val = fir::getBase(genLoad(builder, loc, exv)); - builder.create<fir::ResultOp>(loc, val); + fir::ResultOp::create(builder, loc, val); }) .genElse([&]() { mlir::Value zero = fir::factory::createZeroValue(builder, loc, eleType); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } @@ -521,9 +521,9 @@ static fir::ExtendedValue genOptionalBox(fir::FirOpBuilder &builder, // ensures it won't be. mlir::Value box = builder.createBox(loc, newExv); mlir::Type boxType = box.getType(); - auto absent = builder.create<fir::AbsentOp>(loc, boxType); - auto boxOrAbsent = builder.create<mlir::arith::SelectOp>( - loc, boxType, isPresent, box, absent); + auto absent = fir::AbsentOp::create(builder, loc, boxType); + auto boxOrAbsent = mlir::arith::SelectOp::create(builder, loc, boxType, + isPresent, box, absent); return fir::BoxValue(boxOrAbsent); } @@ -569,13 +569,13 @@ createBoxProcCharTuple(Fortran::lower::AbstractConverter &converter, if (fir::isa_ref_type(fromTy)) funcAddr = builder.createConvert(loc, toTy, funcAddr); else if (mlir::isa<fir::BoxProcType>(fromTy)) - funcAddr = builder.create<fir::BoxAddrOp>(loc, toTy, funcAddr); + funcAddr = fir::BoxAddrOp::create(builder, loc, toTy, funcAddr); auto boxProc = [&]() -> mlir::Value { if (auto host = Fortran::lower::argumentHostAssocs(converter, funcAddr)) - return builder.create<fir::EmboxProcOp>( - loc, boxTy, llvm::ArrayRef<mlir::Value>{funcAddr, host}); - return builder.create<fir::EmboxProcOp>(loc, boxTy, funcAddr); + return fir::EmboxProcOp::create( + builder, loc, boxTy, llvm::ArrayRef<mlir::Value>{funcAddr, host}); + return fir::EmboxProcOp::create(builder, loc, boxTy, funcAddr); }(); return fir::factory::createCharacterProcedureTuple(builder, loc, argTy, boxProc, charLen); @@ -598,7 +598,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value emptyBox = fir::factory::createUnallocatedBox(builder, loc, boxType, {}); auto safeToReadBox = - builder.create<mlir::arith::SelectOp>(loc, isPresent, box, emptyBox); + mlir::arith::SelectOp::create(builder, loc, isPresent, box, emptyBox); return fir::substBase(exv, safeToReadBox); } @@ -822,9 +822,9 @@ public: Fortran::common::TypeCategory::Integer, *unsignedKind); mlir::Value lhsSL = builder.createConvert(loc, signlessType, *lhs); mlir::Value rhsSL = builder.createConvert(loc, signlessType, *rhs); - return builder.create<OpTy>(loc, pred, lhsSL, rhsSL); + return OpTy::create(builder, loc, pred, lhsSL, rhsSL); } - return builder.create<OpTy>(loc, pred, *lhs, *rhs); + return OpTy::create(builder, loc, pred, *lhs, *rhs); } } fir::emitFatalError(getLoc(), "array compare should be handled in genarr"); @@ -841,7 +841,7 @@ public: const ExtValue &left, const ExtValue &right) { if (const fir::UnboxedValue *lhs = left.getUnboxed()) if (const fir::UnboxedValue *rhs = right.getUnboxed()) - return builder.create<OpTy>(getLoc(), pred, *lhs, *rhs); + return OpTy::create(builder, getLoc(), pred, *lhs, *rhs); fir::emitFatalError(getLoc(), "array compare should be handled in genarr"); } template <typename OpTy, typename A> @@ -904,7 +904,7 @@ public: mlir::Value cnvrt = Fortran::lower::addCrayPointerInst( loc, builder, ptrVal, ptrTy, pteVal.getType()); - addr = builder.create<fir::LoadOp>(loc, cnvrt); + addr = fir::LoadOp::create(builder, loc, cnvrt); } return genLoad(addr); } @@ -970,12 +970,12 @@ public: std::string name = converter.getRecordTypeFieldName(sym); // FIXME: type parameters must come from the derived-type-spec - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fieldTy, name, ty, - /*typeParams=*/mlir::ValueRange{} /*TODO*/); + mlir::Value field = + fir::FieldIndexOp::create(builder, loc, fieldTy, name, ty, + /*typeParams=*/mlir::ValueRange{} /*TODO*/); mlir::Type coorTy = builder.getRefType(recTy.getType(name)); - auto coor = builder.create<fir::CoordinateOp>(loc, coorTy, - fir::getBase(res), field); + auto coor = fir::CoordinateOp::create(builder, loc, coorTy, + fir::getBase(res), field); ExtValue to = fir::factory::componentToExtendedValue(builder, loc, coor); to.match( [&](const fir::UnboxedValue &toPtr) { @@ -1003,9 +1003,9 @@ public: }, [&](const fir::MutableBoxValue &toBox) { if (toBox.isPointer()) { - Fortran::lower::associateMutableBox(converter, loc, toBox, expr, - /*lbounds=*/std::nullopt, - stmtCtx); + Fortran::lower::associateMutableBox( + converter, loc, toBox, expr, + /*lbounds=*/mlir::ValueRange{}, stmtCtx); return; } // For allocatable components, a deep copy is needed. @@ -1077,7 +1077,7 @@ public: mlir::Value input = genunbox(op.left()); // Like LLVM, integer negation is the binary op "0 - value" mlir::Value zero = genIntegerConstant<KIND>(builder.getContext(), 0); - return builder.create<mlir::arith::SubIOp>(getLoc(), zero, input); + return mlir::arith::SubIOp::create(builder, getLoc(), zero, input); } template <int KIND> ExtValue genval(const Fortran::evaluate::Negate<Fortran::evaluate::Type< @@ -1088,18 +1088,18 @@ public: mlir::Value input = genunbox(op.left()); mlir::Value signless = builder.createConvert(loc, signlessType, input); mlir::Value zero = genIntegerConstant<KIND>(builder.getContext(), 0); - mlir::Value neg = builder.create<mlir::arith::SubIOp>(loc, zero, signless); + mlir::Value neg = mlir::arith::SubIOp::create(builder, loc, zero, signless); return builder.createConvert(loc, input.getType(), neg); } template <int KIND> ExtValue genval(const Fortran::evaluate::Negate<Fortran::evaluate::Type< Fortran::common::TypeCategory::Real, KIND>> &op) { - return builder.create<mlir::arith::NegFOp>(getLoc(), genunbox(op.left())); + return mlir::arith::NegFOp::create(builder, getLoc(), genunbox(op.left())); } template <int KIND> ExtValue genval(const Fortran::evaluate::Negate<Fortran::evaluate::Type< Fortran::common::TypeCategory::Complex, KIND>> &op) { - return builder.create<fir::NegcOp>(getLoc(), genunbox(op.left())); + return fir::NegcOp::create(builder, getLoc(), genunbox(op.left())); } template <typename OpTy> @@ -1312,7 +1312,7 @@ public: ExtValue input = genval(op.left()); mlir::Value base = fir::getBase(input); mlir::Value newBase = - builder.create<fir::NoReassocOp>(getLoc(), base.getType(), base); + fir::NoReassocOp::create(builder, getLoc(), base.getType(), base); return fir::substBase(input, newBase); } @@ -1322,7 +1322,7 @@ public: mlir::Value one = genBoolConstant(true); mlir::Value val = builder.createConvert(getLoc(), builder.getI1Type(), logical); - return builder.create<mlir::arith::XOrIOp>(getLoc(), val, one); + return mlir::arith::XOrIOp::create(builder, getLoc(), val, one); } template <int KIND> @@ -1384,8 +1384,9 @@ public: mlir::Value offset = builder.createIntegerConstant( loc, idxTy, x.part() == Fortran::evaluate::ComplexPart::Part::RE ? 0 : 1); - mlir::Value result = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(eleTy), base, mlir::ValueRange{offset}); + mlir::Value result = + fir::CoordinateOp::create(builder, loc, builder.getRefType(eleTy), base, + mlir::ValueRange{offset}); return {result}; } ExtValue genval(const Fortran::evaluate::ComplexPart &x) { @@ -1500,8 +1501,8 @@ public: auto recTy = mlir::cast<fir::RecordType>(ty); const Fortran::semantics::Symbol &sym = getLastSym(*field); std::string name = converter.getRecordTypeFieldName(sym); - coorArgs.push_back(builder.create<fir::FieldIndexOp>( - loc, fldTy, name, recTy, fir::getTypeParams(obj))); + coorArgs.push_back(fir::FieldIndexOp::create( + builder, loc, fldTy, name, recTy, fir::getTypeParams(obj))); ty = recTy.getType(name); } // If parent component is referred then it has no coordinate argument. @@ -1510,8 +1511,8 @@ public: ty = builder.getRefType(ty); return fir::factory::componentToExtendedValue( builder, loc, - builder.create<fir::CoordinateOp>(loc, ty, fir::getBase(obj), - coorArgs)); + fir::CoordinateOp::create(builder, loc, ty, fir::getBase(obj), + coorArgs)); } ExtValue gen(const Fortran::evaluate::Component &cmpt) { @@ -1587,7 +1588,7 @@ public: mlir::Value val = fir::getBase(subVal); mlir::Type ty = val.getType(); mlir::Value lb = getLBound(array, subsc.index(), ty); - args.push_back(builder.create<mlir::arith::SubIOp>(loc, ty, val, lb)); + args.push_back(mlir::arith::SubIOp::create(builder, loc, ty, val, lb)); } mlir::Value base = fir::getBase(array); @@ -1602,7 +1603,7 @@ public: mlir::Value cnvrt = Fortran::lower::addCrayPointerInst( loc, builder, ptrVal, ptrTy, base.getType()); - base = builder.create<fir::LoadOp>(loc, cnvrt); + base = fir::LoadOp::create(builder, loc, cnvrt); } mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(base.getType()); @@ -1611,7 +1612,7 @@ public: auto seqTy = mlir::cast<fir::SequenceType>(eleTy); assert(args.size() == seqTy.getDimension()); mlir::Type ty = builder.getRefType(seqTy.getEleTy()); - auto addr = builder.create<fir::CoordinateOp>(loc, ty, base, args); + auto addr = fir::CoordinateOp::create(builder, loc, ty, base, args); return fir::factory::arrayElementToExtendedValue(builder, loc, array, addr); } @@ -1648,12 +1649,12 @@ public: mlir::Value val = builder.createConvert(loc, idxTy, fir::getBase(subVal)); mlir::Value lb = builder.createConvert(loc, idxTy, getLB(arr, dim)); - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, val, lb); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, val, lb); mlir::Value prod = - builder.create<mlir::arith::MulIOp>(loc, delta, diff); - total = builder.create<mlir::arith::AddIOp>(loc, prod, total); + mlir::arith::MulIOp::create(builder, loc, delta, diff); + total = mlir::arith::AddIOp::create(builder, loc, prod, total); if (ext) - delta = builder.create<mlir::arith::MulIOp>(loc, delta, ext); + delta = mlir::arith::MulIOp::create(builder, loc, delta, ext); ++dim; } mlir::Type origRefTy = refTy; @@ -1672,8 +1673,8 @@ public: base = builder.createConvert(loc, seqRefTy, base); } } - auto coor = builder.create<fir::CoordinateOp>( - loc, refTy, base, llvm::ArrayRef<mlir::Value>{total}); + auto coor = fir::CoordinateOp::create(builder, loc, refTy, base, + llvm::ArrayRef<mlir::Value>{total}); // Convert to expected, original type after address arithmetic. return builder.createConvert(loc, origRefTy, coor); }; @@ -1725,9 +1726,9 @@ public: builder.createConvert(loc, idxTy, fir::getBase(subVal))); } mlir::Value shape = builder.createShape(loc, exv); - mlir::Value elementAddr = builder.create<fir::ArrayCoorOp>( - loc, refTy, addr, shape, /*slice=*/mlir::Value{}, arrayCoorArgs, - fir::getTypeParams(exv)); + mlir::Value elementAddr = fir::ArrayCoorOp::create( + builder, loc, refTy, addr, shape, /*slice=*/mlir::Value{}, + arrayCoorArgs, fir::getTypeParams(exv)); return fir::factory::arrayElementToExtendedValue(builder, loc, exv, elementAddr); } @@ -1826,8 +1827,8 @@ public: if (mlir::isa<mlir::FunctionType>(exvTy)) { auto boxProcTy = builder.getBoxProcType(mlir::cast<mlir::FunctionType>(exvTy)); - return builder.create<fir::EmboxProcOp>(loc, boxProcTy, - fir::getBase(exv)); + return fir::EmboxProcOp::create(builder, loc, boxProcTy, + fir::getBase(exv)); } mlir::Value box = builder.createBox(loc, exv, exv.isPolymorphic()); if (Fortran::lower::isParentComponent(expr)) { @@ -2073,8 +2074,8 @@ public: TODO(loc, "creating temporary for derived type with length parameters"); } - mlir::Value temp = builder.create<fir::AllocMemOp>( - loc, type, tempName, allocMemTypeParams, extents); + mlir::Value temp = fir::AllocMemOp::create(builder, loc, type, tempName, + allocMemTypeParams, extents); if (mlir::isa<fir::CharacterType>(fir::unwrapSequenceType(type))) return fir::CharArrayBoxValue{temp, charLen, extents}; return fir::ArrayBoxValue{temp, extents}; @@ -2124,9 +2125,9 @@ public: mlir::Type type = v.getType(); mlir::Value value = v; if (fir::isa_ref_type(type)) - value = builder.create<fir::LoadOp>(loc, value); + value = fir::LoadOp::create(builder, loc, value); mlir::Value temp = builder.createTemporary(loc, value.getType()); - builder.create<fir::StoreOp>(loc, value, temp); + fir::StoreOp::create(builder, loc, value, temp); return temp; }, [&](const fir::BoxValue &x) -> ExtValue { @@ -2141,9 +2142,9 @@ public: // created always has the declared type. mlir::Value var = fir::getBase(fir::factory::readBoxValue(builder, loc, x)); - auto value = builder.create<fir::LoadOp>(loc, var); + auto value = fir::LoadOp::create(builder, loc, var); mlir::Value temp = builder.createTemporary(loc, value.getType()); - builder.create<fir::StoreOp>(loc, value, temp); + fir::StoreOp::create(builder, loc, value, temp); return temp; }, [&](const fir::PolymorphicValue &p) -> ExtValue { @@ -2242,7 +2243,7 @@ public: // at this point. mlir::Value destBox = fir::getBase(builder.createBox(loc, temp)); mlir::Value boxRef = builder.createTemporary(loc, destBox.getType()); - builder.create<fir::StoreOp>(loc, destBox, boxRef); + fir::StoreOp::create(builder, loc, destBox, boxRef); fir::runtime::genAssignTemporary(builder, loc, boxRef, fir::getBase(actualArg)); return temp; @@ -2250,21 +2251,22 @@ public: auto noCopy = [&]() { mlir::Value box = fir::getBase(actualArg); - mlir::Value boxAddr = builder.create<fir::BoxAddrOp>(loc, addrType, box); - builder.create<fir::ResultOp>(loc, boxAddr); + mlir::Value boxAddr = fir::BoxAddrOp::create(builder, loc, addrType, box); + fir::ResultOp::create(builder, loc, boxAddr); }; auto combinedCondition = [&]() { if (isActualArgBox) { mlir::Value zero = builder.createIntegerConstant(loc, builder.getI1Type(), 0); - mlir::Value notContiguous = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, isContiguousResult, zero); + mlir::Value notContiguous = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, isContiguousResult, + zero); if (!restrictCopyAtRuntime) { restrictCopyAtRuntime = notContiguous; } else { - mlir::Value cond = builder.create<mlir::arith::AndIOp>( - loc, *restrictCopyAtRuntime, notContiguous); + mlir::Value cond = mlir::arith::AndIOp::create( + builder, loc, *restrictCopyAtRuntime, notContiguous); restrictCopyAtRuntime = cond; } } @@ -2280,7 +2282,7 @@ public: .genThen([&]() { noCopy(); }) .genElse([&] { ExtValue temp = doCopyIn(); - builder.create<fir::ResultOp>(loc, fir::getBase(temp)); + fir::ResultOp::create(builder, loc, fir::getBase(temp)); }) .getResults()[0]; fir::ExtendedValue temp = @@ -2312,19 +2314,19 @@ public: .genThen([&]() { noCopy(); }) .genElse([&]() { ExtValue temp = doCopyIn(); - builder.create<fir::ResultOp>(loc, - fir::getBase(temp)); + fir::ResultOp::create(builder, loc, + fir::getBase(temp)); }) .getResults()[0]; - builder.create<fir::ResultOp>(loc, addr1); + fir::ResultOp::create(builder, loc, addr1); } else { ExtValue temp = doCopyIn(); - builder.create<fir::ResultOp>(loc, fir::getBase(temp)); + fir::ResultOp::create(builder, loc, fir::getBase(temp)); } }) .genElse([&]() { mlir::Value nullPtr = builder.createNullConstant(loc, addrType); - builder.create<fir::ResultOp>(loc, nullPtr); + fir::ResultOp::create(builder, loc, nullPtr); }) .getResults()[0]; // Associate the temp address with actualArg lengths and extents if a @@ -2357,7 +2359,7 @@ public: tempBox); } // Deallocate the top-level entity of the temporary. - builder.create<fir::FreeMemOp>(loc, fir::getBase(copyOutPair.temp)); + fir::FreeMemOp::create(builder, loc, fir::getBase(copyOutPair.temp)); return; } // Generate CopyOutAssign() call to copy data from the temporary @@ -2376,11 +2378,11 @@ public: mlir::Type allocBoxTy = mlir::cast<fir::BaseBoxType>(srcBox.getType()) .getBoxTypeWithNewAttr(fir::BaseBoxType::Attribute::Allocatable); - srcBox = builder.create<fir::ReboxOp>(loc, allocBoxTy, srcBox, - /*shift=*/mlir::Value{}, - /*slice=*/mlir::Value{}); + srcBox = fir::ReboxOp::create(builder, loc, allocBoxTy, srcBox, + /*shift=*/mlir::Value{}, + /*slice=*/mlir::Value{}); mlir::Value srcBoxRef = builder.createTemporary(loc, srcBox.getType()); - builder.create<fir::StoreOp>(loc, srcBox, srcBoxRef); + fir::StoreOp::create(builder, loc, srcBox, srcBoxRef); // Create descriptor pointer to variable descriptor if copy out is needed, // and nullptr otherwise. mlir::Value destBoxRef; @@ -2388,9 +2390,9 @@ public: mlir::Value destBox = fir::getBase(builder.createBox(loc, copyOutPair.var)); destBoxRef = builder.createTemporary(loc, destBox.getType()); - builder.create<fir::StoreOp>(loc, destBox, destBoxRef); + fir::StoreOp::create(builder, loc, destBox, destBoxRef); } else { - destBoxRef = builder.create<fir::ZeroOp>(loc, srcBoxRef.getType()); + destBoxRef = fir::ZeroOp::create(builder, loc, srcBoxRef.getType()); } fir::runtime::genCopyOutAssign(builder, loc, destBoxRef, srcBoxRef); }; @@ -2436,8 +2438,8 @@ public: // fir.box is absent. ExtValue actualArg = gen(expr); mlir::Value actualArgBase = fir::getBase(actualArg); - mlir::Value isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), actualArgBase); + mlir::Value isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), actualArgBase); if (!mlir::isa<fir::BoxType>(actualArgBase.getType())) return {actualArg, isPresent}; ExtValue safeToReadBox = @@ -2457,7 +2459,7 @@ public: if (const fir::CharBoxValue *charBox = actualArg.getCharBox()) { mlir::Value len = charBox->getLen(); mlir::Value zero = builder.createIntegerConstant(loc, len.getType(), 0); - len = builder.create<mlir::arith::SelectOp>(loc, isPresent, len, zero); + len = mlir::arith::SelectOp::create(builder, loc, isPresent, len, zero); mlir::Value temp = builder.createTemporary(loc, type, /*name=*/{}, /*shape=*/{}, mlir::ValueRange{len}, @@ -2538,12 +2540,12 @@ public: .genThen([&]() { fir::factory::genScalarAssignment(builder, loc, temp, actualArg); - builder.create<fir::ResultOp>(loc, fir::getBase(temp)); + fir::ResultOp::create(builder, loc, fir::getBase(temp)); }) .genElse([&]() { mlir::Value absent = - builder.create<fir::AbsentOp>(loc, tempAddrTy); - builder.create<fir::ResultOp>(loc, absent); + fir::AbsentOp::create(builder, loc, tempAddrTy); + fir::ResultOp::create(builder, loc, absent); }) .getResults()[0]; return {fir::substBase(temp, selectAddr), isPresent}; @@ -2647,7 +2649,7 @@ public: mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( builder, loc, boxTy, /*nonDeferredParams=*/{}); - builder.create<fir::StoreOp>(loc, nullBox, boxStorage); + fir::StoreOp::create(builder, loc, nullBox, boxStorage); caller.placeInput(arg, boxStorage); continue; } @@ -2706,9 +2708,10 @@ public: mlir::cast<fir::BoxCharType>(funcTy.getResult(0)); mlir::Value ref = builder.createConvertWithVolatileCast( loc, builder.getRefType(boxTy.getEleTy()), x.getAddr()); - auto len = builder.create<fir::UndefOp>( - loc, builder.getCharacterLengthType()); - return builder.create<fir::EmboxCharOp>(loc, boxTy, ref, len); + auto len = fir::UndefOp::create( + builder, loc, builder.getCharacterLengthType()); + return fir::EmboxCharOp::create(builder, loc, boxTy, ref, + len); } return helper.createEmbox(x); }, @@ -2758,10 +2761,10 @@ public: mlir::Value box = builder.createBox(loc, argAddr); if (isPresentValue) { mlir::Value convertedBox = builder.createConvert(loc, argTy, box); - auto absent = builder.create<fir::AbsentOp>(loc, argTy); - caller.placeInput(arg, - builder.create<mlir::arith::SelectOp>( - loc, *isPresentValue, convertedBox, absent)); + auto absent = fir::AbsentOp::create(builder, loc, argTy); + caller.placeInput( + arg, mlir::arith::SelectOp::create( + builder, loc, *isPresentValue, convertedBox, absent)); } else { caller.placeInput(arg, builder.createBox(loc, argAddr)); } @@ -2782,7 +2785,7 @@ public: mlir::Value isAllocated = fir::factory::genIsAllocatedOrAssociatedTest(builder, loc, mutableBox); - auto absent = builder.create<fir::AbsentOp>(loc, argTy); + auto absent = fir::AbsentOp::create(builder, loc, argTy); /// For now, assume it is not OK to pass the allocatable/pointer /// descriptor to a non pointer/allocatable dummy. That is a strict /// interpretation of 18.3.6 point 4 that stipulates the descriptor @@ -2801,14 +2804,15 @@ public: box); } else if (mlir::isa<fir::BoxType>(box.getType()) && fir::isPolymorphicType(argTy)) { - box = builder.create<fir::ReboxOp>(loc, argTy, box, mlir::Value{}, - /*slice=*/mlir::Value{}); + box = fir::ReboxOp::create(builder, loc, argTy, box, mlir::Value{}, + /*slice=*/mlir::Value{}); } // Need the box types to be exactly similar for the selectOp. mlir::Value convertedBox = builder.createConvert(loc, argTy, box); - caller.placeInput(arg, builder.create<mlir::arith::SelectOp>( - loc, isAllocated, convertedBox, absent)); + caller.placeInput( + arg, mlir::arith::SelectOp::create(builder, loc, isAllocated, + convertedBox, absent)); } else { auto dynamicType = expr->GetType(); mlir::Value box; @@ -2830,12 +2834,12 @@ public: .genThen([&]() { auto boxed = builder.createBox( loc, genBoxArg(*expr), fir::isPolymorphicType(argTy)); - builder.create<fir::ResultOp>(loc, boxed); + fir::ResultOp::create(builder, loc, boxed); }) .genElse([&]() { - auto absent = - builder.create<fir::AbsentOp>(loc, argTy).getResult(); - builder.create<fir::ResultOp>(loc, absent); + auto absent = fir::AbsentOp::create(builder, loc, argTy) + .getResult(); + fir::ResultOp::create(builder, loc, absent); }) .getResults()[0]; } else { @@ -2867,19 +2871,19 @@ public: loc, actualTy, box, mlir::Value{}, /*slice=*/mlir::Value{}) .getResult(); - builder.create<fir::ResultOp>(loc, rebox); + fir::ResultOp::create(builder, loc, rebox); }) .genElse([&]() { auto absent = - builder.create<fir::AbsentOp>(loc, actualTy) + fir::AbsentOp::create(builder, loc, actualTy) .getResult(); - builder.create<fir::ResultOp>(loc, absent); + fir::ResultOp::create(builder, loc, absent); }) .getResults()[0]; } else { - box = builder.create<fir::ReboxOp>(loc, actualTy, box, - mlir::Value{}, - /*slice=*/mlir::Value{}); + box = fir::ReboxOp::create(builder, loc, actualTy, box, + mlir::Value{}, + /*slice=*/mlir::Value{}); } } else if (Fortran::lower::isParentComponent(*expr)) { fir::ExtendedValue newExv = @@ -3132,12 +3136,12 @@ static void genScalarUserDefinedAssignmentCall(fir::FirOpBuilder &builder, if (argBaseType != fir::unwrapRefType(from.getType())) { // With logicals, it is possible that from is i1 here. if (fir::isa_ref_type(from.getType())) - from = builder.create<fir::LoadOp>(loc, from); + from = fir::LoadOp::create(builder, loc, from); from = builder.createConvert(loc, argBaseType, from); } if (!fir::isa_ref_type(from.getType())) { mlir::Value temp = builder.createTemporary(loc, argBaseType); - builder.create<fir::StoreOp>(loc, from, temp); + fir::StoreOp::create(builder, loc, from, temp); from = temp; } return builder.createConvert(loc, argType, from); @@ -3147,7 +3151,7 @@ static void genScalarUserDefinedAssignmentCall(fir::FirOpBuilder &builder, mlir::Type rhsType = func.getFunctionType().getInput(1); mlir::Value lhsArg = prepareUserDefinedArg(builder, loc, lhs, lhsType); mlir::Value rhsArg = prepareUserDefinedArg(builder, loc, rhs, rhsType); - builder.create<fir::CallOp>(loc, func, mlir::ValueRange{lhsArg, rhsArg}); + fir::CallOp::create(builder, loc, func, mlir::ValueRange{lhsArg, rhsArg}); } /// Convert the result of a fir.array_modify to an ExtendedValue given the @@ -3187,17 +3191,17 @@ createDerivedArrayAmend(mlir::Location loc, fir::ArrayLoadOp destLoad, fir::factory::genRecordAssignment(builder, loc, destAcc, elementExv); } else { auto boxTy = fir::BoxType::get(eleTy); - auto toBox = builder.create<fir::EmboxOp>(loc, boxTy, destAcc.getResult(), - mlir::Value{}, mlir::Value{}, - destLoad.getTypeparams()); - auto fromBox = builder.create<fir::EmboxOp>( - loc, boxTy, fir::getBase(elementExv), mlir::Value{}, mlir::Value{}, - destLoad.getTypeparams()); + auto toBox = fir::EmboxOp::create(builder, loc, boxTy, destAcc.getResult(), + mlir::Value{}, mlir::Value{}, + destLoad.getTypeparams()); + auto fromBox = fir::EmboxOp::create( + builder, loc, boxTy, fir::getBase(elementExv), mlir::Value{}, + mlir::Value{}, destLoad.getTypeparams()); fir::factory::genRecordAssignment(builder, loc, fir::BoxValue(toBox), fir::BoxValue(fromBox)); } - return builder.create<fir::ArrayAmendOp>(loc, innerArg.getType(), innerArg, - destAcc); + return fir::ArrayAmendOp::create(builder, loc, innerArg.getType(), innerArg, + destAcc); } inline static fir::ArrayAmendOp @@ -3219,7 +3223,7 @@ createCharArrayAmend(mlir::Location loc, fir::FirOpBuilder &builder, helper.createAssign(fir::ExtendedValue{dstChar}, srcExv); // Mark this array element as amended. mlir::Type ty = innerArg.getType(); - auto amend = builder.create<fir::ArrayAmendOp>(loc, ty, innerArg, dstOp); + auto amend = fir::ArrayAmendOp::create(builder, loc, ty, innerArg, dstOp); return amend; } @@ -3235,7 +3239,7 @@ convertToArrayBoxValue(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type ty = fir::unwrapRefType(val.getType()); mlir::IndexType idxTy = builder.getIndexType(); auto seqTy = mlir::cast<fir::SequenceType>(ty); - auto undef = builder.create<fir::UndefOp>(loc, idxTy); + auto undef = fir::UndefOp::create(builder, loc, idxTy); llvm::SmallVector<mlir::Value> extents(seqTy.getDimension(), undef); if (fir::isa_char(seqTy.getEleTy())) return fir::CharArrayBoxValue(val, len ? len : undef, extents); @@ -3315,10 +3319,10 @@ public: ExtValue exv = lowerArrayExpression(rhs); if (explicitSpaceIsActive()) { explicitSpace->finalizeContext(); - builder.create<fir::ResultOp>(loc, fir::getBase(exv)); + fir::ResultOp::create(builder, loc, fir::getBase(exv)); } else { - builder.create<fir::ArrayMergeStoreOp>( - loc, destination, fir::getBase(exv), destination.getMemref(), + fir::ArrayMergeStoreOp::create( + builder, loc, destination, fir::getBase(exv), destination.getMemref(), destination.getSlice(), destination.getTypeparams()); } } @@ -3432,8 +3436,8 @@ public: assert(destination && "destination must have been set"); ExtValue exv = lowerArrayExpression(rhsCC, destination.getType()); if (!explicitSpaceIsActive()) - builder.create<fir::ArrayMergeStoreOp>( - loc, destination, fir::getBase(exv), destination.getMemref(), + fir::ArrayMergeStoreOp::create( + builder, loc, destination, fir::getBase(exv), destination.getMemref(), destination.getSlice(), destination.getTypeparams()); // destShape may originally be null, if rhs did not define a shape. // In this case the destShape is computed from lhs, and we may have @@ -3502,7 +3506,7 @@ public: lengthParams, assignToStorage); if (explicitSpaceIsActive()) { explicitSpace->finalizeContext(); - builder.create<fir::ResultOp>(loc, fir::getBase(realloc.newValue)); + fir::ResultOp::create(builder, loc, fir::getBase(realloc.newValue)); } fir::factory::finalizeRealloc(builder, loc, mutableBox, lbounds, takeLboundsIfRealloc, realloc); @@ -3547,9 +3551,9 @@ public: mlir::Value tempRes = dest.getMemref(); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Location loc = converter.getCurrentLocation(); - builder.create<fir::ArrayMergeStoreOp>(loc, dest, fir::getBase(loopRes), - tempRes, dest.getSlice(), - dest.getTypeparams()); + fir::ArrayMergeStoreOp::create(builder, loc, dest, fir::getBase(loopRes), + tempRes, dest.getSlice(), + dest.getTypeparams()); auto arrTy = mlir::cast<fir::SequenceType>( fir::dyn_cast_ptrEleTy(tempRes.getType())); @@ -3595,25 +3599,26 @@ public: // as there isn't any necessity for it. ccLoadDest = [=](llvm::ArrayRef<mlir::Value> shape) -> fir::ArrayLoadOp { mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - auto var = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(hdrTy.getType(1)), header, one); - auto load = builder.create<fir::LoadOp>(loc, var); + auto var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(hdrTy.getType(1)), header, one); + auto load = fir::LoadOp::create(builder, loc, var); mlir::Type eleTy = fir::unwrapSequenceType(fir::unwrapRefType(load.getType())); auto seqTy = fir::SequenceType::get(eleTy, shape.size()); mlir::Value castTo = builder.createConvert(loc, fir::HeapType::get(seqTy), load); mlir::Value shapeOp = builder.genShape(loc, shape); - return builder.create<fir::ArrayLoadOp>( - loc, seqTy, castTo, shapeOp, /*slice=*/mlir::Value{}, std::nullopt); + return fir::ArrayLoadOp::create(builder, loc, seqTy, castTo, shapeOp, + /*slice=*/mlir::Value{}, + mlir::ValueRange{}); }; // Custom lowering of the element store to deal with the extra indirection // to the lazy allocated buffer. ccStoreToDest = [=](IterSpace iters) { mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - auto var = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(hdrTy.getType(1)), header, one); - auto load = builder.create<fir::LoadOp>(loc, var); + auto var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(hdrTy.getType(1)), header, one); + auto load = fir::LoadOp::create(builder, loc, var); mlir::Type eleTy = fir::unwrapSequenceType(fir::unwrapRefType(load.getType())); auto seqTy = fir::SequenceType::get(eleTy, iters.iterVec().size()); @@ -3622,12 +3627,12 @@ public: mlir::Value shape = builder.genShape(loc, genIterationShape()); llvm::SmallVector<mlir::Value> indices = fir::factory::originateIndices( loc, builder, castTo.getType(), shape, iters.iterVec()); - auto eleAddr = builder.create<fir::ArrayCoorOp>( - loc, builder.getRefType(eleTy), castTo, shape, + auto eleAddr = fir::ArrayCoorOp::create( + builder, loc, builder.getRefType(eleTy), castTo, shape, /*slice=*/mlir::Value{}, indices, destination.getTypeparams()); mlir::Value eleVal = builder.createConvert(loc, eleTy, iters.getElement()); - builder.create<fir::StoreOp>(loc, eleVal, eleAddr); + fir::StoreOp::create(builder, loc, eleVal, eleAddr); return iters.innerArgument(); }; @@ -3683,10 +3688,10 @@ public: auto exv = lowerArrayExpression(rhs); if (explicitSpaceIsActive()) { explicitSpace->finalizeContext(); - builder.create<fir::ResultOp>(loc, fir::getBase(exv)); + fir::ResultOp::create(builder, loc, fir::getBase(exv)); } else { - builder.create<fir::ArrayMergeStoreOp>( - loc, destination, fir::getBase(exv), destination.getMemref(), + fir::ArrayMergeStoreOp::create( + builder, loc, destination, fir::getBase(exv), destination.getMemref(), destination.getSlice(), destination.getTypeparams()); } } @@ -3765,7 +3770,7 @@ public: std::size_t offset = explicitSpace->argPosition(oldInnerArg); explicitSpace->setInnerArg(offset, fir::getBase(lexv)); finalizeElementCtx(); - builder.create<fir::ResultOp>(loc, fir::getBase(lexv)); + fir::ResultOp::create(builder, loc, fir::getBase(lexv)); }; if (mlir::Operation *defOp = fir::getBase(lexv).getDefiningOp()) { llvm::TypeSwitch<mlir::Operation *>(defOp) @@ -3835,7 +3840,7 @@ public: // 5). Thread the array value updated forward. if (!isIllFormedLHS) { finalizeElementCtx(); - builder.create<fir::ResultOp>(getLoc(), fir::getBase(lexv)); + fir::ResultOp::create(builder, getLoc(), fir::getBase(lexv)); } return lexv; } @@ -3978,7 +3983,7 @@ private: if (auto origEleTy = fir::dyn_cast_ptrEleTy(origVal.getType())) if (mlir::isa<fir::BaseBoxType>(origEleTy)) { // If origVal is a box variable, load it so it is in the value domain. - origVal = builder.create<fir::LoadOp>(loc, origVal); + origVal = fir::LoadOp::create(builder, loc, origVal); } if (mlir::isa<fir::BoxType>(origVal.getType()) && !mlir::isa<fir::BoxType>(eleTy)) { @@ -3997,7 +4002,7 @@ private: TODO(loc, "TARGET of pointer assignment with runtime size/shape"); auto memrefTy = fir::boxMemRefType(mlir::cast<fir::BoxType>(eleTy)); auto castTo = builder.createConvert(loc, memrefTy, origVal); - origVal = builder.create<fir::EmboxOp>(loc, eleTy, castTo); + origVal = fir::EmboxOp::create(builder, loc, eleTy, castTo); } mlir::Value val = builder.convertWithSemantics(loc, eleTy, origVal); if (isBoundsSpec()) { @@ -4006,9 +4011,9 @@ private: if (lbs.size() > 0) { // Rebox the value with user-specified shift. auto shiftTy = fir::ShiftType::get(eleTy.getContext(), lbs.size()); - mlir::Value shiftOp = builder.create<fir::ShiftOp>(loc, shiftTy, lbs); - val = builder.create<fir::ReboxOp>(loc, eleTy, val, shiftOp, - mlir::Value{}); + mlir::Value shiftOp = fir::ShiftOp::create(builder, loc, shiftTy, lbs); + val = fir::ReboxOp::create(builder, loc, eleTy, val, shiftOp, + mlir::Value{}); } } else if (isBoundsRemap()) { assert(lbounds.has_value()); @@ -4019,9 +4024,9 @@ private: auto shapeShiftArgs = flatZip(lbs, *ubounds); auto shapeTy = fir::ShapeShiftType::get(eleTy.getContext(), lbs.size()); mlir::Value shapeShift = - builder.create<fir::ShapeShiftOp>(loc, shapeTy, shapeShiftArgs); - val = builder.create<fir::ReboxOp>(loc, eleTy, val, shapeShift, - mlir::Value{}); + fir::ShapeShiftOp::create(builder, loc, shapeTy, shapeShiftArgs); + val = fir::ReboxOp::create(builder, loc, eleTy, val, shapeShift, + mlir::Value{}); } } return val; @@ -4044,8 +4049,8 @@ private: // memory into the destination array. mlir::Type resRefTy = builder.getRefType(eleTy); // Get a reference to the array element to be amended. - auto arrayOp = builder.create<fir::ArrayAccessOp>( - loc, resRefTy, innerArg, iterSpace.iterVec(), + auto arrayOp = fir::ArrayAccessOp::create( + builder, loc, resRefTy, innerArg, iterSpace.iterVec(), fir::factory::getTypeParams(loc, builder, destination)); if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { llvm::SmallVector<mlir::Value> substringBounds; @@ -4066,9 +4071,9 @@ private: } // By value semantics. The element is being assigned by value. auto ele = convertElementForUpdate(loc, eleTy, fir::getBase(exv)); - auto update = builder.create<fir::ArrayUpdateOp>( - loc, arrTy, innerArg, ele, iterSpace.iterVec(), - destination.getTypeparams()); + auto update = fir::ArrayUpdateOp::create(builder, loc, arrTy, innerArg, + ele, iterSpace.iterVec(), + destination.getTypeparams()); return abstractArrayExtValue(update); }; } @@ -4093,7 +4098,7 @@ private: : defaultStoreToDestination(/*substring=*/nullptr); mlir::Value updVal = fir::getBase(lambda(iterSpace)); finalizeElementCtx(); - builder.create<fir::ResultOp>(loc, updVal); + fir::ResultOp::create(builder, loc, updVal); builder.restoreInsertionPoint(insPt); return abstractArrayExtValue(iterSpace.outerResult()); } @@ -4207,7 +4212,7 @@ private: auto addr = builder->create<fir::ArrayCoorOp>(loc, eleRefTy, tmp, shape, /*slice=*/mlir::Value{}, indices, - /*typeParams=*/std::nullopt); + /*typeParams=*/mlir::ValueRange{}); auto load = builder->create<fir::LoadOp>(loc, addr); return builder->createConvert(loc, i1Ty, load); }; @@ -4246,31 +4251,34 @@ private: // Compute the dynamic position into the header. llvm::SmallVector<mlir::Value> offsets; for (auto doLoop : loopStack[i]) { - auto m = builder.create<mlir::arith::SubIOp>( - loc, doLoop.getInductionVar(), doLoop.getLowerBound()); - auto n = builder.create<mlir::arith::DivSIOp>(loc, m, doLoop.getStep()); + auto m = mlir::arith::SubIOp::create( + builder, loc, doLoop.getInductionVar(), doLoop.getLowerBound()); + auto n = + mlir::arith::DivSIOp::create(builder, loc, m, doLoop.getStep()); mlir::Value one = builder.createIntegerConstant(loc, n.getType(), 1); - offsets.push_back(builder.create<mlir::arith::AddIOp>(loc, n, one)); + offsets.push_back(mlir::arith::AddIOp::create(builder, loc, n, one)); } mlir::IntegerType i32Ty = builder.getIntegerType(32); mlir::Value uno = builder.createIntegerConstant(loc, i32Ty, 1); mlir::Type coorTy = builder.getRefType(raggedTy.getType(1)); - auto hdOff = builder.create<fir::CoordinateOp>(loc, coorTy, header, uno); + auto hdOff = fir::CoordinateOp::create(builder, loc, coorTy, header, uno); auto toTy = fir::SequenceType::get(raggedTy, offsets.size()); mlir::Type toRefTy = builder.getRefType(toTy); - auto ldHdr = builder.create<fir::LoadOp>(loc, hdOff); + auto ldHdr = fir::LoadOp::create(builder, loc, hdOff); mlir::Value hdArr = builder.createConvert(loc, toRefTy, ldHdr); auto shapeOp = builder.genShape(loc, extents); - header = builder.create<fir::ArrayCoorOp>( - loc, builder.getRefType(raggedTy), hdArr, shapeOp, + header = fir::ArrayCoorOp::create( + builder, loc, builder.getRefType(raggedTy), hdArr, shapeOp, /*slice=*/mlir::Value{}, offsets, /*typeparams=*/mlir::ValueRange{}); - auto hdrVar = builder.create<fir::CoordinateOp>(loc, coorTy, header, uno); - auto inVar = builder.create<fir::LoadOp>(loc, hdrVar); + auto hdrVar = + fir::CoordinateOp::create(builder, loc, coorTy, header, uno); + auto inVar = fir::LoadOp::create(builder, loc, hdrVar); mlir::Value two = builder.createIntegerConstant(loc, i32Ty, 2); mlir::Type coorTy2 = builder.getRefType(raggedTy.getType(2)); - auto hdrSh = builder.create<fir::CoordinateOp>(loc, coorTy2, header, two); - auto shapePtr = builder.create<fir::LoadOp>(loc, hdrSh); + auto hdrSh = + fir::CoordinateOp::create(builder, loc, coorTy2, header, two); + auto shapePtr = fir::LoadOp::create(builder, loc, hdrSh); // Replace the binding. implicitSpace->rebind(expr, genMaskAccess(inVar, shapePtr)); if (i < depth - 1) @@ -4300,7 +4308,7 @@ private: Fortran::lower::createLazyArrayTempValue(converter, *e, header, symMap, stmtCtx); // Close the explicit loops. - builder.create<fir::ResultOp>(loc, explicitSpace->getInnerArgs()); + fir::ResultOp::create(builder, loc, explicitSpace->getInnerArgs()); builder.setInsertionPointAfter(explicitSpace->getOuterLoop()); // Open a new copy of the explicit loop nest. explicitSpace->genLoopNest(); @@ -4326,9 +4334,10 @@ private: fir::factory::getRaggedArrayHeaderType(builder); mlir::IntegerType i32Ty = builder.getIntegerType(32); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - auto coor1 = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(raggedTy.getType(1)), header, one); - auto db = builder.create<fir::LoadOp>(loc, coor1); + auto coor1 = fir::CoordinateOp::create( + builder, loc, builder.getRefType(raggedTy.getType(1)), header, + one); + auto db = fir::LoadOp::create(builder, loc, coor1); mlir::Type eleTy = fir::unwrapSequenceType(fir::unwrapRefType(db.getType())); mlir::Type buffTy = @@ -4337,17 +4346,18 @@ private: mlir::Value buff = builder.createConvert(loc, buffTy, db); mlir::Value two = builder.createIntegerConstant(loc, i32Ty, 2); - auto coor2 = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(raggedTy.getType(2)), header, two); - auto shBuff = builder.create<fir::LoadOp>(loc, coor2); + auto coor2 = fir::CoordinateOp::create( + builder, loc, builder.getRefType(raggedTy.getType(2)), header, + two); + auto shBuff = fir::LoadOp::create(builder, loc, coor2); mlir::IntegerType i64Ty = builder.getIntegerType(64); mlir::IndexType idxTy = builder.getIndexType(); llvm::SmallVector<mlir::Value> extents; for (std::remove_const_t<decltype(rank)> i = 0; i < rank; ++i) { mlir::Value off = builder.createIntegerConstant(loc, i32Ty, i); - auto coor = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(i64Ty), shBuff, off); - auto ldExt = builder.create<fir::LoadOp>(loc, coor); + auto coor = fir::CoordinateOp::create( + builder, loc, builder.getRefType(i64Ty), shBuff, off); + auto ldExt = fir::LoadOp::create(builder, loc, coor); extents.push_back(builder.createConvert(loc, idxTy, ldExt)); } if (destShape.empty()) @@ -4375,7 +4385,7 @@ private: // run from 0 to `extent - 1` inclusive. for (auto extent : shape) loopUppers.push_back( - builder.create<mlir::arith::SubIOp>(loc, extent, one)); + mlir::arith::SubIOp::create(builder, loc, extent, one)); // Iteration space is created with outermost columns, innermost rows llvm::SmallVector<fir::DoLoopOp> loops; @@ -4390,16 +4400,16 @@ private: } fir::DoLoopOp loop; if (innerArg) { - loop = builder.create<fir::DoLoopOp>( - loc, zero, i.value(), one, isUnordered(), + loop = fir::DoLoopOp::create( + builder, loc, zero, i.value(), one, isUnordered(), /*finalCount=*/false, mlir::ValueRange{innerArg}); innerArg = loop.getRegionIterArgs().front(); if (explicitSpaceIsActive()) explicitSpace->setInnerArg(0, innerArg); } else { - loop = builder.create<fir::DoLoopOp>(loc, zero, i.value(), one, - isUnordered(), - /*finalCount=*/false); + loop = fir::DoLoopOp::create(builder, loc, zero, i.value(), one, + isUnordered(), + /*finalCount=*/false); } ivars.push_back(loop.getInductionVar()); loops.push_back(loop); @@ -4409,7 +4419,7 @@ private: for (std::remove_const_t<decltype(loopDepth)> i = 0; i + 1 < loopDepth; ++i) { builder.setInsertionPointToEnd(loops[i].getBody()); - builder.create<fir::ResultOp>(loc, loops[i + 1].getResult(0)); + fir::ResultOp::create(builder, loc, loops[i + 1].getResult(0)); } // Move insertion point to the start of the innermost loop in the nest. @@ -4467,21 +4477,23 @@ private: implicitSpace->getMasks()) { const std::size_t size = maskExprs.size() - 1; auto genFalseBlock = [&](const auto *e, auto &&cond) { - auto ifOp = builder.create<fir::IfOp>( - loc, mlir::TypeRange{innerArg.getType()}, fir::getBase(cond), - /*withElseRegion=*/true); - builder.create<fir::ResultOp>(loc, ifOp.getResult(0)); + auto ifOp = fir::IfOp::create(builder, loc, + mlir::TypeRange{innerArg.getType()}, + fir::getBase(cond), + /*withElseRegion=*/true); + fir::ResultOp::create(builder, loc, ifOp.getResult(0)); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, innerArg); + fir::ResultOp::create(builder, loc, innerArg); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); }; auto genTrueBlock = [&](const auto *e, auto &&cond) { - auto ifOp = builder.create<fir::IfOp>( - loc, mlir::TypeRange{innerArg.getType()}, fir::getBase(cond), - /*withElseRegion=*/true); - builder.create<fir::ResultOp>(loc, ifOp.getResult(0)); + auto ifOp = fir::IfOp::create(builder, loc, + mlir::TypeRange{innerArg.getType()}, + fir::getBase(cond), + /*withElseRegion=*/true); + fir::ResultOp::create(builder, loc, ifOp.getResult(0)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, innerArg); + fir::ResultOp::create(builder, loc, innerArg); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); }; for (std::remove_const_t<decltype(size)> i = 0; i < size; ++i) @@ -4522,17 +4534,18 @@ private: fir::isRecordWithAllocatableMember(eleTy)) TODO(loc, "creating an array temp where the element type has " "allocatable members"); - mlir::Value temp = !seqTy.hasDynamicExtents() - ? builder.create<fir::AllocMemOp>(loc, type) - : builder.create<fir::AllocMemOp>( - loc, type, ".array.expr", std::nullopt, shape); + mlir::Value temp = + !seqTy.hasDynamicExtents() + ? fir::AllocMemOp::create(builder, loc, type) + : fir::AllocMemOp::create(builder, loc, type, ".array.expr", + mlir::ValueRange{}, shape); fir::FirOpBuilder *bldr = &converter.getFirOpBuilder(); stmtCtx.attachCleanup( [bldr, loc, temp]() { bldr->create<fir::FreeMemOp>(loc, temp); }); mlir::Value shapeOp = genShapeOp(shape); - return builder.create<fir::ArrayLoadOp>(loc, seqTy, temp, shapeOp, - /*slice=*/mlir::Value{}, - std::nullopt); + return fir::ArrayLoadOp::create(builder, loc, seqTy, temp, shapeOp, + /*slice=*/mlir::Value{}, + mlir::ValueRange{}); } static fir::ShapeOp genShapeOp(mlir::Location loc, fir::FirOpBuilder &builder, @@ -4541,7 +4554,7 @@ private: llvm::SmallVector<mlir::Value> idxShape; for (auto s : shape) idxShape.push_back(builder.createConvert(loc, idxTy, s)); - return builder.create<fir::ShapeOp>(loc, idxShape); + return fir::ShapeOp::create(builder, loc, idxShape); } fir::ShapeOp genShapeOp(llvm::ArrayRef<mlir::Value> shape) { @@ -4789,7 +4802,7 @@ private: mlir::Type argTy = callSiteType.getInput(arg.firArgument); if (!actual) { // Optional dummy argument for which there is no actual argument. - auto absent = builder.create<fir::AbsentOp>(loc, argTy); + auto absent = fir::AbsentOp::create(builder, loc, argTy); operands.emplace_back([=](IterSpace) { return absent; }); continue; } @@ -4822,7 +4835,7 @@ private: builder.createTemporary(loc, val.getType(), llvm::ArrayRef<mlir::NamedAttribute>{ fir::getAdaptToByRefAttr(builder)}); - builder.create<fir::StoreOp>(loc, val, temp); + fir::StoreOp::create(builder, loc, val, temp); operands.emplace_back( [=](IterSpace iters) -> ExtValue { return temp; }); } @@ -4881,14 +4894,14 @@ private: fir::dyn_cast_ptrOrBoxEleTy(fir::getBase(exv).getType()); mlir::Type innerTy = fir::unwrapSequenceType(baseTy); operands.emplace_back([=](IterSpace iters) -> ExtValue { - mlir::Value coord = builder.create<fir::CoordinateOp>( - loc, fir::ReferenceType::get(innerTy), fir::getBase(exv), - iters.iterVec()); + mlir::Value coord = fir::CoordinateOp::create( + builder, loc, fir::ReferenceType::get(innerTy), + fir::getBase(exv), iters.iterVec()); mlir::Value empty; mlir::ValueRange emptyRange; - return builder.create<fir::EmboxOp>( - loc, fir::ClassType::get(innerTy), coord, empty, empty, - emptyRange, sourceBox); + return fir::EmboxOp::create(builder, loc, + fir::ClassType::get(innerTy), coord, + empty, empty, emptyRange, sourceBox); }); } else { ExtValue exv = asScalarRef(*expr); @@ -4901,9 +4914,9 @@ private: operands.emplace_back([=](IterSpace iters) -> ExtValue { mlir::Value empty; mlir::ValueRange emptyRange; - return builder.create<fir::EmboxOp>( - loc, fir::ClassType::get(baseTy), fir::getBase(exv), empty, - empty, emptyRange); + return fir::EmboxOp::create( + builder, loc, fir::ClassType::get(baseTy), + fir::getBase(exv), empty, empty, emptyRange); }); } } @@ -5095,8 +5108,8 @@ private: return exv.match( [&](const fir::CharBoxValue &cb) -> ExtValue { mlir::Value len = cb.getLen(); - auto mem = - builder.create<fir::AllocaOp>(loc, toType, mlir::ValueRange{len}); + auto mem = fir::AllocaOp::create(builder, loc, toType, + mlir::ValueRange{len}); fir::CharBoxValue result(mem, len); fir::factory::CharacterExprHelper{builder, loc}.createAssign( ExtValue{result}, exv); @@ -5151,7 +5164,7 @@ private: auto val = f(iters); mlir::Value base = fir::getBase(val); auto newBase = - builder.create<fir::NoReassocOp>(loc, base.getType(), base); + fir::NoReassocOp::create(builder, loc, base.getType(), base); return fir::substBase(val, newBase); }; } @@ -5168,10 +5181,10 @@ private: if constexpr (CAT == Fortran::common::TypeCategory::Unsigned) { mlir::Value signless = builder.createConvert(loc, ty, val); mlir::Value neg = - builder.create<mlir::arith::SubIOp>(loc, zero, signless); + mlir::arith::SubIOp::create(builder, loc, zero, signless); return builder.createConvert(loc, val.getType(), neg); } - return builder.create<mlir::arith::SubIOp>(loc, zero, val); + return mlir::arith::SubIOp::create(builder, loc, zero, val); }; } template <int KIND> @@ -5190,7 +5203,7 @@ private: mlir::Location loc = getLoc(); auto f = genarr(x.left()); return [=](IterSpace iters) -> ExtValue { - return builder.create<mlir::arith::NegFOp>(loc, fir::getBase(f(iters))); + return mlir::arith::NegFOp::create(builder, loc, fir::getBase(f(iters))); }; } template <int KIND> @@ -5199,7 +5212,7 @@ private: mlir::Location loc = getLoc(); auto f = genarr(x.left()); return [=](IterSpace iters) -> ExtValue { - return builder.create<fir::NegcOp>(loc, fir::getBase(f(iters))); + return fir::NegcOp::create(builder, loc, fir::getBase(f(iters))); }; } @@ -5424,8 +5437,8 @@ private: mlir::Location loc = getLoc(); mlir::Value lb = getLBound(x, dim, one); mlir::Value extent = fir::factory::readExtent(builder, loc, x, dim); - auto add = builder.create<mlir::arith::AddIOp>(loc, lb, extent); - return builder.create<mlir::arith::SubIOp>(loc, add, one); + auto add = mlir::arith::AddIOp::create(builder, loc, lb, extent); + return mlir::arith::SubIOp::create(builder, loc, add, one); } /// Return the extent of the boxed array `x` in dimesion `dim`. @@ -5467,11 +5480,11 @@ private: if (destShape[0] != savedDestShape[dim]) { // Not the same, so choose the smaller value. mlir::Location loc = getLoc(); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, destShape[0], - savedDestShape[dim]); - auto sel = builder.create<mlir::arith::SelectOp>( - loc, cmp, savedDestShape[dim], destShape[0]); + auto cmp = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::sgt, + destShape[0], savedDestShape[dim]); + auto sel = mlir::arith::SelectOp::create( + builder, loc, cmp, savedDestShape[dim], destShape[0]); savedDestShape[dim] = sel; destShape = savedDestShape; } @@ -5547,12 +5560,12 @@ private: // FIXME: must use the lower bound of this component. auto arrLowerBound = atBase ? getLBound(arrayExv, subsIndex, one) : one; - auto initial = builder.create<mlir::arith::SubIOp>( - loc, lowerBound, arrLowerBound); - auto prod = builder.create<mlir::arith::MulIOp>( - loc, impliedIter, stride); - auto result = - builder.create<mlir::arith::AddIOp>(loc, initial, prod); + auto initial = mlir::arith::SubIOp::create( + builder, loc, lowerBound, arrLowerBound); + auto prod = mlir::arith::MulIOp::create( + builder, loc, impliedIter, stride); + auto result = mlir::arith::AddIOp::create(builder, loc, + initial, prod); newIters.setIndexValue(subsIndex, result); return newIters; }; @@ -5586,15 +5599,15 @@ private: // using the base array's lower bound value. mlir::Value lb = fir::factory::readLowerBound( builder, loc, arrayExv, subsIndex, one); - auto origin = builder.create<mlir::arith::SubIOp>( - loc, idxTy, val, lb); + auto origin = mlir::arith::SubIOp::create(builder, loc, + idxTy, val, lb); newIters.setIndexValue(subsIndex, origin); return newIters; }; if (useTripsForSlice) { LLVM_ATTRIBUTE_UNUSED auto vectorSubscriptShape = getShape(arrayOperands.back()); - auto undef = builder.create<fir::UndefOp>(loc, idxTy); + auto undef = fir::UndefOp::create(builder, loc, idxTy); trips.push_back(undef); trips.push_back(undef); trips.push_back(undef); @@ -5612,7 +5625,7 @@ private: // the array's declared rank. mlir::Value v = fir::getBase(asScalarArray(e)); trips.push_back(v); - auto undef = builder.create<fir::UndefOp>(loc, idxTy); + auto undef = fir::UndefOp::create(builder, loc, idxTy); trips.push_back(undef); trips.push_back(undef); auto currentPC = pc; @@ -5621,8 +5634,8 @@ private: // Normalize `e` by subtracting the declared lbound. mlir::Value lb = fir::factory::readLowerBound( builder, loc, arrayExv, subsIndex, one); - mlir::Value ivAdj = - builder.create<mlir::arith::SubIOp>(loc, idxTy, iv, lb); + mlir::Value ivAdj = mlir::arith::SubIOp::create( + builder, loc, idxTy, iv, lb); // Add lbound adjusted value of `e` to the iteration vector // (except when creating a box because the iteration vector // is empty). @@ -5639,8 +5652,8 @@ private: builder.createConvert(loc, idxTy, newValue); mlir::Value lb = fir::factory::readLowerBound( builder, loc, arrayExv, subsIndex, one); - result = builder.create<mlir::arith::SubIOp>(loc, idxTy, - result, lb); + result = mlir::arith::SubIOp::create(builder, loc, idxTy, + result, lb); pc = [=](IterSpace iters) { IterationSpace newIters = currentPC(iters); newIters.insertIndexValue(subsIndex, result); @@ -5669,7 +5682,7 @@ private: auto seqType = mlir::cast<fir::SequenceType>(ty); for (auto extent : seqType.getShape()) { auto v = extent == fir::SequenceType::getUnknownExtent() - ? builder.create<fir::UndefOp>(loc, idxTy).getResult() + ? fir::UndefOp::create(builder, loc, idxTy).getResult() : builder.createIntegerConstant(loc, idxTy, extent); result.push_back(v); } @@ -5762,20 +5775,20 @@ private: mlir::Value one = builder.createIntegerConstant(loc, substringBounds[0].getType(), 1); substringBounds[0] = - builder.create<mlir::arith::SubIOp>(loc, substringBounds[0], one); + mlir::arith::SubIOp::create(builder, loc, substringBounds[0], one); // Convert the upper bound to a length. mlir::Value cast = builder.createConvert(loc, iTy, substringBounds[1]); mlir::Value zero = builder.createIntegerConstant(loc, iTy, 0); auto size = - builder.create<mlir::arith::SubIOp>(loc, cast, substringBounds[0]); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, size, zero); + mlir::arith::SubIOp::create(builder, loc, cast, substringBounds[0]); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, size, zero); // size = MAX(upper - (lower - 1), 0) substringBounds[1] = - builder.create<mlir::arith::SelectOp>(loc, cmp, size, zero); - slice = builder.create<fir::SliceOp>( - loc, padSlice(components.trips, shape), components.suffixComponents, - substringBounds); + mlir::arith::SelectOp::create(builder, loc, cmp, size, zero); + slice = fir::SliceOp::create( + builder, loc, padSlice(components.trips, shape), + components.suffixComponents, substringBounds); } else { slice = builder.createSlice(loc, extMemref, components.trips, components.suffixComponents); @@ -5825,7 +5838,7 @@ private: } mlir::Value embox = mlir::isa<fir::BaseBoxType>(memref.getType()) - ? builder.create<fir::ReboxOp>(loc, boxTy, memref, shape, slice) + ? fir::ReboxOp::create(builder, loc, boxTy, memref, shape, slice) .getResult() : builder .create<fir::EmboxOp>(loc, boxTy, memref, shape, slice, @@ -5847,8 +5860,8 @@ private: // ArrayCoorOp does not expect zero based indices. llvm::SmallVector<mlir::Value> indices = fir::factory::originateIndices( loc, builder, memref.getType(), shape, iters.iterVec()); - mlir::Value coor = builder.create<fir::ArrayCoorOp>( - loc, refEleTy, memref, shape, slice, indices, + mlir::Value coor = fir::ArrayCoorOp::create( + builder, loc, refEleTy, memref, shape, slice, indices, fir::getTypeParams(extMemref)); if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { llvm::SmallVector<mlir::Value> substringBounds; @@ -5867,16 +5880,17 @@ private: builder, loc, extMemref, coor, slice); }; } - auto arrLoad = builder.create<fir::ArrayLoadOp>( - loc, arrTy, memref, shape, slice, fir::getTypeParams(extMemref)); + auto arrLoad = + fir::ArrayLoadOp::create(builder, loc, arrTy, memref, shape, slice, + fir::getTypeParams(extMemref)); if (CrayPtr) { mlir::Type ptrTy = CrayPtr.getType(); mlir::Value cnvrt = Fortran::lower::addCrayPointerInst( loc, builder, CrayPtr, ptrTy, memref.getType()); - auto addr = builder.create<fir::LoadOp>(loc, cnvrt); - arrLoad = builder.create<fir::ArrayLoadOp>(loc, arrTy, addr, shape, slice, - fir::getTypeParams(extMemref)); + auto addr = fir::LoadOp::create(builder, loc, cnvrt); + arrLoad = fir::ArrayLoadOp::create(builder, loc, arrTy, addr, shape, + slice, fir::getTypeParams(extMemref)); } mlir::Value arrLd = arrLoad.getResult(); @@ -5904,9 +5918,9 @@ private: mlir::Type eleTy = fir::applyPathToType(resTy, iters.iterVec()); mlir::Type refEleTy = fir::isa_ref_type(eleTy) ? eleTy : builder.getRefType(eleTy); - auto arrModify = builder.create<fir::ArrayModifyOp>( - loc, mlir::TypeRange{refEleTy, resTy}, innerArg, iters.iterVec(), - destination.getTypeparams()); + auto arrModify = fir::ArrayModifyOp::create( + builder, loc, mlir::TypeRange{refEleTy, resTy}, innerArg, + iters.iterVec(), destination.getTypeparams()); return abstractArrayExtValue(arrModify.getResult(1)); }; } @@ -5930,17 +5944,17 @@ private: mlir::Type eleTy = fir::applyPathToType(arrTy, iters.iterVec()); if (isAdjustedArrayElementType(eleTy)) { mlir::Type eleRefTy = builder.getRefType(eleTy); - base = builder.create<fir::ArrayAccessOp>( - loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams); + base = fir::ArrayAccessOp::create(builder, loc, eleRefTy, arrLd, + iters.iterVec(), arrLdTypeParams); } else { - base = builder.create<fir::ArrayFetchOp>( - loc, eleTy, arrLd, iters.iterVec(), arrLdTypeParams); + base = fir::ArrayFetchOp::create(builder, loc, eleTy, arrLd, + iters.iterVec(), arrLdTypeParams); } mlir::Value temp = builder.createTemporary(loc, base.getType(), llvm::ArrayRef<mlir::NamedAttribute>{ fir::getAdaptToByRefAttr(builder)}); - builder.create<fir::StoreOp>(loc, base, temp); + fir::StoreOp::create(builder, loc, base, temp); return fir::factory::arraySectionElementToExtendedValue( builder, loc, extMemref, temp, slice); }; @@ -5951,8 +5965,8 @@ private: mlir::Type eleTy = fir::applyPathToType(arrTy, iters.iterVec()); if (isAdjustedArrayElementType(eleTy)) { mlir::Type eleRefTy = builder.getRefType(eleTy); - mlir::Value arrayOp = builder.create<fir::ArrayAccessOp>( - loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams); + mlir::Value arrayOp = fir::ArrayAccessOp::create( + builder, loc, eleRefTy, arrLd, iters.iterVec(), arrLdTypeParams); if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { llvm::SmallVector<mlir::Value> substringBounds; populateBounds(substringBounds, components.substring); @@ -5967,8 +5981,8 @@ private: return fir::factory::arraySectionElementToExtendedValue( builder, loc, extMemref, arrayOp, slice); } - auto arrFetch = builder.create<fir::ArrayFetchOp>( - loc, eleTy, arrLd, iters.iterVec(), arrLdTypeParams); + auto arrFetch = fir::ArrayFetchOp::create( + builder, loc, eleTy, arrLd, iters.iterVec(), arrLdTypeParams); return fir::factory::arraySectionElementToExtendedValue( builder, loc, extMemref, arrFetch, slice); }; @@ -6007,8 +6021,8 @@ private: mlir::Value memref = fir::getBase(exv); mlir::Value shape = builder.createShape(loc, exv); mlir::Value noSlice; - auto arrLoad = builder.create<fir::ArrayLoadOp>( - loc, arrType, memref, shape, noSlice, fir::getTypeParams(exv)); + auto arrLoad = fir::ArrayLoadOp::create( + builder, loc, arrType, memref, shape, noSlice, fir::getTypeParams(exv)); mlir::Operation::operand_range arrLdTypeParams = arrLoad.getTypeparams(); mlir::Value arrLd = arrLoad.getResult(); // Mark the load to tell later passes it is unsafe to use this array_load @@ -6023,8 +6037,8 @@ private: // By value semantics. auto cc = [=](IterSpace iters) -> ExtValue { - auto arrFetch = builder.create<fir::ArrayFetchOp>( - loc, eleType, arrLd, iters.iterVec(), arrLdTypeParams); + auto arrFetch = fir::ArrayFetchOp::create( + builder, loc, eleType, arrLd, iters.iterVec(), arrLdTypeParams); return fir::factory::arraySectionElementToExtendedValue( builder, loc, exv, arrFetch, noSlice); }; @@ -6062,12 +6076,12 @@ private: .genIfOp(loc, {eleType}, isPresent, /*withElseRegion=*/true) .genThen([&]() { - builder.create<fir::ResultOp>(loc, fir::getBase(cc(iters))); + fir::ResultOp::create(builder, loc, fir::getBase(cc(iters))); }) .genElse([&]() { mlir::Value zero = fir::factory::createZeroValue(builder, loc, eleType); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; return elementValue; @@ -6176,8 +6190,8 @@ private: mlir::Type eleRefTy = builder.getRefType(eleTy); mlir::Type resRefTy = builder.getRefType(resTy); mlir::Value nullPtr = builder.createNullConstant(loc, resRefTy); - auto offset = builder.create<fir::CoordinateOp>( - loc, eleRefTy, nullPtr, mlir::ValueRange{multiplier}); + auto offset = fir::CoordinateOp::create(builder, loc, eleRefTy, nullPtr, + mlir::ValueRange{multiplier}); return builder.createConvert(loc, idxTy, offset); } @@ -6191,8 +6205,8 @@ private: /// Create a call to the LLVM memcpy intrinsic. void createCallMemcpy(llvm::ArrayRef<mlir::Value> args, bool isVolatile) { mlir::Location loc = getLoc(); - builder.create<mlir::LLVM::MemcpyOp>(loc, args[0], args[1], args[2], - isVolatile); + mlir::LLVM::MemcpyOp::create(builder, loc, args[0], args[1], args[2], + isVolatile); } // Construct code to check for a buffer overrun and realloc the buffer when @@ -6202,32 +6216,33 @@ private: mlir::Value eleSz) { mlir::Location loc = getLoc(); mlir::func::FuncOp reallocFunc = fir::factory::getRealloc(builder); - auto cond = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sle, bufferSize, needed); - auto ifOp = builder.create<fir::IfOp>(loc, mem.getType(), cond, - /*withElseRegion=*/true); + auto cond = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sle, bufferSize, needed); + auto ifOp = fir::IfOp::create(builder, loc, mem.getType(), cond, + /*withElseRegion=*/true); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); // Not enough space, resize the buffer. mlir::IndexType idxTy = builder.getIndexType(); mlir::Value two = builder.createIntegerConstant(loc, idxTy, 2); - auto newSz = builder.create<mlir::arith::MulIOp>(loc, needed, two); - builder.create<fir::StoreOp>(loc, newSz, buffSize); - mlir::Value byteSz = builder.create<mlir::arith::MulIOp>(loc, newSz, eleSz); + auto newSz = mlir::arith::MulIOp::create(builder, loc, needed, two); + fir::StoreOp::create(builder, loc, newSz, buffSize); + mlir::Value byteSz = + mlir::arith::MulIOp::create(builder, loc, newSz, eleSz); mlir::SymbolRefAttr funcSymAttr = builder.getSymbolRefAttr(reallocFunc.getName()); mlir::FunctionType funcTy = reallocFunc.getFunctionType(); - auto newMem = builder.create<fir::CallOp>( - loc, funcSymAttr, funcTy.getResults(), + auto newMem = fir::CallOp::create( + builder, loc, funcSymAttr, funcTy.getResults(), llvm::ArrayRef<mlir::Value>{ builder.createConvert(loc, funcTy.getInputs()[0], mem), builder.createConvert(loc, funcTy.getInputs()[1], byteSz)}); mlir::Value castNewMem = builder.createConvert(loc, mem.getType(), newMem.getResult(0)); - builder.create<fir::ResultOp>(loc, castNewMem); + fir::ResultOp::create(builder, loc, castNewMem); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); // Otherwise, just forward the buffer. - builder.create<fir::ResultOp>(loc, mem); + fir::ResultOp::create(builder, loc, mem); builder.restoreInsertionPoint(insPt); return ifOp.getResult(0); } @@ -6239,8 +6254,8 @@ private: mlir::Value eleSz, mlir::Type eleTy, mlir::Type eleRefTy, mlir::Type resTy) { mlir::Location loc = getLoc(); - auto off = builder.create<fir::LoadOp>(loc, buffPos); - auto limit = builder.create<fir::LoadOp>(loc, buffSize); + auto off = fir::LoadOp::create(builder, loc, buffPos); + auto limit = fir::LoadOp::create(builder, loc, buffSize); mlir::IndexType idxTy = builder.getIndexType(); mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); @@ -6258,7 +6273,7 @@ private: mlir::Value length = fir::getLen(exv); if (!length) fir::emitFatalError(loc, "result is not boxed character"); - eleSz = builder.create<mlir::arith::MulIOp>(loc, bytes, length); + eleSz = mlir::arith::MulIOp::create(builder, loc, bytes, length); } else { TODO(loc, "PDT size"); // Will call the PDT's size function with the type parameters. @@ -6277,13 +6292,13 @@ private: refTy = builder.getRefType(chTy); mlir::Type toTy = builder.getRefType(builder.getVarLenSeqTy(chTy)); buff = builder.createConvert(loc, toTy, buff); - off = builder.create<mlir::arith::MulIOp>(loc, off, eleSz); + off = mlir::arith::MulIOp::create(builder, loc, off, eleSz); } else { TODO(loc, "PDT offset"); } } - auto coor = builder.create<fir::CoordinateOp>(loc, refTy, buff, - mlir::ValueRange{off}); + auto coor = fir::CoordinateOp::create(builder, loc, refTy, buff, + mlir::ValueRange{off}); return builder.createConvert(loc, eleRefTy, coor); }; @@ -6292,15 +6307,15 @@ private: // Compute the array size. mlir::Value arrSz = one; for (auto ext : v.getExtents()) - arrSz = builder.create<mlir::arith::MulIOp>(loc, arrSz, ext); + arrSz = mlir::arith::MulIOp::create(builder, loc, arrSz, ext); // Grow the buffer as needed. - auto endOff = builder.create<mlir::arith::AddIOp>(loc, off, arrSz); + auto endOff = mlir::arith::AddIOp::create(builder, loc, off, arrSz); mem = growBuffer(mem, endOff, limit, buffSize, eleSz); // Copy the elements to the buffer. mlir::Value byteSz = - builder.create<mlir::arith::MulIOp>(loc, arrSz, eleSz); + mlir::arith::MulIOp::create(builder, loc, arrSz, eleSz); auto buff = builder.createConvert(loc, fir::HeapType::get(resTy), mem); mlir::Value buffi = computeCoordinate(buff, off); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( @@ -6309,13 +6324,13 @@ private: createCallMemcpy(args, isVolatile); // Save the incremented buffer position. - builder.create<fir::StoreOp>(loc, endOff, buffPos); + fir::StoreOp::create(builder, loc, endOff, buffPos); }; // Copy a trivial scalar value into the buffer. auto doTrivialScalar = [&](const ExtValue &v, mlir::Value len = {}) { // Increment the buffer position. - auto plusOne = builder.create<mlir::arith::AddIOp>(loc, off, one); + auto plusOne = mlir::arith::AddIOp::create(builder, loc, off, one); // Grow the buffer as needed. mem = growBuffer(mem, plusOne, limit, buffSize, eleSz); @@ -6323,8 +6338,8 @@ private: // Store the element in the buffer. mlir::Value buff = builder.createConvert(loc, fir::HeapType::get(resTy), mem); - auto buffi = builder.create<fir::CoordinateOp>(loc, eleRefTy, buff, - mlir::ValueRange{off}); + auto buffi = fir::CoordinateOp::create(builder, loc, eleRefTy, buff, + mlir::ValueRange{off}); fir::factory::genScalarAssignment( builder, loc, [&]() -> ExtValue { @@ -6333,7 +6348,7 @@ private: return buffi; }(), v); - builder.create<fir::StoreOp>(loc, plusOne, buffPos); + fir::StoreOp::create(builder, loc, plusOne, buffPos); }; // Copy the value. @@ -6345,7 +6360,7 @@ private: doTrivialScalar(exv, eleSz); } else { // Increment the buffer position. - auto plusOne = builder.create<mlir::arith::AddIOp>(loc, off, one); + auto plusOne = mlir::arith::AddIOp::create(builder, loc, off, one); // Grow the buffer as needed. mem = growBuffer(mem, plusOne, limit, buffSize, eleSz); @@ -6360,7 +6375,7 @@ private: fir::isa_volatile_type(v.getAddr().getType()); createCallMemcpy(args, isVolatile); - builder.create<fir::StoreOp>(loc, plusOne, buffPos); + fir::StoreOp::create(builder, loc, plusOne, buffPos); } }, [&](const fir::ArrayBoxValue &v) { doAbstractArray(v); }, @@ -6401,8 +6416,8 @@ private: auto seqTy = mlir::cast<fir::SequenceType>(resTy); mlir::Type eleTy = fir::unwrapSequenceType(seqTy); auto loop = - builder.create<fir::DoLoopOp>(loc, lo, up, step, /*unordered=*/false, - /*finalCount=*/false, mem); + fir::DoLoopOp::create(builder, loc, lo, up, step, /*unordered=*/false, + /*finalCount=*/false, mem); // create a new binding for x.name(), to ac-do-variable, to the iteration // value. symMap.pushImpliedDoBinding(toStringRef(x.name()), loop.getInductionVar()); @@ -6432,22 +6447,22 @@ private: mlir::Value castLen = builder.createConvert(loc, builder.getI64Type(), fir::getLen(exv)); assert(charLen.has_value()); - builder.create<fir::StoreOp>(loc, castLen, *charLen); + fir::StoreOp::create(builder, loc, castLen, *charLen); } } stmtCtx.finalizeAndPop(); - builder.create<fir::ResultOp>(loc, mem); + fir::ResultOp::create(builder, loc, mem); builder.restoreInsertionPoint(insPt); mem = loop.getResult(0); symMap.popImpliedDoBinding(); llvm::SmallVector<mlir::Value> extents = { - builder.create<fir::LoadOp>(loc, buffPos).getResult()}; + fir::LoadOp::create(builder, loc, buffPos).getResult()}; // Convert to extended value. if (fir::isa_char(seqTy.getEleTy())) { assert(charLen.has_value()); - auto len = builder.create<fir::LoadOp>(loc, *charLen); + auto len = fir::LoadOp::create(builder, loc, *charLen); return {fir::CharArrayBoxValue{mem, len, extents}, /*needCopy=*/false}; } return {fir::ArrayBoxValue{mem, extents}, /*needCopy=*/false}; @@ -6470,7 +6485,7 @@ private: mlir::Value buffSize = builder.createTemporary(loc, idxTy, ".buff.size"); mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0); mlir::Value buffPos = builder.createTemporary(loc, idxTy, ".buff.pos"); - builder.create<fir::StoreOp>(loc, zero, buffPos); + fir::StoreOp::create(builder, loc, zero, buffPos); // Allocate space for the array to be constructed. mlir::Value mem; if (fir::hasDynamicSize(resTy)) { @@ -6478,22 +6493,22 @@ private: // The size of each element may depend on a general expression. Defer // creating the buffer until after the expression is evaluated. mem = builder.createNullConstant(loc, builder.getRefType(eleTy)); - builder.create<fir::StoreOp>(loc, zero, buffSize); + fir::StoreOp::create(builder, loc, zero, buffSize); } else { mlir::Value initBuffSz = builder.createIntegerConstant(loc, idxTy, clInitialBufferSize); - mem = builder.create<fir::AllocMemOp>( - loc, eleTy, /*typeparams=*/std::nullopt, initBuffSz); - builder.create<fir::StoreOp>(loc, initBuffSz, buffSize); + mem = fir::AllocMemOp::create( + builder, loc, eleTy, /*typeparams=*/mlir::ValueRange{}, initBuffSz); + fir::StoreOp::create(builder, loc, initBuffSz, buffSize); } } else { - mem = builder.create<fir::AllocMemOp>(loc, resTy); + mem = fir::AllocMemOp::create(builder, loc, resTy); int64_t buffSz = 1; for (auto extent : seqTy.getShape()) buffSz *= extent; mlir::Value initBuffSz = builder.createIntegerConstant(loc, idxTy, buffSz); - builder.create<fir::StoreOp>(loc, initBuffSz, buffSize); + fir::StoreOp::create(builder, loc, initBuffSz, buffSize); } // Compute size of element mlir::Type eleRefTy = builder.getRefType(eleTy); @@ -6515,12 +6530,12 @@ private: charLen = builder.createTemporary(loc, builder.getI64Type()); mlir::Value castLen = builder.createConvert(loc, builder.getI64Type(), fir::getLen(exv)); - builder.create<fir::StoreOp>(loc, castLen, *charLen); + fir::StoreOp::create(builder, loc, castLen, *charLen); } } mem = builder.createConvert(loc, fir::HeapType::get(resTy), mem); llvm::SmallVector<mlir::Value> extents = { - builder.create<fir::LoadOp>(loc, buffPos)}; + fir::LoadOp::create(builder, loc, buffPos)}; // Cleanup the temporary. fir::FirOpBuilder *bldr = &converter.getFirOpBuilder(); @@ -6530,7 +6545,7 @@ private: // Return the continuation. if (fir::isa_char(seqTy.getEleTy())) { if (charLen) { - auto len = builder.create<fir::LoadOp>(loc, *charLen); + auto len = fir::LoadOp::create(builder, loc, *charLen); return genarr(fir::CharArrayBoxValue{mem, len, extents}); } return genarr(fir::CharArrayBoxValue{mem, zero, extents}); @@ -6567,7 +6582,7 @@ private: return [=](IterSpace iters) -> ExtValue { mlir::Value logical = fir::getBase(lambda(iters)); mlir::Value val = builder.createConvert(loc, i1Ty, logical); - return builder.create<mlir::arith::XOrIOp>(loc, val, truth); + return mlir::arith::XOrIOp::create(builder, loc, val, truth); }; } template <typename OP, typename A> @@ -6581,7 +6596,7 @@ private: mlir::Value right = fir::getBase(rf(iters)); mlir::Value lhs = builder.createConvert(loc, i1Ty, left); mlir::Value rhs = builder.createConvert(loc, i1Ty, right); - return builder.create<OP>(loc, lhs, rhs); + return OP::create(builder, loc, lhs, rhs); }; } template <typename OP, typename A> @@ -6595,7 +6610,7 @@ private: mlir::Value right = fir::getBase(rf(iters)); mlir::Value lhs = builder.createConvert(loc, i1Ty, left); mlir::Value rhs = builder.createConvert(loc, i1Ty, right); - return builder.create<OP>(loc, pred, lhs, rhs); + return OP::create(builder, loc, pred, lhs, rhs); }; } template <int KIND> @@ -6635,9 +6650,9 @@ private: Fortran::common::TypeCategory::Integer, *unsignedKind); mlir::Value lhsSL = builder.createConvert(loc, signlessType, lhs); mlir::Value rhsSL = builder.createConvert(loc, signlessType, rhs); - return builder.create<OP>(loc, pred, lhsSL, rhsSL); + return OP::create(builder, loc, pred, lhsSL, rhsSL); } - return builder.create<OP>(loc, pred, lhs, rhs); + return OP::create(builder, loc, pred, lhs, rhs); }; } template <typename A> @@ -6804,9 +6819,8 @@ private: : one; mlir::Value val = builder.createConvert( loc, idxTy, subscriptVal); - mlir::Value ivAdj = - builder.create<mlir::arith::SubIOp>( - loc, idxTy, val, lb); + mlir::Value ivAdj = mlir::arith::SubIOp::create( + builder, loc, idxTy, val, lb); componentsToAdd.push_back( builder.createConvert(loc, idxTy, ivAdj)); }, @@ -6828,8 +6842,9 @@ private: converter.getRecordTypeFieldName(getLastSym(*x)); if (auto recTy = mlir::dyn_cast<fir::RecordType>(ty)) { ty = recTy.getType(name); - auto fld = builder.create<fir::FieldIndexOp>( - loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); + auto fld = fir::FieldIndexOp::create( + builder, loc, fieldTy, name, recTy, + fir::getTypeParams(arrayExv)); addComponentList(ty, {fld}); if (index != revPath.size() - 1 || !isPointerAssignment()) { // Need an intermediate dereference if the boxed value @@ -6850,8 +6865,9 @@ private: ty = fir::unwrapRefType(boxTy.getEleTy()); auto recTy = mlir::cast<fir::RecordType>(ty); ty = recTy.getType(name); - auto fld = builder.create<fir::FieldIndexOp>( - loc, fieldTy, name, recTy, fir::getTypeParams(arrayExv)); + auto fld = fir::FieldIndexOp::create( + builder, loc, fieldTy, name, recTy, + fir::getTypeParams(arrayExv)); extendComponent(components, ty, {fld}); } else { TODO(loc, "other component type"); @@ -6894,8 +6910,8 @@ private: mlir::Value innerArg = esp->findArgumentOfLoad(load); if (isAdjustedArrayElementType(eleTy)) { mlir::Type eleRefTy = builder.getRefType(eleTy); - auto arrayOp = builder.create<fir::ArrayAccessOp>( - loc, eleRefTy, innerArg, iters.iterVec(), + auto arrayOp = fir::ArrayAccessOp::create( + builder, loc, eleRefTy, innerArg, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { mlir::Value dstLen = fir::factory::genLenOfCharacter( @@ -6922,9 +6938,9 @@ private: if (!eleBoxTy || !mlir::isa<fir::BoxType>(eleBoxTy)) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); - auto arrayOp = builder.create<fir::ArrayAccessOp>( - loc, builder.getRefType(eleBoxTy), innerArg, iters.iterVec(), - fir::factory::getTypeParams(loc, builder, load)); + auto arrayOp = fir::ArrayAccessOp::create( + builder, loc, builder.getRefType(eleBoxTy), innerArg, + iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); mlir::Value addr = components.getExtendCoorRef()(arrayOp); components.resetExtendCoorRef(); // When the lhs is a boxed value and the context is not a pointer @@ -6933,19 +6949,19 @@ private: if (!isPointerAssignment()) { if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(eleTy)) { eleTy = fir::boxMemRefType(boxTy); - addr = builder.create<fir::BoxAddrOp>(loc, eleTy, addr); + addr = fir::BoxAddrOp::create(builder, loc, eleTy, addr); eleTy = fir::unwrapRefType(eleTy); } } auto ele = convertElementForUpdate(loc, eleTy, iters.getElement()); - builder.create<fir::StoreOp>(loc, ele, addr); - auto amend = builder.create<fir::ArrayAmendOp>( - loc, innerArg.getType(), innerArg, arrayOp); + fir::StoreOp::create(builder, loc, ele, addr); + auto amend = fir::ArrayAmendOp::create( + builder, loc, innerArg.getType(), innerArg, arrayOp); return arrayLoadExtValue(builder, loc, load, iters.iterVec(), amend); } auto ele = convertElementForUpdate(loc, eleTy, iters.getElement()); - auto update = builder.create<fir::ArrayUpdateOp>( - loc, innerArg.getType(), innerArg, ele, iters.iterVec(), + auto update = fir::ArrayUpdateOp::create( + builder, loc, innerArg.getType(), innerArg, ele, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); return arrayLoadExtValue(builder, loc, load, iters.iterVec(), update); }; @@ -6959,9 +6975,9 @@ private: mlir::Value innerArg = explicitSpace->findArgumentOfLoad(load); mlir::Type refEleTy = fir::isa_ref_type(eleTy) ? eleTy : builder.getRefType(eleTy); - auto arrModify = builder.create<fir::ArrayModifyOp>( - loc, mlir::TypeRange{refEleTy, innerArg.getType()}, innerArg, - iters.iterVec(), load.getTypeparams()); + auto arrModify = fir::ArrayModifyOp::create( + builder, loc, mlir::TypeRange{refEleTy, innerArg.getType()}, + innerArg, iters.iterVec(), load.getTypeparams()); return arrayLoadExtValue(builder, loc, load, iters.iterVec(), arrModify.getResult(1)); }; @@ -6972,8 +6988,8 @@ private: isAdjustedArrayElementType(eleTy)) { mlir::Type resTy = builder.getRefType(eleTy); // Use array element reference semantics. - auto access = builder.create<fir::ArrayAccessOp>( - loc, resTy, load, iters.iterVec(), + auto access = fir::ArrayAccessOp::create( + builder, loc, resTy, load, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); mlir::Value newBase = access; if (fir::isa_char(eleTy)) { @@ -6995,8 +7011,8 @@ private: if (!eleBoxTy || !mlir::isa<fir::BoxType>(eleBoxTy)) TODO(loc, "assignment in a FORALL involving a designator with a " "POINTER or ALLOCATABLE component part-ref"); - auto access = builder.create<fir::ArrayAccessOp>( - loc, builder.getRefType(eleBoxTy), load, iters.iterVec(), + auto access = fir::ArrayAccessOp::create( + builder, loc, builder.getRefType(eleBoxTy), load, iters.iterVec(), fir::factory::getTypeParams(loc, builder, load)); mlir::Value addr = components.getExtendCoorRef()(access); components.resetExtendCoorRef(); @@ -7008,8 +7024,8 @@ private: // Rhs is a regular expression that will need to be boxed before // assigning to the boxed variable. auto typeParams = fir::factory::getTypeParams(loc, builder, load); - auto access = builder.create<fir::ArrayAccessOp>( - loc, builder.getRefType(eleTy), load, iters.iterVec(), + auto access = fir::ArrayAccessOp::create( + builder, loc, builder.getRefType(eleTy), load, iters.iterVec(), typeParams); auto addr = components.getExtendCoorRef()(access); components.resetExtendCoorRef(); @@ -7023,14 +7039,14 @@ private: TODO(loc, "need to adjust typeparameter(s) to reflect the final " "component"); mlir::Value embox = - builder.create<fir::EmboxOp>(loc, boxTy, ptrAddr, - /*shape=*/mlir::Value{}, - /*slice=*/mlir::Value{}, typeParams); + fir::EmboxOp::create(builder, loc, boxTy, ptrAddr, + /*shape=*/mlir::Value{}, + /*slice=*/mlir::Value{}, typeParams); return arrayLoadExtValue(builder, loc, load, iters.iterVec(), embox); } } - auto fetch = builder.create<fir::ArrayFetchOp>( - loc, eleTy, load, iters.iterVec(), load.getTypeparams()); + auto fetch = fir::ArrayFetchOp::create( + builder, loc, eleTy, load, iters.iterVec(), load.getTypeparams()); return arrayLoadExtValue(builder, loc, load, iters.iterVec(), fetch); }; return [=](IterSpace iters) mutable { return lambda(pc(iters)); }; @@ -7539,24 +7555,25 @@ fir::ExtendedValue Fortran::lower::updateBoxForParentComponent( if (op) { if (auto embox = mlir::dyn_cast<fir::EmboxOp>(op)) { - auto newBox = builder.create<fir::EmboxOp>( - loc, fir::BoxType::get(actualTy), embox.getMemref(), embox.getShape(), - embox.getSlice(), embox.getTypeparams()); + auto newBox = fir::EmboxOp::create( + builder, loc, fir::BoxType::get(actualTy), embox.getMemref(), + embox.getShape(), embox.getSlice(), embox.getTypeparams()); return fir::substBase(box, newBox); } if (auto rebox = mlir::dyn_cast<fir::ReboxOp>(op)) { - auto newBox = builder.create<fir::ReboxOp>( - loc, fir::BoxType::get(actualTy), rebox.getBox(), rebox.getShape(), - rebox.getSlice()); + auto newBox = fir::ReboxOp::create( + builder, loc, fir::BoxType::get(actualTy), rebox.getBox(), + rebox.getShape(), rebox.getSlice()); return fir::substBase(box, newBox); } } mlir::Value empty; mlir::ValueRange emptyRange; - return builder.create<fir::ReboxOp>(loc, fir::BoxType::get(actualTy), boxBase, - /*shape=*/empty, - /*slice=*/empty); + return fir::ReboxOp::create(builder, loc, fir::BoxType::get(actualTy), + boxBase, + /*shape=*/empty, + /*slice=*/empty); } fir::ExtendedValue Fortran::lower::createBoxValue( @@ -7647,9 +7664,9 @@ fir::ArrayLoadOp genArrayLoad(mlir::Location loc, mlir::Value addr = fir::getBase(exv); mlir::Value shapeOp = builder.createShape(loc, exv); mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(addr.getType()); - return builder.create<fir::ArrayLoadOp>(loc, arrTy, addr, shapeOp, - /*slice=*/mlir::Value{}, - fir::getTypeParams(exv)); + return fir::ArrayLoadOp::create(builder, loc, arrTy, addr, shapeOp, + /*slice=*/mlir::Value{}, + fir::getTypeParams(exv)); } template <> fir::ArrayLoadOp @@ -7696,9 +7713,9 @@ void Fortran::lower::createArrayMergeStores( for (auto i : llvm::enumerate(esp.getOuterLoop().getResults())) if (std::optional<fir::ArrayLoadOp> ldOpt = esp.getLhsLoad(i.index())) { fir::ArrayLoadOp load = *ldOpt; - builder.create<fir::ArrayMergeStoreOp>(loc, load, i.value(), - load.getMemref(), load.getSlice(), - load.getTypeparams()); + fir::ArrayMergeStoreOp::create(builder, loc, load, i.value(), + load.getMemref(), load.getSlice(), + load.getTypeparams()); } if (esp.loopCleanup) { (*esp.loopCleanup)(builder); @@ -7720,12 +7737,12 @@ mlir::Value Fortran::lower::addCrayPointerInst(mlir::Location loc, mlir::Value empty; mlir::ValueRange emptyRange; auto boxTy = fir::BoxType::get(ptrTy); - auto box = builder.create<fir::EmboxOp>(loc, boxTy, ptrVal, empty, empty, - emptyRange); - mlir::Value addrof = - (mlir::isa<fir::ReferenceType>(ptrTy)) - ? builder.create<fir::BoxAddrOp>(loc, ptrTy, box) - : builder.create<fir::BoxAddrOp>(loc, builder.getRefType(ptrTy), box); + auto box = fir::EmboxOp::create(builder, loc, boxTy, ptrVal, empty, empty, + emptyRange); + mlir::Value addrof = (mlir::isa<fir::ReferenceType>(ptrTy)) + ? fir::BoxAddrOp::create(builder, loc, ptrTy, box) + : fir::BoxAddrOp::create( + builder, loc, builder.getRefType(ptrTy), box); auto refPtrTy = builder.getRefType(fir::PointerType::get(fir::dyn_cast_ptrEleTy(pteTy))); diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index 7de433d..46be111 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -167,7 +167,7 @@ public: extents.push_back(builder.createIntegerConstant(loc, idxTy, extent)); } if (!mayHaveNonDefaultLowerBounds(componentSym)) - return builder.create<fir::ShapeOp>(loc, extents); + return fir::ShapeOp::create(builder, loc, extents); llvm::SmallVector<mlir::Value> lbounds; if (const auto *objDetails = @@ -312,8 +312,8 @@ private: // hlfir.elemental_addr. if (auto elementalAddrOp = getVectorSubscriptElementAddrOp()) builder.setInsertionPointToEnd(&elementalAddrOp->getBody().front()); - auto designate = builder.create<hlfir::DesignateOp>( - getLoc(), designatorType, partInfo.base.value().getBase(), + auto designate = hlfir::DesignateOp::create( + builder, getLoc(), designatorType, partInfo.base.value().getBase(), partInfo.componentName, partInfo.componentShape, partInfo.subscripts, partInfo.substring, partInfo.complexPart, partInfo.resultShape, partInfo.typeParams, attributes); @@ -344,7 +344,7 @@ private: mlir::Type refPtrType = builder.getRefType( fir::PointerType::get(fir::dyn_cast_ptrEleTy(ptrAddr.getType()))); mlir::Value cast = builder.createConvert(loc, refPtrType, ptrAddr); - mlir::Value ptrVal = builder.create<fir::LoadOp>(loc, cast); + mlir::Value ptrVal = fir::LoadOp::create(builder, loc, cast); // Update the base_addr to the value of the Cray pointer. // This is a hacky way to do the update, and it may harm @@ -442,9 +442,9 @@ private: } else { // Compute "len = max(ub-lb+1,0)" (Fortran 2018 9.4.1). mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); - auto boundsDiff = builder.create<mlir::arith::SubIOp>( - loc, partInfo.substring[1], partInfo.substring[0]); - auto rawLen = builder.create<mlir::arith::AddIOp>(loc, boundsDiff, one); + auto boundsDiff = mlir::arith::SubIOp::create( + builder, loc, partInfo.substring[1], partInfo.substring[0]); + auto rawLen = mlir::arith::AddIOp::create(builder, loc, boundsDiff, one); partInfo.typeParams[0] = fir::factory::genMaxWithZero(builder, loc, rawLen); } @@ -803,10 +803,10 @@ private: mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); oneBasedIndex = builder.createConvert(loc, idxTy, oneBasedIndex); mlir::Value zeroBased = - builder.create<mlir::arith::SubIOp>(loc, oneBasedIndex, one); + mlir::arith::SubIOp::create(builder, loc, oneBasedIndex, one); mlir::Value offset = - builder.create<mlir::arith::MulIOp>(loc, zeroBased, step); - return builder.create<mlir::arith::AddIOp>(loc, lb, offset); + mlir::arith::MulIOp::create(builder, loc, zeroBased, step); + return mlir::arith::AddIOp::create(builder, loc, lb, offset); } /// Create an hlfir.element_addr operation to deal with vector subscripted @@ -836,8 +836,8 @@ private: assert(partInfo.base.has_value() && "vector subscripted part must have a base"); mlir::Value mold = *partInfo.base; - auto elementalAddrOp = builder.create<hlfir::ElementalAddrOp>( - loc, shape, mold, mlir::ValueRange{}, + auto elementalAddrOp = hlfir::ElementalAddrOp::create( + builder, loc, shape, mold, mlir::ValueRange{}, /*isUnordered=*/true); setVectorSubscriptElementAddrOp(elementalAddrOp); builder.setInsertionPointToEnd(&elementalAddrOp.getBody().front()); @@ -881,7 +881,7 @@ private: builder.setInsertionPointToEnd(&elementalAddrOp.getBody().front()); if (!elementAddr.isPolymorphic()) elementalAddrOp.getMoldMutable().clear(); - builder.create<hlfir::YieldOp>(loc, elementAddr); + hlfir::YieldOp::create(builder, loc, elementAddr); builder.setInsertionPointAfter(elementalAddrOp); } @@ -1001,7 +1001,7 @@ HlfirDesignatorBuilder::convertVectorSubscriptedExprToElementalAddr( elementalAddrOp.getMoldMutable().clear(); // Create the hlfir.yield terminator inside the hlfir.elemental_body. builder.setInsertionPointToEnd(&elementalAddrOp.getBody().front()); - builder.create<hlfir::YieldOp>(loc, elementAddrEntity); + hlfir::YieldOp::create(builder, loc, elementAddrEntity); builder.setInsertionPointAfter(elementalAddrOp); // Reset the HlfirDesignatorBuilder state, in case it is used on a new // designator. @@ -1034,7 +1034,7 @@ struct BinaryOp {}; rhs)}; \ } else { \ return hlfir::EntityWithAttributes{ \ - builder.create<GenBinFirOp>(loc, lhs, rhs)}; \ + GenBinFirOp::create(builder, loc, lhs, rhs)}; \ } \ } \ }; @@ -1075,7 +1075,7 @@ struct BinaryOp<Fortran::evaluate::Divide< fir::genDivC(builder, loc, ty, lhs, rhs)}; } else { return hlfir::EntityWithAttributes{ - builder.create<mlir::complex::DivOp>(loc, lhs, rhs)}; + mlir::complex::DivOp::create(builder, loc, lhs, rhs)}; } } }; @@ -1219,8 +1219,8 @@ struct BinaryOp<Fortran::evaluate::Relational< fir::FirOpBuilder &builder, const Op &op, hlfir::Entity lhs, hlfir::Entity rhs) { - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, translateSignedRelational(op.opr), lhs, rhs); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, translateSignedRelational(op.opr), lhs, rhs); return hlfir::EntityWithAttributes{cmp}; } }; @@ -1241,8 +1241,8 @@ struct BinaryOp<Fortran::evaluate::Relational< mlir::IntegerType::SignednessSemantics::Signless); mlir::Value lhsSL = builder.createConvert(loc, signlessType, lhs); mlir::Value rhsSL = builder.createConvert(loc, signlessType, rhs); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, translateUnsignedRelational(op.opr), lhsSL, rhsSL); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, translateUnsignedRelational(op.opr), lhsSL, rhsSL); return hlfir::EntityWithAttributes{cmp}; } }; @@ -1256,8 +1256,8 @@ struct BinaryOp<Fortran::evaluate::Relational< fir::FirOpBuilder &builder, const Op &op, hlfir::Entity lhs, hlfir::Entity rhs) { - auto cmp = builder.create<mlir::arith::CmpFOp>( - loc, translateFloatRelational(op.opr), lhs, rhs); + auto cmp = mlir::arith::CmpFOp::create( + builder, loc, translateFloatRelational(op.opr), lhs, rhs); return hlfir::EntityWithAttributes{cmp}; } }; @@ -1271,8 +1271,8 @@ struct BinaryOp<Fortran::evaluate::Relational< fir::FirOpBuilder &builder, const Op &op, hlfir::Entity lhs, hlfir::Entity rhs) { - auto cmp = builder.create<fir::CmpcOp>( - loc, translateFloatRelational(op.opr), lhs, rhs); + auto cmp = fir::CmpcOp::create(builder, loc, + translateFloatRelational(op.opr), lhs, rhs); return hlfir::EntityWithAttributes{cmp}; } }; @@ -1313,16 +1313,16 @@ struct BinaryOp<Fortran::evaluate::LogicalOperation<KIND>> { switch (op.logicalOperator) { case Fortran::evaluate::LogicalOperator::And: return hlfir::EntityWithAttributes{ - builder.create<mlir::arith::AndIOp>(loc, i1Lhs, i1Rhs)}; + mlir::arith::AndIOp::create(builder, loc, i1Lhs, i1Rhs)}; case Fortran::evaluate::LogicalOperator::Or: return hlfir::EntityWithAttributes{ - builder.create<mlir::arith::OrIOp>(loc, i1Lhs, i1Rhs)}; + mlir::arith::OrIOp::create(builder, loc, i1Lhs, i1Rhs)}; case Fortran::evaluate::LogicalOperator::Eqv: - return hlfir::EntityWithAttributes{builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, i1Lhs, i1Rhs)}; + return hlfir::EntityWithAttributes{mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, i1Lhs, i1Rhs)}; case Fortran::evaluate::LogicalOperator::Neqv: - return hlfir::EntityWithAttributes{builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, i1Lhs, i1Rhs)}; + return hlfir::EntityWithAttributes{mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, i1Lhs, i1Rhs)}; case Fortran::evaluate::LogicalOperator::Not: // lib/evaluate expression for .NOT. is Fortran::evaluate::Not<KIND>. llvm_unreachable(".NOT. is not a binary operator"); @@ -1354,7 +1354,7 @@ struct BinaryOp<Fortran::evaluate::SetLength<KIND>> { // Fortran 2018 7.4.4.2 point 5. mlir::Value safeLength = fir::factory::genMaxWithZero(builder, loc, length); return hlfir::EntityWithAttributes{ - builder.create<hlfir::SetLengthOp>(loc, string, safeLength)}; + hlfir::SetLengthOp::create(builder, loc, string, safeLength)}; } static void genResultTypeParams(mlir::Location, fir::FirOpBuilder &, hlfir::Entity, @@ -1372,7 +1372,7 @@ struct BinaryOp<Fortran::evaluate::Concat<KIND>> { hlfir::Entity lhs, hlfir::Entity rhs) { assert(len && "genResultTypeParams must have been called"); auto concat = - builder.create<hlfir::ConcatOp>(loc, mlir::ValueRange{lhs, rhs}, len); + hlfir::ConcatOp::create(builder, loc, mlir::ValueRange{lhs, rhs}, len); return hlfir::EntityWithAttributes{concat.getResult()}; } void @@ -1386,7 +1386,7 @@ struct BinaryOp<Fortran::evaluate::Concat<KIND>> { mlir::Type idxType = builder.getIndexType(); mlir::Value lhsLen = builder.createConvert(loc, idxType, lengths[0]); mlir::Value rhsLen = builder.createConvert(loc, idxType, lengths[1]); - len = builder.create<mlir::arith::AddIOp>(loc, lhsLen, rhsLen); + len = mlir::arith::AddIOp::create(builder, loc, lhsLen, rhsLen); resultTypeParams.push_back(len); } @@ -1410,7 +1410,7 @@ struct UnaryOp<Fortran::evaluate::Not<KIND>> { mlir::Value one = builder.createBool(loc, true); mlir::Value val = builder.createConvert(loc, builder.getI1Type(), lhs); return hlfir::EntityWithAttributes{ - builder.create<mlir::arith::XOrIOp>(loc, val, one)}; + mlir::arith::XOrIOp::create(builder, loc, val, one)}; } }; @@ -1428,7 +1428,7 @@ struct UnaryOp<Fortran::evaluate::Negate< /*params=*/{}); mlir::Value zero = builder.createIntegerConstant(loc, type, 0); return hlfir::EntityWithAttributes{ - builder.create<mlir::arith::SubIOp>(loc, zero, lhs)}; + mlir::arith::SubIOp::create(builder, loc, zero, lhs)}; } }; @@ -1448,7 +1448,7 @@ struct UnaryOp<Fortran::evaluate::Negate< mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value signless = builder.createConvert(loc, signlessType, lhs); mlir::Value negated = - builder.create<mlir::arith::SubIOp>(loc, zero, signless); + mlir::arith::SubIOp::create(builder, loc, zero, signless); return hlfir::EntityWithAttributes( builder.createConvert(loc, lhs.getType(), negated)); } @@ -1463,7 +1463,7 @@ struct UnaryOp<Fortran::evaluate::Negate< fir::FirOpBuilder &builder, const Op &, hlfir::Entity lhs) { return hlfir::EntityWithAttributes{ - builder.create<mlir::arith::NegFOp>(loc, lhs)}; + mlir::arith::NegFOp::create(builder, loc, lhs)}; } }; @@ -1475,7 +1475,7 @@ struct UnaryOp<Fortran::evaluate::Negate< static hlfir::EntityWithAttributes gen(mlir::Location loc, fir::FirOpBuilder &builder, const Op &, hlfir::Entity lhs) { - return hlfir::EntityWithAttributes{builder.create<fir::NegcOp>(loc, lhs)}; + return hlfir::EntityWithAttributes{fir::NegcOp::create(builder, loc, lhs)}; } }; @@ -1499,9 +1499,9 @@ struct UnaryOp<Fortran::evaluate::Parentheses<T>> { const Op &op, hlfir::Entity lhs) { if (lhs.isVariable()) return hlfir::EntityWithAttributes{ - builder.create<hlfir::AsExprOp>(loc, lhs)}; + hlfir::AsExprOp::create(builder, loc, lhs)}; return hlfir::EntityWithAttributes{ - builder.create<hlfir::NoReassocOp>(loc, lhs.getType(), lhs)}; + hlfir::NoReassocOp::create(builder, loc, lhs.getType(), lhs)}; } static void @@ -1822,8 +1822,8 @@ private: // Allocate scalar temporary that will be initialized // with the values specified by the constructor. mlir::Value storagePtr = builder.createTemporary(loc, recTy); - auto varOp = hlfir::EntityWithAttributes{builder.create<hlfir::DeclareOp>( - loc, storagePtr, "ctor.temp", /*shape=*/nullptr, + auto varOp = hlfir::EntityWithAttributes{hlfir::DeclareOp::create( + builder, loc, storagePtr, "ctor.temp", /*shape=*/nullptr, /*typeparams=*/mlir::ValueRange{}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{})}; @@ -1855,8 +1855,8 @@ private: auto parentCompType = baseRecTy.getType(parentName); assert(parentCompType && "failed to retrieve parent component type"); mlir::Type designatorType = builder.getRefType(parentCompType); - mlir::Value newParent = builder.create<hlfir::DesignateOp>( - loc, designatorType, currentParent, parentName, + mlir::Value newParent = hlfir::DesignateOp::create( + builder, loc, designatorType, currentParent, parentName, /*compShape=*/mlir::Value{}, hlfir::DesignateOp::Subscripts{}, /*substring=*/mlir::ValueRange{}, /*complexPart=*/std::nullopt, @@ -1912,8 +1912,8 @@ private: extraAttributeFlags); // Get the component designator. - auto lhs = builder.create<hlfir::DesignateOp>( - loc, designatorType, baseOp, name, compShape, + auto lhs = hlfir::DesignateOp::create( + builder, loc, designatorType, baseOp, name, compShape, hlfir::DesignateOp::Subscripts{}, /*substring=*/mlir::ValueRange{}, /*complexPart=*/std::nullopt, @@ -1997,10 +1997,10 @@ private: auto rhsCastAndCleanup = hlfir::genTypeAndKindConvert(loc, builder, rhs, lhs.getType(), /*preserveLowerBounds=*/allowRealloc); - builder.create<hlfir::AssignOp>(loc, rhsCastAndCleanup.first, lhs, - allowRealloc, - allowRealloc ? keepLhsLength : false, - /*temporary_lhs=*/true); + hlfir::AssignOp::create(builder, loc, rhsCastAndCleanup.first, lhs, + allowRealloc, + allowRealloc ? keepLhsLength : false, + /*temporary_lhs=*/true); if (rhsCastAndCleanup.second) (*rhsCastAndCleanup.second)(); }; diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp index b528544..d4c535d 100644 --- a/flang/lib/Lower/ConvertProcedureDesignator.cpp +++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp @@ -49,7 +49,7 @@ fir::ExtendedValue Fortran::lower::convertProcedureDesignator( fir::getUnrestrictedIntrinsicSymbolRefAttr(builder, loc, genericName, signature); mlir::Value funcPtr = - builder.create<fir::AddrOfOp>(loc, signature, symbolRefAttr); + fir::AddrOfOp::create(builder, loc, signature, symbolRefAttr); return funcPtr; } const Fortran::semantics::Symbol *symbol = proc.GetSymbol(); @@ -69,7 +69,7 @@ fir::ExtendedValue Fortran::lower::convertProcedureDesignator( Fortran::lower::getOrDeclareFunction(proc, converter); mlir::SymbolRefAttr nameAttr = builder.getSymbolRefAttr(func.getSymName()); funcPtr = - builder.create<fir::AddrOfOp>(loc, func.getFunctionType(), nameAttr); + fir::AddrOfOp::create(builder, loc, func.getFunctionType(), nameAttr); } if (Fortran::lower::mustPassLengthWithDummyProcedure(proc, converter)) { // The result length, if available here, must be propagated along the @@ -114,7 +114,7 @@ static hlfir::EntityWithAttributes designateProcedurePointerComponent( /// Passed argument may be a descriptor. This is a scalar reference, so the /// base address can be directly addressed. if (mlir::isa<fir::BaseBoxType>(base.getType())) - base = builder.create<fir::BoxAddrOp>(loc, base); + base = fir::BoxAddrOp::create(builder, loc, base); std::string fieldName = converter.getRecordTypeFieldName(procComponentSym); auto recordType = mlir::cast<fir::RecordType>(hlfir::getFortranElementType(base.getType())); @@ -124,8 +124,8 @@ static hlfir::EntityWithAttributes designateProcedurePointerComponent( if (!fieldType) TODO(loc, "passing type bound procedure (extension)"); mlir::Type designatorType = fir::ReferenceType::get(fieldType); - mlir::Value compRef = builder.create<hlfir::DesignateOp>( - loc, designatorType, base, fieldName, + mlir::Value compRef = hlfir::DesignateOp::create( + builder, loc, designatorType, base, fieldName, /*compShape=*/mlir::Value{}, hlfir::DesignateOp::Subscripts{}, /*substring=*/mlir::ValueRange{}, /*complexPart=*/std::nullopt, @@ -174,10 +174,10 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR( mlir::Type boxTy = Fortran::lower::getUntypedBoxProcType(&converter.getMLIRContext()); if (auto host = Fortran::lower::argumentHostAssocs(converter, funcAddr)) - funcAddr = builder.create<fir::EmboxProcOp>( - loc, boxTy, llvm::ArrayRef<mlir::Value>{funcAddr, host}); + funcAddr = fir::EmboxProcOp::create( + builder, loc, boxTy, llvm::ArrayRef<mlir::Value>{funcAddr, host}); else - funcAddr = builder.create<fir::EmboxProcOp>(loc, boxTy, funcAddr); + funcAddr = fir::EmboxProcOp::create(builder, loc, boxTy, funcAddr); } mlir::Value res = procExv.match( diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index cacf4e2..647bd0d 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -312,8 +312,8 @@ mlir::Value Fortran::lower::genInitialDataTarget( // initial value of the descriptor). // Create a fir.rebox to set the attribute correctly, and use targetShift // to preserve the target lower bounds if any. - return builder.create<fir::ReboxOp>(loc, boxType, targetBox, targetShift, - /*slice=*/mlir::Value{}); + return fir::ReboxOp::create(builder, loc, boxType, targetBox, targetShift, + /*slice=*/mlir::Value{}); } /// Generate default initial value for a derived type object \p sym with mlir @@ -362,7 +362,7 @@ static mlir::Value genComponentDefaultInit( } else { // Component has no initial value. Set its bits to zero by extension // to match what is expected because other compilers are doing it. - componentValue = builder.create<fir::ZeroOp>(loc, componentTy); + componentValue = fir::ZeroOp::create(builder, loc, componentTy); } } else if (const auto *proc{ component @@ -377,17 +377,17 @@ static mlir::Value genComponentDefaultInit( componentValue = fir::factory::createNullBoxProc(builder, loc, componentTy); } else - componentValue = builder.create<fir::ZeroOp>(loc, componentTy); + componentValue = fir::ZeroOp::create(builder, loc, componentTy); } assert(componentValue && "must have been computed"); componentValue = builder.createConvert(loc, componentTy, componentValue); auto fieldTy = fir::FieldType::get(recTy.getContext()); // FIXME: type parameters must come from the derived-type-spec - auto field = builder.create<fir::FieldIndexOp>( - loc, fieldTy, name, recTy, - /*typeParams=*/mlir::ValueRange{} /*TODO*/); - return builder.create<fir::InsertValueOp>( - loc, recTy, insertInto, componentValue, + auto field = + fir::FieldIndexOp::create(builder, loc, fieldTy, name, recTy, + /*typeParams=*/mlir::ValueRange{} /*TODO*/); + return fir::InsertValueOp::create( + builder, loc, recTy, insertInto, componentValue, builder.getArrayAttr(field.getAttributes())); } @@ -405,7 +405,7 @@ static mlir::Value genDefaultInitializerValue( // Build a scalar default value of the symbol type, looping through the // components to build each component initial value. auto recTy = mlir::cast<fir::RecordType>(scalarType); - mlir::Value initialValue = builder.create<fir::UndefOp>(loc, scalarType); + mlir::Value initialValue = fir::UndefOp::create(builder, loc, scalarType); const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType(); assert(declTy && "var with default initialization must have a type"); @@ -444,7 +444,7 @@ static mlir::Value genDefaultInitializerValue( if (sequenceType) { // For arrays, duplicate the scalar value to all elements with an // fir.insert_range covering the whole array. - auto arrayInitialValue = builder.create<fir::UndefOp>(loc, sequenceType); + auto arrayInitialValue = fir::UndefOp::create(builder, loc, sequenceType); llvm::SmallVector<int64_t> rangeBounds; for (int64_t extent : sequenceType.getShape()) { if (extent == fir::SequenceType::getUnknownExtent()) @@ -453,8 +453,8 @@ static mlir::Value genDefaultInitializerValue( rangeBounds.push_back(0); rangeBounds.push_back(extent - 1); } - return builder.create<fir::InsertOnRangeOp>( - loc, sequenceType, arrayInitialValue, initialValue, + return fir::InsertOnRangeOp::create( + builder, loc, sequenceType, arrayInitialValue, initialValue, builder.getIndexVectorAttr(rangeBounds)); } return initialValue; @@ -546,7 +546,7 @@ fir::GlobalOp Fortran::lower::defineGlobal( createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) { mlir::Value box = Fortran::lower::genInitialDataTarget(converter, loc, symTy, expr); - b.create<fir::HasValueOp>(loc, box); + fir::HasValueOp::create(b, loc, box); }); } else { // Create unallocated/disassociated descriptor if no explicit init @@ -555,7 +555,7 @@ fir::GlobalOp Fortran::lower::defineGlobal( b, loc, symTy, /*nonDeferredParams=*/{}, /*typeSourceBox=*/{}, getAllocatorIdxFromDataAttr(dataAttr)); - b.create<fir::HasValueOp>(loc, box); + fir::HasValueOp::create(b, loc, box); }); } } else if (const auto *details = @@ -569,7 +569,7 @@ fir::GlobalOp Fortran::lower::defineGlobal( converter, loc, details->init().value(), stmtCtx); mlir::Value castTo = builder.createConvert(loc, symTy, fir::getBase(initVal)); - builder.create<fir::HasValueOp>(loc, castTo); + fir::HasValueOp::create(builder, loc, castTo); }); } else if (Fortran::lower::hasDefaultInitialization(sym)) { createGlobalInitialization( @@ -579,7 +579,7 @@ fir::GlobalOp Fortran::lower::defineGlobal( mlir::Value initVal = genDefaultInitializerValue(converter, loc, sym, symTy, stmtCtx); mlir::Value castTo = builder.createConvert(loc, symTy, initVal); - builder.create<fir::HasValueOp>(loc, castTo); + fir::HasValueOp::create(builder, loc, castTo); }); } } else if (Fortran::semantics::IsProcedurePointer(sym)) { @@ -594,19 +594,19 @@ fir::GlobalOp Fortran::lower::defineGlobal( auto box{Fortran::lower::convertProcedureDesignatorInitialTarget( converter, loc, *sym)}; auto castTo{builder.createConvert(loc, symTy, box)}; - b.create<fir::HasValueOp>(loc, castTo); + fir::HasValueOp::create(b, loc, castTo); }); else { // Has NULL() target. createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) { auto box{fir::factory::createNullBoxProc(b, loc, symTy)}; - b.create<fir::HasValueOp>(loc, box); + fir::HasValueOp::create(b, loc, box); }); } } else { // No initialization. createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) { auto box{fir::factory::createNullBoxProc(b, loc, symTy)}; - b.create<fir::HasValueOp>(loc, box); + fir::HasValueOp::create(b, loc, box); }); } } else if (sym.has<Fortran::semantics::CommonBlockDetails>()) { @@ -632,10 +632,10 @@ fir::GlobalOp Fortran::lower::defineGlobal( builder, global, [&](fir::FirOpBuilder &builder) { mlir::Value initValue; if (converter.getLoweringOptions().getInitGlobalZero()) - initValue = builder.create<fir::ZeroOp>(loc, symTy); + initValue = fir::ZeroOp::create(builder, loc, symTy); else - initValue = builder.create<fir::UndefOp>(loc, symTy); - builder.create<fir::HasValueOp>(loc, initValue); + initValue = fir::UndefOp::create(builder, loc, symTy); + fir::HasValueOp::create(builder, loc, initValue); }); } // Set public visibility to prevent global definition to be optimized out @@ -690,8 +690,8 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter, sym); global = defineGlobal(converter, var, globalName, linkage, dataAttr); } - auto addrOf = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + auto addrOf = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); // The type of the global cannot be trusted to be the same as the one // of the variable as some existing programs map common blocks to // BIND(C) module variables (e.g. mpi_argv_null in MPI and MPI_F08). @@ -752,7 +752,7 @@ static mlir::Value createNewLocal(Fortran::lower::AbstractConverter &converter, // would be a waste of space, and incorrect if the pointee is a non dummy // assumed-size (possible with cray pointee). if (ultimateSymbol.test(Fortran::semantics::Symbol::Flag::CrayPointee)) - return builder.create<fir::ZeroOp>(loc, fir::ReferenceType::get(ty)); + return fir::ZeroOp::create(builder, loc, fir::ReferenceType::get(ty)); if (needCUDAAlloc(ultimateSymbol)) { cuf::DataAttributeAttr dataAttr = @@ -767,12 +767,12 @@ static mlir::Value createNewLocal(Fortran::lower::AbstractConverter &converter, for (mlir::Value sh : elidedShape) indices.push_back(builder.createConvert(loc, idxTy, sh)); if (dataAttr.getValue() == cuf::DataAttribute::Shared) - return builder.create<cuf::SharedMemoryOp>(loc, ty, nm, symNm, lenParams, - indices); + return cuf::SharedMemoryOp::create(builder, loc, ty, nm, symNm, lenParams, + indices); if (!cuf::isCUDADeviceContext(builder.getRegion())) - return builder.create<cuf::AllocOp>(loc, ty, nm, symNm, dataAttr, - lenParams, indices); + return cuf::AllocOp::create(builder, loc, ty, nm, symNm, dataAttr, + lenParams, indices); } // Let the builder do all the heavy lifting. @@ -782,7 +782,7 @@ static mlir::Value createNewLocal(Fortran::lower::AbstractConverter &converter, // Local procedure pointer. auto res{builder.allocateLocal(loc, ty, nm, symNm, shape, lenParams, isTarg)}; auto box{fir::factory::createNullBoxProc(builder, loc, ty)}; - builder.create<fir::StoreOp>(loc, box, res); + fir::StoreOp::create(builder, loc, box, res); return res; } @@ -833,9 +833,9 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter, // Field found in the base record type. auto fieldName = recTy.getTypeList()[fieldIdx].first; fieldTy = recTy.getTypeList()[fieldIdx].second; - mlir::Value fieldIndex = builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(fieldTy.getContext()), fieldName, - recTy, + mlir::Value fieldIndex = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(fieldTy.getContext()), + fieldName, recTy, /*typeParams=*/mlir::ValueRange{}); coordinates.push_back(fieldIndex); } else { @@ -846,19 +846,18 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter, mlir::dyn_cast<fir::RecordType>(component.second)) { fieldIdx = childRecTy.getFieldIndex(sym.name().ToString()); if (fieldIdx != std::numeric_limits<unsigned>::max()) { - mlir::Value parentFieldIndex = - builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(childRecTy.getContext()), - component.first, recTy, - /*typeParams=*/mlir::ValueRange{}); + mlir::Value parentFieldIndex = fir::FieldIndexOp::create( + builder, loc, + fir::FieldType::get(childRecTy.getContext()), + component.first, recTy, + /*typeParams=*/mlir::ValueRange{}); coordinates.push_back(parentFieldIndex); auto fieldName = childRecTy.getTypeList()[fieldIdx].first; fieldTy = childRecTy.getTypeList()[fieldIdx].second; - mlir::Value childFieldIndex = - builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(fieldTy.getContext()), - fieldName, childRecTy, - /*typeParams=*/mlir::ValueRange{}); + mlir::Value childFieldIndex = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(fieldTy.getContext()), + fieldName, childRecTy, + /*typeParams=*/mlir::ValueRange{}); coordinates.push_back(childFieldIndex); break; } @@ -873,25 +872,25 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter, mlir::Value base = fir::getBase(exv); mlir::Value comp; if (mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(base.getType()))) { - mlir::Value box = builder.create<fir::LoadOp>(loc, base); - mlir::Value addr = builder.create<fir::BoxAddrOp>(loc, box); + mlir::Value box = fir::LoadOp::create(builder, loc, base); + mlir::Value addr = fir::BoxAddrOp::create(builder, loc, box); llvm::SmallVector<mlir::Value> lenParams; assert(coordinates.size() == 1 && "expect one coordinate"); auto field = mlir::dyn_cast<fir::FieldIndexOp>( coordinates[0].getDefiningOp()); - comp = builder.create<hlfir::DesignateOp>( - loc, builder.getRefType(fieldTy), addr, + comp = hlfir::DesignateOp::create( + builder, loc, builder.getRefType(fieldTy), addr, /*component=*/field.getFieldName(), /*componentShape=*/mlir::Value{}, hlfir::DesignateOp::Subscripts{}); } else { - comp = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(fieldTy), base, coordinates); + comp = fir::CoordinateOp::create( + builder, loc, builder.getRefType(fieldTy), base, coordinates); } cuf::DataAttributeAttr dataAttr = Fortran::lower::translateSymbolCUFDataAttribute( builder.getContext(), sym); - builder.create<cuf::SetAllocatorIndexOp>(loc, comp, dataAttr); + cuf::SetAllocatorIndexOp::create(builder, loc, comp, dataAttr); } } } @@ -933,8 +932,8 @@ void Fortran::lower::defaultInitializeAtRuntime( // 15.5.2.12 point 3, absent optional dummies are not initialized. // Creating descriptor/passing null descriptor to the runtime would // create runtime crashes. - auto isPresent = builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(exv)); + auto isPresent = fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(exv)); builder.genIfThen(loc, isPresent) .genThen([&]() { auto box = builder.createBox(loc, exv); @@ -976,7 +975,7 @@ void Fortran::lower::defaultInitializeAtRuntime( converter, loc, details->init().value(), stmtCtx); mlir::Value castTo = builder.createConvert(loc, symTy, fir::getBase(initVal)); - builder.create<fir::HasValueOp>(loc, castTo); + fir::HasValueOp::create(builder, loc, castTo); }); } else if (!global) { global = builder.createGlobal(loc, symTy, globalName, linkage, @@ -991,13 +990,13 @@ void Fortran::lower::defaultInitializeAtRuntime( mlir::Value initVal = genDefaultInitializerValue( converter, loc, sym, symTy, stmtCtx); mlir::Value castTo = builder.createConvert(loc, symTy, initVal); - builder.create<fir::HasValueOp>(loc, castTo); + fir::HasValueOp::create(builder, loc, castTo); }); } - auto addrOf = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); - builder.create<fir::CopyOp>(loc, addrOf, fir::getBase(exv), - /*noOverlap=*/true); + auto addrOf = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); + fir::CopyOp::create(builder, loc, addrOf, fir::getBase(exv), + /*noOverlap=*/true); } else { mlir::Value box = builder.createBox(loc, exv); fir::runtime::genDerivedTypeInitialize(builder, loc, box); @@ -1097,8 +1096,8 @@ static void finalizeAtRuntime(Fortran::lower::AbstractConverter &converter, fir::ExtendedValue exv = converter.getSymbolExtendedValue(sym, &symMap); if (Fortran::semantics::IsOptional(sym)) { // Only finalize if present. - auto isPresent = builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(exv)); + auto isPresent = fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(exv)); builder.genIfThen(loc, isPresent) .genThen([&]() { auto box = builder.createBox(loc, exv); @@ -1144,8 +1143,8 @@ static void deallocateIntentOut(Fortran::lower::AbstractConverter &converter, fir::FirOpBuilder &builder = converter.getFirOpBuilder(); if (Fortran::semantics::IsOptional(sym)) { - auto isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), fir::getBase(extVal)); + auto isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), fir::getBase(extVal)); builder.genIfThen(loc, isPresent) .genThen([&]() { Fortran::lower::genDeallocateIfAllocated(converter, *mutBox, loc); @@ -1358,7 +1357,7 @@ static fir::GlobalOp defineGlobalAggregateStore( Fortran::lower::StatementContext stmtCtx; mlir::Value initVal = fir::getBase(genInitializerExprValue( converter, loc, objectDetails->init().value(), stmtCtx)); - builder.create<fir::HasValueOp>(loc, initVal); + fir::HasValueOp::create(builder, loc, initVal); }); return global; } @@ -1367,8 +1366,8 @@ static fir::GlobalOp defineGlobalAggregateStore( // of the linkage. createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &builder) { Fortran::lower::StatementContext stmtCtx; - mlir::Value initVal = builder.create<fir::ZeroOp>(loc, aggTy); - builder.create<fir::HasValueOp>(loc, initVal); + mlir::Value initVal = fir::ZeroOp::create(builder, loc, aggTy); + fir::HasValueOp::create(builder, loc, initVal); }); return global; } @@ -1418,8 +1417,8 @@ instantiateAggregateStore(Fortran::lower::AbstractConverter &converter, global = defineGlobalAggregateStore(converter, aggregate, aggName, linkage); } - auto addr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + auto addr = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); auto size = std::get<1>(var.getInterval()); fir::SequenceType::Shape shape(1, size); auto seqTy = fir::SequenceType::get(shape, i8Ty); @@ -1466,8 +1465,8 @@ static void instantiateAlias(Fortran::lower::AbstractConverter &converter, std::size_t off = sym.GetUltimate().offset() - var.getAliasOffset(); mlir::Value storeAddr = getAggregateStore(storeMap, var); mlir::Value offset = builder.createIntegerConstant(loc, idxTy, off); - mlir::Value bytePtr = builder.create<fir::CoordinateOp>( - loc, i8Ptr, storeAddr, mlir::ValueRange{offset}); + mlir::Value bytePtr = fir::CoordinateOp::create( + builder, loc, i8Ptr, storeAddr, mlir::ValueRange{offset}); mlir::Value typedPtr = castAliasToPointer(builder, loc, symType, bytePtr); Fortran::lower::StatementContext stmtCtx; mapSymbolAttributes(converter, var, symMap, stmtCtx, typedPtr); @@ -1656,7 +1655,7 @@ static void finalizeCommonBlockDefinition( mlir::TupleType commonTy = mlir::cast<mlir::TupleType>(global.getType()); auto initFunc = [&](fir::FirOpBuilder &builder) { mlir::IndexType idxTy = builder.getIndexType(); - mlir::Value cb = builder.create<fir::ZeroOp>(loc, commonTy); + mlir::Value cb = fir::ZeroOp::create(builder, loc, commonTy); unsigned tupIdx = 0; std::size_t offset = 0; LLVM_DEBUG(llvm::dbgs() << "block {\n"); @@ -1680,15 +1679,15 @@ static void finalizeCommonBlockDefinition( mlir::IntegerAttr offVal = builder.getIntegerAttr(idxTy, tupIdx); mlir::Value castVal = builder.createConvert( loc, commonTy.getType(tupIdx), fir::getBase(initVal)); - cb = builder.create<fir::InsertValueOp>(loc, commonTy, cb, castVal, - builder.getArrayAttr(offVal)); + cb = fir::InsertValueOp::create(builder, loc, commonTy, cb, castVal, + builder.getArrayAttr(offVal)); ++tupIdx; offset = mem->offset() + mem->size(); } } } LLVM_DEBUG(llvm::dbgs() << "}\n"); - builder.create<fir::HasValueOp>(loc, cb); + fir::HasValueOp::create(builder, loc, cb); }; createGlobalInitialization(builder, global, initFunc); } @@ -1722,8 +1721,8 @@ mlir::Value Fortran::lower::genCommonBlockMember( mlir::Value offs = builder.createIntegerConstant(loc, builder.getIndexType(), byteOffset); - mlir::Value varAddr = builder.create<fir::CoordinateOp>( - loc, i8Ptr, base, mlir::ValueRange{offs}); + mlir::Value varAddr = fir::CoordinateOp::create(builder, loc, i8Ptr, base, + mlir::ValueRange{offs}); mlir::Type symType = converter.genType(sym); return Fortran::semantics::FindEquivalenceSet(sym) != nullptr @@ -1748,8 +1747,8 @@ static void instantiateCommon(Fortran::lower::AbstractConverter &converter, if (!commonAddr) { // introduce a local AddrOf and add it to the map fir::GlobalOp global = getCommonBlockGlobal(converter, common); - commonAddr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + commonAddr = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); symMap.addSymbol(common, commonAddr); } @@ -2031,8 +2030,8 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter, Fortran::semantics::GetCUDADataAttr(&sym.GetUltimate())); // Declare a local pointer variable. - auto newBase = builder.create<hlfir::DeclareOp>( - loc, boxAlloc, name, /*shape=*/nullptr, lenParams, + auto newBase = hlfir::DeclareOp::create( + builder, loc, boxAlloc, name, /*shape=*/nullptr, lenParams, /*dummy_scope=*/nullptr, attributes); mlir::Value nullAddr = builder.createNullConstant( loc, llvm::cast<fir::BaseBoxType>(ptrBoxType).getEleTy()); @@ -2047,9 +2046,9 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter, // Inherit the shape (and maybe length parameters) from the pointee // declaration. mlir::Value initVal = - builder.create<fir::EmboxOp>(loc, ptrBoxType, nullAddr, shapeOrShift, - /*slice=*/nullptr, lenParams); - builder.create<fir::StoreOp>(loc, initVal, newBase.getBase()); + fir::EmboxOp::create(builder, loc, ptrBoxType, nullAddr, shapeOrShift, + /*slice=*/nullptr, lenParams); + fir::StoreOp::create(builder, loc, initVal, newBase.getBase()); // Any reference to the pointee is going to be using the pointer // box from now on. The base_addr of the descriptor must be updated @@ -2063,9 +2062,9 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter, mlir::Value dummyScope; if (converter.isRegisteredDummySymbol(sym)) dummyScope = converter.dummyArgsScopeValue(); - auto newBase = builder.create<hlfir::DeclareOp>( - loc, base, name, shapeOrShift, lenParams, dummyScope, attributes, - dataAttr); + auto newBase = + hlfir::DeclareOp::create(builder, loc, base, name, shapeOrShift, + lenParams, dummyScope, attributes, dataAttr); symMap.addVariableDefinition(sym, newBase, force); return; } @@ -2214,7 +2213,7 @@ void Fortran::lower::mapSymbolAttributes( // Additional discussion below. mlir::Type dummyProcType = Fortran::lower::getDummyProcedureType(sym, converter); - mlir::Value undefOp = builder.create<fir::UndefOp>(loc, dummyProcType); + mlir::Value undefOp = fir::UndefOp::create(builder, loc, dummyProcType); Fortran::lower::genDeclareSymbol(converter, symMap, sym, undefOp); } @@ -2304,32 +2303,32 @@ void Fortran::lower::mapSymbolAttributes( mlir::Type lenType = builder.getCharacterLengthType(); mlir::Value addr, len; if (Fortran::semantics::IsOptional(sym)) { - auto isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), dummyArg); + auto isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), dummyArg); auto addrAndLen = builder .genIfOp(loc, {refTy, lenType}, isPresent, /*withElseRegion=*/true) .genThen([&]() { mlir::Value readAddr = - builder.create<fir::BoxAddrOp>(loc, refTy, dummyArg); + fir::BoxAddrOp::create(builder, loc, refTy, dummyArg); mlir::Value readLength = charHelp.readLengthFromBox(dummyArg); - builder.create<fir::ResultOp>( - loc, mlir::ValueRange{readAddr, readLength}); + fir::ResultOp::create( + builder, loc, mlir::ValueRange{readAddr, readLength}); }) .genElse([&] { mlir::Value readAddr = builder.genAbsentOp(loc, refTy); mlir::Value readLength = fir::factory::createZeroValue(builder, loc, lenType); - builder.create<fir::ResultOp>( - loc, mlir::ValueRange{readAddr, readLength}); + fir::ResultOp::create( + builder, loc, mlir::ValueRange{readAddr, readLength}); }) .getResults(); addr = addrAndLen[0]; len = addrAndLen[1]; } else { - addr = builder.create<fir::BoxAddrOp>(loc, refTy, dummyArg); + addr = fir::BoxAddrOp::create(builder, loc, refTy, dummyArg); len = charHelp.readLengthFromBox(dummyArg); } if (!explicitParams.empty()) @@ -2428,7 +2427,7 @@ void Fortran::lower::mapSymbolAttributes( mlir::Value dim = builder.createIntegerConstant(loc, idxTy, iter.index()); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim); shapes.emplace_back(dimInfo.getResult(1)); } else if (spec->ubound().isStar()) { shapes.emplace_back(getAssumedSizeExtent(loc, builder)); @@ -2452,7 +2451,7 @@ void Fortran::lower::mapSymbolAttributes( mlir::Value dim = builder.createIntegerConstant(loc, idxTy, iter.index()); dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim); extents.emplace_back(dimInfo.getResult(1)); if (auto low = spec->lbound().GetExplicit()) { auto expr = Fortran::lower::SomeExpr{*low}; @@ -2501,7 +2500,7 @@ void Fortran::lower::mapSymbolAttributes( if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(arg.getType())) { // Contiguous assumed shape that can be tracked without a fir.box. mlir::Type refTy = builder.getRefType(boxTy.getEleTy()); - addr = builder.create<fir::BoxAddrOp>(loc, refTy, arg); + addr = fir::BoxAddrOp::create(builder, loc, refTy, arg); } // Compute/Extract character length. @@ -2512,8 +2511,8 @@ void Fortran::lower::mapSymbolAttributes( std::tie(addr, len) = charHelp.createUnboxChar(arg); } else if (mlir::isa<fir::CharacterType>(arg.getType())) { // fir.char<1> passed by value (BIND(C) with VALUE attribute). - addr = builder.create<fir::AllocaOp>(loc, arg.getType()); - builder.create<fir::StoreOp>(loc, arg, addr); + addr = fir::AllocaOp::create(builder, loc, arg.getType()); + fir::StoreOp::create(builder, loc, arg, addr); } else if (!addr) { addr = arg; } @@ -2583,7 +2582,7 @@ void Fortran::lower::mapSymbolAttributes( // Dummy argument passed in register. Place the value in memory at that // point since lowering expect symbols to be mapped to memory addresses. mlir::Type symType = converter.genType(sym); - addr = builder.create<fir::AllocaOp>(loc, symType); + addr = fir::AllocaOp::create(builder, loc, symType); if (isCptrByVal) { // Place the void* address into the CPTR address component. mlir::Value addrComponent = @@ -2803,8 +2802,8 @@ Fortran::lower::genPackArray(Fortran::lower::AbstractConverter &converter, mlir::Type elementType = boxType.unwrapInnerType(); llvm::SmallVector<mlir::Value> elidedLenParams = fir::factory::elideLengthsAlreadyInType(elementType, lenParams); - auto packOp = builder.create<fir::PackArrayOp>( - loc, fir::getBase(exv), stackAlloc, isInnermostMode, noCopy, + auto packOp = fir::PackArrayOp::create( + builder, loc, fir::getBase(exv), stackAlloc, isInnermostMode, noCopy, /*max_size=*/mlir::IntegerAttr{}, /*max_element_size=*/mlir::IntegerAttr{}, /*min_stride=*/mlir::IntegerAttr{}, fir::PackArrayHeuristics::None, @@ -2842,6 +2841,6 @@ void Fortran::lower::genUnpackArray( // Avoid copy-out for 'intent(in)' variables. bool noCopy = Fortran::semantics::IsIntentIn(sym); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - builder.create<fir::UnpackArrayOp>(loc, temp, original, stackAlloc, noCopy, - getSafeRepackAttrs(converter)); + fir::UnpackArrayOp::create(builder, loc, temp, original, stackAlloc, noCopy, + getSafeRepackAttrs(converter)); } diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp index 30c6ce7..2c5233bd 100644 --- a/flang/lib/Lower/CustomIntrinsicCall.cpp +++ b/flang/lib/Lower/CustomIntrinsicCall.cpp @@ -101,7 +101,7 @@ Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value addr = fir::getBase(result); if (auto *box = result.getBoxOf<fir::BoxValue>()) addr = - builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), box->getAddr()); + fir::BoxAddrOp::create(builder, loc, box->getMemTy(), box->getAddr()); fir::FirOpBuilder *bldr = &builder; stmtCtx.attachCleanup([=]() { bldr->create<fir::FreeMemOp>(loc, addr); }); } @@ -171,9 +171,9 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc, args.emplace_back(getOperand(opIndex, loadOperand)); fir::ExtendedValue newExtremum = genIntrinsicCall( builder, loc, name, resultType, args, stmtCtx); - builder.create<fir::ResultOp>(loc, fir::getBase(newExtremum)); + fir::ResultOp::create(builder, loc, fir::getBase(newExtremum)); }) - .genElse([&]() { builder.create<fir::ResultOp>(loc, extremum); }) + .genElse([&]() { fir::ResultOp::create(builder, loc, extremum); }) .getResults()[0]; } else { // Argument is know to be present at compile time. @@ -235,13 +235,13 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc, fir::ExtendedValue sizeExv = getOperand(2, loadOperand); mlir::Value size = builder.createConvert(loc, resultType, fir::getBase(sizeExv)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .genElse([&]() { mlir::Value bitSize = builder.createIntegerConstant( loc, resultType, mlir::cast<mlir::IntegerType>(resultType).getWidth()); - builder.create<fir::ResultOp>(loc, bitSize); + fir::ResultOp::create(builder, loc, bitSize); }) .getResults()[0]); return genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx); @@ -280,7 +280,7 @@ lowerAssociated(fir::FirOpBuilder &builder, mlir::Location loc, // while the optionality of the target pointer/allocatable is what must be // checked here. mlir::Value isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), targetBase); + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), targetBase); mlir::Type targetType = fir::unwrapRefType(targetBase.getType()); mlir::Type targetValueType = fir::unwrapPassByRefType(targetType); mlir::Type boxType = mlir::isa<fir::BaseBoxType>(targetType) @@ -293,11 +293,12 @@ lowerAssociated(fir::FirOpBuilder &builder, mlir::Location loc, .genThen([&]() { mlir::Value box = builder.createBox(loc, targetExv); mlir::Value cast = builder.createConvert(loc, boxType, box); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { - mlir::Value absentBox = builder.create<fir::AbsentOp>(loc, boxType); - builder.create<fir::ResultOp>(loc, absentBox); + mlir::Value absentBox = + fir::AbsentOp::create(builder, loc, boxType); + fir::ResultOp::create(builder, loc, absentBox); }) .getResults()[0]; args.emplace_back(std::move(targetBox)); diff --git a/flang/lib/Lower/HlfirIntrinsics.cpp b/flang/lib/Lower/HlfirIntrinsics.cpp index 8b96b20..6e1d06a 100644 --- a/flang/lib/Lower/HlfirIntrinsics.cpp +++ b/flang/lib/Lower/HlfirIntrinsics.cpp @@ -63,7 +63,7 @@ protected: template <typename OP, typename... BUILD_ARGS> inline OP createOp(BUILD_ARGS... args) { - return builder.create<OP>(loc, args...); + return OP::create(builder, loc, args...); } mlir::Value loadBoxAddress( @@ -195,7 +195,7 @@ mlir::Value HlfirTransformationalIntrinsic::loadBoxAddress( // this is a box address type but is not dynamically optional. Just load // the box, assuming it is well formed (!fir.ref<!fir.box<...>> -> // !fir.box<...>) - return builder.create<fir::LoadOp>(loc, actual.getBase()); + return fir::LoadOp::create(builder, loc, actual.getBase()); } return actual; } @@ -209,9 +209,9 @@ mlir::Value HlfirTransformationalIntrinsic::loadBoxAddress( // ensures it won't be. mlir::Value box = builder.createBox(loc, exv); mlir::Type boxType = box.getType(); - auto absent = builder.create<fir::AbsentOp>(loc, boxType); - auto boxOrAbsent = builder.create<mlir::arith::SelectOp>( - loc, boxType, isPresent, box, absent); + auto absent = fir::AbsentOp::create(builder, loc, boxType); + auto boxOrAbsent = mlir::arith::SelectOp::create(builder, loc, boxType, + isPresent, box, absent); return boxOrAbsent; } @@ -232,11 +232,11 @@ static mlir::Value loadOptionalValue( assert(actual.isScalar() && fir::isa_trivial(eleType) && "must be a numerical or logical scalar"); hlfir::Entity val = hlfir::loadTrivialScalar(loc, builder, actual); - builder.create<fir::ResultOp>(loc, val); + fir::ResultOp::create(builder, loc, val); }) .genElse([&]() { mlir::Value zero = fir::factory::createZeroValue(builder, loc, eleType); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp index 95ea74b..2a330cc 100644 --- a/flang/lib/Lower/HostAssociations.cpp +++ b/flang/lib/Lower/HostAssociations.cpp @@ -165,7 +165,7 @@ public: assert(typeInTuple && "addrInTuple must be an address"); mlir::Value castBox = builder.createConvertWithVolatileCast( args.loc, typeInTuple, fir::getBase(args.hostValue)); - builder.create<fir::StoreOp>(args.loc, castBox, args.addrInTuple); + fir::StoreOp::create(builder, args.loc, castBox, args.addrInTuple); } static void getFromTuple(const GetFromTuple &args, @@ -196,7 +196,7 @@ public: assert(typeInTuple && "addrInTuple must be an address"); mlir::Value castBox = builder.createConvertWithVolatileCast( args.loc, typeInTuple, fir::getBase(args.hostValue)); - builder.create<fir::StoreOp>(args.loc, castBox, args.addrInTuple); + fir::StoreOp::create(builder, args.loc, castBox, args.addrInTuple); } static void getFromTuple(const GetFromTuple &args, @@ -231,7 +231,7 @@ public: fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Value boxchar = fir::factory::CharacterExprHelper(builder, args.loc) .createEmbox(*charBox); - builder.create<fir::StoreOp>(args.loc, boxchar, args.addrInTuple); + fir::StoreOp::create(builder, args.loc, boxchar, args.addrInTuple); } static void getFromTuple(const GetFromTuple &args, @@ -269,20 +269,20 @@ public: args.loc, typeInTuple, fir::getBase(args.hostValue)); if (Fortran::semantics::IsOptional(sym)) { auto isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), castBox); + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), castBox); builder.genIfThenElse(loc, isPresent) .genThen([&]() { - builder.create<fir::StoreOp>(loc, castBox, args.addrInTuple); + fir::StoreOp::create(builder, loc, castBox, args.addrInTuple); }) .genElse([&]() { mlir::Value null = fir::factory::createUnallocatedBox( builder, loc, typeInTuple, /*nonDeferredParams=*/mlir::ValueRange{}); - builder.create<fir::StoreOp>(loc, null, args.addrInTuple); + fir::StoreOp::create(builder, loc, null, args.addrInTuple); }) .end(); } else { - builder.create<fir::StoreOp>(loc, castBox, args.addrInTuple); + fir::StoreOp::create(builder, loc, castBox, args.addrInTuple); } } static void getFromTuple(const GetFromTuple &args, @@ -297,11 +297,11 @@ public: auto eleTy = boxTy.getEleTy(); if (!fir::isa_ref_type(eleTy)) eleTy = builder.getRefType(eleTy); - auto addr = builder.create<fir::BoxAddrOp>(loc, eleTy, box); + auto addr = fir::BoxAddrOp::create(builder, loc, eleTy, box); mlir::Value isPresent = builder.genIsNotNullAddr(loc, addr); - auto absentBox = builder.create<fir::AbsentOp>(loc, boxTy); - box = - builder.create<mlir::arith::SelectOp>(loc, isPresent, box, absentBox); + auto absentBox = fir::AbsentOp::create(builder, loc, boxTy); + box = mlir::arith::SelectOp::create(builder, loc, isPresent, box, + absentBox); } bindCapturedSymbol(sym, box, converter, args.symMap); } @@ -331,7 +331,7 @@ public: assert(typeInTuple && "addrInTuple must be an address"); mlir::Value castBox = builder.createConvertWithVolatileCast( args.loc, typeInTuple, fir::getBase(args.hostValue)); - builder.create<fir::StoreOp>(args.loc, castBox, args.addrInTuple); + fir::StoreOp::create(builder, args.loc, castBox, args.addrInTuple); } static void getFromTuple(const GetFromTuple &args, Fortran::lower::AbstractConverter &converter, @@ -404,8 +404,8 @@ public: // done on present optional. For absent optionals, simply create a // disassociated pointer (it is illegal to inquire about lower bounds or // lengths of optional according to 15.5.2.12 3 (9) and 10.1.11 2 (7)b). - auto isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), fir::getBase(args.hostValue)); + auto isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), fir::getBase(args.hostValue)); builder.genIfThenElse(loc, isPresent) .genThen([&]() { fir::factory::associateMutableBox(builder, loc, boxInTuple, @@ -441,8 +441,8 @@ public: const unsigned rank = sym.Rank(); for (unsigned dim = 0; dim < rank; ++dim) { mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dims = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - box, dimVal); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + box, dimVal); lbounds.emplace_back(dims.getResult(0)); } } @@ -464,11 +464,11 @@ public: auto eleTy = boxTy.getEleTy(); if (!fir::isa_ref_type(eleTy)) eleTy = builder.getRefType(eleTy); - auto addr = builder.create<fir::BoxAddrOp>(loc, eleTy, box); + auto addr = fir::BoxAddrOp::create(builder, loc, eleTy, box); mlir::Value isPresent = builder.genIsNotNullAddr(loc, addr); - auto absentBox = builder.create<fir::AbsentOp>(loc, boxTy); - box = builder.create<mlir::arith::SelectOp>(loc, isPresent, box, - absentBox); + auto absentBox = fir::AbsentOp::create(builder, loc, boxTy); + box = mlir::arith::SelectOp::create(builder, loc, isPresent, box, + absentBox); } fir::BoxValue boxValue(box, lbounds, /*explicitParams=*/{}); bindCapturedSymbol(sym, boxValue, converter, args.symMap); @@ -540,7 +540,7 @@ static mlir::Value genTupleCoor(fir::FirOpBuilder &builder, mlir::Location loc, auto ty = mlir::isa<fir::ReferenceType>(varTy) ? mlir::Type(fir::LLVMPointerType::get(varTy)) : mlir::Type(builder.getRefType(varTy)); - return builder.create<fir::CoordinateOp>(loc, ty, tupleArg, offset); + return fir::CoordinateOp::create(builder, loc, ty, tupleArg, offset); } void Fortran::lower::HostAssociations::addSymbolsToBind( @@ -572,7 +572,7 @@ void Fortran::lower::HostAssociations::hostProcedureBindings( mlir::TupleType tupTy = unwrapTupleTy(getArgumentType(converter)); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Location loc = converter.getCurrentLocation(); - auto hostTuple = builder.create<fir::AllocaOp>(loc, tupTy); + auto hostTuple = fir::AllocaOp::create(builder, loc, tupTy); mlir::IntegerType offTy = builder.getIntegerType(32); // Walk the list of tupleSymbols and update the pointers in the tuple. @@ -639,7 +639,7 @@ void Fortran::lower::HostAssociations::internalProcedureBindings( mlir::Value off = builder.createIntegerConstant(loc, offTy, s.index()); mlir::Type varTy = tupTy.getType(s.index()); mlir::Value eleOff = genTupleCoor(builder, loc, varTy, tupleArg, off); - mlir::Value valueInTuple = builder.create<fir::LoadOp>(loc, eleOff); + mlir::Value valueInTuple = fir::LoadOp::create(builder, loc, eleOff); GetFromTuple getFromTuple{symMap, valueInTuple, loc}; walkCaptureCategories(getFromTuple, converter, *s.value()); } diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index 53bf619..c95c340 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -153,8 +153,8 @@ static mlir::Value genEndIO(Fortran::lower::AbstractConverter &converter, if (csi.ioMsg) { mlir::func::FuncOp getIoMsg = fir::runtime::getIORuntimeFunc<mkIOKey(GetIoMsg)>(loc, builder); - builder.create<fir::CallOp>( - loc, getIoMsg, + fir::CallOp::create( + builder, loc, getIoMsg, mlir::ValueRange{ cookie, builder.createConvert(loc, getIoMsg.getFunctionType().getInput(1), @@ -164,12 +164,12 @@ static mlir::Value genEndIO(Fortran::lower::AbstractConverter &converter, } mlir::func::FuncOp endIoStatement = fir::runtime::getIORuntimeFunc<mkIOKey(EndIoStatement)>(loc, builder); - auto call = builder.create<fir::CallOp>(loc, endIoStatement, - mlir::ValueRange{cookie}); + auto call = fir::CallOp::create(builder, loc, endIoStatement, + mlir::ValueRange{cookie}); mlir::Value iostat = call.getResult(0); if (csi.bigUnitIfOp) { stmtCtx.finalizeAndPop(); - builder.create<fir::ResultOp>(loc, iostat); + fir::ResultOp::create(builder, loc, iostat); builder.setInsertionPointAfter(csi.bigUnitIfOp); iostat = csi.bigUnitIfOp.getResult(0); } @@ -178,7 +178,7 @@ static mlir::Value genEndIO(Fortran::lower::AbstractConverter &converter, fir::getBase(converter.genExprAddr(loc, csi.ioStatExpr, stmtCtx)); mlir::Value ioStatResult = builder.createConvert(loc, converter.genType(*csi.ioStatExpr), iostat); - builder.create<fir::StoreOp>(loc, ioStatResult, ioStatVar); + fir::StoreOp::create(builder, loc, ioStatResult, ioStatVar); } return csi.hasTransferConditionSpec() ? iostat : mlir::Value{}; } @@ -203,8 +203,8 @@ static void makeNextConditionalOn(fir::FirOpBuilder &builder, mlir::IntegerType boolTy = builder.getI1Type(); if (inLoop) resTy = boolTy; - auto ifOp = builder.create<fir::IfOp>(loc, resTy, ok, - /*withElseRegion=*/inLoop); + auto ifOp = fir::IfOp::create(builder, loc, resTy, ok, + /*withElseRegion=*/inLoop); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } @@ -259,10 +259,10 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, ? fir::NameUniquer::doGenerated("default" + suffix) : converter.mangleName(suffix); if (auto table = builder.getNamedGlobal(tableMangleName)) - return builder.createConvert( - loc, refTy, - builder.create<fir::AddrOfOp>(loc, table.resultType(), - table.getSymbol())); + return builder.createConvert(loc, refTy, + fir::AddrOfOp::create(builder, loc, + table.resultType(), + table.getSymbol())); mlir::StringAttr linkOnce = builder.createLinkOnceLinkage(); mlir::Type idxTy = builder.getIndexType(); @@ -281,11 +281,12 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, // Define the list of NonTbpDefinedIo procedures. bool tableIsLocal = !definedIoProcMap.empty() && hasLocalDefinedIoProc(definedIoProcMap); - mlir::Value listAddr = - tableIsLocal ? builder.create<fir::AllocaOp>(loc, listTy) : mlir::Value{}; + mlir::Value listAddr = tableIsLocal + ? fir::AllocaOp::create(builder, loc, listTy) + : mlir::Value{}; std::string listMangleName = tableMangleName + ".list"; auto listFunc = [&](fir::FirOpBuilder &builder) { - mlir::Value list = builder.create<fir::UndefOp>(loc, listTy); + mlir::Value list = fir::UndefOp::create(builder, loc, listTy); mlir::IntegerAttr intAttr[4]; for (int i = 0; i < 4; ++i) intAttr[i] = builder.getIntegerAttr(idxTy, i); @@ -294,8 +295,8 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, int n0 = 0, n1; auto insert = [&](mlir::Value val) { idx[1] = intAttr[n1++]; - list = builder.create<fir::InsertValueOp>(loc, listTy, list, val, - builder.getArrayAttr(idx)); + list = fir::InsertValueOp::create(builder, loc, listTy, list, val, + builder.getArrayAttr(idx)); }; for (auto &iface : definedIoProcMap) { idx[0] = builder.getIntegerAttr(idxTy, n0++); @@ -305,8 +306,8 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, std::string dtName = converter.mangleName(dtSym); insert(builder.createConvert( loc, refTy, - builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(converter.genType(dtSym)), + fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(converter.genType(dtSym)), builder.getSymbolRefAttr(dtName)))); // defined IO procedure [void (*subroutine)()], may be null const Fortran::semantics::Symbol *procSym = iface.second.subroutine; @@ -316,8 +317,8 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, TODO(loc, "defined IO procedure pointers"); } else if (Fortran::semantics::IsDummy(*procSym)) { Fortran::lower::StatementContext stmtCtx; - insert(builder.create<fir::BoxAddrOp>( - loc, refTy, + insert(fir::BoxAddrOp::create( + builder, loc, refTy, fir::getBase(converter.genExprAddr( loc, Fortran::lower::SomeExpr{ @@ -330,8 +331,8 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, builder.getSymbolRefAttr(procDef.getSymName()); insert(builder.createConvert( loc, refTy, - builder.create<fir::AddrOfOp>(loc, procDef.getFunctionType(), - nameAttr))); + fir::AddrOfOp::create(builder, loc, procDef.getFunctionType(), + nameAttr))); } } else { insert(builder.createNullConstant(loc, refTy)); @@ -346,9 +347,9 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, insert(builder.createIntegerConstant(loc, byteTy, iface.second.flags)); } if (tableIsLocal) - builder.create<fir::StoreOp>(loc, list, listAddr); + fir::StoreOp::create(builder, loc, list, listAddr); else - builder.create<fir::HasValueOp>(loc, list); + fir::HasValueOp::create(builder, loc, list); }; if (!definedIoProcMap.empty()) { if (tableIsLocal) @@ -360,33 +361,34 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, // Define the NonTbpDefinedIoTable. mlir::Value tableAddr = tableIsLocal - ? builder.create<fir::AllocaOp>(loc, tableTy) + ? fir::AllocaOp::create(builder, loc, tableTy) : mlir::Value{}; auto tableFunc = [&](fir::FirOpBuilder &builder) { - mlir::Value table = builder.create<fir::UndefOp>(loc, tableTy); + mlir::Value table = fir::UndefOp::create(builder, loc, tableTy); // list item count [std::size_t items] - table = builder.create<fir::InsertValueOp>( - loc, tableTy, table, + table = fir::InsertValueOp::create( + builder, loc, tableTy, table, builder.createIntegerConstant(loc, sizeTy, definedIoProcMap.size()), builder.getArrayAttr(builder.getIntegerAttr(idxTy, 0))); // item list [const NonTbpDefinedIo *item] if (definedIoProcMap.empty()) listAddr = builder.createNullConstant(loc, builder.getRefType(listTy)); else if (fir::GlobalOp list = builder.getNamedGlobal(listMangleName)) - listAddr = builder.create<fir::AddrOfOp>(loc, list.resultType(), - list.getSymbol()); + listAddr = fir::AddrOfOp::create(builder, loc, list.resultType(), + list.getSymbol()); assert(listAddr && "missing namelist object list"); - table = builder.create<fir::InsertValueOp>( - loc, tableTy, table, listAddr, + table = fir::InsertValueOp::create( + builder, loc, tableTy, table, listAddr, builder.getArrayAttr(builder.getIntegerAttr(idxTy, 1))); // [bool ignoreNonTbpEntries] conservatively set to true - table = builder.create<fir::InsertValueOp>( - loc, tableTy, table, builder.createIntegerConstant(loc, boolTy, true), + table = fir::InsertValueOp::create( + builder, loc, tableTy, table, + builder.createIntegerConstant(loc, boolTy, true), builder.getArrayAttr(builder.getIntegerAttr(idxTy, 2))); if (tableIsLocal) - builder.create<fir::StoreOp>(loc, table, tableAddr); + fir::StoreOp::create(builder, loc, table, tableAddr); else - builder.create<fir::HasValueOp>(loc, table); + fir::HasValueOp::create(builder, loc, table); }; if (tableIsLocal) { tableFunc(builder); @@ -394,8 +396,8 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, fir::GlobalOp table = builder.createGlobal( loc, tableTy, tableMangleName, /*isConst=*/true, /*isTarget=*/false, tableFunc, linkOnce); - tableAddr = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(tableTy), table.getSymbol()); + tableAddr = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(tableTy), table.getSymbol()); } assert(tableAddr && "missing NonTbpDefinedIo table result"); return builder.createConvert(loc, refTy, tableAddr); @@ -420,8 +422,8 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, mlir::Location loc = converter.getCurrentLocation(); std::string groupMangleName = converter.mangleName(symbol); if (auto group = builder.getNamedGlobal(groupMangleName)) - return builder.create<fir::AddrOfOp>(loc, group.resultType(), - group.getSymbol()); + return fir::AddrOfOp::create(builder, loc, group.resultType(), + group.getSymbol()); const auto &details = symbol.GetUltimate().get<Fortran::semantics::NamelistDetails>(); @@ -468,18 +470,19 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, auto descFunc = [&](fir::FirOpBuilder &b) { auto box = Fortran::lower::genInitialDataTarget( converter, loc, boxTy, *expr, /*couldBeInEquivalence=*/true); - b.create<fir::HasValueOp>(loc, box); + fir::HasValueOp::create(b, loc, box); }; builder.createGlobalConstant(loc, boxTy, mangleName, descFunc, linkOnce); } } // Define the list of Items. - mlir::Value listAddr = - groupIsLocal ? builder.create<fir::AllocaOp>(loc, listTy) : mlir::Value{}; + mlir::Value listAddr = groupIsLocal + ? fir::AllocaOp::create(builder, loc, listTy) + : mlir::Value{}; std::string listMangleName = groupMangleName + ".list"; auto listFunc = [&](fir::FirOpBuilder &builder) { - mlir::Value list = builder.create<fir::UndefOp>(loc, listTy); + mlir::Value list = fir::UndefOp::create(builder, loc, listTy); mlir::IntegerAttr zero = builder.getIntegerAttr(idxTy, 0); mlir::IntegerAttr one = builder.getIntegerAttr(idxTy, 1); llvm::SmallVector<mlir::Attribute, 2> idx = {mlir::Attribute{}, @@ -490,14 +493,14 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, idx[1] = zero; mlir::Value nameAddr = builder.createConvert(loc, charRefTy, fir::getBase(stringAddress(s))); - list = builder.create<fir::InsertValueOp>(loc, listTy, list, nameAddr, - builder.getArrayAttr(idx)); + list = fir::InsertValueOp::create(builder, loc, listTy, list, nameAddr, + builder.getArrayAttr(idx)); idx[1] = one; mlir::Value descAddr; if (auto desc = builder.getNamedGlobal( Fortran::lower::mangle::globalNamelistDescriptorName(s))) { - descAddr = builder.create<fir::AddrOfOp>(loc, desc.resultType(), - desc.getSymbol()); + descAddr = fir::AddrOfOp::create(builder, loc, desc.resultType(), + desc.getSymbol()); } else if (Fortran::semantics::FindCommonBlockContaining(s) && IsAllocatableOrPointer(s)) { mlir::Type symType = converter.genType(s); @@ -505,8 +508,8 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, Fortran::semantics::FindCommonBlockContaining(s); std::string commonBlockName = converter.mangleName(*commonBlockSym); fir::GlobalOp commonGlobal = builder.getNamedGlobal(commonBlockName); - mlir::Value commonBlockAddr = builder.create<fir::AddrOfOp>( - loc, commonGlobal.resultType(), commonGlobal.getSymbol()); + mlir::Value commonBlockAddr = fir::AddrOfOp::create( + builder, loc, commonGlobal.resultType(), commonGlobal.getSymbol()); mlir::IntegerType i8Ty = builder.getIntegerType(8); mlir::Type i8Ptr = builder.getRefType(i8Ty); mlir::Type seqTy = builder.getRefType(builder.getVarLenSeqTy(i8Ty)); @@ -514,8 +517,8 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, std::size_t byteOffset = s.GetUltimate().offset(); mlir::Value offs = builder.createIntegerConstant( loc, builder.getIndexType(), byteOffset); - mlir::Value varAddr = builder.create<fir::CoordinateOp>( - loc, i8Ptr, base, mlir::ValueRange{offs}); + mlir::Value varAddr = fir::CoordinateOp::create( + builder, loc, i8Ptr, base, mlir::ValueRange{offs}); descAddr = builder.createConvert(loc, builder.getRefType(symType), varAddr); } else { @@ -531,13 +534,13 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, /*lbounds=*/{}); } descAddr = builder.createConvert(loc, descRefTy, descAddr); - list = builder.create<fir::InsertValueOp>(loc, listTy, list, descAddr, - builder.getArrayAttr(idx)); + list = fir::InsertValueOp::create(builder, loc, listTy, list, descAddr, + builder.getArrayAttr(idx)); } if (groupIsLocal) - builder.create<fir::StoreOp>(loc, list, listAddr); + fir::StoreOp::create(builder, loc, list, listAddr); else - builder.create<fir::HasValueOp>(loc, list); + fir::HasValueOp::create(builder, loc, list); }; if (groupIsLocal) listFunc(builder); @@ -547,39 +550,39 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, // Define the group. mlir::Value groupAddr = groupIsLocal - ? builder.create<fir::AllocaOp>(loc, groupTy) + ? fir::AllocaOp::create(builder, loc, groupTy) : mlir::Value{}; auto groupFunc = [&](fir::FirOpBuilder &builder) { - mlir::Value group = builder.create<fir::UndefOp>(loc, groupTy); + mlir::Value group = fir::UndefOp::create(builder, loc, groupTy); // group name [const char *groupName] - group = builder.create<fir::InsertValueOp>( - loc, groupTy, group, + group = fir::InsertValueOp::create( + builder, loc, groupTy, group, builder.createConvert(loc, charRefTy, fir::getBase(stringAddress(symbol))), builder.getArrayAttr(builder.getIntegerAttr(idxTy, 0))); // list item count [std::size_t items] - group = builder.create<fir::InsertValueOp>( - loc, groupTy, group, + group = fir::InsertValueOp::create( + builder, loc, groupTy, group, builder.createIntegerConstant(loc, sizeTy, details.objects().size()), builder.getArrayAttr(builder.getIntegerAttr(idxTy, 1))); // item list [const Item *item] if (fir::GlobalOp list = builder.getNamedGlobal(listMangleName)) - listAddr = builder.create<fir::AddrOfOp>(loc, list.resultType(), - list.getSymbol()); + listAddr = fir::AddrOfOp::create(builder, loc, list.resultType(), + list.getSymbol()); assert(listAddr && "missing namelist object list"); - group = builder.create<fir::InsertValueOp>( - loc, groupTy, group, listAddr, + group = fir::InsertValueOp::create( + builder, loc, groupTy, group, listAddr, builder.getArrayAttr(builder.getIntegerAttr(idxTy, 2))); // non-type-bound defined IO procedures // [const NonTbpDefinedIoTable *nonTbpDefinedIo] - group = builder.create<fir::InsertValueOp>( - loc, groupTy, group, + group = fir::InsertValueOp::create( + builder, loc, groupTy, group, getNonTbpDefinedIoTableAddr(converter, definedIoProcMap), builder.getArrayAttr(builder.getIntegerAttr(idxTy, 3))); if (groupIsLocal) - builder.create<fir::StoreOp>(loc, group, groupAddr); + fir::StoreOp::create(builder, loc, group, groupAddr); else - builder.create<fir::HasValueOp>(loc, group); + fir::HasValueOp::create(builder, loc, group); }; if (groupIsLocal) { groupFunc(builder); @@ -587,8 +590,8 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, fir::GlobalOp group = builder.createGlobal( loc, groupTy, groupMangleName, /*isConst=*/true, /*isTarget=*/false, groupFunc, linkOnce); - groupAddr = builder.create<fir::AddrOfOp>(loc, group.resultType(), - group.getSymbol()); + groupAddr = fir::AddrOfOp::create(builder, loc, group.resultType(), + group.getSymbol()); } assert(groupAddr && "missing namelist group result"); return groupAddr; @@ -608,7 +611,7 @@ static void genNamelistIO(Fortran::lower::AbstractConverter &converter, getNamelistGroup(converter, symbol.GetUltimate(), stmtCtx); groupAddr = builder.createConvert(loc, argType, groupAddr); llvm::SmallVector<mlir::Value> args = {cookie, groupAddr}; - ok = builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + ok = fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } /// Is \p type a derived type or an array of derived type? @@ -751,7 +754,7 @@ static void genOutputItemList( outputFuncArgs.push_back(itemValue); } } - ok = builder.create<fir::CallOp>(loc, outputFunc, outputFuncArgs) + ok = fir::CallOp::create(builder, loc, outputFunc, outputFuncArgs) .getResult(0); } } @@ -812,12 +815,12 @@ static void boolRefToLogical(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value addr) { auto boolType = builder.getRefType(builder.getI1Type()); auto boolAddr = builder.createConvert(loc, boolType, addr); - auto boolValue = builder.create<fir::LoadOp>(loc, boolAddr); + auto boolValue = fir::LoadOp::create(builder, loc, boolAddr); auto logicalType = fir::unwrapPassByRefType(addr.getType()); // The convert avoid making any assumptions about how LOGICALs are actually // represented (it might end-up being either a signed or zero extension). auto logicalValue = builder.createConvert(loc, logicalType, boolValue); - builder.create<fir::StoreOp>(loc, logicalValue, addr); + fir::StoreOp::create(builder, loc, logicalValue, addr); } static mlir::Value @@ -849,12 +852,13 @@ createIoRuntimeCallForItem(Fortran::lower::AbstractConverter &converter, inputFuncArgs.push_back(builder.createConvert( loc, inputFunc.getFunctionType().getInput(2), len)); } else if (mlir::isa<mlir::IntegerType>(itemTy)) { - inputFuncArgs.push_back(builder.create<mlir::arith::ConstantOp>( - loc, builder.getI32IntegerAttr( - mlir::cast<mlir::IntegerType>(itemTy).getWidth() / 8))); + inputFuncArgs.push_back(mlir::arith::ConstantOp::create( + builder, loc, + builder.getI32IntegerAttr( + mlir::cast<mlir::IntegerType>(itemTy).getWidth() / 8))); } } - auto call = builder.create<fir::CallOp>(loc, inputFunc, inputFuncArgs); + auto call = fir::CallOp::create(builder, loc, inputFunc, inputFuncArgs); auto itemAddr = fir::getBase(item); auto itemTy = fir::unwrapRefType(itemAddr.getType()); if (mlir::isa<fir::LogicalType>(itemTy)) @@ -951,7 +955,7 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter, mlir::Value stepValue = control.step.has_value() ? genControlValue(*control.step) - : builder.create<mlir::arith::ConstantIndexOp>(loc, 1); + : mlir::arith::ConstantIndexOp::create(builder, loc, 1); auto genItemList = [&](const D &ioImpliedDo) { if constexpr (std::is_same_v<D, Fortran::parser::InputImpliedDo>) genInputItemList(converter, cookie, itemList, isFormatted, checkResult, @@ -962,35 +966,36 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter, }; if (!checkResult) { // No IO call result checks - the loop is a fir.do_loop op. - auto doLoopOp = builder.create<fir::DoLoopOp>( - loc, lowerValue, upperValue, stepValue, /*unordered=*/false, - /*finalCountValue=*/true); + auto doLoopOp = fir::DoLoopOp::create(builder, loc, lowerValue, upperValue, + stepValue, /*unordered=*/false, + /*finalCountValue=*/true); builder.setInsertionPointToStart(doLoopOp.getBody()); mlir::Value lcv = builder.createConvert( loc, fir::unwrapRefType(loopVar.getType()), doLoopOp.getInductionVar()); - builder.create<fir::StoreOp>(loc, lcv, loopVar); + fir::StoreOp::create(builder, loc, lcv, loopVar); genItemList(ioImpliedDo); builder.setInsertionPointToEnd(doLoopOp.getBody()); - mlir::Value result = builder.create<mlir::arith::AddIOp>( - loc, doLoopOp.getInductionVar(), doLoopOp.getStep(), iofAttr); - builder.create<fir::ResultOp>(loc, result); + mlir::Value result = mlir::arith::AddIOp::create( + builder, loc, doLoopOp.getInductionVar(), doLoopOp.getStep(), iofAttr); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointAfter(doLoopOp); // The loop control variable may be used after the loop. lcv = builder.createConvert(loc, fir::unwrapRefType(loopVar.getType()), doLoopOp.getResult(0)); - builder.create<fir::StoreOp>(loc, lcv, loopVar); + fir::StoreOp::create(builder, loc, lcv, loopVar); return; } // Check IO call results - the loop is a fir.iterate_while op. if (!ok) ok = builder.createBool(loc, true); - auto iterWhileOp = builder.create<fir::IterWhileOp>( - loc, lowerValue, upperValue, stepValue, ok, /*finalCountValue*/ true); + auto iterWhileOp = + fir::IterWhileOp::create(builder, loc, lowerValue, upperValue, stepValue, + ok, /*finalCountValue*/ true); builder.setInsertionPointToStart(iterWhileOp.getBody()); mlir::Value lcv = builder.createConvert(loc, fir::unwrapRefType(loopVar.getType()), iterWhileOp.getInductionVar()); - builder.create<fir::StoreOp>(loc, lcv, loopVar); + fir::StoreOp::create(builder, loc, lcv, loopVar); ok = iterWhileOp.getIterateVar(); mlir::Value falseValue = builder.createIntegerConstant(loc, builder.getI1Type(), 0); @@ -1003,28 +1008,28 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter, builder.setInsertionPointAfter(lastOp); // The primary ifOp result is the result of an IO call or loop. if (mlir::isa<fir::CallOp, fir::IfOp>(*lastOp)) - builder.create<fir::ResultOp>(loc, lastOp->getResult(0)); + fir::ResultOp::create(builder, loc, lastOp->getResult(0)); else - builder.create<fir::ResultOp>(loc, ok); // loop result + fir::ResultOp::create(builder, loc, ok); // loop result // The else branch propagates an early exit false result. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, falseValue); + fir::ResultOp::create(builder, loc, falseValue); } builder.setInsertionPointToEnd(iterWhileOp.getBody()); mlir::OpResult iterateResult = builder.getBlock()->back().getResult(0); mlir::Value inductionResult0 = iterWhileOp.getInductionVar(); - auto inductionResult1 = builder.create<mlir::arith::AddIOp>( - loc, inductionResult0, iterWhileOp.getStep(), iofAttr); - auto inductionResult = builder.create<mlir::arith::SelectOp>( - loc, iterateResult, inductionResult1, inductionResult0); + auto inductionResult1 = mlir::arith::AddIOp::create( + builder, loc, inductionResult0, iterWhileOp.getStep(), iofAttr); + auto inductionResult = mlir::arith::SelectOp::create( + builder, loc, iterateResult, inductionResult1, inductionResult0); llvm::SmallVector<mlir::Value> results = {inductionResult, iterateResult}; - builder.create<fir::ResultOp>(loc, results); + fir::ResultOp::create(builder, loc, results); ok = iterWhileOp.getResult(1); builder.setInsertionPointAfter(iterWhileOp); // The loop control variable may be used after the loop. lcv = builder.createConvert(loc, fir::unwrapRefType(loopVar.getType()), iterWhileOp.getResult(0)); - builder.create<fir::StoreOp>(loc, lcv, loopVar); + fir::StoreOp::create(builder, loc, lcv, loopVar); } //===----------------------------------------------------------------------===// @@ -1046,15 +1051,15 @@ static mlir::Value locToLineNo(Fortran::lower::AbstractConverter &converter, static mlir::Value getDefaultScratch(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type toType) { - mlir::Value null = builder.create<mlir::arith::ConstantOp>( - loc, builder.getI64IntegerAttr(0)); + mlir::Value null = mlir::arith::ConstantOp::create( + builder, loc, builder.getI64IntegerAttr(0)); return builder.createConvert(loc, toType, null); } static mlir::Value getDefaultScratchLen(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type toType) { - return builder.create<mlir::arith::ConstantOp>( - loc, builder.getIntegerAttr(toType, 0)); + return mlir::arith::ConstantOp::create(builder, loc, + builder.getIntegerAttr(toType, 0)); } /// Generate a reference to a buffer and the length of buffer given @@ -1105,8 +1110,8 @@ lowerStringLit(Fortran::lower::AbstractConverter &converter, mlir::Location loc, mlir::Value kind; if (ty2) { auto kindVal = expr->GetType().value().kind(); - kind = builder.create<mlir::arith::ConstantOp>( - loc, builder.getIntegerAttr(ty2, kindVal)); + kind = mlir::arith::ConstantOp::create( + builder, loc, builder.getIntegerAttr(ty2, kindVal)); } return {buff, len, kind}; } @@ -1146,7 +1151,7 @@ mlir::Value genIntIOOption(Fortran::lower::AbstractConverter &converter, loc, Fortran::semantics::GetExpr(spec.v), localStatementCtx)); mlir::Value val = builder.createConvert(loc, ioFuncTy.getInput(1), expr); llvm::SmallVector<mlir::Value> ioArgs = {cookie, val}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } /// Generic to build a string argument to the runtime. This passes a CHARACTER @@ -1164,7 +1169,7 @@ mlir::Value genCharIOOption(Fortran::lower::AbstractConverter &converter, ioFuncTy.getInput(1), ioFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> ioArgs = {cookie, std::get<0>(tup), std::get<1>(tup)}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } template <typename A> @@ -1197,7 +1202,7 @@ mlir::Value genIOOption<Fortran::parser::FileNameExpr>( ioFuncTy.getInput(1), ioFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> ioArgs{cookie, std::get<0>(tup), std::get<1>(tup)}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } template <> @@ -1262,7 +1267,7 @@ mlir::Value genIOOption<Fortran::parser::ConnectSpec::CharExpr>( ioFuncTy.getInput(1), ioFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> ioArgs = {cookie, std::get<0>(tup), std::get<1>(tup)}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } template <> @@ -1316,7 +1321,7 @@ mlir::Value genIOOption<Fortran::parser::IoControlSpec::CharExpr>( ioFuncTy.getInput(1), ioFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> ioArgs = {cookie, std::get<0>(tup), std::get<1>(tup)}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } template <> @@ -1352,7 +1357,7 @@ static void genIOGetVar(Fortran::lower::AbstractConverter &converter, mlir::func::FuncOp ioFunc = fir::runtime::getIORuntimeFunc<IoRuntimeKey>(loc, builder); mlir::Value value = - builder.create<fir::CallOp>(loc, ioFunc, mlir::ValueRange{cookie}) + fir::CallOp::create(builder, loc, ioFunc, mlir::ValueRange{cookie}) .getResult(0); Fortran::lower::StatementContext localStatementCtx; fir::ExtendedValue var = converter.genExprAddr( @@ -1480,8 +1485,8 @@ genConditionHandlerCall(Fortran::lower::AbstractConverter &converter, fir::runtime::getIORuntimeFunc<mkIOKey(EnableHandlers)>(loc, builder); mlir::Type boolType = enableHandlers.getFunctionType().getInput(1); auto boolValue = [&](bool specifierIsPresent) { - return builder.create<mlir::arith::ConstantOp>( - loc, builder.getIntegerAttr(boolType, specifierIsPresent)); + return mlir::arith::ConstantOp::create( + builder, loc, builder.getIntegerAttr(boolType, specifierIsPresent)); }; llvm::SmallVector<mlir::Value> ioArgs = {cookie, boolValue(csi.ioStatExpr != nullptr), @@ -1489,7 +1494,7 @@ genConditionHandlerCall(Fortran::lower::AbstractConverter &converter, boolValue(csi.hasEnd), boolValue(csi.hasEor), boolValue(csi.ioMsg.has_value())}; - builder.create<fir::CallOp>(loc, enableHandlers, ioArgs); + fir::CallOp::create(builder, loc, enableHandlers, ioArgs); } //===----------------------------------------------------------------------===// @@ -1663,7 +1668,7 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter, // Pass the format string reference and the string length out of the select // statement. llvm::SmallVector<mlir::Value> args = {stringRef, stringLen}; - builder.create<mlir::cf::BranchOp>(loc, endBlock, args); + mlir::cf::BranchOp::create(builder, loc, endBlock, args); // Add block to the list of cases and make a new one. blockList.push_back(block); @@ -1678,13 +1683,13 @@ lowerReferenceAsStringSelect(Fortran::lower::AbstractConverter &converter, builder, loc, "Assigned format variable '" + symbol->name().ToString() + "' has not been assigned a valid format label"); - builder.create<fir::UnreachableOp>(loc); + fir::UnreachableOp::create(builder, loc); blockList.push_back(unitBlock); // Lower the selectOp. builder.setInsertionPointToEnd(startBlock); auto label = fir::getBase(converter.genExprValue(loc, &expr, stmtCtx)); - builder.create<fir::SelectOp>(loc, label, indexList, blockList); + fir::SelectOp::create(builder, loc, label, indexList, blockList); builder.setInsertionPointToEnd(endBlock); endBlock->addArgument(strTy, loc); @@ -1814,17 +1819,17 @@ static mlir::Value genIOUnitNumber(Fortran::lower::AbstractConverter &converter, mlir::Value line = locToLineNo(converter, loc, funcTy.getInput(5)); args.push_back(file); args.push_back(line); - auto checkCall = builder.create<fir::CallOp>(loc, check, args); + auto checkCall = fir::CallOp::create(builder, loc, check, args); if (csi.hasErrorConditionSpec()) { mlir::Value iostat = checkCall.getResult(0); mlir::Type iostatTy = iostat.getType(); mlir::Value zero = fir::factory::createZeroValue(builder, loc, iostatTy); - mlir::Value unitIsOK = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, iostat, zero); - auto ifOp = builder.create<fir::IfOp>(loc, iostatTy, unitIsOK, - /*withElseRegion=*/true); + mlir::Value unitIsOK = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, iostat, zero); + auto ifOp = fir::IfOp::create(builder, loc, iostatTy, unitIsOK, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, iostat); + fir::ResultOp::create(builder, loc, iostat); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); stmtCtx.pushScope(); csi.bigUnitIfOp = ifOp; @@ -1846,8 +1851,8 @@ static mlir::Value genIOUnit(Fortran::lower::AbstractConverter &converter, &iounit->u)) return genIOUnitNumber(converter, loc, Fortran::semantics::GetExpr(*e), ty, csi, stmtCtx); - return builder.create<mlir::arith::ConstantOp>( - loc, builder.getIntegerAttr(ty, defaultUnitNumber)); + return mlir::arith::ConstantOp::create( + builder, loc, builder.getIntegerAttr(ty, defaultUnitNumber)); } template <typename A> @@ -1879,8 +1884,8 @@ static mlir::Value genBasicIOStmt(Fortran::lower::AbstractConverter &converter, mlir::Value un = builder.createConvert(loc, beginFuncTy.getInput(0), unit); mlir::Value file = locToFilename(converter, loc, beginFuncTy.getInput(1)); mlir::Value line = locToLineNo(converter, loc, beginFuncTy.getInput(2)); - auto call = builder.create<fir::CallOp>(loc, beginFunc, - mlir::ValueRange{un, file, line}); + auto call = fir::CallOp::create(builder, loc, beginFunc, + mlir::ValueRange{un, file, line}); mlir::Value cookie = call.getResult(0); genConditionHandlerCall(converter, loc, cookie, stmt.v, csi); mlir::Value ok; @@ -1934,7 +1939,7 @@ genNewunitSpec(Fortran::lower::AbstractConverter &converter, mlir::Location loc, auto kind = builder.createIntegerConstant(loc, ioFuncTy.getInput(2), var->GetType().value().kind()); llvm::SmallVector<mlir::Value> ioArgs = {cookie, addr, kind}; - return builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + return fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); } llvm_unreachable("missing Newunit spec"); } @@ -1969,7 +1974,7 @@ Fortran::lower::genOpenStatement(Fortran::lower::AbstractConverter &converter, beginArgs.push_back(locToLineNo(converter, loc, beginFuncTy.getInput(1))); } auto cookie = - builder.create<fir::CallOp>(loc, beginFunc, beginArgs).getResult(0); + fir::CallOp::create(builder, loc, beginFunc, beginArgs).getResult(0); genConditionHandlerCall(converter, loc, cookie, stmt.v, csi); mlir::Value ok; auto insertPt = builder.saveInsertionPoint(); @@ -2013,7 +2018,7 @@ Fortran::lower::genWaitStatement(Fortran::lower::AbstractConverter &converter, args.push_back(locToFilename(converter, loc, beginFuncTy.getInput(1))); args.push_back(locToLineNo(converter, loc, beginFuncTy.getInput(2))); } - auto cookie = builder.create<fir::CallOp>(loc, beginFunc, args).getResult(0); + auto cookie = fir::CallOp::create(builder, loc, beginFunc, args).getResult(0); genConditionHandlerCall(converter, loc, cookie, stmt.v, csi); return genEndIO(converter, converter.getCurrentLocation(), cookie, csi, stmtCtx); @@ -2149,9 +2154,10 @@ void genBeginDataTransferCallArgs( } } else { // PRINT - maybe explicit format; default unit maybeGetFormatArgs(); - ioArgs.push_back(builder.create<mlir::arith::ConstantOp>( - loc, builder.getIntegerAttr(ioFuncTy.getInput(ioArgs.size()), - defaultUnitNumber))); + ioArgs.push_back(mlir::arith::ConstantOp::create( + builder, loc, + builder.getIntegerAttr(ioFuncTy.getInput(ioArgs.size()), + defaultUnitNumber))); } // File name and line number are always the last two arguments. ioArgs.push_back( @@ -2198,7 +2204,7 @@ genDataTransferStmt(Fortran::lower::AbstractConverter &converter, ioArgs, converter, loc, stmt, ioFunc.getFunctionType(), isFormatted, isList || isNml, isInternal, descRef, csi, stmtCtx); mlir::Value cookie = - builder.create<fir::CallOp>(loc, ioFunc, ioArgs).getResult(0); + fir::CallOp::create(builder, loc, ioFunc, ioArgs).getResult(0); auto insertPt = builder.saveInsertionPoint(); mlir::Value ok; @@ -2332,7 +2338,7 @@ mlir::Value genInquireSpec<Fortran::parser::InquireSpec::CharVar>( .c_str())), builder.createConvert(loc, specFuncTy.getInput(2), fir::getBase(str)), builder.createConvert(loc, specFuncTy.getInput(3), fir::getLen(str))}; - return builder.create<fir::CallOp>(loc, specFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, specFunc, args).getResult(0); } /// Specialization for INTEGER. template <> @@ -2369,7 +2375,7 @@ mlir::Value genInquireSpec<Fortran::parser::InquireSpec::IntVar>( .c_str())), builder.createConvert(loc, specFuncTy.getInput(2), addr), builder.createConvert(loc, specFuncTy.getInput(3), kind)}; - return builder.create<fir::CallOp>(loc, specFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, specFunc, args).getResult(0); } /// Specialization for LOGICAL and (PENDING + ID). template <> @@ -2406,7 +2412,7 @@ mlir::Value genInquireSpec<Fortran::parser::InquireSpec::LogVar>( Fortran::parser::InquireSpec::LogVar::EnumToString(logVarKind)} .c_str()))); args.push_back(builder.createConvert(loc, specFuncTy.getInput(2), addr)); - auto call = builder.create<fir::CallOp>(loc, specFunc, args); + auto call = fir::CallOp::create(builder, loc, specFunc, args); boolRefToLogical(loc, builder, addr); return call.getResult(0); } @@ -2502,7 +2508,7 @@ mlir::Value Fortran::lower::genInquireStatement( beginArgs = {locToFilename(converter, loc, beginFuncTy.getInput(0)), locToLineNo(converter, loc, beginFuncTy.getInput(1))}; auto cookie = - builder.create<fir::CallOp>(loc, beginFunc, beginArgs).getResult(0); + fir::CallOp::create(builder, loc, beginFunc, beginArgs).getResult(0); mlir::Value ok; genOutputItemList( converter, cookie, @@ -2523,14 +2529,14 @@ mlir::Value Fortran::lower::genInquireStatement( .getResult(0); mlir::Value length1 = builder.createConvert(loc, converter.genType(*ioLengthVar), length); - builder.create<fir::StoreOp>(loc, length1, ioLengthVarAddr); + fir::StoreOp::create(builder, loc, length1, ioLengthVarAddr); return genEndIO(converter, loc, cookie, csi, stmtCtx); } // Common handling for inquire by unit or file. assert(list && "inquire-spec list must be present"); auto cookie = - builder.create<fir::CallOp>(loc, beginFunc, beginArgs).getResult(0); + fir::CallOp::create(builder, loc, beginFunc, beginArgs).getResult(0); genConditionHandlerCall(converter, loc, cookie, *list, csi); // Handle remaining arguments in specifier list. mlir::Value ok; diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 51eb33d..471f368 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -132,21 +132,21 @@ createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc, /*withElseRegion=*/true) .genThen([&]() { if (fir::isBoxAddress(baseAddr.getType())) - baseAddr = builder.create<fir::LoadOp>(loc, baseAddr); + baseAddr = fir::LoadOp::create(builder, loc, baseAddr); mlir::Value boxAddr = - builder.create<fir::BoxAddrOp>(loc, baseAddr); - builder.create<fir::ResultOp>(loc, mlir::ValueRange{boxAddr}); + fir::BoxAddrOp::create(builder, loc, baseAddr); + fir::ResultOp::create(builder, loc, mlir::ValueRange{boxAddr}); }) .genElse([&] { mlir::Value absent = - builder.create<fir::AbsentOp>(loc, ifRetTy); - builder.create<fir::ResultOp>(loc, mlir::ValueRange{absent}); + fir::AbsentOp::create(builder, loc, ifRetTy); + fir::ResultOp::create(builder, loc, mlir::ValueRange{absent}); }) .getResults()[0]; } else { if (fir::isBoxAddress(baseAddr.getType())) - baseAddr = builder.create<fir::LoadOp>(loc, baseAddr); - baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr); + baseAddr = fir::LoadOp::create(builder, loc, baseAddr); + baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); } retTy = baseAddr.getType(); } @@ -159,7 +159,7 @@ createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc, addOperands(operands, operandSegments, bounds); addOperands(operands, operandSegments, async); - Op op = builder.create<Op>(loc, retTy, operands); + Op op = Op::create(builder, loc, retTy, operands); op.setNameAttr(builder.getStringAttr(name.str())); op.setStructured(structured); op.setImplicit(implicit); @@ -198,12 +198,12 @@ createDeclareFunc(mlir::OpBuilder &modBuilder, fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Type> argsTy = {}, llvm::SmallVector<mlir::Location> locs = {}) { auto funcTy = mlir::FunctionType::get(modBuilder.getContext(), argsTy, {}); - auto funcOp = modBuilder.create<mlir::func::FuncOp>(loc, funcName, funcTy); + auto funcOp = mlir::func::FuncOp::create(modBuilder, loc, funcName, funcTy); funcOp.setVisibility(mlir::SymbolTable::Visibility::Private); builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), argsTy, locs); builder.setInsertionPointToEnd(&funcOp.getRegion().back()); - builder.create<mlir::func::ReturnOp>(loc); + mlir::func::ReturnOp::create(builder, loc); builder.setInsertionPointToStart(&funcOp.getRegion().back()); return funcOp; } @@ -214,7 +214,7 @@ createSimpleOp(fir::FirOpBuilder &builder, mlir::Location loc, const llvm::SmallVectorImpl<mlir::Value> &operands, const llvm::SmallVectorImpl<int32_t> &operandSegments) { llvm::ArrayRef<mlir::Type> argTy; - Op op = builder.create<Op>(loc, argTy, operands); + Op op = Op::create(builder, loc, argTy, operands); op->setAttr(Op::getOperandSegmentSizeAttr(), builder.getDenseI32ArrayAttr(operandSegments)); return op; @@ -257,15 +257,15 @@ static void createDeclareAllocFuncWithArg(mlir::OpBuilder &modBuilder, if (unwrapFirBox) { mlir::Value desc = - builder.create<fir::LoadOp>(loc, registerFuncOp.getArgument(0)); - fir::BoxAddrOp boxAddrOp = builder.create<fir::BoxAddrOp>(loc, desc); + fir::LoadOp::create(builder, loc, registerFuncOp.getArgument(0)); + fir::BoxAddrOp boxAddrOp = fir::BoxAddrOp::create(builder, loc, desc); addDeclareAttr(builder, boxAddrOp.getOperation(), clause); EntryOp entryOp = createDataEntryOp<EntryOp>( builder, loc, boxAddrOp.getResult(), asFortran, bounds, /*structured=*/false, /*implicit=*/false, clause, boxAddrOp.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - builder.create<mlir::acc::DeclareEnterOp>( - loc, mlir::acc::DeclareTokenType::get(entryOp.getContext()), + mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(entryOp.getContext()), mlir::ValueRange(entryOp.getAccVar())); } @@ -291,8 +291,8 @@ static void createDeclareDeallocFuncWithArg( mlir::Value var = preDeallocOp.getArgument(0); if (unwrapFirBox) { mlir::Value loadOp = - builder.create<fir::LoadOp>(loc, preDeallocOp.getArgument(0)); - fir::BoxAddrOp boxAddrOp = builder.create<fir::BoxAddrOp>(loc, loadOp); + fir::LoadOp::create(builder, loc, preDeallocOp.getArgument(0)); + fir::BoxAddrOp boxAddrOp = fir::BoxAddrOp::create(builder, loc, loadOp); addDeclareAttr(builder, boxAddrOp.getOperation(), clause); var = boxAddrOp.getResult(); } @@ -303,25 +303,25 @@ static void createDeclareDeallocFuncWithArg( builder, loc, var, asFortran, bounds, /*structured=*/false, /*implicit=*/false, clause, var.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - builder.create<mlir::acc::DeclareExitOp>( - loc, mlir::Value{}, mlir::ValueRange(entryOp.getAccVar())); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(entryOp.getAccVar())); if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> || std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>) - builder.create<ExitOp>(entryOp.getLoc(), entryOp.getAccVar(), - entryOp.getVar(), entryOp.getVarType(), - entryOp.getBounds(), entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getVar(), entryOp.getVarType(), entryOp.getBounds(), + entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); else - builder.create<ExitOp>(entryOp.getLoc(), entryOp.getAccVar(), - entryOp.getBounds(), entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); // Generate the post dealloc function. modBuilder.setInsertionPointAfter(preDeallocOp); @@ -333,7 +333,7 @@ static void createDeclareDeallocFuncWithArg( var = postDeallocOp.getArgument(0); if (unwrapFirBox) { - var = builder.create<fir::LoadOp>(loc, postDeallocOp.getArgument(0)); + var = fir::LoadOp::create(builder, loc, postDeallocOp.getArgument(0)); asFortran << accFirDescriptorPostfix.str(); } @@ -385,8 +385,8 @@ genAtomicCaptureStatement(Fortran::lower::AbstractConverter &converter, // Generate `atomic.read` operation for atomic assigment statements fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - firOpBuilder.create<mlir::acc::AtomicReadOp>( - loc, fromAddress, toAddress, mlir::TypeAttr::get(elementType)); + mlir::acc::AtomicReadOp::create(firOpBuilder, loc, fromAddress, toAddress, + mlir::TypeAttr::get(elementType)); } /// Used to generate atomic.write operation which is created in existing @@ -406,7 +406,7 @@ genAtomicWriteStatement(Fortran::lower::AbstractConverter &converter, rhsExpr = firOpBuilder.createConvert(loc, varType, rhsExpr); firOpBuilder.restoreInsertionPoint(insertionPoint); - firOpBuilder.create<mlir::acc::AtomicWriteOp>(loc, lhsAddr, rhsExpr); + mlir::acc::AtomicWriteOp::create(firOpBuilder, loc, lhsAddr, rhsExpr); } /// Used to generate atomic.update operation which is created in existing @@ -522,7 +522,7 @@ static inline void genAtomicUpdateStatement( mlir::Operation *atomicUpdateOp = nullptr; atomicUpdateOp = - firOpBuilder.create<mlir::acc::AtomicUpdateOp>(currentLocation, lhsAddr); + mlir::acc::AtomicUpdateOp::create(firOpBuilder, currentLocation, lhsAddr); llvm::SmallVector<mlir::Type> varTys = {varType}; llvm::SmallVector<mlir::Location> locs = {currentLocation}; @@ -540,7 +540,7 @@ static inline void genAtomicUpdateStatement( *Fortran::semantics::GetExpr(assignmentStmtExpr), atomicStmtCtx)); mlir::Value convertResult = firOpBuilder.createConvert(currentLocation, varType, rhsExpr); - firOpBuilder.create<mlir::acc::YieldOp>(currentLocation, convertResult); + mlir::acc::YieldOp::create(firOpBuilder, currentLocation, convertResult); converter.resetExprOverrides(); } firOpBuilder.setInsertionPointAfter(atomicUpdateOp); @@ -647,7 +647,7 @@ void genAtomicCapture(Fortran::lower::AbstractConverter &converter, fir::getBase(converter.genExprValue(assign2.lhs, stmtCtx)).getType(); mlir::Operation *atomicCaptureOp = nullptr; - atomicCaptureOp = firOpBuilder.create<mlir::acc::AtomicCaptureOp>(loc); + atomicCaptureOp = mlir::acc::AtomicCaptureOp::create(firOpBuilder, loc); firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0))); mlir::Block &block = atomicCaptureOp->getRegion(0).back(); @@ -688,7 +688,7 @@ void genAtomicCapture(Fortran::lower::AbstractConverter &converter, loc); } firOpBuilder.setInsertionPointToEnd(&block); - firOpBuilder.create<mlir::acc::TerminatorOp>(loc); + mlir::acc::TerminatorOp::create(firOpBuilder, loc); // The clean-ups associated with the statements inside the capture // construct must be generated after the AtomicCaptureOp. firOpBuilder.setInsertionPointAfter(atomicCaptureOp); @@ -839,15 +839,15 @@ genDataExitOperations(fir::FirOpBuilder &builder, mlir::Location opLoc = exitLoc ? *exitLoc : entryOp.getLoc(); if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> || std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>) - builder.create<ExitOp>( - opLoc, entryOp.getAccVar(), entryOp.getVar(), entryOp.getVarType(), - entryOp.getBounds(), entryOp.getAsyncOperands(), + ExitOp::create( + builder, opLoc, entryOp.getAccVar(), entryOp.getVar(), + entryOp.getVarType(), entryOp.getBounds(), entryOp.getAsyncOperands(), entryOp.getAsyncOperandsDeviceTypeAttr(), entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), structured, entryOp.getImplicit(), builder.getStringAttr(*entryOp.getName())); else - builder.create<ExitOp>( - opLoc, entryOp.getAccVar(), entryOp.getBounds(), + ExitOp::create( + builder, opLoc, entryOp.getAccVar(), entryOp.getBounds(), entryOp.getAsyncOperands(), entryOp.getAsyncOperandsDeviceTypeAttr(), entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), structured, entryOp.getImplicit(), builder.getStringAttr(*entryOp.getName())); @@ -859,9 +859,9 @@ fir::ShapeOp genShapeOp(mlir::OpBuilder &builder, fir::SequenceType seqTy, llvm::SmallVector<mlir::Value> extents; mlir::Type idxTy = builder.getIndexType(); for (auto extent : seqTy.getShape()) - extents.push_back(builder.create<mlir::arith::ConstantOp>( - loc, idxTy, builder.getIntegerAttr(idxTy, extent))); - return builder.create<fir::ShapeOp>(loc, extents); + extents.push_back(mlir::arith::ConstantOp::create( + builder, loc, idxTy, builder.getIntegerAttr(idxTy, extent))); + return fir::ShapeOp::create(builder, loc, extents); } /// Get the initial value for reduction operator. @@ -936,8 +936,8 @@ static mlir::Value getReductionInitValue(fir::FirOpBuilder &builder, return builder.createBool(loc, value); } if (ty.isIntOrIndex()) - return builder.create<mlir::arith::ConstantOp>( - loc, ty, + return mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getIntegerAttr(ty, getReductionInitValue<llvm::APInt>(op, ty))); if (op == mlir::acc::ReductionOperator::AccMin || op == mlir::acc::ReductionOperator::AccMax) { @@ -945,13 +945,13 @@ static mlir::Value getReductionInitValue(fir::FirOpBuilder &builder, llvm::report_fatal_error( "min/max reduction not supported for complex type"); if (auto floatTy = mlir::dyn_cast_or_null<mlir::FloatType>(ty)) - return builder.create<mlir::arith::ConstantOp>( - loc, ty, + return mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getFloatAttr(ty, getReductionInitValue<llvm::APFloat>(op, ty))); } else if (auto floatTy = mlir::dyn_cast_or_null<mlir::FloatType>(ty)) { - return builder.create<mlir::arith::ConstantOp>( - loc, ty, + return mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getFloatAttr(ty, getReductionInitValue<int64_t>(op, ty))); } else if (auto cmplxTy = mlir::dyn_cast_or_null<mlir::ComplexType>(ty)) { mlir::Type floatTy = cmplxTy.getElementType(); @@ -985,10 +985,10 @@ static RecipeOp genRecipeOp( mlir::OpBuilder modBuilder(mod.getBodyRegion()); RecipeOp recipe; if constexpr (std::is_same_v<RecipeOp, mlir::acc::ReductionRecipeOp>) { - recipe = modBuilder.create<mlir::acc::ReductionRecipeOp>(loc, recipeName, - ty, op); + recipe = mlir::acc::ReductionRecipeOp::create(modBuilder, loc, recipeName, + ty, op); } else { - recipe = modBuilder.create<RecipeOp>(loc, recipeName, ty); + recipe = RecipeOp::create(modBuilder, loc, recipeName, ty); } llvm::SmallVector<mlir::Type> argsTy{ty}; @@ -1032,8 +1032,8 @@ static RecipeOp genRecipeOp( initName, initBlock->getArguments().take_back(initBlock->getArguments().size() - 1), initValue); - builder.create<mlir::acc::YieldOp>(loc, retVal ? retVal - : initBlock->getArgument(0)); + mlir::acc::YieldOp::create(builder, loc, + retVal ? retVal : initBlock->getArgument(0)); return recipe; } @@ -1132,15 +1132,17 @@ static mlir::Value genShapeFromBoundsOrArgs( mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0); for (unsigned i = 0; i < args.size(); i += 3) { mlir::Value s1 = - builder.create<mlir::arith::SubIOp>(loc, args[i + 1], args[0]); - mlir::Value s2 = builder.create<mlir::arith::AddIOp>(loc, s1, one); - mlir::Value s3 = builder.create<mlir::arith::DivSIOp>(loc, s2, args[i + 2]); - mlir::Value cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, s3, zero); - mlir::Value ext = builder.create<mlir::arith::SelectOp>(loc, cmp, s3, zero); + mlir::arith::SubIOp::create(builder, loc, args[i + 1], args[0]); + mlir::Value s2 = mlir::arith::AddIOp::create(builder, loc, s1, one); + mlir::Value s3 = + mlir::arith::DivSIOp::create(builder, loc, s2, args[i + 2]); + mlir::Value cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, s3, zero); + mlir::Value ext = + mlir::arith::SelectOp::create(builder, loc, cmp, s3, zero); extents.push_back(ext); } - return builder.create<fir::ShapeOp>(loc, extents); + return fir::ShapeOp::create(builder, loc, extents); } static hlfir::DesignateOp::Subscripts @@ -1157,8 +1159,8 @@ static hlfir::Entity genDesignateWithTriplets( hlfir::DesignateOp::Subscripts &triplets, mlir::Value shape) { llvm::SmallVector<mlir::Value> lenParams; hlfir::genLengthParameters(loc, builder, entity, lenParams); - auto designate = builder.create<hlfir::DesignateOp>( - loc, entity.getBase().getType(), entity, /*component=*/"", + auto designate = hlfir::DesignateOp::create( + builder, loc, entity.getBase().getType(), entity, /*component=*/"", /*componentShape=*/mlir::Value{}, triplets, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, shape, lenParams); @@ -1198,22 +1200,22 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( builder.setInsertionPointToEnd(&recipe.getCopyRegion().back()); ty = fir::unwrapRefType(ty); if (fir::isa_trivial(ty)) { - mlir::Value initValue = builder.create<fir::LoadOp>( - loc, recipe.getCopyRegion().front().getArgument(0)); - builder.create<fir::StoreOp>(loc, initValue, - recipe.getCopyRegion().front().getArgument(1)); + mlir::Value initValue = fir::LoadOp::create( + builder, loc, recipe.getCopyRegion().front().getArgument(0)); + fir::StoreOp::create(builder, loc, initValue, + recipe.getCopyRegion().front().getArgument(1)); } else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(ty)) { fir::FirOpBuilder firBuilder{builder, recipe.getOperation()}; auto shape = genShapeFromBoundsOrArgs( loc, firBuilder, seqTy, bounds, recipe.getCopyRegion().getArguments()); - auto leftDeclOp = builder.create<hlfir::DeclareOp>( - loc, recipe.getCopyRegion().getArgument(0), llvm::StringRef{}, shape, - llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, + auto leftDeclOp = hlfir::DeclareOp::create( + builder, loc, recipe.getCopyRegion().getArgument(0), llvm::StringRef{}, + shape, llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); - auto rightDeclOp = builder.create<hlfir::DeclareOp>( - loc, recipe.getCopyRegion().getArgument(1), llvm::StringRef{}, shape, - llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, + auto rightDeclOp = hlfir::DeclareOp::create( + builder, loc, recipe.getCopyRegion().getArgument(1), llvm::StringRef{}, + shape, llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); hlfir::DesignateOp::Subscripts triplets = @@ -1225,7 +1227,7 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( auto right = genDesignateWithTriplets(firBuilder, loc, rightEntity, triplets, shape); - firBuilder.create<hlfir::AssignOp>(loc, left, right); + hlfir::AssignOp::create(firBuilder, loc, left, right); } else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) { fir::FirOpBuilder firBuilder{builder, recipe.getOperation()}; @@ -1246,10 +1248,10 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe( auto rightEntity = hlfir::Entity{recipe.getCopyRegion().getArgument(1)}; auto right = genDesignateWithTriplets(firBuilder, loc, rightEntity, triplets, shape); - firBuilder.create<hlfir::AssignOp>(loc, left, right); + hlfir::AssignOp::create(firBuilder, loc, left, right); } - builder.create<mlir::acc::TerminatorOp>(loc); + mlir::acc::TerminatorOp::create(builder, loc); builder.restoreInsertionPoint(ip); return recipe; } @@ -1414,10 +1416,10 @@ static mlir::Value genLogicalCombiner(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value value1, mlir::Value value2) { mlir::Type i1 = builder.getI1Type(); - mlir::Value v1 = builder.create<fir::ConvertOp>(loc, i1, value1); - mlir::Value v2 = builder.create<fir::ConvertOp>(loc, i1, value2); - mlir::Value combined = builder.create<Op>(loc, v1, v2); - return builder.create<fir::ConvertOp>(loc, value1.getType(), combined); + mlir::Value v1 = fir::ConvertOp::create(builder, loc, i1, value1); + mlir::Value v2 = fir::ConvertOp::create(builder, loc, i1, value2); + mlir::Value combined = Op::create(builder, loc, v1, v2); + return fir::ConvertOp::create(builder, loc, value1.getType(), combined); } static mlir::Value genComparisonCombiner(fir::FirOpBuilder &builder, @@ -1426,10 +1428,10 @@ static mlir::Value genComparisonCombiner(fir::FirOpBuilder &builder, mlir::Value value1, mlir::Value value2) { mlir::Type i1 = builder.getI1Type(); - mlir::Value v1 = builder.create<fir::ConvertOp>(loc, i1, value1); - mlir::Value v2 = builder.create<fir::ConvertOp>(loc, i1, value2); - mlir::Value add = builder.create<mlir::arith::CmpIOp>(loc, pred, v1, v2); - return builder.create<fir::ConvertOp>(loc, value1.getType(), add); + mlir::Value v1 = fir::ConvertOp::create(builder, loc, i1, value1); + mlir::Value v2 = fir::ConvertOp::create(builder, loc, i1, value2); + mlir::Value add = mlir::arith::CmpIOp::create(builder, loc, pred, v1, v2); + return fir::ConvertOp::create(builder, loc, value1.getType(), add); } static mlir::Value genScalarCombiner(fir::FirOpBuilder &builder, @@ -1441,21 +1443,21 @@ static mlir::Value genScalarCombiner(fir::FirOpBuilder &builder, value2 = builder.loadIfRef(loc, value2); if (op == mlir::acc::ReductionOperator::AccAdd) { if (ty.isIntOrIndex()) - return builder.create<mlir::arith::AddIOp>(loc, value1, value2); + return mlir::arith::AddIOp::create(builder, loc, value1, value2); if (mlir::isa<mlir::FloatType>(ty)) - return builder.create<mlir::arith::AddFOp>(loc, value1, value2); + return mlir::arith::AddFOp::create(builder, loc, value1, value2); if (auto cmplxTy = mlir::dyn_cast_or_null<mlir::ComplexType>(ty)) - return builder.create<fir::AddcOp>(loc, value1, value2); + return fir::AddcOp::create(builder, loc, value1, value2); TODO(loc, "reduction add type"); } if (op == mlir::acc::ReductionOperator::AccMul) { if (ty.isIntOrIndex()) - return builder.create<mlir::arith::MulIOp>(loc, value1, value2); + return mlir::arith::MulIOp::create(builder, loc, value1, value2); if (mlir::isa<mlir::FloatType>(ty)) - return builder.create<mlir::arith::MulFOp>(loc, value1, value2); + return mlir::arith::MulFOp::create(builder, loc, value1, value2); if (mlir::isa<mlir::ComplexType>(ty)) - return builder.create<fir::MulcOp>(loc, value1, value2); + return fir::MulcOp::create(builder, loc, value1, value2); TODO(loc, "reduction mul type"); } @@ -1466,13 +1468,13 @@ static mlir::Value genScalarCombiner(fir::FirOpBuilder &builder, return fir::genMax(builder, loc, {value1, value2}); if (op == mlir::acc::ReductionOperator::AccIand) - return builder.create<mlir::arith::AndIOp>(loc, value1, value2); + return mlir::arith::AndIOp::create(builder, loc, value1, value2); if (op == mlir::acc::ReductionOperator::AccIor) - return builder.create<mlir::arith::OrIOp>(loc, value1, value2); + return mlir::arith::OrIOp::create(builder, loc, value1, value2); if (op == mlir::acc::ReductionOperator::AccXor) - return builder.create<mlir::arith::XOrIOp>(loc, value1, value2); + return mlir::arith::XOrIOp::create(builder, loc, value1, value2); if (op == mlir::acc::ReductionOperator::AccLand) return genLogicalCombiner<mlir::arith::AndIOp>(builder, loc, value1, @@ -1520,19 +1522,21 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, auto shape = genShapeFromBoundsOrArgs(loc, builder, seqTy, bounds, recipe.getCombinerRegion().getArguments()); - auto v1DeclareOp = builder.create<hlfir::DeclareOp>( - loc, value1, llvm::StringRef{}, shape, llvm::ArrayRef<mlir::Value>{}, + auto v1DeclareOp = hlfir::DeclareOp::create( + builder, loc, value1, llvm::StringRef{}, shape, + llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); - auto v2DeclareOp = builder.create<hlfir::DeclareOp>( - loc, value2, llvm::StringRef{}, shape, llvm::ArrayRef<mlir::Value>{}, + auto v2DeclareOp = hlfir::DeclareOp::create( + builder, loc, value2, llvm::StringRef{}, shape, + llvm::ArrayRef<mlir::Value>{}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); hlfir::DesignateOp::Subscripts triplets = getTripletsFromArgs(recipe); llvm::SmallVector<mlir::Value> lenParamsLeft; auto leftEntity = hlfir::Entity{v1DeclareOp.getBase()}; hlfir::genLengthParameters(loc, builder, leftEntity, lenParamsLeft); - auto leftDesignate = builder.create<hlfir::DesignateOp>( - loc, v1DeclareOp.getBase().getType(), v1DeclareOp.getBase(), + auto leftDesignate = hlfir::DesignateOp::create( + builder, loc, v1DeclareOp.getBase().getType(), v1DeclareOp.getBase(), /*component=*/"", /*componentShape=*/mlir::Value{}, triplets, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, @@ -1542,8 +1546,8 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> lenParamsRight; auto rightEntity = hlfir::Entity{v2DeclareOp.getBase()}; hlfir::genLengthParameters(loc, builder, rightEntity, lenParamsLeft); - auto rightDesignate = builder.create<hlfir::DesignateOp>( - loc, v2DeclareOp.getBase().getType(), v2DeclareOp.getBase(), + auto rightDesignate = hlfir::DesignateOp::create( + builder, loc, v2DeclareOp.getBase().getType(), v2DeclareOp.getBase(), /*component=*/"", /*componentShape=*/mlir::Value{}, triplets, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, @@ -1564,21 +1568,21 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value elemental = hlfir::genElementalOp( loc, builder, seqTy.getEleTy(), shape, typeParams, genKernel, /*isUnordered=*/true); - builder.create<hlfir::AssignOp>(loc, elemental, v1DeclareOp.getBase()); + hlfir::AssignOp::create(builder, loc, elemental, v1DeclareOp.getBase()); return; } if (bounds.empty()) { llvm::SmallVector<mlir::Value> extents; mlir::Type idxTy = builder.getIndexType(); for (auto extent : seqTy.getShape()) { - mlir::Value lb = builder.create<mlir::arith::ConstantOp>( - loc, idxTy, builder.getIntegerAttr(idxTy, 0)); - mlir::Value ub = builder.create<mlir::arith::ConstantOp>( - loc, idxTy, builder.getIntegerAttr(idxTy, extent - 1)); - mlir::Value step = builder.create<mlir::arith::ConstantOp>( - loc, idxTy, builder.getIntegerAttr(idxTy, 1)); - auto loop = builder.create<fir::DoLoopOp>(loc, lb, ub, step, - /*unordered=*/false); + mlir::Value lb = mlir::arith::ConstantOp::create( + builder, loc, idxTy, builder.getIntegerAttr(idxTy, 0)); + mlir::Value ub = mlir::arith::ConstantOp::create( + builder, loc, idxTy, builder.getIntegerAttr(idxTy, extent - 1)); + mlir::Value step = mlir::arith::ConstantOp::create( + builder, loc, idxTy, builder.getIntegerAttr(idxTy, 1)); + auto loop = fir::DoLoopOp::create(builder, loc, lb, ub, step, + /*unordered=*/false); builder.setInsertionPointToStart(loop.getBody()); loops.push_back(loop); ivs.push_back(loop.getInductionVar()); @@ -1594,8 +1598,8 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> values = genConstantBounds(builder, loc, dataBound); auto loop = - builder.create<fir::DoLoopOp>(loc, values[0], values[1], values[2], - /*unordered=*/false); + fir::DoLoopOp::create(builder, loc, values[0], values[1], values[2], + /*unordered=*/false); builder.setInsertionPointToStart(loop.getBody()); loops.push_back(loop); ivs.push_back(loop.getInductionVar()); @@ -1611,31 +1615,31 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb = recipe.getCombinerRegion().getArgument(i); mlir::Value ub = recipe.getCombinerRegion().getArgument(i + 1); mlir::Value step = recipe.getCombinerRegion().getArgument(i + 2); - auto loop = builder.create<fir::DoLoopOp>(loc, lb, ub, step, - /*unordered=*/false); + auto loop = fir::DoLoopOp::create(builder, loc, lb, ub, step, + /*unordered=*/false); builder.setInsertionPointToStart(loop.getBody()); loops.push_back(loop); ivs.push_back(loop.getInductionVar()); } } - auto addr1 = builder.create<fir::CoordinateOp>(loc, refTy, value1, ivs); - auto addr2 = builder.create<fir::CoordinateOp>(loc, refTy, value2, ivs); - auto load1 = builder.create<fir::LoadOp>(loc, addr1); - auto load2 = builder.create<fir::LoadOp>(loc, addr2); + auto addr1 = fir::CoordinateOp::create(builder, loc, refTy, value1, ivs); + auto addr2 = fir::CoordinateOp::create(builder, loc, refTy, value2, ivs); + auto load1 = fir::LoadOp::create(builder, loc, addr1); + auto load2 = fir::LoadOp::create(builder, loc, addr2); mlir::Value res = genScalarCombiner(builder, loc, op, seqTy.getEleTy(), load1, load2); - builder.create<fir::StoreOp>(loc, res, addr1); + fir::StoreOp::create(builder, loc, res, addr1); builder.setInsertionPointAfter(loops[0]); } else if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty)) { mlir::Type innerTy = fir::unwrapRefType(boxTy.getEleTy()); if (fir::isa_trivial(innerTy)) { mlir::Value boxAddr1 = value1, boxAddr2 = value2; if (fir::isBoxAddress(boxAddr1.getType())) - boxAddr1 = builder.create<fir::LoadOp>(loc, boxAddr1); + boxAddr1 = fir::LoadOp::create(builder, loc, boxAddr1); if (fir::isBoxAddress(boxAddr2.getType())) - boxAddr2 = builder.create<fir::LoadOp>(loc, boxAddr2); - boxAddr1 = builder.create<fir::BoxAddrOp>(loc, boxAddr1); - boxAddr2 = builder.create<fir::BoxAddrOp>(loc, boxAddr2); + boxAddr2 = fir::LoadOp::create(builder, loc, boxAddr2); + boxAddr1 = fir::BoxAddrOp::create(builder, loc, boxAddr1); + boxAddr2 = fir::BoxAddrOp::create(builder, loc, boxAddr2); auto leftEntity = hlfir::Entity{boxAddr1}; auto rightEntity = hlfir::Entity{boxAddr2}; @@ -1643,7 +1647,7 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, auto rightVal = hlfir::loadTrivialScalar(loc, builder, rightEntity); mlir::Value res = genScalarCombiner(builder, loc, op, innerTy, leftVal, rightVal); - builder.create<hlfir::AssignOp>(loc, res, boxAddr1); + hlfir::AssignOp::create(builder, loc, res, boxAddr1); } else { mlir::Type innerTy = fir::extractSequenceType(boxTy); fir::SequenceType seqTy = @@ -1658,14 +1662,14 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, getSubscriptsFromArgs(recipe.getCombinerRegion().getArguments()); auto leftEntity = hlfir::Entity{value1}; if (fir::isBoxAddress(value1.getType())) - leftEntity = - hlfir::Entity{builder.create<fir::LoadOp>(loc, value1).getResult()}; + leftEntity = hlfir::Entity{ + fir::LoadOp::create(builder, loc, value1).getResult()}; auto left = genDesignateWithTriplets(builder, loc, leftEntity, triplets, shape); auto rightEntity = hlfir::Entity{value2}; if (fir::isBoxAddress(value2.getType())) - rightEntity = - hlfir::Entity{builder.create<fir::LoadOp>(loc, value2).getResult()}; + rightEntity = hlfir::Entity{ + fir::LoadOp::create(builder, loc, value2).getResult()}; auto right = genDesignateWithTriplets(builder, loc, rightEntity, triplets, shape); @@ -1683,11 +1687,11 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value elemental = hlfir::genElementalOp( loc, builder, seqTy.getEleTy(), shape, typeParams, genKernel, /*isUnordered=*/true); - builder.create<hlfir::AssignOp>(loc, elemental, value1); + hlfir::AssignOp::create(builder, loc, elemental, value1); } } else { mlir::Value res = genScalarCombiner(builder, loc, op, ty, value1, value2); - builder.create<fir::StoreOp>(loc, res, value1); + fir::StoreOp::create(builder, loc, res, value1); } } @@ -1729,7 +1733,7 @@ mlir::acc::ReductionRecipeOp Fortran::lower::createOrGetReductionRecipe( mlir::Value v1 = recipe.getCombinerRegion().front().getArgument(0); mlir::Value v2 = recipe.getCombinerRegion().front().getArgument(1); genCombiner(builder, loc, op, ty, v1, v2, recipe, bounds, allConstantBound); - builder.create<mlir::acc::YieldOp>(loc, v1); + mlir::acc::YieldOp::create(builder, loc, v1); builder.restoreInsertionPoint(ip); return recipe; } @@ -1821,7 +1825,7 @@ createRegionOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Type> retTy = {}, mlir::Value yieldValue = {}, mlir::TypeRange argsTy = {}, llvm::SmallVector<mlir::Location> locs = {}) { - Op op = builder.create<Op>(loc, retTy, operands); + Op op = Op::create(builder, loc, retTy, operands); builder.createBlock(&op.getRegion(), op.getRegion().end(), argsTy, locs); mlir::Block &block = op.getRegion().back(); builder.setInsertionPointToStart(&block); @@ -1841,13 +1845,13 @@ createRegionOp(fir::FirOpBuilder &builder, mlir::Location loc, if (yieldValue) { if constexpr (std::is_same_v<Terminator, mlir::acc::YieldOp>) { - Terminator yieldOp = builder.create<Terminator>(returnLoc, yieldValue); + Terminator yieldOp = Terminator::create(builder, returnLoc, yieldValue); yieldValue.getDefiningOp()->moveBefore(yieldOp); } else { - builder.create<Terminator>(returnLoc); + Terminator::create(builder, returnLoc); } } else { - builder.create<Terminator>(returnLoc); + Terminator::create(builder, returnLoc); } builder.setInsertionPointToStart(&block); return op; @@ -2437,7 +2441,7 @@ static mlir::acc::LoopOp createLoopOp( for (auto [arg, value] : llvm::zip( loopOp.getLoopRegions().front()->front().getArguments(), ivPrivate)) - builder.create<fir::StoreOp>(currentLocation, arg, value); + fir::StoreOp::create(builder, currentLocation, arg, value); loopOp.setInclusiveUpperbound(inclusiveBounds); @@ -3750,8 +3754,8 @@ genACCUpdateOp(Fortran::lower::AbstractConverter &converter, dataClauseOperands.append(updateHostOperands); - builder.create<mlir::acc::UpdateOp>( - currentLocation, ifCond, asyncOperands, + mlir::acc::UpdateOp::create( + builder, currentLocation, ifCond, asyncOperands, getArrayAttr(builder, asyncOperandsDeviceTypes), getArrayAttr(builder, asyncOnlyDeviceTypes), waitOperands, getDenseI32ArrayAttr(builder, waitOperandsSegments), @@ -3873,13 +3877,14 @@ static void createDeclareGlobalOp(mlir::OpBuilder &modBuilder, const std::string &declareGlobalName, bool implicit, std::stringstream &asFortran) { GlobalOp declareGlobalOp = - modBuilder.create<GlobalOp>(loc, declareGlobalName); + GlobalOp::create(modBuilder, loc, declareGlobalName); builder.createBlock(&declareGlobalOp.getRegion(), declareGlobalOp.getRegion().end(), {}, {}); builder.setInsertionPointToEnd(&declareGlobalOp.getRegion().back()); - fir::AddrOfOp addrOp = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), globalOp.getSymbol()); + fir::AddrOfOp addrOp = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + globalOp.getSymbol()); addDeclareAttr(builder, addrOp, clause); llvm::SmallVector<mlir::Value> bounds; @@ -3888,21 +3893,21 @@ static void createDeclareGlobalOp(mlir::OpBuilder &modBuilder, /*structured=*/false, implicit, clause, addrOp.getResTy().getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); if constexpr (std::is_same_v<DeclareOp, mlir::acc::DeclareEnterOp>) - builder.create<DeclareOp>( - loc, mlir::acc::DeclareTokenType::get(entryOp.getContext()), - mlir::ValueRange(entryOp.getAccVar())); + DeclareOp::create(builder, loc, + mlir::acc::DeclareTokenType::get(entryOp.getContext()), + mlir::ValueRange(entryOp.getAccVar())); else - builder.create<DeclareOp>(loc, mlir::Value{}, - mlir::ValueRange(entryOp.getAccVar())); + DeclareOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(entryOp.getAccVar())); if constexpr (std::is_same_v<GlobalOp, mlir::acc::GlobalDestructorOp>) { - builder.create<ExitOp>(entryOp.getLoc(), entryOp.getAccVar(), - entryOp.getBounds(), entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); } - builder.create<mlir::acc::TerminatorOp>(loc); + mlir::acc::TerminatorOp::create(builder, loc); modBuilder.setInsertionPointAfter(declareGlobalOp); } @@ -3917,8 +3922,9 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder, auto registerFuncOp = createDeclareFunc(modBuilder, builder, loc, registerFuncName.str()); - fir::AddrOfOp addrOp = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), globalOp.getSymbol()); + fir::AddrOfOp addrOp = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + globalOp.getSymbol()); std::stringstream asFortran; asFortran << Fortran::lower::mangle::demangleName(globalOp.getSymName()); @@ -3941,15 +3947,15 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder, createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments); if (unwrapFirBox) { - auto loadOp = builder.create<fir::LoadOp>(loc, addrOp.getResult()); - fir::BoxAddrOp boxAddrOp = builder.create<fir::BoxAddrOp>(loc, loadOp); + auto loadOp = fir::LoadOp::create(builder, loc, addrOp.getResult()); + fir::BoxAddrOp boxAddrOp = fir::BoxAddrOp::create(builder, loc, loadOp); addDeclareAttr(builder, boxAddrOp.getOperation(), clause); EntryOp entryOp = createDataEntryOp<EntryOp>( builder, loc, boxAddrOp.getResult(), asFortran, bounds, /*structured=*/false, /*implicit=*/false, clause, boxAddrOp.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - builder.create<mlir::acc::DeclareEnterOp>( - loc, mlir::acc::DeclareTokenType::get(entryOp.getContext()), + mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(entryOp.getContext()), mlir::ValueRange(entryOp.getAccVar())); } @@ -3980,10 +3986,11 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder, auto preDeallocOp = createDeclareFunc(modBuilder, builder, loc, preDeallocFuncName.str()); - fir::AddrOfOp addrOp = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), globalOp.getSymbol()); - auto loadOp = builder.create<fir::LoadOp>(loc, addrOp.getResult()); - fir::BoxAddrOp boxAddrOp = builder.create<fir::BoxAddrOp>(loc, loadOp); + fir::AddrOfOp addrOp = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + globalOp.getSymbol()); + auto loadOp = fir::LoadOp::create(builder, loc, addrOp.getResult()); + fir::BoxAddrOp boxAddrOp = fir::BoxAddrOp::create(builder, loc, loadOp); mlir::Value var = boxAddrOp.getResult(); addDeclareAttr(builder, var.getDefiningOp(), clause); @@ -3994,25 +4001,25 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder, /*structured=*/false, /*implicit=*/false, clause, var.getType(), /*async=*/{}, /*asyncDeviceTypes=*/{}, /*asyncOnlyDeviceTypes=*/{}); - builder.create<mlir::acc::DeclareExitOp>( - loc, mlir::Value{}, mlir::ValueRange(entryOp.getAccVar())); + mlir::acc::DeclareExitOp::create(builder, loc, mlir::Value{}, + mlir::ValueRange(entryOp.getAccVar())); if constexpr (std::is_same_v<ExitOp, mlir::acc::CopyoutOp> || std::is_same_v<ExitOp, mlir::acc::UpdateHostOp>) - builder.create<ExitOp>( - entryOp.getLoc(), entryOp.getAccVar(), entryOp.getVar(), - entryOp.getBounds(), entryOp.getAsyncOperands(), - entryOp.getAsyncOperandsDeviceTypeAttr(), entryOp.getAsyncOnlyAttr(), - entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getVar(), entryOp.getBounds(), + entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); else - builder.create<ExitOp>( - entryOp.getLoc(), entryOp.getAccVar(), entryOp.getBounds(), - entryOp.getAsyncOperands(), entryOp.getAsyncOperandsDeviceTypeAttr(), - entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), - /*structured=*/false, /*implicit=*/false, - builder.getStringAttr(*entryOp.getName())); + ExitOp::create(builder, entryOp.getLoc(), entryOp.getAccVar(), + entryOp.getBounds(), entryOp.getAsyncOperands(), + entryOp.getAsyncOperandsDeviceTypeAttr(), + entryOp.getAsyncOnlyAttr(), entryOp.getDataClause(), + /*structured=*/false, /*implicit=*/false, + builder.getStringAttr(*entryOp.getName())); // Generate the post dealloc function. modBuilder.setInsertionPointAfter(preDeallocOp); @@ -4024,8 +4031,9 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder, auto postDeallocOp = createDeclareFunc(modBuilder, builder, loc, postDeallocFuncName.str()); - fir::AddrOfOp addrOp = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), globalOp.getSymbol()); + fir::AddrOfOp addrOp = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + globalOp.getSymbol()); if (unwrapFirBox) asFortran << accFirDescriptorPostfix.str(); llvm::SmallVector<mlir::Value> bounds; @@ -4262,13 +4270,13 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter, auto ops = funcOp.getOps<mlir::acc::DeclareEnterOp>(); mlir::Value declareToken; if (ops.empty()) { - declareToken = builder.create<mlir::acc::DeclareEnterOp>( - loc, mlir::acc::DeclareTokenType::get(builder.getContext()), + declareToken = mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(builder.getContext()), dataClauseOperands); } else { auto declareOp = *ops.begin(); - auto newDeclareOp = builder.create<mlir::acc::DeclareEnterOp>( - loc, mlir::acc::DeclareTokenType::get(builder.getContext()), + auto newDeclareOp = mlir::acc::DeclareEnterOp::create( + builder, loc, mlir::acc::DeclareTokenType::get(builder.getContext()), declareOp.getDataClauseOperands()); newDeclareOp.getDataClauseOperandsMutable().append(dataClauseOperands); declareToken = newDeclareOp.getToken(); @@ -4290,7 +4298,7 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter, mlir::func::FuncOp funcOp = builder.getFunction(); auto ops = funcOp.getOps<mlir::acc::DeclareExitOp>(); if (ops.empty()) { - builder.create<mlir::acc::DeclareExitOp>(loc, declareToken, operands); + mlir::acc::DeclareExitOp::create(builder, loc, declareToken, operands); } else { auto declareOp = *ops.begin(); declareOp.getDataClauseOperandsMutable().append(operands); @@ -4535,8 +4543,8 @@ void createOpenACCRoutineConstruct( std::string routineOpStr = routineOpName.str(); mlir::OpBuilder modBuilder(mod.getBodyRegion()); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - modBuilder.create<mlir::acc::RoutineOp>( - loc, routineOpStr, + mlir::acc::RoutineOp::create( + modBuilder, loc, routineOpStr, mlir::SymbolRefAttr::get(builder.getContext(), funcName), getArrayAttrOrNull(builder, bindIdNames), getArrayAttrOrNull(builder, bindStrNames), @@ -4880,9 +4888,9 @@ void Fortran::lower::genOpenACCTerminator(fir::FirOpBuilder &builder, mlir::Operation *op, mlir::Location loc) { if (mlir::isa<mlir::acc::ParallelOp, mlir::acc::LoopOp>(op)) - builder.create<mlir::acc::YieldOp>(loc); + mlir::acc::YieldOp::create(builder, loc); else - builder.create<mlir::acc::TerminatorOp>(loc); + mlir::acc::TerminatorOp::create(builder, loc); } bool Fortran::lower::isInOpenACCLoop(fir::FirOpBuilder &builder) { @@ -4902,7 +4910,7 @@ void Fortran::lower::genEarlyReturnInOpenACCLoop(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::Value yieldValue = builder.createIntegerConstant(loc, builder.getI1Type(), 1); - builder.create<mlir::acc::YieldOp>(loc, yieldValue); + mlir::acc::YieldOp::create(builder, loc, yieldValue); } int64_t Fortran::lower::getLoopCountForCollapseAndTile( diff --git a/flang/lib/Lower/OpenMP/Atomic.cpp b/flang/lib/Lower/OpenMP/Atomic.cpp index 6ea331c..9a233d2 100644 --- a/flang/lib/Lower/OpenMP/Atomic.cpp +++ b/flang/lib/Lower/OpenMP/Atomic.cpp @@ -528,8 +528,8 @@ genAtomicRead(lower::AbstractConverter &converter, }(); builder.restoreInsertionPoint(atomicAt); - mlir::Operation *op = builder.create<mlir::omp::AtomicReadOp>( - loc, atomAddr, toAddr, mlir::TypeAttr::get(atomType), hint, + mlir::Operation *op = mlir::omp::AtomicReadOp::create( + builder, loc, atomAddr, toAddr, mlir::TypeAttr::get(atomType), hint, makeMemOrderAttr(converter, memOrder)); if (atomType != storeType) { @@ -537,7 +537,7 @@ genAtomicRead(lower::AbstractConverter &converter, // The READ operation could be a part of UPDATE CAPTURE, so make sure // we don't emit extra code into the body of the atomic op. builder.restoreInsertionPoint(postAt); - mlir::Value load = builder.create<fir::LoadOp>(loc, toAddr); + mlir::Value load = fir::LoadOp::create(builder, loc, toAddr); overrides.try_emplace(&atom, load); converter.overrideExprValues(&overrides); @@ -545,7 +545,7 @@ genAtomicRead(lower::AbstractConverter &converter, fir::getBase(converter.genExprValue(assign.rhs, stmtCtx, &loc)); converter.resetExprOverrides(); - builder.create<fir::StoreOp>(loc, value, storeAddr); + fir::StoreOp::create(builder, loc, value, storeAddr); } return op; } @@ -581,8 +581,9 @@ genAtomicWrite(lower::AbstractConverter &converter, mlir::Value converted = builder.createConvert(loc, atomType, value); builder.restoreInsertionPoint(atomicAt); - mlir::Operation *op = builder.create<mlir::omp::AtomicWriteOp>( - loc, atomAddr, converted, hint, makeMemOrderAttr(converter, memOrder)); + mlir::Operation *op = + mlir::omp::AtomicWriteOp::create(builder, loc, atomAddr, converted, hint, + makeMemOrderAttr(converter, memOrder)); return op; } @@ -635,8 +636,8 @@ genAtomicUpdate(lower::AbstractConverter &converter, } builder.restoreInsertionPoint(atomicAt); - auto updateOp = builder.create<mlir::omp::AtomicUpdateOp>( - loc, atomAddr, hint, makeMemOrderAttr(converter, memOrder)); + auto updateOp = mlir::omp::AtomicUpdateOp::create( + builder, loc, atomAddr, hint, makeMemOrderAttr(converter, memOrder)); mlir::Region ®ion = updateOp->getRegion(0); mlir::Block *block = builder.createBlock(®ion, {}, {atomType}, {loc}); @@ -647,7 +648,7 @@ genAtomicUpdate(lower::AbstractConverter &converter, mlir::Value updated = fir::getBase(converter.genExprValue(rhs, stmtCtx, &loc)); mlir::Value converted = builder.createConvert(loc, atomType, updated); - builder.create<mlir::omp::YieldOp>(loc, converted); + mlir::omp::YieldOp::create(builder, loc, converted); converter.resetExprOverrides(); builder.restoreInsertionPoint(postAt); // For naCtx cleanups @@ -731,8 +732,8 @@ void Fortran::lower::omp::lowerAtomic( "Expexcing two actions"); (void)action0; (void)action1; - captureOp = builder.create<mlir::omp::AtomicCaptureOp>( - loc, hint, makeMemOrderAttr(converter, memOrder)); + captureOp = mlir::omp::AtomicCaptureOp::create( + builder, loc, hint, makeMemOrderAttr(converter, memOrder)); // Set the non-atomic insertion point to before the atomic.capture. preAt = getInsertionPointBefore(captureOp); @@ -740,7 +741,7 @@ void Fortran::lower::omp::lowerAtomic( builder.setInsertionPointToEnd(block); // Set the atomic insertion point to before the terminator inside // atomic.capture. - mlir::Operation *term = builder.create<mlir::omp::TerminatorOp>(loc); + mlir::Operation *term = mlir::omp::TerminatorOp::create(builder, loc); atomicAt = getInsertionPointBefore(term); postAt = getInsertionPointAfter(captureOp); hint = nullptr; diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 74087d4..594f95e 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -723,7 +723,7 @@ bool ClauseProcessor::processCopyin() const { // barrier is inserted following all of them. firOpBuilder.restoreInsertionPoint(insPt); if (hasCopyin) - firOpBuilder.create<mlir::omp::BarrierOp>(converter.getCurrentLocation()); + mlir::omp::BarrierOp::create(firOpBuilder, converter.getCurrentLocation()); return hasCopyin; } @@ -803,7 +803,7 @@ createCopyFunc(mlir::Location loc, lower::AbstractConverter &converter, llvm::SmallVector<mlir::Type> argsTy = {varType, varType}; auto funcType = mlir::FunctionType::get(builder.getContext(), argsTy, {}); mlir::func::FuncOp funcOp = - modBuilder.create<mlir::func::FuncOp>(loc, copyFuncName, funcType); + mlir::func::FuncOp::create(modBuilder, loc, copyFuncName, funcType); funcOp.setVisibility(mlir::SymbolTable::Visibility::Private); fir::factory::setInternalLinkage(funcOp); builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), argsTy, @@ -819,22 +819,22 @@ createCopyFunc(mlir::Location loc, lower::AbstractConverter &converter, for (auto extent : typeInfo.getShape()) extents.push_back( builder.createIntegerConstant(loc, builder.getIndexType(), extent)); - shape = builder.create<fir::ShapeOp>(loc, extents); + shape = fir::ShapeOp::create(builder, loc, extents); } mlir::Value dst = funcOp.getArgument(0); mlir::Value src = funcOp.getArgument(1); llvm::SmallVector<mlir::Value> typeparams; if (typeInfo.isBoxChar()) { // fir.boxchar will be passed here as fir.ref<fir.boxchar> - auto loadDst = builder.create<fir::LoadOp>(loc, dst); - auto loadSrc = builder.create<fir::LoadOp>(loc, src); + auto loadDst = fir::LoadOp::create(builder, loc, dst); + auto loadSrc = fir::LoadOp::create(builder, loc, src); // get the actual fir.ref<fir.char> type mlir::Type refType = fir::ReferenceType::get(mlir::cast<fir::BoxCharType>(eleTy).getEleTy()); - auto unboxedDst = builder.create<fir::UnboxCharOp>( - loc, refType, builder.getIndexType(), loadDst); - auto unboxedSrc = builder.create<fir::UnboxCharOp>( - loc, refType, builder.getIndexType(), loadSrc); + auto unboxedDst = fir::UnboxCharOp::create(builder, loc, refType, + builder.getIndexType(), loadDst); + auto unboxedSrc = fir::UnboxCharOp::create(builder, loc, refType, + builder.getIndexType(), loadSrc); // Add length to type parameters typeparams.push_back(unboxedDst.getResult(1)); dst = unboxedDst.getResult(0); @@ -844,14 +844,14 @@ createCopyFunc(mlir::Location loc, lower::AbstractConverter &converter, loc, builder.getCharacterLengthType(), *typeInfo.getCharLength()); typeparams.push_back(charLen); } - auto declDst = builder.create<hlfir::DeclareOp>( - loc, dst, copyFuncName + "_dst", shape, typeparams, + auto declDst = hlfir::DeclareOp::create( + builder, loc, dst, copyFuncName + "_dst", shape, typeparams, /*dummy_scope=*/nullptr, attrs); - auto declSrc = builder.create<hlfir::DeclareOp>( - loc, src, copyFuncName + "_src", shape, typeparams, + auto declSrc = hlfir::DeclareOp::create( + builder, loc, src, copyFuncName + "_src", shape, typeparams, /*dummy_scope=*/nullptr, attrs); converter.copyVar(loc, declDst.getBase(), declSrc.getBase(), varAttrs); - builder.create<mlir::func::ReturnOp>(loc); + mlir::func::ReturnOp::create(builder, loc); return funcOp; } @@ -882,8 +882,8 @@ bool ClauseProcessor::processCopyprivate( if (mlir::isa<fir::BaseBoxType>(symType) || mlir::isa<fir::BoxCharType>(symType)) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - auto alloca = builder.create<fir::AllocaOp>(currentLocation, symType); - builder.create<fir::StoreOp>(currentLocation, symVal, alloca); + auto alloca = fir::AllocaOp::create(builder, currentLocation, symType); + fir::StoreOp::create(builder, currentLocation, symVal, alloca); cpVar = alloca; } @@ -1002,8 +1002,8 @@ bool ClauseProcessor::processDepend(lower::SymMap &symMap, // allocations so this is not a reliable way to identify the dependency. if (auto ref = mlir::dyn_cast<fir::ReferenceType>(dependVar.getType())) if (fir::isa_box_type(ref.getElementType())) - dependVar = builder.create<fir::LoadOp>( - converter.getCurrentLocation(), dependVar); + dependVar = fir::LoadOp::create( + builder, converter.getCurrentLocation(), dependVar); // The openmp dialect doesn't know what to do with boxes (and it would // break layering to teach it about them). The dependency variable can be @@ -1012,8 +1012,8 @@ bool ClauseProcessor::processDepend(lower::SymMap &symMap, // Getting the address of the box data is okay because all the runtime // ultimately cares about is the base address of the array. if (fir::isa_box_type(dependVar.getType())) - dependVar = builder.create<fir::BoxAddrOp>( - converter.getCurrentLocation(), dependVar); + dependVar = fir::BoxAddrOp::create( + builder, converter.getCurrentLocation(), dependVar); result.dependVars.push_back(dependVar); } @@ -1116,11 +1116,12 @@ bool ClauseProcessor::processInReduction( collectReductionSyms(clause, inReductionSyms); ReductionProcessor rp; - rp.processReductionArguments<mlir::omp::DeclareReductionOp>( - currentLocation, converter, - std::get<typename omp::clause::ReductionOperatorList>(clause.t), - inReductionVars, inReduceVarByRef, inReductionDeclSymbols, - inReductionSyms); + if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>( + currentLocation, converter, + std::get<typename omp::clause::ReductionOperatorList>(clause.t), + inReductionVars, inReduceVarByRef, inReductionDeclSymbols, + inReductionSyms)) + inReductionSyms.clear(); // Copy local lists into the output. llvm::copy(inReductionVars, std::back_inserter(result.inReductionVars)); @@ -1315,7 +1316,8 @@ bool ClauseProcessor::processMap( const parser::CharBlock &source) { using Map = omp::clause::Map; mlir::Location clauseLocation = converter.genLocation(source); - const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t; + const auto &[mapType, typeMods, refMod, mappers, iterator, objects] = + clause.t; llvm::omp::OpenMPOffloadMappingFlags mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE; std::string mapperIdName = "__implicit_mapper"; @@ -1342,16 +1344,13 @@ bool ClauseProcessor::processMap( mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO | llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM; break; - case Map::MapType::Alloc: - case Map::MapType::Release: + case Map::MapType::Storage: // alloc and release is the default map_type for the Target Data // Ops, i.e. if no bits for map_type is supplied then alloc/release - // is implicitly assumed based on the target directive. Default - // value for Target Data and Enter Data is alloc and for Exit Data - // it is release. + // (aka storage in 6.0+) is implicitly assumed based on the target + // directive. Default value for Target Data and Enter Data is alloc + // and for Exit Data it is release. break; - case Map::MapType::Delete: - mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE; } if (typeMods) { @@ -1362,6 +1361,8 @@ bool ClauseProcessor::processMap( mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PRESENT; if (llvm::is_contained(*typeMods, Map::MapTypeModifier::Close)) mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_CLOSE; + if (llvm::is_contained(*typeMods, Map::MapTypeModifier::Delete)) + mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE; if (llvm::is_contained(*typeMods, Map::MapTypeModifier::OmpxHold)) mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_OMPX_HOLD; } @@ -1461,10 +1462,12 @@ bool ClauseProcessor::processReduction( } ReductionProcessor rp; - rp.processReductionArguments<mlir::omp::DeclareReductionOp>( - currentLocation, converter, - std::get<typename omp::clause::ReductionOperatorList>(clause.t), - reductionVars, reduceVarByRef, reductionDeclSymbols, reductionSyms); + if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>( + currentLocation, converter, + std::get<typename omp::clause::ReductionOperatorList>(clause.t), + reductionVars, reduceVarByRef, reductionDeclSymbols, + reductionSyms)) + reductionSyms.clear(); // Copy local lists into the output. llvm::copy(reductionVars, std::back_inserter(result.reductionVars)); llvm::copy(reduceVarByRef, std::back_inserter(result.reductionByref)); @@ -1486,11 +1489,12 @@ bool ClauseProcessor::processTaskReduction( collectReductionSyms(clause, taskReductionSyms); ReductionProcessor rp; - rp.processReductionArguments<mlir::omp::DeclareReductionOp>( - currentLocation, converter, - std::get<typename omp::clause::ReductionOperatorList>(clause.t), - taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols, - taskReductionSyms); + if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>( + currentLocation, converter, + std::get<typename omp::clause::ReductionOperatorList>(clause.t), + taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols, + taskReductionSyms)) + taskReductionSyms.clear(); // Copy local lists into the output. llvm::copy(taskReductionVars, std::back_inserter(result.taskReductionVars)); diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index 22a0721..686fba0 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -1001,19 +1001,21 @@ Map make(const parser::OmpClause::Map &inp, semantics::SemanticsContext &semaCtx) { // inp.v -> parser::OmpMapClause CLAUSET_ENUM_CONVERT( // - convert1, parser::OmpMapType::Value, Map::MapType, + convertMapType, parser::OmpMapType::Value, Map::MapType, // clang-format off - MS(Alloc, Alloc) - MS(Delete, Delete) - MS(From, From) - MS(Release, Release) - MS(To, To) - MS(Tofrom, Tofrom) + MS(Alloc, Storage) + MS(Delete, Storage) + MS(Release, Storage) + MS(Storage, Storage) + MS(From, From) + MS(To, To) + MS(Tofrom, Tofrom) // clang-format on ); CLAUSET_ENUM_CONVERT( // - convert2, parser::OmpMapTypeModifier::Value, Map::MapTypeModifier, + convertMapTypeMod, parser::OmpMapTypeModifier::Value, + Map::MapTypeModifier, // clang-format off MS(Always, Always) MS(Close, Close) @@ -1022,43 +1024,76 @@ Map make(const parser::OmpClause::Map &inp, // clang-format on ); + CLAUSET_ENUM_CONVERT( // + convertRefMod, parser::OmpRefModifier::Value, Map::RefModifier, + // clang-format off + MS(Ref_Ptee, RefPtee) + MS(Ref_Ptr, RefPtr) + MS(Ref_Ptr_Ptee, RefPtrPtee) + // clang-format on + ); + + // Treat always, close, present, self, delete modifiers as map-type- + // modifiers. auto &mods = semantics::OmpGetModifiers(inp.v); - auto *t1 = semantics::OmpGetUniqueModifier<parser::OmpMapper>(mods); - auto *t2 = semantics::OmpGetUniqueModifier<parser::OmpIterator>(mods); - auto *t3 = semantics::OmpGetUniqueModifier<parser::OmpMapType>(mods); - auto &t4 = std::get<parser::OmpObjectList>(inp.v.t); - auto mappers = [&]() -> std::optional<List<Mapper>> { + auto *t1 = semantics::OmpGetUniqueModifier<parser::OmpMapType>(mods); + auto &t2 = std::get<parser::OmpObjectList>(inp.v.t); + + auto type = [&]() -> std::optional<Map::MapType> { if (t1) - return List<Mapper>{Mapper{makeObject(t1->v, semaCtx)}}; + return convertMapType(t1->v); return std::nullopt; }(); - auto iterator = [&]() -> std::optional<Iterator> { - if (t2) - return makeIterator(*t2, semaCtx); + llvm::DenseSet<Map::MapTypeModifier> modSet; + if (t1 && t1->v == parser::OmpMapType::Value::Delete) + modSet.insert(Map::MapTypeModifier::Delete); + + for (auto *typeMod : + semantics::OmpGetRepeatableModifier<parser::OmpMapTypeModifier>(mods)) { + modSet.insert(convertMapTypeMod(typeMod->v)); + } + if (semantics::OmpGetUniqueModifier<parser::OmpAlwaysModifier>(mods)) + modSet.insert(Map::MapTypeModifier::Always); + if (semantics::OmpGetUniqueModifier<parser::OmpCloseModifier>(mods)) + modSet.insert(Map::MapTypeModifier::Close); + if (semantics::OmpGetUniqueModifier<parser::OmpDeleteModifier>(mods)) + modSet.insert(Map::MapTypeModifier::Delete); + if (semantics::OmpGetUniqueModifier<parser::OmpPresentModifier>(mods)) + modSet.insert(Map::MapTypeModifier::Present); + if (semantics::OmpGetUniqueModifier<parser::OmpSelfModifier>(mods)) + modSet.insert(Map::MapTypeModifier::Self); + if (semantics::OmpGetUniqueModifier<parser::OmpxHoldModifier>(mods)) + modSet.insert(Map::MapTypeModifier::OmpxHold); + + std::optional<Map::MapTypeModifiers> maybeTypeMods{}; + if (!modSet.empty()) + maybeTypeMods = Map::MapTypeModifiers(modSet.begin(), modSet.end()); + + auto refMod = [&]() -> std::optional<Map::RefModifier> { + if (auto *t = semantics::OmpGetUniqueModifier<parser::OmpRefModifier>(mods)) + return convertRefMod(t->v); return std::nullopt; }(); - auto type = [&]() -> std::optional<Map::MapType> { - if (t3) - return convert1(t3->v); + auto mappers = [&]() -> std::optional<List<Mapper>> { + if (auto *t = semantics::OmpGetUniqueModifier<parser::OmpMapper>(mods)) + return List<Mapper>{Mapper{makeObject(t->v, semaCtx)}}; return std::nullopt; }(); - Map::MapTypeModifiers typeMods; - for (auto *typeMod : - semantics::OmpGetRepeatableModifier<parser::OmpMapTypeModifier>(mods)) { - typeMods.push_back(convert2(typeMod->v)); - } - std::optional<Map::MapTypeModifiers> maybeTypeMods{}; - if (!typeMods.empty()) - maybeTypeMods = std::move(typeMods); + auto iterator = [&]() -> std::optional<Iterator> { + if (auto *t = semantics::OmpGetUniqueModifier<parser::OmpIterator>(mods)) + return makeIterator(*t, semaCtx); + return std::nullopt; + }(); return Map{{/*MapType=*/std::move(type), /*MapTypeModifiers=*/std::move(maybeTypeMods), - /*Mapper=*/std::move(mappers), /*Iterator=*/std::move(iterator), - /*LocatorList=*/makeObjects(t4, semaCtx)}}; + /*RefModifier=*/std::move(refMod), /*Mapper=*/std::move(mappers), + /*Iterator=*/std::move(iterator), + /*LocatorList=*/makeObjects(t2, semaCtx)}}; } Match make(const parser::OmpClause::Match &inp, diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp index 675a58e..2ac4d95 100644 --- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp +++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp @@ -24,6 +24,7 @@ #include "flang/Optimizer/Dialect/FIROps.h" #include "flang/Optimizer/HLFIR/HLFIRDialect.h" #include "flang/Optimizer/HLFIR/HLFIROps.h" +#include "flang/Parser/openmp-utils.h" #include "flang/Semantics/attr.h" #include "flang/Semantics/tools.h" #include "llvm/ADT/Sequence.h" @@ -291,7 +292,7 @@ void DataSharingProcessor::insertBarrier( clauseOps->privateNeedsBarrier = mlir::UnitAttr::get(&converter.getMLIRContext()); } else { - firOpBuilder.create<mlir::omp::BarrierOp>(converter.getCurrentLocation()); + mlir::omp::BarrierOp::create(firOpBuilder, converter.getCurrentLocation()); } } @@ -351,32 +352,32 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) { loopOp.getIVs(), result.loopUpperBounds, result.loopSteps)) { // v = iv + step // cmp = step < 0 ? v < ub : v > ub - mlir::Value v = firOpBuilder.create<mlir::arith::AddIOp>(loc, iv, step); + mlir::Value v = mlir::arith::AddIOp::create(firOpBuilder, loc, iv, step); vs.push_back(v); mlir::Value zero = firOpBuilder.createIntegerConstant(loc, step.getType(), 0); - mlir::Value negativeStep = firOpBuilder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, step, zero); - mlir::Value vLT = firOpBuilder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, v, ub); - mlir::Value vGT = firOpBuilder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, v, ub); - mlir::Value icmpOp = firOpBuilder.create<mlir::arith::SelectOp>( - loc, negativeStep, vLT, vGT); + mlir::Value negativeStep = mlir::arith::CmpIOp::create( + firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, step, zero); + mlir::Value vLT = mlir::arith::CmpIOp::create( + firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, v, ub); + mlir::Value vGT = mlir::arith::CmpIOp::create( + firOpBuilder, loc, mlir::arith::CmpIPredicate::sgt, v, ub); + mlir::Value icmpOp = mlir::arith::SelectOp::create( + firOpBuilder, loc, negativeStep, vLT, vGT); if (cmpOp) - cmpOp = firOpBuilder.create<mlir::arith::AndIOp>(loc, cmpOp, icmpOp); + cmpOp = mlir::arith::AndIOp::create(firOpBuilder, loc, cmpOp, icmpOp); else cmpOp = icmpOp; } - auto ifOp = firOpBuilder.create<fir::IfOp>(loc, cmpOp, /*else*/ false); + auto ifOp = fir::IfOp::create(firOpBuilder, loc, cmpOp, /*else*/ false); firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front()); for (auto [v, loopIV] : llvm::zip_equal(vs, loopIVs)) { hlfir::Entity loopIVEntity{loopIV}; loopIVEntity = hlfir::derefPointersAndAllocatables(loc, firOpBuilder, loopIVEntity); - firOpBuilder.create<hlfir::AssignOp>(loc, v, loopIVEntity); + hlfir::AssignOp::create(firOpBuilder, loc, v, loopIVEntity); } lastPrivIP = firOpBuilder.saveInsertionPoint(); } else if (mlir::isa<mlir::omp::SectionsOp>(op)) { @@ -465,7 +466,8 @@ bool DataSharingProcessor::isOpenMPPrivatizingConstruct( // allow a privatizing clause) are: dispatch, distribute, do, for, loop, // parallel, scope, sections, simd, single, target, target_data, task, // taskgroup, taskloop, and teams. - return llvm::is_contained(privatizing, extractOmpDirective(omp)); + return llvm::is_contained(privatizing, + parser::omp::GetOmpDirectiveName(omp).v); } bool DataSharingProcessor::isOpenMPPrivatizingEvaluation( diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index fcb20fd..4c2d7bad 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -31,6 +31,7 @@ #include "flang/Optimizer/Dialect/FIRType.h" #include "flang/Optimizer/HLFIR/HLFIROps.h" #include "flang/Parser/characters.h" +#include "flang/Parser/openmp-utils.h" #include "flang/Parser/parse-tree.h" #include "flang/Semantics/openmp-directive-sets.h" #include "flang/Semantics/tools.h" @@ -446,7 +447,7 @@ static void processHostEvalClauses(lower::AbstractConverter &converter, llvm::omp::Directive dir; auto &nested = parent.getFirstNestedEvaluation(); if (const auto *ompEval = nested.getIf<parser::OpenMPConstruct>()) - dir = extractOmpDirective(*ompEval); + dir = parser::omp::GetOmpDirectiveName(*ompEval).v; else return std::nullopt; @@ -486,7 +487,7 @@ static void processHostEvalClauses(lower::AbstractConverter &converter, HostEvalInfo *hostInfo = getHostEvalInfoStackTop(converter); assert(hostInfo && "expected HOST_EVAL info structure"); - switch (extractOmpDirective(*ompEval)) { + switch (parser::omp::GetOmpDirectiveName(*ompEval).v) { case OMPD_teams_distribute_parallel_do: case OMPD_teams_distribute_parallel_do_simd: cp.processThreadLimit(stmtCtx, hostInfo->ops); @@ -547,7 +548,8 @@ static void processHostEvalClauses(lower::AbstractConverter &converter, const auto *ompEval = eval.getIf<parser::OpenMPConstruct>(); assert(ompEval && - llvm::omp::allTargetSet.test(extractOmpDirective(*ompEval)) && + llvm::omp::allTargetSet.test( + parser::omp::GetOmpDirectiveName(*ompEval).v) && "expected TARGET construct evaluation"); (void)ompEval; @@ -642,8 +644,8 @@ static void threadPrivatizeVars(lower::AbstractConverter &converter, op = declOp.getMemref().getDefiningOp(); if (mlir::isa<mlir::omp::ThreadprivateOp>(op)) symValue = mlir::dyn_cast<mlir::omp::ThreadprivateOp>(op).getSymAddr(); - return firOpBuilder.create<mlir::omp::ThreadprivateOp>( - currentLocation, symValue.getType(), symValue); + return mlir::omp::ThreadprivateOp::create(firOpBuilder, currentLocation, + symValue.getType(), symValue); }; llvm::SetVector<const semantics::Symbol *> threadprivateSyms; @@ -710,7 +712,7 @@ createAndSetPrivatizedLoopVar(lower::AbstractConverter &converter, lhs = hlfir::derefPointersAndAllocatables(loc, firOpBuilder, lhs); mlir::Operation *storeOp = - firOpBuilder.create<hlfir::AssignOp>(loc, cvtVal, lhs); + hlfir::AssignOp::create(firOpBuilder, loc, cvtVal, lhs); return storeOp; } @@ -1156,8 +1158,8 @@ static void createBodyOfOp(mlir::Operation &op, const OpWithBodyGenInfo &info, fir::FirOpBuilder &firOpBuilder = info.converter.getFirOpBuilder(); auto insertMarker = [](fir::FirOpBuilder &builder) { - mlir::Value undef = builder.create<fir::UndefOp>(builder.getUnknownLoc(), - builder.getIndexType()); + mlir::Value undef = fir::UndefOp::create(builder, builder.getUnknownLoc(), + builder.getIndexType()); return undef.getDefiningOp(); }; @@ -1271,7 +1273,7 @@ static void createBodyOfOp(mlir::Operation &op, const OpWithBodyGenInfo &info, mlir::Block *exit = firOpBuilder.createBlock(®ion); for (mlir::Block *b : exits) { firOpBuilder.setInsertionPointToEnd(b); - firOpBuilder.create<mlir::cf::BranchOp>(info.loc, exit); + mlir::cf::BranchOp::create(firOpBuilder, info.loc, exit); } return exit; }; @@ -1332,8 +1334,8 @@ static void genBodyOfTargetDataOp( // Remembering the position for further insertion is important since // there are hlfir.declares inserted above while setting block arguments // and new code from the body should be inserted after that. - mlir::Value undefMarker = firOpBuilder.create<fir::UndefOp>( - dataOp.getLoc(), firOpBuilder.getIndexType()); + mlir::Value undefMarker = fir::UndefOp::create(firOpBuilder, dataOp.getLoc(), + firOpBuilder.getIndexType()); // Create blocks for unstructured regions. This has to be done since // blocks are initially allocated with the function as the parent region. @@ -1342,7 +1344,7 @@ static void genBodyOfTargetDataOp( firOpBuilder, eval.getNestedEvaluations()); } - firOpBuilder.create<mlir::omp::TerminatorOp>(currentLocation); + mlir::omp::TerminatorOp::create(firOpBuilder, currentLocation); // Set the insertion point after the marker. firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp()); @@ -1496,8 +1498,8 @@ static void genBodyOfTargetOp( insertIndex, copyVal.getType(), copyVal.getLoc()); firOpBuilder.setInsertionPointToStart(entryBlock); - auto loadOp = firOpBuilder.create<fir::LoadOp>(clonedValArg.getLoc(), - clonedValArg); + auto loadOp = fir::LoadOp::create(firOpBuilder, clonedValArg.getLoc(), + clonedValArg); val.replaceUsesWithIf(loadOp->getResult(0), [entryBlock](mlir::OpOperand &use) { return use.getOwner()->getBlock() == entryBlock; @@ -1513,8 +1515,8 @@ static void genBodyOfTargetOp( // marker will be deleted since there are not uses. // In the HLFIR flow there are hlfir.declares inserted above while // setting block arguments. - mlir::Value undefMarker = firOpBuilder.create<fir::UndefOp>( - targetOp.getLoc(), firOpBuilder.getIndexType()); + mlir::Value undefMarker = fir::UndefOp::create( + firOpBuilder, targetOp.getLoc(), firOpBuilder.getIndexType()); // Create blocks for unstructured regions. This has to be done since // blocks are initially allocated with the function as the parent region. @@ -1524,7 +1526,7 @@ static void genBodyOfTargetOp( firOpBuilder, eval.getNestedEvaluations()); } - firOpBuilder.create<mlir::omp::TerminatorOp>(currentLocation); + mlir::omp::TerminatorOp::create(firOpBuilder, currentLocation); // Create the insertion point after the marker. firOpBuilder.setInsertionPointAfter(undefMarker.getDefiningOp()); @@ -1570,7 +1572,7 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter, fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); // Create wrapper. - auto op = firOpBuilder.create<OpTy>(loc, clauseOps); + auto op = OpTy::create(firOpBuilder, loc, clauseOps); // Create entry block with arguments. genEntryBlock(firOpBuilder, args, op.getRegion()); @@ -1983,7 +1985,7 @@ genCriticalOp(lower::AbstractConverter &converter, lower::SymMap &symTable, clauseOps, nameStr); mlir::OpBuilder modBuilder(mod.getBodyRegion()); - global = modBuilder.create<mlir::omp::CriticalDeclareOp>(loc, clauseOps); + global = mlir::omp::CriticalDeclareOp::create(modBuilder, loc, clauseOps); } nameAttr = mlir::FlatSymbolRefAttr::get(firOpBuilder.getContext(), global.getSymName()); @@ -2069,6 +2071,163 @@ genLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable, return loopOp; } +static mlir::omp::CanonicalLoopOp +genCanonicalLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable, + semantics::SemanticsContext &semaCtx, + lower::pft::Evaluation &eval, mlir::Location loc, + const ConstructQueue &queue, + ConstructQueue::const_iterator item, + llvm::ArrayRef<const semantics::Symbol *> ivs, + llvm::omp::Directive directive, DataSharingProcessor &dsp) { + fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + + assert(ivs.size() == 1 && "Nested loops not yet implemented"); + const semantics::Symbol *iv = ivs[0]; + + auto &nestedEval = eval.getFirstNestedEvaluation(); + if (nestedEval.getIf<parser::DoConstruct>()->IsDoConcurrent()) { + // OpenMP specifies DO CONCURRENT only with the `!omp loop` construct. Will + // need to add special cases for this combination. + TODO(loc, "DO CONCURRENT as canonical loop not supported"); + } + + // Get the loop bounds (and increment) + auto &doLoopEval = nestedEval.getFirstNestedEvaluation(); + auto *doStmt = doLoopEval.getIf<parser::NonLabelDoStmt>(); + assert(doStmt && "Expected do loop to be in the nested evaluation"); + auto &loopControl = std::get<std::optional<parser::LoopControl>>(doStmt->t); + assert(loopControl.has_value()); + auto *bounds = std::get_if<parser::LoopControl::Bounds>(&loopControl->u); + assert(bounds && "Expected bounds for canonical loop"); + lower::StatementContext stmtCtx; + mlir::Value loopLBVar = fir::getBase( + converter.genExprValue(*semantics::GetExpr(bounds->lower), stmtCtx)); + mlir::Value loopUBVar = fir::getBase( + converter.genExprValue(*semantics::GetExpr(bounds->upper), stmtCtx)); + mlir::Value loopStepVar = [&]() { + if (bounds->step) { + return fir::getBase( + converter.genExprValue(*semantics::GetExpr(bounds->step), stmtCtx)); + } + + // If `step` is not present, assume it is `1`. + return firOpBuilder.createIntegerConstant(loc, firOpBuilder.getI32Type(), + 1); + }(); + + // Get the integer kind for the loop variable and cast the loop bounds + size_t loopVarTypeSize = bounds->name.thing.symbol->GetUltimate().size(); + mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize); + loopLBVar = firOpBuilder.createConvert(loc, loopVarType, loopLBVar); + loopUBVar = firOpBuilder.createConvert(loc, loopVarType, loopUBVar); + loopStepVar = firOpBuilder.createConvert(loc, loopVarType, loopStepVar); + + // Start lowering + mlir::Value zero = firOpBuilder.createIntegerConstant(loc, loopVarType, 0); + mlir::Value one = firOpBuilder.createIntegerConstant(loc, loopVarType, 1); + mlir::Value isDownwards = firOpBuilder.create<mlir::arith::CmpIOp>( + 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<mlir::arith::SubIOp>(loc, zero, loopStepVar); + mlir::Value incr = firOpBuilder.create<mlir::arith::SelectOp>( + loc, isDownwards, negStep, loopStepVar); + mlir::Value lb = firOpBuilder.create<mlir::arith::SelectOp>( + loc, isDownwards, loopUBVar, loopLBVar); + mlir::Value ub = firOpBuilder.create<mlir::arith::SelectOp>( + 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<mlir::arith::SubIOp>( + loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw); + mlir::Value tcMinusOne = + firOpBuilder.create<mlir::arith::DivUIOp>(loc, span, incr); + mlir::Value tcIfLooping = firOpBuilder.create<mlir::arith::AddIOp>( + loc, tcMinusOne, one, ::mlir::arith::IntegerOverflowFlags::nuw); + + // Fall back to 0 if lb > ub + mlir::Value isZeroTC = firOpBuilder.create<mlir::arith::CmpIOp>( + loc, mlir::arith::CmpIPredicate::slt, ub, lb); + mlir::Value tripcount = firOpBuilder.create<mlir::arith::SelectOp>( + loc, isZeroTC, zero, tcIfLooping); + + // Create the CLI handle. + auto newcli = firOpBuilder.create<mlir::omp::NewCliOp>(loc); + mlir::Value cli = newcli.getResult(); + + auto ivCallback = [&](mlir::Operation *op) + -> llvm::SmallVector<const Fortran::semantics::Symbol *> { + mlir::Region ®ion = op->getRegion(0); + + // Create the op's region skeleton (BB taking the iv as argument) + firOpBuilder.createBlock(®ion, {}, {loopVarType}, {loc}); + + // 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<mlir::arith::MulIOp>(loc, natIterNum, loopStepVar); + mlir::Value userVal = + firOpBuilder.create<mlir::arith::AddIOp>(loc, loopLBVar, scaled); + + // The argument is not currently in memory, so make a temporary for the + // argument, and store it there, then bind that location to the argument. + mlir::Operation *storeOp = + createAndSetPrivatizedLoopVar(converter, loc, userVal, iv); + + firOpBuilder.setInsertionPointAfter(storeOp); + return {iv}; + }; + + // Create the omp.canonical_loop operation + auto canonLoop = genOpWithBody<mlir::omp::CanonicalLoopOp>( + OpWithBodyGenInfo(converter, symTable, semaCtx, loc, nestedEval, + directive) + .setClauses(&item->clauses) + .setDataSharingProcessor(&dsp) + .setGenRegionEntryCb(ivCallback), + queue, item, tripcount, cli); + + firOpBuilder.setInsertionPointAfter(canonLoop); + return canonLoop; +} + +static void genUnrollOp(Fortran::lower::AbstractConverter &converter, + Fortran::lower::SymMap &symTable, + lower::StatementContext &stmtCtx, + Fortran::semantics::SemanticsContext &semaCtx, + Fortran::lower::pft::Evaluation &eval, + mlir::Location loc, const ConstructQueue &queue, + ConstructQueue::const_iterator item) { + fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + + mlir::omp::LoopRelatedClauseOps loopInfo; + llvm::SmallVector<const semantics::Symbol *> iv; + collectLoopRelatedInfo(converter, loc, eval, item->clauses, loopInfo, iv); + + // Clauses for unrolling not yet implemnted + ClauseProcessor cp(converter, semaCtx, item->clauses); + cp.processTODO<clause::Partial, clause::Full>( + loc, llvm::omp::Directive::OMPD_unroll); + + // Even though unroll does not support data-sharing clauses, but this is + // required to fill the symbol table. + DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval, + /*shouldCollectPreDeterminedSymbols=*/true, + /*useDelayedPrivatization=*/false, symTable); + dsp.processStep1(); + + // Emit the associated loop + auto canonLoop = + genCanonicalLoopOp(converter, symTable, semaCtx, eval, loc, queue, item, + iv, llvm::omp::Directive::OMPD_unroll, dsp); + + // Apply unrolling to it + auto cli = canonLoop.getCli(); + firOpBuilder.create<mlir::omp::UnrollHeuristicOp>(loc, cli); +} + static mlir::omp::MaskedOp genMaskedOp(lower::AbstractConverter &converter, lower::SymMap &symTable, lower::StatementContext &stmtCtx, @@ -2201,7 +2360,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, } // SECTIONS construct. - auto sectionsOp = builder.create<mlir::omp::SectionsOp>(loc, clauseOps); + auto sectionsOp = mlir::omp::SectionsOp::create(builder, loc, clauseOps); // Create entry block with reduction variables as arguments. EntryBlockArgs args; @@ -2277,7 +2436,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, // races on post-update of lastprivate variables when `nowait` // clause is present. if (clauseOps.nowait && !lastprivates.empty()) - builder.create<mlir::omp::BarrierOp>(loc); + mlir::omp::BarrierOp::create(builder, loc); return sectionsOp; } @@ -2429,7 +2588,7 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable, }; lower::pft::visitAllSymbols(eval, captureImplicitMap); - auto targetOp = firOpBuilder.create<mlir::omp::TargetOp>(loc, clauseOps); + auto targetOp = mlir::omp::TargetOp::create(firOpBuilder, loc, clauseOps); llvm::SmallVector<mlir::Value> hasDeviceAddrBaseValues, mapBaseValues; extractMappedBaseValues(clauseOps.hasDeviceAddrVars, hasDeviceAddrBaseValues); @@ -2509,7 +2668,7 @@ static OpTy genTargetEnterExitUpdateDataOp( genTargetEnterExitUpdateDataClauses(converter, semaCtx, symTable, stmtCtx, item->clauses, loc, directive, clauseOps); - return firOpBuilder.create<OpTy>(loc, clauseOps); + return OpTy::create(firOpBuilder, loc, clauseOps); } static mlir::omp::TaskOp @@ -3249,12 +3408,14 @@ static void genOMPDispatch(lower::AbstractConverter &converter, newOp = genTeamsOp(converter, symTable, stmtCtx, semaCtx, eval, loc, queue, item); break; - case llvm::omp::Directive::OMPD_tile: - case llvm::omp::Directive::OMPD_unroll: { + case llvm::omp::Directive::OMPD_tile: { unsigned version = semaCtx.langOptions().OpenMPVersion; TODO(loc, "Unhandled loop directive (" + llvm::omp::getOpenMPDirectiveName(dir, version) + ")"); } + case llvm::omp::Directive::OMPD_unroll: + genUnrollOp(converter, symTable, stmtCtx, semaCtx, eval, loc, queue, item); + break; // case llvm::omp::Directive::OMPD_workdistribute: case llvm::omp::Directive::OMPD_workshare: newOp = genWorkshareOp(converter, symTable, stmtCtx, semaCtx, eval, loc, @@ -3342,8 +3503,8 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, firOpBuilder.setInsertionPointToStart(converter.getModuleOp().getBody()); auto mlirType = converter.genType(varType.declTypeSpec->derivedTypeSpec()); - auto declMapperOp = firOpBuilder.create<mlir::omp::DeclareMapperOp>( - loc, mapperNameStr, mlirType); + auto declMapperOp = mlir::omp::DeclareMapperOp::create( + firOpBuilder, loc, mapperNameStr, mlirType); auto ®ion = declMapperOp.getRegion(); firOpBuilder.createBlock(®ion); auto varVal = region.addArgument(firOpBuilder.getRefType(mlirType), loc); @@ -3356,7 +3517,7 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, List<Clause> clauses = makeClauses(*clauseList, semaCtx); ClauseProcessor cp(converter, semaCtx, clauses); cp.processMap(loc, stmtCtx, clauseOps); - firOpBuilder.create<mlir::omp::DeclareMapperInfoOp>(loc, clauseOps.mapVars); + mlir::omp::DeclareMapperInfoOp::create(firOpBuilder, loc, clauseOps.mapVars); } static void @@ -3690,12 +3851,26 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, if (auto *ompNestedLoopCons{ std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>( &*optLoopCons)}) { - genOMP(converter, symTable, semaCtx, eval, ompNestedLoopCons->value()); + llvm::omp::Directive nestedDirective = + parser::omp::GetOmpDirectiveName(*ompNestedLoopCons).v; + switch (nestedDirective) { + case llvm::omp::Directive::OMPD_tile: + // Emit the omp.loop_nest with annotation for tiling + genOMP(converter, symTable, semaCtx, eval, ompNestedLoopCons->value()); + break; + default: { + unsigned version = semaCtx.langOptions().OpenMPVersion; + TODO(currentLocation, + "Applying a loop-associated on the loop generated by the " + + llvm::omp::getOpenMPDirectiveName(nestedDirective, version) + + " construct"); + } + } } } llvm::omp::Directive directive = - std::get<parser::OmpLoopDirective>(beginLoopDirective.t).v; + parser::omp::GetOmpDirectiveName(beginLoopDirective).v; const parser::CharBlock &source = std::get<parser::OmpLoopDirective>(beginLoopDirective.t).source; ConstructQueue queue{ @@ -3758,8 +3933,8 @@ mlir::Operation *Fortran::lower::genOpenMPTerminator(fir::FirOpBuilder &builder, mlir::Location loc) { if (mlir::isa<mlir::omp::AtomicUpdateOp, mlir::omp::DeclareReductionOp, mlir::omp::LoopNestOp>(op)) - return builder.create<mlir::omp::YieldOp>(loc); - return builder.create<mlir::omp::TerminatorOp>(loc); + return mlir::omp::YieldOp::create(builder, loc); + return mlir::omp::TerminatorOp::create(builder, loc); } void Fortran::lower::genOpenMPConstruct(lower::AbstractConverter &converter, @@ -3819,9 +3994,8 @@ void Fortran::lower::genThreadprivateOp(lower::AbstractConverter &converter, return; } // Generate ThreadprivateOp and rebind the common block. - mlir::Value commonThreadprivateValue = - firOpBuilder.create<mlir::omp::ThreadprivateOp>( - currentLocation, commonValue.getType(), commonValue); + mlir::Value commonThreadprivateValue = mlir::omp::ThreadprivateOp::create( + firOpBuilder, currentLocation, commonValue.getType(), commonValue); converter.bindSymbol(*common, commonThreadprivateValue); // Generate the threadprivate value for the common block member. symThreadprivateValue = genCommonBlockMember(converter, currentLocation, @@ -3841,10 +4015,10 @@ void Fortran::lower::genThreadprivateOp(lower::AbstractConverter &converter, global = globalInitialization(converter, firOpBuilder, sym, var, currentLocation); - mlir::Value symValue = firOpBuilder.create<fir::AddrOfOp>( - currentLocation, global.resultType(), global.getSymbol()); - symThreadprivateValue = firOpBuilder.create<mlir::omp::ThreadprivateOp>( - currentLocation, symValue.getType(), symValue); + mlir::Value symValue = fir::AddrOfOp::create( + firOpBuilder, currentLocation, global.resultType(), global.getSymbol()); + symThreadprivateValue = mlir::omp::ThreadprivateOp::create( + firOpBuilder, currentLocation, symValue.getType(), symValue); } else { mlir::Value symValue = converter.getSymbolAddress(sym); @@ -3859,8 +4033,8 @@ void Fortran::lower::genThreadprivateOp(lower::AbstractConverter &converter, if (mlir::isa<mlir::omp::ThreadprivateOp>(op)) return; - symThreadprivateValue = firOpBuilder.create<mlir::omp::ThreadprivateOp>( - currentLocation, symValue.getType(), symValue); + symThreadprivateValue = mlir::omp::ThreadprivateOp::create( + firOpBuilder, currentLocation, symValue.getType(), symValue); } fir::ExtendedValue sexv = converter.getSymbolExtendedValue(sym); diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index b194150..13fda97 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -20,6 +20,7 @@ #include <flang/Lower/PFTBuilder.h> #include <flang/Optimizer/Builder/FIRBuilder.h> #include <flang/Optimizer/Builder/Todo.h> +#include <flang/Parser/openmp-utils.h> #include <flang/Parser/parse-tree.h> #include <flang/Parser/tools.h> #include <flang/Semantics/tools.h> @@ -115,7 +116,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, bool partialMap, mlir::FlatSymbolRefAttr mapperId) { if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) { - baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr); + baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); retTy = baseAddr.getType(); } @@ -129,8 +130,8 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, if (seqType.hasDynamicExtents()) varType = mlir::TypeAttr::get(seqType.getEleTy()); - mlir::omp::MapInfoOp op = builder.create<mlir::omp::MapInfoOp>( - loc, retTy, baseAddr, varType, + mlir::omp::MapInfoOp op = mlir::omp::MapInfoOp::create( + builder, loc, retTy, baseAddr, varType, builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType), varPtrPtr, members, membersIndex, bounds, mapperId, @@ -195,8 +196,8 @@ static void generateArrayIndices(lower::AbstractConverter &converter, clauseLocation, firOpBuilder.getIndexType(), 1); subscript = firOpBuilder.createConvert( clauseLocation, firOpBuilder.getIndexType(), subscript); - indices.push_back(firOpBuilder.create<mlir::arith::SubIOp>(clauseLocation, - subscript, one)); + indices.push_back(mlir::arith::SubIOp::create(firOpBuilder, clauseLocation, + subscript, one)); } } @@ -329,9 +330,10 @@ mlir::Value createParentSymAndGenIntermediateMaps( subscriptIndices, objectList[i]); assert(!subscriptIndices.empty() && "missing expected indices for map clause"); - curValue = firOpBuilder.create<fir::CoordinateOp>( - clauseLocation, firOpBuilder.getRefType(arrType.getEleTy()), - curValue, subscriptIndices); + curValue = fir::CoordinateOp::create( + firOpBuilder, clauseLocation, + firOpBuilder.getRefType(arrType.getEleTy()), curValue, + subscriptIndices); } } @@ -345,9 +347,9 @@ mlir::Value createParentSymAndGenIntermediateMaps( fir::IntOrValue idxConst = mlir::IntegerAttr::get( firOpBuilder.getI32Type(), indices[currentIndicesIdx]); mlir::Type memberTy = recordType.getType(indices[currentIndicesIdx]); - curValue = firOpBuilder.create<fir::CoordinateOp>( - clauseLocation, firOpBuilder.getRefType(memberTy), curValue, - llvm::SmallVector<fir::IntOrValue, 1>{idxConst}); + curValue = fir::CoordinateOp::create( + firOpBuilder, clauseLocation, firOpBuilder.getRefType(memberTy), + curValue, llvm::SmallVector<fir::IntOrValue, 1>{idxConst}); // If we're a final member, the map will be generated by the processMap // call that invoked this function. @@ -417,7 +419,7 @@ mlir::Value createParentSymAndGenIntermediateMaps( // Load the currently accessed member, so we can continue to access // further segments. - curValue = firOpBuilder.create<fir::LoadOp>(clauseLocation, curValue); + curValue = fir::LoadOp::create(firOpBuilder, clauseLocation, curValue); currentIndicesIdx++; } } @@ -662,89 +664,6 @@ bool collectLoopRelatedInfo( return found; } -/// Get the directive enumeration value corresponding to the given OpenMP -/// construct PFT node. -llvm::omp::Directive -extractOmpDirective(const parser::OpenMPConstruct &ompConstruct) { - return common::visit( - common::visitors{ - [](const parser::OpenMPAllocatorsConstruct &c) { - return llvm::omp::OMPD_allocators; - }, - [](const parser::OpenMPAssumeConstruct &c) { - return llvm::omp::OMPD_assume; - }, - [](const parser::OpenMPAtomicConstruct &c) { - return llvm::omp::OMPD_atomic; - }, - [](const parser::OpenMPBlockConstruct &c) { - return std::get<parser::OmpBlockDirective>( - std::get<parser::OmpBeginBlockDirective>(c.t).t) - .v; - }, - [](const parser::OpenMPCriticalConstruct &c) { - return llvm::omp::OMPD_critical; - }, - [](const parser::OpenMPDeclarativeAllocate &c) { - return llvm::omp::OMPD_allocate; - }, - [](const parser::OpenMPDispatchConstruct &c) { - return llvm::omp::OMPD_dispatch; - }, - [](const parser::OpenMPExecutableAllocate &c) { - return llvm::omp::OMPD_allocate; - }, - [](const parser::OpenMPLoopConstruct &c) { - return std::get<parser::OmpLoopDirective>( - std::get<parser::OmpBeginLoopDirective>(c.t).t) - .v; - }, - [](const parser::OpenMPSectionConstruct &c) { - return llvm::omp::OMPD_section; - }, - [](const parser::OpenMPSectionsConstruct &c) { - return std::get<parser::OmpSectionsDirective>( - std::get<parser::OmpBeginSectionsDirective>(c.t).t) - .v; - }, - [](const parser::OpenMPStandaloneConstruct &c) { - return common::visit( - common::visitors{ - [](const parser::OpenMPSimpleStandaloneConstruct &c) { - return c.v.DirId(); - }, - [](const parser::OpenMPFlushConstruct &c) { - return llvm::omp::OMPD_flush; - }, - [](const parser::OpenMPCancelConstruct &c) { - return llvm::omp::OMPD_cancel; - }, - [](const parser::OpenMPCancellationPointConstruct &c) { - return llvm::omp::OMPD_cancellation_point; - }, - [](const parser::OmpMetadirectiveDirective &c) { - return llvm::omp::OMPD_metadirective; - }, - [](const parser::OpenMPDepobjConstruct &c) { - return llvm::omp::OMPD_depobj; - }, - [](const parser::OpenMPInteropConstruct &c) { - return llvm::omp::OMPD_interop; - }}, - c.u); - }, - [](const parser::OpenMPUtilityConstruct &c) { - return common::visit( - common::visitors{[](const parser::OmpErrorDirective &c) { - return llvm::omp::OMPD_error; - }, - [](const parser::OmpNothingDirective &c) { - return llvm::omp::OMPD_nothing; - }}, - c.u); - }}, - ompConstruct.u); -} } // namespace omp } // namespace lower } // namespace Fortran diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index 8e3ad5c..11641ba 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -167,8 +167,6 @@ bool collectLoopRelatedInfo( mlir::omp::LoopRelatedClauseOps &result, llvm::SmallVectorImpl<const semantics::Symbol *> &iv); -llvm::omp::Directive -extractOmpDirective(const parser::OpenMPConstruct &ompConstruct); } // namespace omp } // namespace lower } // namespace Fortran diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp index 2be5ef7..fc59a24 100644 --- a/flang/lib/Lower/Runtime.cpp +++ b/flang/lib/Lower/Runtime.cpp @@ -43,7 +43,7 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::acc::OpenACCDialect::getDialectNamespace()) Fortran::lower::genOpenACCTerminator(builder, parentOp, loc); else - builder.create<fir::UnreachableOp>(loc); + fir::UnreachableOp::create(builder, loc); mlir::Block *newBlock = curBlock->splitBlock(builder.getInsertionPoint()); builder.setInsertionPointToStart(newBlock); } @@ -118,7 +118,7 @@ void Fortran::lower::genStopStatement( loc, calleeType.getInput(operands.size()), 0)); } - builder.create<fir::CallOp>(loc, callee, operands); + fir::CallOp::create(builder, loc, callee, operands); auto blockIsUnterminated = [&builder]() { mlir::Block *currentBlock = builder.getBlock(); return currentBlock->empty() || @@ -134,7 +134,7 @@ void Fortran::lower::genFailImageStatement( mlir::Location loc = converter.getCurrentLocation(); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(FailImageStatement)>(loc, builder); - builder.create<fir::CallOp>(loc, callee, std::nullopt); + fir::CallOp::create(builder, loc, callee, mlir::ValueRange{}); genUnreachable(builder, loc); } @@ -199,7 +199,7 @@ void Fortran::lower::genPauseStatement( mlir::Location loc = converter.getCurrentLocation(); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatement)>(loc, builder); - builder.create<fir::CallOp>(loc, callee, std::nullopt); + fir::CallOp::create(builder, loc, callee, mlir::ValueRange{}); } void Fortran::lower::genPointerAssociate(fir::FirOpBuilder &builder, @@ -210,17 +210,18 @@ void Fortran::lower::genPointerAssociate(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(PointerAssociate)>(loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), pointer, target); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } -void Fortran::lower::genPointerAssociateRemapping(fir::FirOpBuilder &builder, - mlir::Location loc, - mlir::Value pointer, - mlir::Value target, - mlir::Value bounds) { +void Fortran::lower::genPointerAssociateRemapping( + fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value pointer, + mlir::Value target, mlir::Value bounds, bool isMonomorphic) { mlir::func::FuncOp func = - fir::runtime::getRuntimeFunc<mkRTKey(PointerAssociateRemapping)>(loc, - builder); + isMonomorphic + ? fir::runtime::getRuntimeFunc<mkRTKey( + PointerAssociateRemappingMonomorphic)>(loc, builder) + : fir::runtime::getRuntimeFunc<mkRTKey(PointerAssociateRemapping)>( + loc, builder); auto fTy = func.getFunctionType(); auto sourceFile = fir::factory::locationToFilename(builder, loc); auto sourceLine = @@ -228,7 +229,7 @@ void Fortran::lower::genPointerAssociateRemapping(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), pointer, target, bounds, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void Fortran::lower::genPointerAssociateLowerBounds(fir::FirOpBuilder &builder, @@ -241,5 +242,5 @@ void Fortran::lower::genPointerAssociateLowerBounds(fir::FirOpBuilder &builder, loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), pointer, target, lbounds); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Lower/Support/PrivateReductionUtils.cpp b/flang/lib/Lower/Support/PrivateReductionUtils.cpp index c3a5b61..fff060b 100644 --- a/flang/lib/Lower/Support/PrivateReductionUtils.cpp +++ b/flang/lib/Lower/Support/PrivateReductionUtils.cpp @@ -75,9 +75,9 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter, /*mutableProperties=*/{}}; Fortran::lower::genDeallocateIfAllocated(converter, mutableBox, loc); if (isDoConcurrent) - builder.create<fir::YieldOp>(loc); + fir::YieldOp::create(builder, loc); else - builder.create<mlir::omp::YieldOp>(loc); + mlir::omp::YieldOp::create(builder, loc); return; } } @@ -97,18 +97,18 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter, hlfir::genVariableRawAddress(loc, builder, hlfir::Entity{arg}); mlir::Value isAllocated = builder.genIsNotNullAddr(loc, addr); fir::IfOp ifOp = - builder.create<fir::IfOp>(loc, isAllocated, /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, isAllocated, /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); mlir::Value cast = builder.createConvert( loc, fir::HeapType::get(fir::dyn_cast_ptrEleTy(addr.getType())), addr); - builder.create<fir::FreeMemOp>(loc, cast); + fir::FreeMemOp::create(builder, loc, cast); builder.setInsertionPointAfter(ifOp); if (isDoConcurrent) - builder.create<fir::YieldOp>(loc); + fir::YieldOp::create(builder, loc); else - builder.create<mlir::omp::YieldOp>(loc); + mlir::omp::YieldOp::create(builder, loc); return; } @@ -122,11 +122,11 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter, auto heapTy = fir::HeapType::get(refTy.getEleTy()); addr = builder.createConvert(loc, heapTy, addr); - builder.create<fir::FreeMemOp>(loc, addr); + fir::FreeMemOp::create(builder, loc, addr); if (isDoConcurrent) - builder.create<fir::YieldOp>(loc); + fir::YieldOp::create(builder, loc); else - builder.create<mlir::omp::YieldOp>(loc); + mlir::omp::YieldOp::create(builder, loc); return; } @@ -172,7 +172,7 @@ fir::ShapeShiftOp Fortran::lower::getShapeShift( // OpenACC does mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim); lbAndExtents.push_back(useDefaultLowerBounds ? one() : dimInfo.getLowerBound()); lbAndExtents.push_back(dimInfo.getExtent()); @@ -181,7 +181,7 @@ fir::ShapeShiftOp Fortran::lower::getShapeShift( auto shapeShiftTy = fir::ShapeShiftType::get(builder.getContext(), rank); auto shapeShift = - builder.create<fir::ShapeShiftOp>(loc, shapeShiftTy, lbAndExtents); + fir::ShapeShiftOp::create(builder, loc, shapeShiftTy, lbAndExtents); return shapeShift; } @@ -270,7 +270,7 @@ static mlir::Value generateZeroShapeForRank(fir::FirOpBuilder &builder, mlir::SmallVector<mlir::Value> dims; dims.resize(rank, zero); mlir::Type shapeTy = fir::ShapeType::get(builder.getContext(), rank); - return builder.create<fir::ShapeOp>(loc, shapeTy, dims); + return fir::ShapeOp::create(builder, loc, shapeTy, dims); } namespace { @@ -341,9 +341,9 @@ private: void createYield(mlir::Value ret) { if (isDoConcurrent) - builder.create<fir::YieldOp>(loc, ret); + fir::YieldOp::create(builder, loc, ret); else - builder.create<mlir::omp::YieldOp>(loc, ret); + mlir::omp::YieldOp::create(builder, loc, ret); } void initTrivialType() { @@ -392,9 +392,9 @@ void PopulateInitAndCleanupRegionsHelper::initBoxedPrivatePointer( // Just incase, do initialize the box with a null value mlir::Value null = builder.createNullConstant(loc, boxTy.getEleTy()); mlir::Value nullBox; - nullBox = builder.create<fir::EmboxOp>(loc, boxTy, null, shape, - /*slice=*/mlir::Value{}, lenParams); - builder.create<fir::StoreOp>(loc, nullBox, allocatedPrivVarArg); + nullBox = fir::EmboxOp::create(builder, loc, boxTy, null, shape, + /*slice=*/mlir::Value{}, lenParams); + fir::StoreOp::create(builder, loc, nullBox, allocatedPrivVarArg); createYield(allocatedPrivVarArg); } /// Check if an allocatable box is unallocated. If so, initialize the boxAlloca @@ -410,10 +410,10 @@ void PopulateInitAndCleanupRegionsHelper::initBoxedPrivatePointer( /// } /// omp.yield %box_alloca fir::IfOp PopulateInitAndCleanupRegionsHelper::handleNullAllocatable() { - mlir::Value addr = builder.create<fir::BoxAddrOp>(loc, getLoadedMoldArg()); + mlir::Value addr = fir::BoxAddrOp::create(builder, loc, getLoadedMoldArg()); mlir::Value isNotAllocated = builder.genIsNullAddr(loc, addr); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, isNotAllocated, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, isNotAllocated, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); // Just embox the null address and return. // We have to give the embox a shape so that the LLVM box structure has the @@ -421,9 +421,9 @@ fir::IfOp PopulateInitAndCleanupRegionsHelper::handleNullAllocatable() { mlir::Value shape = generateZeroShapeForRank(builder, loc, moldArg); mlir::Value nullBox = - builder.create<fir::EmboxOp>(loc, valType, addr, shape, - /*slice=*/mlir::Value{}, lenParams); - builder.create<fir::StoreOp>(loc, nullBox, allocatedPrivVarArg); + fir::EmboxOp::create(builder, loc, valType, addr, shape, + /*slice=*/mlir::Value{}, lenParams); + fir::StoreOp::create(builder, loc, nullBox, allocatedPrivVarArg); return ifOp; } @@ -442,14 +442,14 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedScalar( /*shape=*/{}, lenParams); if (scalarInitValue) builder.createStoreWithConvert(loc, scalarInitValue, valAlloc); - mlir::Value box = builder.create<fir::EmboxOp>( - loc, valType, valAlloc, /*shape=*/mlir::Value{}, - /*slice=*/mlir::Value{}, lenParams); + mlir::Value box = fir::EmboxOp::create(builder, loc, valType, valAlloc, + /*shape=*/mlir::Value{}, + /*slice=*/mlir::Value{}, lenParams); initializeIfDerivedTypeBox( builder, loc, box, getLoadedMoldArg(), needsInitialization, /*isFirstPrivate=*/kind == DeclOperationKind::FirstPrivateOrLocalInit); fir::StoreOp lastOp = - builder.create<fir::StoreOp>(loc, box, allocatedPrivVarArg); + fir::StoreOp::create(builder, loc, box, allocatedPrivVarArg); createCleanupRegion(converter, loc, argType, cleanupRegion, sym, isDoConcurrent); @@ -483,14 +483,15 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray( fir::ShapeShiftOp shape = getShapeShift(builder, loc, source, cannotHaveNonDefaultLowerBounds); mlir::Type arrayType = source.getElementOrSequenceType(); - mlir::Value allocatedArray = builder.create<fir::AllocMemOp>( - loc, arrayType, /*typeparams=*/mlir::ValueRange{}, shape.getExtents()); - mlir::Value firClass = builder.create<fir::EmboxOp>(loc, source.getType(), - allocatedArray, shape); + mlir::Value allocatedArray = fir::AllocMemOp::create( + builder, loc, arrayType, /*typeparams=*/mlir::ValueRange{}, + shape.getExtents()); + mlir::Value firClass = fir::EmboxOp::create(builder, loc, source.getType(), + allocatedArray, shape); initializeIfDerivedTypeBox( builder, loc, firClass, source, needsInitialization, /*isFirstprivate=*/kind == DeclOperationKind::FirstPrivateOrLocalInit); - builder.create<fir::StoreOp>(loc, firClass, allocatedPrivVarArg); + fir::StoreOp::create(builder, loc, firClass, allocatedPrivVarArg); if (ifUnallocated) builder.setInsertionPointAfter(ifUnallocated); createYield(allocatedPrivVarArg); @@ -543,22 +544,21 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray( if (mlir::isa<fir::BaseBoxType>(temp.getType())) // the box created by the declare form createTempFromMold is missing // lower bounds info - box = builder.create<fir::ReboxOp>(loc, boxType, temp, shapeShift, - /*shift=*/mlir::Value{}); + box = fir::ReboxOp::create(builder, loc, boxType, temp, shapeShift, + /*shift=*/mlir::Value{}); else - box = builder.create<fir::EmboxOp>( - loc, boxType, temp, shapeShift, - /*slice=*/mlir::Value{}, - /*typeParams=*/llvm::ArrayRef<mlir::Value>{}); + box = fir::EmboxOp::create(builder, loc, boxType, temp, shapeShift, + /*slice=*/mlir::Value{}, + /*typeParams=*/llvm::ArrayRef<mlir::Value>{}); if (scalarInitValue) - builder.create<hlfir::AssignOp>(loc, scalarInitValue, box); + hlfir::AssignOp::create(builder, loc, scalarInitValue, box); initializeIfDerivedTypeBox( builder, loc, box, getLoadedMoldArg(), needsInitialization, /*isFirstPrivate=*/kind == DeclOperationKind::FirstPrivateOrLocalInit); - builder.create<fir::StoreOp>(loc, box, allocatedPrivVarArg); + fir::StoreOp::create(builder, loc, box, allocatedPrivVarArg); if (ifUnallocated) builder.setInsertionPointAfter(ifUnallocated); createYield(allocatedPrivVarArg); @@ -596,8 +596,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupUnboxedDerivedType( builder.setInsertionPointToStart(initBlock); mlir::Type boxedTy = fir::BoxType::get(valType); mlir::Value newBox = - builder.create<fir::EmboxOp>(loc, boxedTy, allocatedPrivVarArg); - mlir::Value moldBox = builder.create<fir::EmboxOp>(loc, boxedTy, moldArg); + fir::EmboxOp::create(builder, loc, boxedTy, allocatedPrivVarArg); + mlir::Value moldBox = fir::EmboxOp::create(builder, loc, boxedTy, moldArg); initializeIfDerivedTypeBox(builder, loc, newBox, moldBox, needsInitialization, /*isFirstPrivate=*/kind == DeclOperationKind::FirstPrivateOrLocalInit); diff --git a/flang/lib/Lower/Support/ReductionProcessor.cpp b/flang/lib/Lower/Support/ReductionProcessor.cpp index c0be1e2..605a5b6b 100644 --- a/flang/lib/Lower/Support/ReductionProcessor.cpp +++ b/flang/lib/Lower/Support/ReductionProcessor.cpp @@ -39,7 +39,7 @@ namespace lower { namespace omp { // explicit template declarations -template void ReductionProcessor::processReductionArguments< +template bool ReductionProcessor::processReductionArguments< mlir::omp::DeclareReductionOp, omp::clause::ReductionOperatorList>( mlir::Location currentLocation, lower::AbstractConverter &converter, const omp::clause::ReductionOperatorList &redOperatorList, @@ -48,7 +48,7 @@ template void ReductionProcessor::processReductionArguments< llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols, const llvm::SmallVectorImpl<const semantics::Symbol *> &reductionSymbols); -template void ReductionProcessor::processReductionArguments< +template bool ReductionProcessor::processReductionArguments< fir::DeclareReductionOp, llvm::SmallVector<fir::ReduceOperationEnum>>( mlir::Location currentLocation, lower::AbstractConverter &converter, const llvm::SmallVector<fir::ReduceOperationEnum> &redOperatorList, @@ -260,20 +260,20 @@ ReductionProcessor::getReductionInitValue(mlir::Location loc, mlir::Type type, initIm); } if (mlir::isa<mlir::FloatType>(type)) - return builder.create<mlir::arith::ConstantOp>( - loc, type, + return mlir::arith::ConstantOp::create( + builder, loc, type, builder.getFloatAttr(type, (double)getOperationIdentity(redId, loc))); if (mlir::isa<fir::LogicalType>(type)) { - mlir::Value intConst = builder.create<mlir::arith::ConstantOp>( - loc, builder.getI1Type(), + mlir::Value intConst = mlir::arith::ConstantOp::create( + builder, loc, builder.getI1Type(), builder.getIntegerAttr(builder.getI1Type(), getOperationIdentity(redId, loc))); return builder.createConvert(loc, type, intConst); } - return builder.create<mlir::arith::ConstantOp>( - loc, type, + return mlir::arith::ConstantOp::create( + builder, loc, type, builder.getIntegerAttr(type, getOperationIdentity(redId, loc))); case ReductionIdentifier::ID: case ReductionIdentifier::USER_DEF_OP: @@ -301,15 +301,15 @@ mlir::Value ReductionProcessor::createScalarCombiner( break; case ReductionIdentifier::IOR: assert((type.isIntOrIndex()) && "only integer is expected"); - reductionOp = builder.create<mlir::arith::OrIOp>(loc, op1, op2); + reductionOp = mlir::arith::OrIOp::create(builder, loc, op1, op2); break; case ReductionIdentifier::IEOR: assert((type.isIntOrIndex()) && "only integer is expected"); - reductionOp = builder.create<mlir::arith::XOrIOp>(loc, op1, op2); + reductionOp = mlir::arith::XOrIOp::create(builder, loc, op1, op2); break; case ReductionIdentifier::IAND: assert((type.isIntOrIndex()) && "only integer is expected"); - reductionOp = builder.create<mlir::arith::AndIOp>(loc, op1, op2); + reductionOp = mlir::arith::AndIOp::create(builder, loc, op1, op2); break; case ReductionIdentifier::ADD: reductionOp = @@ -325,7 +325,8 @@ mlir::Value ReductionProcessor::createScalarCombiner( mlir::Value op1I1 = builder.createConvert(loc, builder.getI1Type(), op1); mlir::Value op2I1 = builder.createConvert(loc, builder.getI1Type(), op2); - mlir::Value andiOp = builder.create<mlir::arith::AndIOp>(loc, op1I1, op2I1); + mlir::Value andiOp = + mlir::arith::AndIOp::create(builder, loc, op1I1, op2I1); reductionOp = builder.createConvert(loc, type, andiOp); break; @@ -334,7 +335,7 @@ mlir::Value ReductionProcessor::createScalarCombiner( mlir::Value op1I1 = builder.createConvert(loc, builder.getI1Type(), op1); mlir::Value op2I1 = builder.createConvert(loc, builder.getI1Type(), op2); - mlir::Value oriOp = builder.create<mlir::arith::OrIOp>(loc, op1I1, op2I1); + mlir::Value oriOp = mlir::arith::OrIOp::create(builder, loc, op1I1, op2I1); reductionOp = builder.createConvert(loc, type, oriOp); break; @@ -343,8 +344,8 @@ mlir::Value ReductionProcessor::createScalarCombiner( mlir::Value op1I1 = builder.createConvert(loc, builder.getI1Type(), op1); mlir::Value op2I1 = builder.createConvert(loc, builder.getI1Type(), op2); - mlir::Value cmpiOp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, op1I1, op2I1); + mlir::Value cmpiOp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, op1I1, op2I1); reductionOp = builder.createConvert(loc, type, cmpiOp); break; @@ -353,8 +354,8 @@ mlir::Value ReductionProcessor::createScalarCombiner( mlir::Value op1I1 = builder.createConvert(loc, builder.getI1Type(), op1); mlir::Value op2I1 = builder.createConvert(loc, builder.getI1Type(), op2); - mlir::Value cmpiOp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, op1I1, op2I1); + mlir::Value cmpiOp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, op1I1, op2I1); reductionOp = builder.createConvert(loc, type, cmpiOp); break; @@ -370,9 +371,9 @@ template <typename ParentDeclOpType> static void genYield(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value yieldedValue) { if constexpr (std::is_same_v<ParentDeclOpType, mlir::omp::DeclareReductionOp>) - builder.create<mlir::omp::YieldOp>(loc, yieldedValue); + mlir::omp::YieldOp::create(builder, loc, yieldedValue); else - builder.create<fir::YieldOp>(loc, yieldedValue); + fir::YieldOp::create(builder, loc, yieldedValue); } /// Create reduction combiner region for reduction variables which are boxed @@ -393,24 +394,24 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, // load fir.ref<fir.box<...>> mlir::Value lhsAddr = lhs; - lhs = builder.create<fir::LoadOp>(loc, lhs); - rhs = builder.create<fir::LoadOp>(loc, rhs); + lhs = fir::LoadOp::create(builder, loc, lhs); + rhs = fir::LoadOp::create(builder, loc, rhs); if ((heapTy || ptrTy) && !seqTy) { // get box contents (heap pointers) - lhs = builder.create<fir::BoxAddrOp>(loc, lhs); - rhs = builder.create<fir::BoxAddrOp>(loc, rhs); + lhs = fir::BoxAddrOp::create(builder, loc, lhs); + rhs = fir::BoxAddrOp::create(builder, loc, rhs); mlir::Value lhsValAddr = lhs; // load heap pointers - lhs = builder.create<fir::LoadOp>(loc, lhs); - rhs = builder.create<fir::LoadOp>(loc, rhs); + lhs = fir::LoadOp::create(builder, loc, lhs); + rhs = fir::LoadOp::create(builder, loc, rhs); mlir::Type eleTy = heapTy ? heapTy.getEleTy() : ptrTy.getEleTy(); mlir::Value result = ReductionProcessor::createScalarCombiner( builder, loc, redId, eleTy, lhs, rhs); - builder.create<fir::StoreOp>(loc, result, lhsValAddr); + fir::StoreOp::create(builder, loc, result, lhsValAddr); genYield<DeclRedOpType>(builder, loc, lhsAddr); return; } @@ -437,17 +438,17 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, builder.setInsertionPointToStart(nest.body); const bool seqIsVolatile = fir::isa_volatile_type(seqTy.getEleTy()); mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy(), seqIsVolatile); - auto lhsEleAddr = builder.create<fir::ArrayCoorOp>( - loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{}, + auto lhsEleAddr = fir::ArrayCoorOp::create( + builder, loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{}, nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{}); - auto rhsEleAddr = builder.create<fir::ArrayCoorOp>( - loc, refTy, rhs, shapeShift, /*slice=*/mlir::Value{}, + auto rhsEleAddr = fir::ArrayCoorOp::create( + builder, loc, refTy, rhs, shapeShift, /*slice=*/mlir::Value{}, nest.oneBasedIndices, /*typeparms=*/mlir::ValueRange{}); - auto lhsEle = builder.create<fir::LoadOp>(loc, lhsEleAddr); - auto rhsEle = builder.create<fir::LoadOp>(loc, rhsEleAddr); + auto lhsEle = fir::LoadOp::create(builder, loc, lhsEleAddr); + auto rhsEle = fir::LoadOp::create(builder, loc, rhsEleAddr); mlir::Value scalarReduction = ReductionProcessor::createScalarCombiner( builder, loc, redId, refTy, lhsEle, rhsEle); - builder.create<fir::StoreOp>(loc, scalarReduction, lhsEleAddr); + fir::StoreOp::create(builder, loc, scalarReduction, lhsEleAddr); builder.setInsertionPointAfter(nest.outerOp); genYield<DeclRedOpType>(builder, loc, lhsAddr); @@ -468,7 +469,7 @@ static void genCombiner(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value result = ReductionProcessor::createScalarCombiner( builder, loc, redId, ty, lhsLoaded, rhsLoaded); if (isByRef) { - builder.create<fir::StoreOp>(loc, result, lhs); + fir::StoreOp::create(builder, loc, result, lhs); genYield<DeclRedOpType>(builder, loc, lhs); } else { genYield<DeclRedOpType>(builder, loc, result); @@ -539,7 +540,7 @@ static void createReductionAllocAndInitRegions( if (isByRef) { // alloc region builder.setInsertionPointToEnd(allocBlock); - mlir::Value alloca = builder.create<fir::AllocaOp>(loc, ty); + mlir::Value alloca = fir::AllocaOp::create(builder, loc, ty); yield(alloca); return; } @@ -551,7 +552,7 @@ static void createReductionAllocAndInitRegions( // alloc region builder.setInsertionPointToEnd(allocBlock); - mlir::Value boxAlloca = builder.create<fir::AllocaOp>(loc, ty); + mlir::Value boxAlloca = fir::AllocaOp::create(builder, loc, ty); yield(boxAlloca); } @@ -575,7 +576,7 @@ OpType ReductionProcessor::createDeclareReduction( if (!isByRef) type = valTy; - decl = modBuilder.create<OpType>(loc, reductionOpName, type); + decl = OpType::create(modBuilder, loc, reductionOpName, type); createReductionAllocAndInitRegions(converter, loc, decl, redId, type, isByRef); @@ -606,7 +607,7 @@ static bool doReductionByRef(mlir::Value reductionVar) { } template <typename OpType, typename RedOperatorListTy> -void ReductionProcessor::processReductionArguments( +bool ReductionProcessor::processReductionArguments( mlir::Location currentLocation, lower::AbstractConverter &converter, const RedOperatorListTy &redOperatorList, llvm::SmallVectorImpl<mlir::Value> &reductionVars, @@ -626,10 +627,10 @@ void ReductionProcessor::processReductionArguments( std::get_if<omp::clause::ProcedureDesignator>(&redOperator.u)) { if (!ReductionProcessor::supportedIntrinsicProcReduction( *reductionIntrinsic)) { - return; + return false; } } else { - return; + return false; } } } @@ -672,8 +673,8 @@ void ReductionProcessor::processReductionArguments( // Always pass the box by reference so that the OpenMP dialect // verifiers don't need to know anything about fir.box auto alloca = - builder.create<fir::AllocaOp>(currentLocation, box.getType()); - builder.create<fir::StoreOp>(currentLocation, box, alloca); + fir::AllocaOp::create(builder, currentLocation, box.getType()); + fir::StoreOp::create(builder, currentLocation, box, alloca); symVal = alloca; } else if (mlir::isa<fir::BaseBoxType>(symVal.getType())) { @@ -683,9 +684,9 @@ void ReductionProcessor::processReductionArguments( auto oldIP = builder.saveInsertionPoint(); builder.setInsertionPointToStart(builder.getAllocaBlock()); auto alloca = - builder.create<fir::AllocaOp>(currentLocation, symVal.getType()); + fir::AllocaOp::create(builder, currentLocation, symVal.getType()); builder.restoreInsertionPoint(oldIP); - builder.create<fir::StoreOp>(currentLocation, symVal, alloca); + fir::StoreOp::create(builder, currentLocation, symVal, alloca); symVal = alloca; } @@ -764,6 +765,8 @@ void ReductionProcessor::processReductionArguments( if (isDoConcurrent) builder.restoreInsertionPoint(dcIP); + + return true; } const semantics::SourceName diff --git a/flang/lib/Lower/Support/Utils.cpp b/flang/lib/Lower/Support/Utils.cpp index b9d2574..881401e 100644 --- a/flang/lib/Lower/Support/Utils.cpp +++ b/flang/lib/Lower/Support/Utils.cpp @@ -702,9 +702,10 @@ void privatizeSymbol( // Boxes should be passed by reference into nested regions: auto oldIP = firOpBuilder.saveInsertionPoint(); firOpBuilder.setInsertionPointToStart(firOpBuilder.getAllocaBlock()); - auto alloca = firOpBuilder.create<fir::AllocaOp>(symLoc, privVal.getType()); + auto alloca = + fir::AllocaOp::create(firOpBuilder, symLoc, privVal.getType()); firOpBuilder.restoreInsertionPoint(oldIP); - firOpBuilder.create<fir::StoreOp>(symLoc, privVal, alloca); + fir::StoreOp::create(firOpBuilder, symLoc, privVal, alloca); privVal = alloca; } @@ -726,15 +727,15 @@ void privatizeSymbol( OpType result; if constexpr (std::is_same_v<OpType, mlir::omp::PrivateClauseOp>) { - result = firOpBuilder.create<OpType>( - symLoc, uniquePrivatizerName, allocType, + result = OpType::create( + firOpBuilder, symLoc, uniquePrivatizerName, allocType, emitCopyRegion ? mlir::omp::DataSharingClauseType::FirstPrivate : mlir::omp::DataSharingClauseType::Private); } else { - result = firOpBuilder.create<OpType>( - symLoc, uniquePrivatizerName, allocType, - emitCopyRegion ? fir::LocalitySpecifierType::LocalInit - : fir::LocalitySpecifierType::Local); + result = + OpType::create(firOpBuilder, symLoc, uniquePrivatizerName, allocType, + emitCopyRegion ? fir::LocalitySpecifierType::LocalInit + : fir::LocalitySpecifierType::Local); } fir::ExtendedValue symExV = converter.getSymbolExtendedValue(*sym); @@ -815,12 +816,12 @@ void privatizeSymbol( copyFirstPrivateSymbol(converter, symToPrivatize, &ip); if constexpr (std::is_same_v<OpType, mlir::omp::PrivateClauseOp>) { - firOpBuilder.create<mlir::omp::YieldOp>( - hsb.getAddr().getLoc(), + mlir::omp::YieldOp::create( + firOpBuilder, hsb.getAddr().getLoc(), symTable.shallowLookupSymbol(*symToPrivatize).getAddr()); } else { - firOpBuilder.create<fir::YieldOp>( - hsb.getAddr().getLoc(), + fir::YieldOp::create( + firOpBuilder, hsb.getAddr().getLoc(), symTable.shallowLookupSymbol(*symToPrivatize).getAddr()); } } diff --git a/flang/lib/Lower/VectorSubscripts.cpp b/flang/lib/Lower/VectorSubscripts.cpp index 389a89d..4d1d6fb 100644 --- a/flang/lib/Lower/VectorSubscripts.cpp +++ b/flang/lib/Lower/VectorSubscripts.cpp @@ -121,8 +121,9 @@ private: if (recTy.getNumLenParams() != 0) TODO(loc, "threading length parameters in field index op"); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - componentPath.emplace_back(builder.create<fir::FieldIndexOp>( - loc, fldTy, componentName, recTy, /*typeParams*/ std::nullopt)); + componentPath.emplace_back( + fir::FieldIndexOp::create(builder, loc, fldTy, componentName, recTy, + /*typeParams=*/mlir::ValueRange{})); return fir::unwrapSequenceType(recTy.getType(componentName)); } @@ -269,16 +270,16 @@ mlir::Value Fortran::lower::VectorSubscriptBox::loopOverElementsBase( for (auto [lb, ub, step] : genLoopBounds(builder, loc)) { LoopType loop; if constexpr (std::is_same_v<LoopType, fir::IterWhileOp>) { - loop = - builder.create<fir::IterWhileOp>(loc, lb, ub, step, initialCondition); + loop = fir::IterWhileOp::create(builder, loc, lb, ub, step, + initialCondition); initialCondition = loop.getIterateVar(); if (!outerLoop) outerLoop = loop; else - builder.create<fir::ResultOp>(loc, loop.getResult(0)); + fir::ResultOp::create(builder, loc, loop.getResult(0)); } else { - loop = - builder.create<fir::DoLoopOp>(loc, lb, ub, step, /*unordered=*/false); + loop = fir::DoLoopOp::create(builder, loc, lb, ub, step, + /*unordered=*/false); if (!outerLoop) outerLoop = loop; } @@ -293,7 +294,7 @@ mlir::Value Fortran::lower::VectorSubscriptBox::loopOverElementsBase( if constexpr (std::is_same_v<LoopType, fir::IterWhileOp>) { auto res = elementalGenerator(elem); - builder.create<fir::ResultOp>(loc, res); + fir::ResultOp::create(builder, loc, res); builder.setInsertionPointAfter(outerLoop); return outerLoop.getResult(0); } else { @@ -326,7 +327,7 @@ Fortran::lower::VectorSubscriptBox::createSlice(fir::FirOpBuilder &builder, mlir::Type idxTy = builder.getIndexType(); llvm::SmallVector<mlir::Value> triples; mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); - auto undef = builder.create<fir::UndefOp>(loc, idxTy); + auto undef = fir::UndefOp::create(builder, loc, idxTy); for (const LoweredSubscript &subscript : loweredSubscripts) Fortran::common::visit(Fortran::common::visitors{ [&](const LoweredTriplet &triplet) { @@ -346,7 +347,7 @@ Fortran::lower::VectorSubscriptBox::createSlice(fir::FirOpBuilder &builder, }, }, subscript); - return builder.create<fir::SliceOp>(loc, triples, componentPath); + return fir::SliceOp::create(builder, loc, triples, componentPath); } llvm::SmallVector<std::tuple<mlir::Value, mlir::Value, mlir::Value>> @@ -369,13 +370,13 @@ Fortran::lower::VectorSubscriptBox::genLoopBounds(fir::FirOpBuilder &builder, builder, loc, loweredBase, dimension, one); baseLb = builder.createConvert(loc, idxTy, baseLb); lb = baseLb; - ub = builder.create<mlir::arith::SubIOp>(loc, idxTy, extent, one); - ub = builder.create<mlir::arith::AddIOp>(loc, idxTy, ub, baseLb); + ub = mlir::arith::SubIOp::create(builder, loc, idxTy, extent, one); + ub = mlir::arith::AddIOp::create(builder, loc, idxTy, ub, baseLb); step = one; } else { const auto &vector = std::get<LoweredVectorSubscript>(subscript); lb = zero; - ub = builder.create<mlir::arith::SubIOp>(loc, idxTy, vector.size, one); + ub = mlir::arith::SubIOp::create(builder, loc, idxTy, vector.size, one); step = one; } bounds.emplace_back(lb, ub, step); @@ -402,10 +403,10 @@ fir::ExtendedValue Fortran::lower::VectorSubscriptBox::getElementAt( mlir::Type vecEleTy = fir::unwrapSequenceType( fir::unwrapPassByRefType(vecBase.getType())); mlir::Type refTy = builder.getRefType(vecEleTy); - auto vecEltRef = builder.create<fir::CoordinateOp>( - loc, refTy, vecBase, vecIndex); + auto vecEltRef = fir::CoordinateOp::create(builder, loc, refTy, + vecBase, vecIndex); auto vecElt = - builder.create<fir::LoadOp>(loc, vecEleTy, vecEltRef); + fir::LoadOp::create(builder, loc, vecEleTy, vecEltRef); indexes.emplace_back(builder.createConvert(loc, idxTy, vecElt)); }, [&](const mlir::Value &i) { @@ -414,8 +415,8 @@ fir::ExtendedValue Fortran::lower::VectorSubscriptBox::getElementAt( }, subscript); mlir::Type refTy = builder.getRefType(getElementType()); - auto elementAddr = builder.create<fir::ArrayCoorOp>( - loc, refTy, fir::getBase(loweredBase), shape, slice, indexes, + auto elementAddr = fir::ArrayCoorOp::create( + builder, loc, refTy, fir::getBase(loweredBase), shape, slice, indexes, fir::getTypeParams(loweredBase)); fir::ExtendedValue element = fir::factory::arraySectionElementToExtendedValue( builder, loc, loweredBase, elementAddr, slice); diff --git a/flang/lib/Optimizer/Builder/CUFCommon.cpp b/flang/lib/Optimizer/Builder/CUFCommon.cpp index dcbf499..cf7588f 100644 --- a/flang/lib/Optimizer/Builder/CUFCommon.cpp +++ b/flang/lib/Optimizer/Builder/CUFCommon.cpp @@ -25,8 +25,8 @@ mlir::gpu::GPUModuleOp cuf::getOrCreateGPUModule(mlir::ModuleOp mod, mlir::UnitAttr::get(ctx)); mlir::OpBuilder builder(ctx); - auto gpuMod = builder.create<mlir::gpu::GPUModuleOp>(mod.getLoc(), - cudaDeviceModuleName); + auto gpuMod = mlir::gpu::GPUModuleOp::create(builder, mod.getLoc(), + cudaDeviceModuleName); mlir::Block::iterator insertPt(mod.getBodyRegion().front().end()); symTab.insert(gpuMod, insertPt); return gpuMod; @@ -84,8 +84,8 @@ void cuf::genPointerSync(const mlir::Value box, fir::FirOpBuilder &builder) { if (auto globalOp = mod.lookupSymbol<fir::GlobalOp>(addrOfOp.getSymbol())) { if (cuf::isRegisteredDeviceGlobal(globalOp)) { - builder.create<cuf::SyncDescriptorOp>(box.getLoc(), - addrOfOp.getSymbol()); + cuf::SyncDescriptorOp::create(builder, box.getLoc(), + addrOfOp.getSymbol()); } } } diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp index 61428ac49..a096099 100644 --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -112,8 +112,8 @@ fir::factory::CharacterExprHelper::materializeValue(mlir::Value str) { } auto len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), charTy.getLen()); - auto temp = builder.create<fir::AllocaOp>(loc, charTy); - builder.create<fir::StoreOp>(loc, str, temp); + auto temp = fir::AllocaOp::create(builder, loc, charTy); + fir::StoreOp::create(builder, loc, str, temp); LLVM_DEBUG(llvm::dbgs() << "materialized as local: " << str << " -> (" << temp << ", " << len << ")\n"); return {temp, len}; @@ -163,7 +163,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character, } if (!boxCharLen) { auto unboxed = - builder.create<fir::UnboxCharOp>(loc, refType, lenType, character); + fir::UnboxCharOp::create(builder, loc, refType, lenType, character); base = builder.createConvert(loc, refType, unboxed.getResult(0)); boxCharLen = unboxed.getResult(1); } @@ -208,7 +208,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) { // not in memory. if (!fir::isa_ref_type(buff.getType())) { auto temp = builder.createTemporary(loc, buff.getType()); - builder.create<fir::StoreOp>(loc, buff, temp); + fir::StoreOp::create(builder, loc, buff, temp); buff = temp; } // fir.emboxchar only accepts scalar, cast array buffer to a scalar buffer. @@ -218,7 +218,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) { // be used in boxchar. auto len = builder.createConvert(loc, builder.getCharacterLengthType(), box.getLen()); - return builder.create<fir::EmboxCharOp>(loc, boxCharType, buff, len); + return fir::EmboxCharOp::create(builder, loc, boxCharType, buff, len); } fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( @@ -231,8 +231,8 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( auto lenType = builder.getCharacterLengthType(); auto len = builder.createConvert(loc, lenType, box.getLen()); for (auto extent : box.getExtents()) - len = builder.create<mlir::arith::MulIOp>( - loc, len, builder.createConvert(loc, lenType, extent)); + len = mlir::arith::MulIOp::create( + builder, loc, len, builder.createConvert(loc, lenType, extent)); // TODO: typeLen can be improved in compiled constant cases // TODO: allow bare fir.array<> (no ref) conversion here ? @@ -277,7 +277,7 @@ fir::factory::CharacterExprHelper::createElementAddr(mlir::Value buffer, auto coor = builder.createConvert(loc, coorTy, buffer); auto i = builder.createConvert(loc, builder.getIndexType(), index); - return builder.create<fir::CoordinateOp>(loc, singleRefTy, coor, i); + return fir::CoordinateOp::create(builder, loc, singleRefTy, coor, i); } /// Load a character out of `buff` from offset `index`. @@ -287,7 +287,7 @@ fir::factory::CharacterExprHelper::createLoadCharAt(mlir::Value buff, mlir::Value index) { LLVM_DEBUG(llvm::dbgs() << "load a char: " << buff << " type: " << buff.getType() << " at: " << index << '\n'); - return builder.create<fir::LoadOp>(loc, createElementAddr(buff, index)); + return fir::LoadOp::create(builder, loc, createElementAddr(buff, index)); } /// Store the singleton character `c` to `str` at offset `index`. @@ -299,7 +299,7 @@ void fir::factory::CharacterExprHelper::createStoreCharAt(mlir::Value str, << " type: " << str.getType() << " at: " << index << '\n'); auto addr = createElementAddr(str, index); - builder.create<fir::StoreOp>(loc, c, addr); + fir::StoreOp::create(builder, loc, c, addr); } // FIXME: this temp is useless... either fir.coordinate_of needs to @@ -311,8 +311,8 @@ mlir::Value fir::factory::CharacterExprHelper::getCharBoxBuffer( const fir::CharBoxValue &box) { auto buff = box.getBuffer(); if (fir::isa_char(buff.getType())) { - auto newBuff = builder.create<fir::AllocaOp>(loc, buff.getType()); - builder.create<fir::StoreOp>(loc, buff, newBuff); + auto newBuff = fir::AllocaOp::create(builder, loc, buff.getType()); + fir::StoreOp::create(builder, loc, buff, newBuff); return newBuff; } return buff; @@ -339,19 +339,19 @@ void fir::factory::CharacterExprHelper::createCopy( auto kindBytes = builder.createIntegerConstant(loc, i64Ty, bytes); auto castCount = builder.createConvert(loc, i64Ty, count); auto totalBytes = - builder.create<mlir::arith::MulIOp>(loc, kindBytes, castCount); + mlir::arith::MulIOp::create(builder, loc, kindBytes, castCount); auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); auto toPtr = builder.createConvert(loc, llvmPointerType, toBuff); auto fromPtr = builder.createConvert(loc, llvmPointerType, fromBuff); - builder.create<mlir::LLVM::MemmoveOp>(loc, toPtr, fromPtr, totalBytes, - isVolatile); + mlir::LLVM::MemmoveOp::create(builder, loc, toPtr, fromPtr, totalBytes, + isVolatile); return; } // Convert a CHARACTER of one KIND into a CHARACTER of another KIND. - builder.create<fir::CharConvertOp>(loc, src.getBuffer(), count, - dest.getBuffer()); + fir::CharConvertOp::create(builder, loc, src.getBuffer(), count, + dest.getBuffer()); } void fir::factory::CharacterExprHelper::createPadding( @@ -397,7 +397,7 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createTempFrom( } else { auto ref = builder.createConvert(loc, builder.getRefType(sourceTy), temp.getBuffer()); - builder.create<fir::StoreOp>(loc, charBox->getBuffer(), ref); + fir::StoreOp::create(builder, loc, charBox->getBuffer(), ref); } return temp; } @@ -412,23 +412,23 @@ void fir::factory::CharacterExprHelper::createLengthOneAssign( auto fromCharLen1RefTy = builder.getRefType(getSingletonCharType( builder.getContext(), getCharacterKind(fir::unwrapRefType(val.getType())))); - val = builder.create<fir::LoadOp>( - loc, builder.createConvert(loc, fromCharLen1RefTy, val)); + val = fir::LoadOp::create( + builder, loc, builder.createConvert(loc, fromCharLen1RefTy, val)); } auto toCharLen1Ty = getSingletonCharType(builder.getContext(), getCharacterKind(toTy)); val = builder.createConvert(loc, toCharLen1Ty, val); - builder.create<fir::StoreOp>( - loc, val, + fir::StoreOp::create( + builder, loc, val, builder.createConvert(loc, builder.getRefType(toCharLen1Ty), addr)); } /// Returns the minimum of integer mlir::Value \p a and \b. mlir::Value genMin(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value a, mlir::Value b) { - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, b); - return builder.create<mlir::arith::SelectOp>(loc, cmp, a, b); + auto cmp = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); + return mlir::arith::SelectOp::create(builder, loc, cmp, a, b); } void fir::factory::CharacterExprHelper::createAssign( @@ -479,7 +479,7 @@ void fir::factory::CharacterExprHelper::createAssign( if (!compileTimeSameLength) { auto one = builder.createIntegerConstant(loc, lhs.getLen().getType(), 1); auto maxPadding = - builder.create<mlir::arith::SubIOp>(loc, lhs.getLen(), one); + mlir::arith::SubIOp::create(builder, loc, lhs.getLen(), one); createPadding(lhs, copyCount, maxPadding); } } @@ -490,18 +490,19 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createConcatenate( lhs.getLen()); auto rhsLen = builder.createConvert(loc, builder.getCharacterLengthType(), rhs.getLen()); - mlir::Value len = builder.create<mlir::arith::AddIOp>(loc, lhsLen, rhsLen); + mlir::Value len = mlir::arith::AddIOp::create(builder, loc, lhsLen, rhsLen); auto temp = createCharacterTemp(getCharacterType(rhs), len); createCopy(temp, lhs, lhsLen); auto one = builder.createIntegerConstant(loc, len.getType(), 1); - auto upperBound = builder.create<mlir::arith::SubIOp>(loc, len, one); + auto upperBound = mlir::arith::SubIOp::create(builder, loc, len, one); auto lhsLenIdx = builder.createConvert(loc, builder.getIndexType(), lhsLen); auto fromBuff = getCharBoxBuffer(rhs); auto toBuff = getCharBoxBuffer(temp); fir::factory::DoLoopHelper{builder, loc}.createLoop( lhsLenIdx, upperBound, one, [&](fir::FirOpBuilder &bldr, mlir::Value index) { - auto rhsIndex = bldr.create<mlir::arith::SubIOp>(loc, index, lhsLenIdx); + auto rhsIndex = + mlir::arith::SubIOp::create(bldr, loc, index, lhsLenIdx); auto charVal = createLoadCharAt(fromBuff, rhsIndex); createStoreCharAt(toBuff, index, charVal); }); @@ -514,7 +515,7 @@ mlir::Value fir::factory::CharacterExprHelper::genSubstringBase( if (!one) one = builder.createIntegerConstant(loc, lowerBound.getType(), 1); auto offset = - builder.create<mlir::arith::SubIOp>(loc, lowerBound, one).getResult(); + mlir::arith::SubIOp::create(builder, loc, lowerBound, one).getResult(); auto addr = createElementAddr(stringRawAddr, offset); return builder.createConvert(loc, substringAddrType, addr); } @@ -545,19 +546,19 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createSubstring( mlir::Value substringLen; if (nbounds < 2) { substringLen = - builder.create<mlir::arith::SubIOp>(loc, box.getLen(), castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, box.getLen(), castBounds[0]); } else { substringLen = - builder.create<mlir::arith::SubIOp>(loc, castBounds[1], castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, castBounds[1], castBounds[0]); } - substringLen = builder.create<mlir::arith::AddIOp>(loc, substringLen, one); + substringLen = mlir::arith::AddIOp::create(builder, loc, substringLen, one); // Set length to zero if bounds were reversed (Fortran 2018 9.4.1) auto zero = builder.createIntegerConstant(loc, substringLen.getType(), 0); - auto cdt = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); + auto cdt = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); substringLen = - builder.create<mlir::arith::SelectOp>(loc, cdt, zero, substringLen); + mlir::arith::SelectOp::create(builder, loc, cdt, zero, substringLen); return {substringRef, substringLen}; } @@ -573,11 +574,11 @@ fir::factory::CharacterExprHelper::createLenTrim(const fir::CharBoxValue &str) { auto zero = builder.createIntegerConstant(loc, indexType, 0); auto trueVal = builder.createIntegerConstant(loc, builder.getI1Type(), 1); auto blank = createBlankConstantCode(getCharacterType(str)); - mlir::Value lastChar = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value lastChar = mlir::arith::SubIOp::create(builder, loc, len, one); auto iterWhile = - builder.create<fir::IterWhileOp>(loc, lastChar, zero, minusOne, trueVal, - /*returnFinalCount=*/false, lastChar); + fir::IterWhileOp::create(builder, loc, lastChar, zero, minusOne, trueVal, + /*returnFinalCount=*/false, lastChar); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(iterWhile.getBody()); auto index = iterWhile.getInductionVar(); @@ -586,17 +587,17 @@ fir::factory::CharacterExprHelper::createLenTrim(const fir::CharBoxValue &str) { auto elemAddr = createElementAddr(fromBuff, index); auto codeAddr = builder.createConvert(loc, builder.getRefType(blank.getType()), elemAddr); - auto c = builder.create<fir::LoadOp>(loc, codeAddr); - auto isBlank = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, blank, c); + auto c = fir::LoadOp::create(builder, loc, codeAddr); + auto isBlank = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, blank, c); llvm::SmallVector<mlir::Value> results = {isBlank, index}; - builder.create<fir::ResultOp>(loc, results); + fir::ResultOp::create(builder, loc, results); builder.restoreInsertionPoint(insPt); // Compute length after iteration (zero if all blanks) mlir::Value newLen = - builder.create<mlir::arith::AddIOp>(loc, iterWhile.getResult(1), one); - auto result = builder.create<mlir::arith::SelectOp>( - loc, iterWhile.getResult(0), zero, newLen); + mlir::arith::AddIOp::create(builder, loc, iterWhile.getResult(1), one); + auto result = mlir::arith::SelectOp::create( + builder, loc, iterWhile.getResult(0), zero, newLen); return builder.createConvert(loc, builder.getCharacterLengthType(), result); } @@ -606,7 +607,7 @@ fir::factory::CharacterExprHelper::createCharacterTemp(mlir::Type type, assert(len >= 0 && "expected positive length"); auto kind = recoverCharacterType(type).getFKind(); auto charType = fir::CharacterType::get(builder.getContext(), kind, len); - auto addr = builder.create<fir::AllocaOp>(loc, charType); + auto addr = fir::AllocaOp::create(builder, loc, charType); auto mlirLen = builder.createIntegerConstant(loc, builder.getCharacterLengthType(), len); return {addr, mlirLen}; @@ -690,10 +691,10 @@ fir::factory::CharacterExprHelper::createSingletonFromCode(mlir::Value code, auto bits = builder.getKindMap().getCharacterBitsize(kind); auto intType = builder.getIntegerType(bits); auto cast = builder.createConvert(loc, intType, code); - auto undef = builder.create<fir::UndefOp>(loc, charType); + auto undef = fir::UndefOp::create(builder, loc, charType); auto zero = builder.getIntegerAttr(builder.getIndexType(), 0); - return builder.create<fir::InsertValueOp>(loc, charType, undef, cast, - builder.getArrayAttr(zero)); + return fir::InsertValueOp::create(builder, loc, charType, undef, cast, + builder.getArrayAttr(zero)); } mlir::Value fir::factory::CharacterExprHelper::extractCodeFromSingleton( @@ -703,8 +704,8 @@ mlir::Value fir::factory::CharacterExprHelper::extractCodeFromSingleton( auto bits = builder.getKindMap().getCharacterBitsize(type.getFKind()); auto intType = builder.getIntegerType(bits); auto zero = builder.getIntegerAttr(builder.getIndexType(), 0); - return builder.create<fir::ExtractValueOp>(loc, intType, singleton, - builder.getArrayAttr(zero)); + return fir::ExtractValueOp::create(builder, loc, intType, singleton, + builder.getArrayAttr(zero)); } mlir::Value @@ -716,12 +717,12 @@ fir::factory::CharacterExprHelper::readLengthFromBox(mlir::Value box) { mlir::Value fir::factory::CharacterExprHelper::readLengthFromBox( mlir::Value box, fir::CharacterType charTy) { auto lenTy = builder.getCharacterLengthType(); - auto size = builder.create<fir::BoxEleSizeOp>(loc, lenTy, box); + auto size = fir::BoxEleSizeOp::create(builder, loc, lenTy, box); auto bits = builder.getKindMap().getCharacterBitsize(charTy.getFKind()); auto width = bits / 8; if (width > 1) { auto widthVal = builder.createIntegerConstant(loc, lenTy, width); - return builder.create<mlir::arith::DivSIOp>(loc, size, widthVal); + return mlir::arith::DivSIOp::create(builder, loc, size, widthVal); } return size; } @@ -748,18 +749,18 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder, mlir::Value tuple, bool openBoxProc) { mlir::TupleType tupleType = mlir::cast<mlir::TupleType>(tuple.getType()); - mlir::Value addr = builder.create<fir::ExtractValueOp>( - loc, tupleType.getType(0), tuple, + mlir::Value addr = fir::ExtractValueOp::create( + builder, loc, tupleType.getType(0), tuple, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)})); mlir::Value proc = [&]() -> mlir::Value { if (openBoxProc) if (auto addrTy = mlir::dyn_cast<fir::BoxProcType>(addr.getType())) - return builder.create<fir::BoxAddrOp>(loc, addrTy.getEleTy(), addr); + return fir::BoxAddrOp::create(builder, loc, addrTy.getEleTy(), addr); return addr; }(); - mlir::Value len = builder.create<fir::ExtractValueOp>( - loc, tupleType.getType(1), tuple, + mlir::Value len = fir::ExtractValueOp::create( + builder, loc, tupleType.getType(1), tuple, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 1)})); return {proc, len}; @@ -773,14 +774,14 @@ mlir::Value fir::factory::createCharacterProcedureTuple( if (len) len = builder.createConvert(loc, tupleType.getType(1), len); else - len = builder.create<fir::UndefOp>(loc, tupleType.getType(1)); - mlir::Value tuple = builder.create<fir::UndefOp>(loc, tupleType); - tuple = builder.create<fir::InsertValueOp>( - loc, tupleType, tuple, addr, + len = fir::UndefOp::create(builder, loc, tupleType.getType(1)); + mlir::Value tuple = fir::UndefOp::create(builder, loc, tupleType); + tuple = fir::InsertValueOp::create( + builder, loc, tupleType, tuple, addr, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)})); - tuple = builder.create<fir::InsertValueOp>( - loc, tupleType, tuple, len, + tuple = fir::InsertValueOp::create( + builder, loc, tupleType, tuple, len, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 1)})); return tuple; @@ -827,10 +828,10 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum( auto currLen = builder.createConvert(loc, builder.getCharacterLengthType(), currChar.getLen()); // biggest len result - mlir::Value lhsBigger = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::uge, biggestLen, currLen); - biggestLen = builder.create<mlir::arith::SelectOp>(loc, lhsBigger, - biggestLen, currLen); + mlir::Value lhsBigger = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, biggestLen, currLen); + biggestLen = mlir::arith::SelectOp::create(builder, loc, lhsBigger, + biggestLen, currLen); auto cmp = predIsMin ? mlir::arith::CmpIPredicate::slt : mlir::arith::CmpIPredicate::sgt; @@ -843,10 +844,10 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum( resultBuf = builder.createConvert(loc, type, resultBuf); currBuf = builder.createConvert(loc, type, currBuf); - resultBuf = builder.create<mlir::arith::SelectOp>(loc, resultCmp, currBuf, - resultBuf); - resultLen = builder.create<mlir::arith::SelectOp>(loc, resultCmp, currLen, - resultLen); + resultBuf = mlir::arith::SelectOp::create(builder, loc, resultCmp, currBuf, + resultBuf); + resultLen = mlir::arith::SelectOp::create(builder, loc, resultCmp, currLen, + resultLen); } // now that we know the lexicographically biggest/smallest char and which char @@ -876,7 +877,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, // As a value, it ought to have a constant LEN value. assert(charTy.hasConstantLen() && "must have constant length"); mlir::Value tmp = builder.createTemporary(loc, charTy); - builder.create<fir::StoreOp>(loc, boxCharAddr, tmp); + fir::StoreOp::create(builder, loc, boxCharAddr, tmp); boxCharAddr = tmp; } auto fromBits = kindMap.getCharacterBitsize( @@ -886,13 +887,13 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, // Scale by relative ratio to give a buffer of the same length. auto ratio = builder.createIntegerConstant(loc, bufferSize.getType(), fromBits / toBits); - bufferSize = builder.create<mlir::arith::MulIOp>(loc, bufferSize, ratio); + bufferSize = mlir::arith::MulIOp::create(builder, loc, bufferSize, ratio); } mlir::Type toType = fir::CharacterType::getUnknownLen(builder.getContext(), toKind); auto dest = builder.createTemporary(loc, toType, /*name=*/{}, /*shape=*/{}, mlir::ValueRange{bufferSize}); - builder.create<fir::CharConvertOp>(loc, boxCharAddr, srcBoxChar.getLen(), - dest); + fir::CharConvertOp::create(builder, loc, boxCharAddr, srcBoxChar.getLen(), + dest); return fir::CharBoxValue{dest, srcBoxChar.getLen()}; } diff --git a/flang/lib/Optimizer/Builder/Complex.cpp b/flang/lib/Optimizer/Builder/Complex.cpp index 69f97dd..61de988 100644 --- a/flang/lib/Optimizer/Builder/Complex.cpp +++ b/flang/lib/Optimizer/Builder/Complex.cpp @@ -24,7 +24,7 @@ mlir::Type fir::factory::Complex::getComplexPartType(mlir::Value cplx) const { mlir::Value fir::factory::Complex::createComplex(mlir::Type cplxTy, mlir::Value real, mlir::Value imag) { - mlir::Value und = builder.create<fir::UndefOp>(loc, cplxTy); + mlir::Value und = fir::UndefOp::create(builder, loc, cplxTy); return insert<Part::Imag>(insert<Part::Real>(und, real), imag); } diff --git a/flang/lib/Optimizer/Builder/DoLoopHelper.cpp b/flang/lib/Optimizer/Builder/DoLoopHelper.cpp index 4b12e28..0ec91d5 100644 --- a/flang/lib/Optimizer/Builder/DoLoopHelper.cpp +++ b/flang/lib/Optimizer/Builder/DoLoopHelper.cpp @@ -20,7 +20,7 @@ fir::factory::DoLoopHelper::createLoop(mlir::Value lb, mlir::Value ub, auto ubi = builder.convertToIndexType(loc, ub); assert(step && "step must be an actual Value"); auto inc = builder.convertToIndexType(loc, step); - auto loop = builder.create<fir::DoLoopOp>(loc, lbi, ubi, inc); + auto loop = fir::DoLoopOp::create(builder, loc, lbi, ubi, inc); auto insertPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(loop.getBody()); auto index = loop.getInductionVar(); @@ -43,6 +43,6 @@ fir::factory::DoLoopHelper::createLoop(mlir::Value count, auto indexType = builder.getIndexType(); auto zero = builder.createIntegerConstant(loc, indexType, 0); auto one = builder.createIntegerConstant(loc, count.getType(), 1); - auto up = builder.create<mlir::arith::SubIOp>(loc, count, one); + auto up = mlir::arith::SubIOp::create(builder, loc, count, one); return createLoop(zero, up, one, bodyGenerator); } diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index acd5a88..eaad54e 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -406,10 +406,10 @@ mlir::Value fir::FirOpBuilder::genTempDeclareOp( llvm::ArrayRef<mlir::Value> typeParams, fir::FortranVariableFlagsAttr fortranAttrs) { auto nameAttr = mlir::StringAttr::get(builder.getContext(), name); - return builder.create<fir::DeclareOp>(loc, memref.getType(), memref, shape, - typeParams, - /*dummy_scope=*/nullptr, nameAttr, - fortranAttrs, cuf::DataAttributeAttr{}); + return fir::DeclareOp::create(builder, loc, memref.getType(), memref, shape, + typeParams, + /*dummy_scope=*/nullptr, nameAttr, fortranAttrs, + cuf::DataAttributeAttr{}); } mlir::Value fir::FirOpBuilder::genStackSave(mlir::Location loc) { @@ -585,7 +585,7 @@ mlir::Value fir::factory::createConvert(mlir::OpBuilder &builder, mlir::cast<fir::RecordType>(val.getType()).getTypeList() == mlir::cast<fir::RecordType>(toTy).getTypeList()) && "incompatible record types"); - return builder.create<fir::ConvertOp>(loc, toTy, val); + return fir::ConvertOp::create(builder, loc, toTy, val); } return val; } @@ -620,7 +620,7 @@ fir::StringLitOp fir::FirOpBuilder::createStringLitOp(mlir::Location loc, mlir::NamedAttribute sizeAttr(sizeTag, getI64IntegerAttr(data.size())); llvm::SmallVector<mlir::NamedAttribute> attrs{dataAttr, sizeAttr}; return create<fir::StringLitOp>(loc, llvm::ArrayRef<mlir::Type>{type}, - std::nullopt, attrs); + mlir::ValueRange{}, attrs); } mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc, @@ -824,7 +824,7 @@ genNullPointerComparison(fir::FirOpBuilder &builder, mlir::Location loc, auto intPtrTy = builder.getIntPtrType(); auto ptrToInt = builder.createConvert(loc, intPtrTy, addr); auto c0 = builder.createIntegerConstant(loc, intPtrTy, 0); - return builder.create<mlir::arith::CmpIOp>(loc, condition, ptrToInt, c0); + return mlir::arith::CmpIOp::create(builder, loc, condition, ptrToInt, c0); } mlir::Value fir::FirOpBuilder::genIsNotNullAddr(mlir::Location loc, @@ -1028,8 +1028,8 @@ fir::factory::readExtents(fir::FirOpBuilder &builder, mlir::Location loc, auto idxTy = builder.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { auto dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - box.getAddr(), dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + box.getAddr(), dimVal); result.emplace_back(dimInfo.getResult(1)); } return result; @@ -1061,7 +1061,7 @@ fir::ExtendedValue fir::factory::readBoxValue(fir::FirOpBuilder &builder, assert(!box.hasAssumedRank() && "cannot read unlimited polymorphic or assumed rank fir.box"); auto addr = - builder.create<fir::BoxAddrOp>(loc, box.getMemTy(), box.getAddr()); + fir::BoxAddrOp::create(builder, loc, box.getMemTy(), box.getAddr()); if (box.isCharacter()) { auto len = fir::factory::readCharLen(builder, loc, box); if (box.rank() == 0) @@ -1139,13 +1139,13 @@ static llvm::SmallVector<mlir::Value> getFromBox(mlir::Location loc, } else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { if (charTy.hasDynamicLen()) { auto idxTy = builder.getIndexType(); - auto eleSz = builder.create<fir::BoxEleSizeOp>(loc, idxTy, boxVal); + auto eleSz = fir::BoxEleSizeOp::create(builder, loc, idxTy, boxVal); auto kindBytes = builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8; mlir::Value charSz = builder.createIntegerConstant(loc, idxTy, kindBytes); mlir::Value len = - builder.create<mlir::arith::DivSIOp>(loc, eleSz, charSz); + mlir::arith::DivSIOp::create(builder, loc, eleSz, charSz); return {len}; } } @@ -1237,11 +1237,11 @@ fir::ExtendedValue fir::factory::createStringLiteral(fir::FirOpBuilder &builder, loc, type, globalName, [&](fir::FirOpBuilder &builder) { auto stringLitOp = builder.createStringLitOp(loc, str); - builder.create<fir::HasValueOp>(loc, stringLitOp); + fir::HasValueOp::create(builder, loc, stringLitOp); }, builder.createLinkOnceLinkage()); - auto addr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + auto addr = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); auto len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), str.size()); return fir::CharBoxValue{addr, len}; @@ -1255,7 +1255,7 @@ fir::factory::createExtents(fir::FirOpBuilder &builder, mlir::Location loc, for (auto ext : seqTy.getShape()) extents.emplace_back( ext == fir::SequenceType::getUnknownExtent() - ? builder.create<fir::UndefOp>(loc, idxTy).getResult() + ? fir::UndefOp::create(builder, loc, idxTy).getResult() : builder.createIntegerConstant(loc, idxTy, ext)); return extents; } @@ -1396,11 +1396,11 @@ void fir::factory::genScalarAssignment(fir::FirOpBuilder &builder, assert(!fir::hasDynamicSize(type)); auto rhsVal = fir::getBase(rhs); if (fir::isa_ref_type(rhsVal.getType())) - rhsVal = builder.create<fir::LoadOp>(loc, rhsVal); + rhsVal = fir::LoadOp::create(builder, loc, rhsVal); mlir::Value lhsAddr = fir::getBase(lhs); rhsVal = builder.createConvert(loc, fir::unwrapRefType(lhsAddr.getType()), rhsVal); - builder.create<fir::StoreOp>(loc, rhsVal, lhsAddr); + fir::StoreOp::create(builder, loc, rhsVal, lhsAddr); } } @@ -1421,16 +1421,18 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, auto &[lFieldName, lFieldTy] = lhsPair; auto &[rFieldName, rFieldTy] = rhsPair; assert(!fir::hasDynamicSize(lFieldTy) && !fir::hasDynamicSize(rFieldTy)); - mlir::Value rField = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rFieldName, rhsType, fir::getTypeParams(rhs)); + mlir::Value rField = + fir::FieldIndexOp::create(builder, loc, fieldIndexType, rFieldName, + rhsType, fir::getTypeParams(rhs)); auto rFieldRefType = builder.getRefType(rFieldTy); - mlir::Value fromCoor = builder.create<fir::CoordinateOp>( - loc, rFieldRefType, fir::getBase(rhs), rField); - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, lFieldName, lhsType, fir::getTypeParams(lhs)); + mlir::Value fromCoor = fir::CoordinateOp::create( + builder, loc, rFieldRefType, fir::getBase(rhs), rField); + mlir::Value field = + fir::FieldIndexOp::create(builder, loc, fieldIndexType, lFieldName, + lhsType, fir::getTypeParams(lhs)); auto fieldRefType = builder.getRefType(lFieldTy); - mlir::Value toCoor = builder.create<fir::CoordinateOp>( - loc, fieldRefType, fir::getBase(lhs), field); + mlir::Value toCoor = fir::CoordinateOp::create(builder, loc, fieldRefType, + fir::getBase(lhs), field); std::optional<fir::DoLoopOp> outerLoop; if (auto sequenceType = mlir::dyn_cast<fir::SequenceType>(lFieldTy)) { // Create loops to assign array components elements by elements. @@ -1444,7 +1446,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, for (auto extent : llvm::reverse(sequenceType.getShape())) { // TODO: add zero size test ! mlir::Value ub = builder.createIntegerConstant(loc, idxTy, extent - 1); - auto loop = builder.create<fir::DoLoopOp>(loc, zero, ub, one); + auto loop = fir::DoLoopOp::create(builder, loc, zero, ub, one); if (!outerLoop) outerLoop = loop; indices.push_back(loop.getInductionVar()); @@ -1453,19 +1455,19 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, // Set indices in column-major order. std::reverse(indices.begin(), indices.end()); auto elementRefType = builder.getRefType(sequenceType.getEleTy()); - toCoor = builder.create<fir::CoordinateOp>(loc, elementRefType, toCoor, - indices); - fromCoor = builder.create<fir::CoordinateOp>(loc, elementRefType, - fromCoor, indices); + toCoor = fir::CoordinateOp::create(builder, loc, elementRefType, toCoor, + indices); + fromCoor = fir::CoordinateOp::create(builder, loc, elementRefType, + fromCoor, indices); } if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy); mlir::isa<fir::BaseBoxType>(fieldEleTy)) { assert(mlir::isa<fir::PointerType>( mlir::cast<fir::BaseBoxType>(fieldEleTy).getEleTy()) && "allocatable members require deep copy"); - auto fromPointerValue = builder.create<fir::LoadOp>(loc, fromCoor); + auto fromPointerValue = fir::LoadOp::create(builder, loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); - builder.create<fir::StoreOp>(loc, castTo, toCoor); + fir::StoreOp::create(builder, loc, castTo, toCoor); } else { auto from = fir::factory::componentToExtendedValue(builder, loc, fromCoor); @@ -1543,7 +1545,7 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder, // runtime interface, but assume the fir.box is unchanged. // TODO: does this holds true with polymorphic entities ? auto toMutableBox = builder.createTemporary(loc, to.getType()); - builder.create<fir::StoreOp>(loc, to, toMutableBox); + fir::StoreOp::create(builder, loc, to, toMutableBox); if (isTemporaryLHS) fir::runtime::genAssignTemporary(builder, loc, toMutableBox, from); else @@ -1588,12 +1590,12 @@ mlir::Value fir::factory::genLenOfCharacter( auto idxTy = builder.getIndexType(); auto zero = builder.createIntegerConstant(loc, idxTy, 0); auto saturatedDiff = [&](mlir::Value lower, mlir::Value upper) { - auto diff = builder.create<mlir::arith::SubIOp>(loc, upper, lower); + auto diff = mlir::arith::SubIOp::create(builder, loc, upper, lower); auto one = builder.createIntegerConstant(loc, idxTy, 1); - auto size = builder.create<mlir::arith::AddIOp>(loc, diff, one); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, size, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, size, zero); + auto size = mlir::arith::AddIOp::create(builder, loc, diff, one); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, size, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, size, zero); }; if (substring.size() == 2) { auto upper = builder.createConvert(loc, idxTy, substring.back()); @@ -1615,7 +1617,7 @@ mlir::Value fir::factory::genLenOfCharacter( } if (fir::isa_box_type(memref.getType())) { if (mlir::isa<fir::BoxCharType>(memref.getType())) - return builder.create<fir::BoxCharLenOp>(loc, idxTy, memref); + return fir::BoxCharLenOp::create(builder, loc, idxTy, memref); if (mlir::isa<fir::BoxType>(memref.getType())) return CharacterExprHelper(builder, loc).readLengthFromBox(memref); fir::emitFatalError(loc, "memref has wrong type"); @@ -1684,10 +1686,10 @@ mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, if (auto cst = mlir::dyn_cast<mlir::arith::ConstantOp>(definingOp)) if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue())) return intAttr.getInt() > 0 ? value : zero; - mlir::Value valueIsGreater = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, value, zero); - return builder.create<mlir::arith::SelectOp>(loc, valueIsGreater, value, - zero); + mlir::Value valueIsGreater = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, value, zero); + return mlir::arith::SelectOp::create(builder, loc, valueIsGreater, value, + zero); } mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, @@ -1703,8 +1705,8 @@ mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder, mlir::Value one) { mlir::Type type = lb.getType(); // Let the folder deal with the common `ub - <const> + 1` case. - auto diff = builder.create<mlir::arith::SubIOp>(loc, type, ub, lb); - auto rawExtent = builder.create<mlir::arith::AddIOp>(loc, type, diff, one); + auto diff = mlir::arith::SubIOp::create(builder, loc, type, ub, lb); + auto rawExtent = mlir::arith::AddIOp::create(builder, loc, type, diff, one); return fir::factory::genMaxWithZero(builder, loc, rawExtent, zero); } mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder, @@ -1724,8 +1726,8 @@ genCPtrOrCFunptrFieldIndex(fir::FirOpBuilder &builder, mlir::Location loc, auto addrFieldName = recTy.getTypeList()[0].first; mlir::Type addrFieldTy = recTy.getTypeList()[0].second; auto fieldIndexType = fir::FieldType::get(cptrTy.getContext()); - mlir::Value addrFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, addrFieldName, recTy, + mlir::Value addrFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, addrFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); return {addrFieldIndex, addrFieldTy}; } @@ -1736,8 +1738,8 @@ mlir::Value fir::factory::genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Type ty) { auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, ty); - return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy), - cPtr, addrFieldIndex); + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); } mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder, @@ -1748,15 +1750,15 @@ mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder, auto cptrFieldName = recTy.getTypeList()[0].first; mlir::Type cptrFieldTy = recTy.getTypeList()[0].second; auto fieldIndexType = fir::FieldType::get(ty.getContext()); - mlir::Value cptrFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, cptrFieldName, recTy, + mlir::Value cptrFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, cptrFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - auto cptrCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex); + auto cptrCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex); auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, cptrFieldTy); - return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy), - cptrCoord, addrFieldIndex); + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cptrCoord, addrFieldIndex); } mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, @@ -1769,13 +1771,13 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy); mlir::Value cPtrCoor; if (fir::isa_ref_type(cPtr.getType())) { - cPtrCoor = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); + cPtrCoor = fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); } else { auto arrayAttr = builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)}); - cPtrCoor = builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr, - arrayAttr); + cPtrCoor = fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr, + arrayAttr); } return genCPtrOrCFunptrValue(builder, loc, cPtrCoor); } @@ -1783,13 +1785,14 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, if (fir::isa_ref_type(cPtr.getType())) { mlir::Value cPtrAddr = fir::factory::genCPtrOrCFunptrAddr(builder, loc, cPtr, cPtrTy); - return builder.create<fir::LoadOp>(loc, cPtrAddr); + return fir::LoadOp::create(builder, loc, cPtrAddr); } auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy); auto arrayAttr = builder.getArrayAttr({builder.getIntegerAttr(builder.getIndexType(), 0)}); - return builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr, arrayAttr); + return fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr, + arrayAttr); } fir::BoxValue fir::factory::createBoxValue(fir::FirOpBuilder &builder, @@ -1837,8 +1840,8 @@ mlir::Value fir::factory::createNullBoxProc(fir::FirOpBuilder &builder, if (!boxTy) fir::emitFatalError(loc, "Procedure pointer must be of BoxProcType"); auto boxEleTy{fir::unwrapRefType(boxTy.getEleTy())}; - mlir::Value initVal{builder.create<fir::ZeroOp>(loc, boxEleTy)}; - return builder.create<fir::EmboxProcOp>(loc, boxTy, initVal); + mlir::Value initVal{fir::ZeroOp::create(builder, loc, boxEleTy)}; + return fir::EmboxProcOp::create(builder, loc, boxTy, initVal); } void fir::factory::setInternalLinkage(mlir::func::FuncOp func) { @@ -1897,15 +1900,15 @@ llvm::SmallVector<mlir::Value> fir::factory::updateRuntimeExtentsForEmptyArrays( mlir::Type type = extent.getType(); mlir::Value zero = createZeroValue(builder, loc, type); zeroes.push_back(zero); - mlir::Value isZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); - isEmpty = builder.create<mlir::arith::OrIOp>(loc, isEmpty, isZero); + mlir::Value isZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); + isEmpty = mlir::arith::OrIOp::create(builder, loc, isEmpty, isZero); } llvm::SmallVector<mlir::Value> newExtents; for (auto [zero, extent] : llvm::zip_equal(zeroes, extents)) { newExtents.push_back( - builder.create<mlir::arith::SelectOp>(loc, isEmpty, zero, extent)); + mlir::arith::SelectOp::create(builder, loc, isEmpty, zero, extent)); } return newExtents; } @@ -1926,7 +1929,7 @@ void fir::factory::genDimInfoFromBox( for (unsigned i = 0; i < rank; ++i) { mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim); if (lbounds) lbounds->push_back(dimInfo.getLowerBound()); if (extents) @@ -1943,12 +1946,12 @@ mlir::Value fir::factory::genLifetimeStart(mlir::OpBuilder &builder, mlir::Type ptrTy = mlir::LLVM::LLVMPointerType::get( alloc.getContext(), getAllocaAddressSpace(dl)); mlir::Value cast = - builder.create<fir::ConvertOp>(loc, ptrTy, alloc.getResult()); - builder.create<mlir::LLVM::LifetimeStartOp>(loc, size, cast); + fir::ConvertOp::create(builder, loc, ptrTy, alloc.getResult()); + mlir::LLVM::LifetimeStartOp::create(builder, loc, size, cast); return cast; } void fir::factory::genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value cast, int64_t size) { - builder.create<mlir::LLVM::LifetimeEndOp>(loc, size, cast); + mlir::LLVM::LifetimeEndOp::create(builder, loc, size, cast); } diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index fb6f0db..c3948f2 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -50,7 +50,7 @@ hlfir::getExplicitExtentsFromShape(mlir::Value shape, int64_t extent = exprShape[i]; mlir::Value extentVal; if (extent == expr.getUnknownExtent()) { - auto op = builder.create<hlfir::GetExtentOp>(shape.getLoc(), shape, i); + auto op = hlfir::GetExtentOp::create(builder, shape.getLoc(), shape, i); extentVal = op.getResult(); } else { extentVal = @@ -150,7 +150,7 @@ static mlir::Value genCharacterVariableLength(mlir::Location loc, return builder.createIntegerConstant(loc, builder.getIndexType(), charType.getLen()); if (var.isMutableBox()) - var = hlfir::Entity{builder.create<fir::LoadOp>(loc, var)}; + var = hlfir::Entity{fir::LoadOp::create(builder, loc, var)}; mlir::Value len = fir::factory::CharacterExprHelper{builder, loc}.getLength( var.getFirBase()); assert(len && "failed to retrieve length"); @@ -164,8 +164,8 @@ static fir::CharBoxValue genUnboxChar(mlir::Location loc, return {emboxChar.getMemref(), emboxChar.getLen()}; mlir::Type refType = fir::ReferenceType::get( mlir::cast<fir::BoxCharType>(boxChar.getType()).getEleTy()); - auto unboxed = builder.create<fir::UnboxCharOp>( - loc, refType, builder.getIndexType(), boxChar); + auto unboxed = fir::UnboxCharOp::create(builder, loc, refType, + builder.getIndexType(), boxChar); mlir::Value addr = unboxed.getResult(0); mlir::Value len = unboxed.getResult(1); if (auto varIface = boxChar.getDefiningOp<fir::FortranVariableOpInterface>()) @@ -278,8 +278,9 @@ hlfir::genDeclare(mlir::Location loc, fir::FirOpBuilder &builder, box.nonDeferredLenParams().end()); }, [](const auto &) {}); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, base, name, shapeOrShift, lenParams, dummyScope, flags, dataAttr); + auto declareOp = + hlfir::DeclareOp::create(builder, loc, base, name, shapeOrShift, + lenParams, dummyScope, flags, dataAttr); return mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation()); } @@ -312,12 +313,12 @@ hlfir::genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder, genLengthParameters(loc, builder, value, lenParams); if (attr) { assert(name.empty() && "It attribute is provided, no-name is expected"); - return builder.create<hlfir::AssociateOp>(loc, source, shape, lenParams, - fir::FortranVariableFlagsAttr{}, - llvm::ArrayRef{*attr}); + return hlfir::AssociateOp::create(builder, loc, source, shape, lenParams, + fir::FortranVariableFlagsAttr{}, + llvm::ArrayRef{*attr}); } - return builder.create<hlfir::AssociateOp>(loc, source, name, shape, lenParams, - fir::FortranVariableFlagsAttr{}); + return hlfir::AssociateOp::create(builder, loc, source, name, shape, + lenParams, fir::FortranVariableFlagsAttr{}); } mlir::Value hlfir::genVariableRawAddress(mlir::Location loc, @@ -326,12 +327,12 @@ mlir::Value hlfir::genVariableRawAddress(mlir::Location loc, assert(var.isVariable() && "only address of variables can be taken"); mlir::Value baseAddr = var.getFirBase(); if (var.isMutableBox()) - baseAddr = builder.create<fir::LoadOp>(loc, baseAddr); + baseAddr = fir::LoadOp::create(builder, loc, baseAddr); // Get raw address. if (mlir::isa<fir::BoxCharType>(var.getType())) baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr(); if (mlir::isa<fir::BaseBoxType>(baseAddr.getType())) - baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr); + baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); return baseAddr; } @@ -350,8 +351,8 @@ mlir::Value hlfir::genVariableBoxChar(mlir::Location loc, fir::BoxCharType::get(builder.getContext(), charType.getFKind()); auto scalarAddr = builder.createConvert(loc, fir::ReferenceType::get(charType), addr); - return builder.create<fir::EmboxCharOp>(loc, boxCharType, scalarAddr, - lengths[0]); + return fir::EmboxCharOp::create(builder, loc, boxCharType, scalarAddr, + lengths[0]); } static hlfir::Entity changeBoxAttributes(mlir::Location loc, @@ -365,8 +366,8 @@ static hlfir::Entity changeBoxAttributes(mlir::Location loc, getNonDefaultLowerBounds(loc, builder, var); if (!lbounds.empty()) shift = builder.genShift(loc, lbounds); - auto rebox = builder.create<fir::ReboxOp>(loc, forceBoxType, var, shift, - /*slice=*/nullptr); + auto rebox = fir::ReboxOp::create(builder, loc, forceBoxType, var, shift, + /*slice=*/nullptr); return hlfir::Entity{rebox}; } @@ -404,9 +405,8 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc, fir::ReferenceType::get(fir::unwrapRefType(forceBoxType.getEleTy())); addr = builder.createConvert(loc, baseType, addr); } - auto embox = - builder.create<fir::EmboxOp>(loc, boxType, addr, shape, - /*slice=*/mlir::Value{}, typeParams); + auto embox = fir::EmboxOp::create(builder, loc, boxType, addr, shape, + /*slice=*/mlir::Value{}, typeParams); return hlfir::Entity{embox.getResult()}; } @@ -416,7 +416,7 @@ hlfir::Entity hlfir::loadTrivialScalar(mlir::Location loc, entity = derefPointersAndAllocatables(loc, builder, entity); if (entity.isVariable() && entity.isScalar() && fir::isa_trivial(entity.getFortranElementType())) { - return Entity{builder.create<fir::LoadOp>(loc, entity)}; + return Entity{fir::LoadOp::create(builder, loc, entity)}; } return entity; } @@ -429,8 +429,8 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc, llvm::SmallVector<mlir::Value> lenParams; genLengthParameters(loc, builder, entity, lenParams); if (mlir::isa<hlfir::ExprType>(entity.getType())) - return hlfir::Entity{builder.create<hlfir::ApplyOp>( - loc, entity, oneBasedIndices, lenParams)}; + return hlfir::Entity{hlfir::ApplyOp::create(builder, loc, entity, + oneBasedIndices, lenParams)}; // Build hlfir.designate. The lower bounds may need to be added to // the oneBasedIndices since hlfir.designate expect indices // based on the array operand lower bounds. @@ -445,16 +445,16 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc, for (auto [oneBased, lb] : llvm::zip(oneBasedIndices, lbounds)) { auto lbIdx = builder.createConvert(loc, idxTy, lb); auto oneBasedIdx = builder.createConvert(loc, idxTy, oneBased); - auto shift = builder.create<mlir::arith::SubIOp>(loc, lbIdx, one); + auto shift = mlir::arith::SubIOp::create(builder, loc, lbIdx, one); mlir::Value index = - builder.create<mlir::arith::AddIOp>(loc, oneBasedIdx, shift); + mlir::arith::AddIOp::create(builder, loc, oneBasedIdx, shift); indices.push_back(index); } - designate = builder.create<hlfir::DesignateOp>(loc, resultType, entity, - indices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + indices, lenParams); } else { - designate = builder.create<hlfir::DesignateOp>(loc, resultType, entity, - oneBasedIndices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + oneBasedIndices, lenParams); } return mlir::cast<fir::FortranVariableOpInterface>(designate.getOperation()); } @@ -467,8 +467,8 @@ static mlir::Value genUBound(mlir::Location loc, fir::FirOpBuilder &builder, return extent; extent = builder.createConvert(loc, one.getType(), extent); lb = builder.createConvert(loc, one.getType(), lb); - auto add = builder.create<mlir::arith::AddIOp>(loc, lb, extent); - return builder.create<mlir::arith::SubIOp>(loc, add, one); + auto add = mlir::arith::AddIOp::create(builder, loc, lb, extent); + return mlir::arith::SubIOp::create(builder, loc, add, one); } llvm::SmallVector<std::pair<mlir::Value, mlir::Value>> @@ -557,8 +557,8 @@ static mlir::Value computeVariableExtent(mlir::Location loc, assert(mlir::isa<fir::BaseBoxType>(variable.getType()) && "array variable with dynamic extent must be boxed"); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - variable, dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + variable, dimVal); return dimInfo.getExtent(); } llvm::SmallVector<mlir::Value> getVariableExtents(mlir::Location loc, @@ -608,14 +608,14 @@ mlir::Value hlfir::genShape(mlir::Location loc, fir::FirOpBuilder &builder, return shape; if (mlir::isa<fir::ShapeShiftType>(shape.getType())) if (auto s = shape.getDefiningOp<fir::ShapeShiftOp>()) - return builder.create<fir::ShapeOp>(loc, s.getExtents()); + return fir::ShapeOp::create(builder, loc, s.getExtents()); } if (mlir::isa<hlfir::ExprType>(entity.getType())) - return builder.create<hlfir::ShapeOfOp>(loc, entity.getBase()); + return hlfir::ShapeOfOp::create(builder, loc, entity.getBase()); // There is no shape lying around for this entity. Retrieve the extents and // build a new fir.shape. - return builder.create<fir::ShapeOp>(loc, - getVariableExtents(loc, builder, entity)); + return fir::ShapeOp::create(builder, loc, + getVariableExtents(loc, builder, entity)); } llvm::SmallVector<mlir::Value> @@ -668,7 +668,7 @@ mlir::Value hlfir::genLBound(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type idxTy = builder.getIndexType(); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, entity, dimVal); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, entity, dimVal); return dimInfo.getLowerBound(); } @@ -708,7 +708,7 @@ void hlfir::genLengthParameters(mlir::Location loc, fir::FirOpBuilder &builder, return; } if (entity.isCharacter()) { - result.push_back(builder.create<hlfir::GetLengthOp>(loc, expr)); + result.push_back(hlfir::GetLengthOp::create(builder, loc, expr)); return; } TODO(loc, "inquire PDTs length parameters of hlfir.expr"); @@ -735,7 +735,7 @@ mlir::Value hlfir::genRank(mlir::Location loc, fir::FirOpBuilder &builder, return builder.createIntegerConstant(loc, resultType, entity.getRank()); assert(entity.isBoxAddressOrValue() && "assumed-ranks are box addresses or values"); - return builder.create<fir::BoxRankOp>(loc, resultType, entity); + return fir::BoxRankOp::create(builder, loc, resultType, entity); } // Return a "shape" that can be used in fir.embox/fir.rebox with \p exv base. @@ -796,20 +796,20 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity) { if (entity.isMutableBox()) { - hlfir::Entity boxLoad{builder.create<fir::LoadOp>(loc, entity)}; + hlfir::Entity boxLoad{fir::LoadOp::create(builder, loc, entity)}; if (entity.isScalar()) { if (!entity.isPolymorphic() && !entity.hasLengthParameters()) - return hlfir::Entity{builder.create<fir::BoxAddrOp>(loc, boxLoad)}; + return hlfir::Entity{fir::BoxAddrOp::create(builder, loc, boxLoad)}; mlir::Type elementType = boxLoad.getFortranElementType(); if (auto charType = mlir::dyn_cast<fir::CharacterType>(elementType)) { - mlir::Value base = builder.create<fir::BoxAddrOp>(loc, boxLoad); + mlir::Value base = fir::BoxAddrOp::create(builder, loc, boxLoad); if (charType.hasConstantLen()) return hlfir::Entity{base}; mlir::Value len = genCharacterVariableLength(loc, builder, entity); auto boxCharType = fir::BoxCharType::get(builder.getContext(), charType.getFKind()); return hlfir::Entity{ - builder.create<fir::EmboxCharOp>(loc, boxCharType, base, len) + fir::EmboxCharOp::create(builder, loc, boxCharType, base, len) .getResult()}; } } @@ -819,7 +819,7 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc, // information. Keep them boxed. return boxLoad; } else if (entity.isProcedurePointer()) { - return hlfir::Entity{builder.create<fir::LoadOp>(loc, entity)}; + return hlfir::Entity{fir::LoadOp::create(builder, loc, entity)}; } return entity; } @@ -870,8 +870,8 @@ hlfir::ElementalOp hlfir::genElementalOp( mlir::Value polymorphicMold, mlir::Type exprType) { if (!exprType) exprType = getArrayExprType(elementType, shape, !!polymorphicMold); - auto elementalOp = builder.create<hlfir::ElementalOp>( - loc, exprType, shape, polymorphicMold, typeParams, isUnordered); + auto elementalOp = hlfir::ElementalOp::create( + builder, loc, exprType, shape, polymorphicMold, typeParams, isUnordered); auto insertPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(elementalOp.getBody()); mlir::Value elementResult = genKernel(loc, builder, elementalOp.getIndices()); @@ -881,7 +881,7 @@ hlfir::ElementalOp hlfir::genElementalOp( // here. if (fir::isa_trivial(elementResult.getType())) elementResult = builder.createConvert(loc, elementType, elementResult); - builder.create<hlfir::YieldElementOp>(loc, elementResult); + hlfir::YieldElementOp::create(builder, loc, elementResult); builder.restoreInsertionPoint(insertPt); return elementalOp; } @@ -948,10 +948,10 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, mlir::OpBuilder::InsertionGuard guard(builder); loopNest.oneBasedIndices.assign(extents.size(), mlir::Value{}); // Build loop nest from column to row. - auto one = builder.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); mlir::Type indexType = builder.getIndexType(); if (emitWorkshareLoop) { - auto wslw = builder.create<mlir::omp::WorkshareLoopWrapperOp>(loc); + auto wslw = mlir::omp::WorkshareLoopWrapperOp::create(builder, loc); loopNest.outerOp = wslw; builder.createBlock(&wslw.getRegion()); mlir::omp::LoopNestOperands lnops; @@ -961,12 +961,12 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, lnops.loopUpperBounds.push_back(extent); lnops.loopSteps.push_back(one); } - auto lnOp = builder.create<mlir::omp::LoopNestOp>(loc, lnops); + auto lnOp = mlir::omp::LoopNestOp::create(builder, loc, lnops); mlir::Block *block = builder.createBlock(&lnOp.getRegion()); for (auto extent : llvm::reverse(extents)) block->addArgument(extent.getType(), extent.getLoc()); loopNest.body = block; - builder.create<mlir::omp::YieldOp>(loc); + mlir::omp::YieldOp::create(builder, loc); for (unsigned dim = 0; dim < extents.size(); dim++) loopNest.oneBasedIndices[extents.size() - dim - 1] = lnOp.getRegion().front().getArgument(dim); @@ -975,7 +975,7 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, for (auto extent : llvm::reverse(extents)) { auto ub = builder.createConvert(loc, indexType, extent); auto doLoop = - builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered); + fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered); if (!couldVectorize) { mlir::LLVM::LoopVectorizeAttr va{mlir::LLVM::LoopVectorizeAttr::get( builder.getContext(), @@ -1002,7 +1002,7 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( bool isUnordered) { assert(!extents.empty() && "must have at least one extent"); // Build loop nest from column to row. - auto one = builder.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); mlir::Type indexType = builder.getIndexType(); unsigned dim = extents.size() - 1; fir::DoLoopOp outerLoop = nullptr; @@ -1018,16 +1018,15 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( // of its parent loop. fir::DoLoopOp doLoop; if (!parentLoop) { - doLoop = builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered, - /*finalCountValue=*/false, - reductionInits); + doLoop = fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered, + /*finalCountValue=*/false, reductionInits); } else { - doLoop = builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered, - /*finalCountValue=*/false, - parentLoop.getRegionIterArgs()); + doLoop = fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered, + /*finalCountValue=*/false, + parentLoop.getRegionIterArgs()); if (!reductionInits.empty()) { // Return the results of the child loop from its parent loop. - builder.create<fir::ResultOp>(loc, doLoop.getResults()); + fir::ResultOp::create(builder, loc, doLoop.getResults()); } } @@ -1044,7 +1043,7 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( genBody(loc, builder, oneBasedIndices, parentLoop.getRegionIterArgs()); builder.setInsertionPointToEnd(parentLoop.getBody()); if (!reductionValues.empty()) - builder.create<fir::ResultOp>(loc, reductionValues); + fir::ResultOp::create(builder, loc, reductionValues); builder.setInsertionPointAfter(outerLoop); return outerLoop->getResults(); } @@ -1057,18 +1056,18 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, // Evaluate in some region that will be moved into the actual ifOp (the actual // ifOp can only be created when the result types are known). - auto badIfOp = builder.create<fir::IfOp>(loc, condition.getType(), condition, - /*withElseRegion=*/false); + auto badIfOp = fir::IfOp::create(builder, loc, condition.getType(), condition, + /*withElseRegion=*/false); mlir::Block *preparationBlock = &badIfOp.getThenRegion().front(); builder.setInsertionPointToStart(preparationBlock); fir::ExtendedValue result = genIfTrue(); fir::ResultOp resultOp = result.match( [&](const fir::CharBoxValue &box) -> fir::ResultOp { - return builder.create<fir::ResultOp>( - loc, mlir::ValueRange{box.getAddr(), box.getLen()}); + return fir::ResultOp::create( + builder, loc, mlir::ValueRange{box.getAddr(), box.getLen()}); }, [&](const mlir::Value &addr) -> fir::ResultOp { - return builder.create<fir::ResultOp>(loc, addr); + return fir::ResultOp::create(builder, loc, addr); }, [&](const auto &) -> fir::ResultOp { TODO(loc, "unboxing non scalar optional fir.box"); @@ -1077,8 +1076,8 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, // Create actual fir.if operation. auto ifOp = - builder.create<fir::IfOp>(loc, resultOp->getOperandTypes(), condition, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultOp->getOperandTypes(), condition, + /*withElseRegion=*/true); // Move evaluation into Then block, preparationBlock->moveBefore(&ifOp.getThenRegion().back()); ifOp.getThenRegion().back().erase(); @@ -1087,11 +1086,11 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> absentValues; for (mlir::Type resTy : ifOp->getResultTypes()) { if (fir::isa_ref_type(resTy) || fir::isa_box_type(resTy)) - absentValues.emplace_back(builder.create<fir::AbsentOp>(loc, resTy)); + absentValues.emplace_back(fir::AbsentOp::create(builder, loc, resTy)); else - absentValues.emplace_back(builder.create<fir::ZeroOp>(loc, resTy)); + absentValues.emplace_back(fir::ZeroOp::create(builder, loc, resTy)); } - builder.create<fir::ResultOp>(loc, absentValues); + fir::ResultOp::create(builder, loc, absentValues); badIfOp->erase(); // Build fir::ExtendedValue from the result values. @@ -1139,8 +1138,8 @@ static fir::ExtendedValue translateVariableToExtendedValue( } if (variable.mayBeOptional()) { if (!keepScalarOptionalBoxed && variable.isScalar()) { - mlir::Value isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), variable); + mlir::Value isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), variable); return conditionallyEvaluate( loc, builder, isPresent, [&]() -> fir::ExtendedValue { mlir::Value base = genVariableRawAddress(loc, builder, variable); @@ -1249,7 +1248,7 @@ static fir::ExtendedValue placeTrivialInMemory(mlir::Location loc, if (targetType != val.getType()) builder.createStoreWithConvert(loc, val, temp); else - builder.create<fir::StoreOp>(loc, val, temp); + fir::StoreOp::create(builder, loc, val, temp); return temp; } @@ -1369,8 +1368,8 @@ hlfir::createTempFromMold(mlir::Location loc, fir::FirOpBuilder &builder, llvm::ArrayRef<mlir::Value> typeParams, fir::FortranVariableFlagsAttr attrs) -> mlir::Value { auto declareOp = - builder.create<hlfir::DeclareOp>(loc, memref, name, shape, typeParams, - /*dummy_scope=*/nullptr, attrs); + hlfir::DeclareOp::create(builder, loc, memref, name, shape, typeParams, + /*dummy_scope=*/nullptr, attrs); return declareOp.getBase(); }; @@ -1406,8 +1405,8 @@ hlfir::Entity hlfir::createStackTempFromMold(mlir::Location loc, /*shape=*/{}, lenParams); } auto declareOp = - builder.create<hlfir::DeclareOp>(loc, alloc, tmpName, shape, lenParams, - /*dummy_scope=*/nullptr, declAttrs); + hlfir::DeclareOp::create(builder, loc, alloc, tmpName, shape, lenParams, + /*dummy_scope=*/nullptr, declAttrs); return hlfir::Entity{declareOp.getBase()}; } @@ -1422,8 +1421,8 @@ hlfir::convertCharacterKind(mlir::Location loc, fir::FirOpBuilder &builder, if (src.second.has_value()) src.second.value()(); - return hlfir::EntityWithAttributes{builder.create<hlfir::DeclareOp>( - loc, res.getAddr(), ".temp.kindconvert", /*shape=*/nullptr, + return hlfir::EntityWithAttributes{hlfir::DeclareOp::create( + builder, loc, res.getAddr(), ".temp.kindconvert", /*shape=*/nullptr, /*typeparams=*/mlir::ValueRange{res.getLen()}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{})}; } @@ -1494,10 +1493,10 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder, } auto shapeShiftType = fir::ShapeShiftType::get(builder.getContext(), rank); mlir::Value shapeShift = - builder.create<fir::ShapeShiftOp>(loc, shapeShiftType, lbAndExtents); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, associate.getFirBase(), *associate.getUniqName(), shapeShift, - associate.getTypeparams(), /*dummy_scope=*/nullptr, + fir::ShapeShiftOp::create(builder, loc, shapeShiftType, lbAndExtents); + auto declareOp = hlfir::DeclareOp::create( + builder, loc, associate.getFirBase(), *associate.getUniqName(), + shapeShift, associate.getTypeparams(), /*dummy_scope=*/nullptr, /*flags=*/fir::FortranVariableFlagsAttr{}); hlfir::Entity castWithLbounds = mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation()); @@ -1536,8 +1535,8 @@ std::pair<hlfir::Entity, bool> hlfir::computeEvaluateOpInNewTemp( extents, typeParams); mlir::Value innerMemory = evalInMem.getMemory(); temp = builder.createConvert(loc, innerMemory.getType(), temp); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, temp, tmpName, shape, typeParams, + auto declareOp = hlfir::DeclareOp::create( + builder, loc, temp, tmpName, shape, typeParams, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); computeEvaluateOpIn(loc, builder, evalInMem, declareOp.getOriginalBase()); return {hlfir::Entity{declareOp.getBase()}, /*heapAllocated=*/heapAllocated}; @@ -1601,7 +1600,7 @@ hlfir::Entity hlfir::gen1DSection(mlir::Location loc, } } mlir::Value sectionShape = - builder.create<fir::ShapeOp>(loc, extents[dim - 1]); + fir::ShapeOp::create(builder, loc, extents[dim - 1]); // The result type is one of: // !fir.box/class<!fir.array<NxT>> @@ -1617,9 +1616,9 @@ hlfir::Entity hlfir::gen1DSection(mlir::Location loc, fir::SequenceType::get({dimExtent}, seqType.getEleTy()); sectionType = fir::wrapInClassOrBoxType(sectionType, array.isPolymorphic()); - auto designate = builder.create<hlfir::DesignateOp>( - loc, sectionType, array, /*component=*/"", /*componentShape=*/nullptr, - subscripts, + auto designate = hlfir::DesignateOp::create( + builder, loc, sectionType, array, /*component=*/"", + /*componentShape=*/nullptr, subscripts, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, sectionShape, typeParams); return hlfir::Entity{designate.getResult()}; diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index d77a656..ba29829 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -901,6 +901,7 @@ static constexpr IntrinsicHandler handlers[]{ {{{"number", asValue}, {"handler", asAddr}, {"status", asAddr}}}, /*isElemental=*/false}, {"sind", &I::genSind}, + {"sinpi", &I::genSinpi}, {"size", &I::genSize, {{{"array", asBox}, @@ -941,6 +942,7 @@ static constexpr IntrinsicHandler handlers[]{ {{{"count", asAddr}, {"count_rate", asAddr}, {"count_max", asAddr}}}, /*isElemental=*/false}, {"tand", &I::genTand}, + {"tanpi", &I::genTanpi}, {"this_grid", &I::genThisGrid, {}, /*isElemental=*/false}, {"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false}, {"this_warp", &I::genThisWarp, {}, /*isElemental=*/false}, @@ -1110,7 +1112,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, // was just created from user functions with the same name. funcOp->setAttr(fir::FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr()); - auto libCall = builder.create<fir::CallOp>(loc, funcOp, args); + auto libCall = fir::CallOp::create(builder, loc, funcOp, args); // TODO: ensure 'strictfp' setting on the call for "precise/strict" // FP mode. Set appropriate Fast-Math Flags otherwise. // TODO: we should also mark as many libm function as possible @@ -1124,7 +1126,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type soughtFuncType = funcOp.getFunctionType(); if (soughtFuncType == libFuncType) { - libCall = builder.create<fir::CallOp>(loc, funcOp, args); + libCall = fir::CallOp::create(builder, loc, funcOp, args); } else { // A function with the same name might have been declared // before (e.g. with an explicit interface and a binding label). @@ -1138,13 +1140,13 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::Twine("' may lead to undefined behavior."))); mlir::SymbolRefAttr funcSymbolAttr = builder.getSymbolRefAttr(libFuncName); mlir::Value funcPointer = - builder.create<fir::AddrOfOp>(loc, soughtFuncType, funcSymbolAttr); + fir::AddrOfOp::create(builder, loc, soughtFuncType, funcSymbolAttr); funcPointer = builder.createConvert(loc, libFuncType, funcPointer); llvm::SmallVector<mlir::Value, 3> operands{funcPointer}; operands.append(args.begin(), args.end()); - libCall = builder.create<fir::CallOp>(loc, mlir::SymbolRefAttr{}, - libFuncType.getResults(), operands); + libCall = fir::CallOp::create(builder, loc, mlir::SymbolRefAttr{}, + libFuncType.getResults(), operands); } LLVM_DEBUG(libCall.dump(); llvm::dbgs() << "\n"); @@ -1220,7 +1222,7 @@ mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc, LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); } LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n"); return result; @@ -1258,12 +1260,12 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc, // the argument types for an operation if constexpr (T::template hasTrait< mlir::OpTrait::SameOperandsAndResultType>()) { - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } else { auto complexTy = mlir::cast<mlir::ComplexType>(mathLibFuncType.getInput(0)); auto realTy = complexTy.getElementType(); - result = builder.create<T>(loc, realTy, args); + result = T::create(builder, loc, realTy, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } @@ -2461,7 +2463,7 @@ IntrinsicLibrary::outlineInWrapper(GeneratorType generator, nameOS << '.' << fmfString; } mlir::func::FuncOp wrapper = getWrapper(generator, funcName, funcType); - return builder.create<fir::CallOp>(loc, wrapper, args).getResult(0); + return fir::CallOp::create(builder, loc, wrapper, args).getResult(0); } template <typename GeneratorType> @@ -2477,7 +2479,7 @@ fir::ExtendedValue IntrinsicLibrary::outlineInExtendedWrapper( mlirArgs.emplace_back(toValue(extendedVal, builder, loc)); mlir::FunctionType funcType = getFunctionType(resultType, mlirArgs, builder); mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); - auto call = builder.create<fir::CallOp>(loc, wrapper, mlirArgs); + auto call = fir::CallOp::create(builder, loc, wrapper, mlirArgs); if (resultType) return toExtendedValue(call.getResult(0), builder, loc); // Subroutine calls @@ -2595,9 +2597,9 @@ IntrinsicLibrary::readAndAddCleanUp(fir::MutableBoxValue resultMutableBox, return box; }, [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { - auto load = builder.create<fir::LoadOp>(loc, resultType, tempAddr); + auto load = fir::LoadOp::create(builder, loc, resultType, tempAddr); // Temp can be freed right away since it was loaded. - builder.create<fir::FreeMemOp>(loc, tempAddr); + fir::FreeMemOp::create(builder, loc, tempAddr); return load; }, [&](const fir::CharBoxValue &box) -> fir::ExtendedValue { @@ -2650,9 +2652,9 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, // So, implement abs here without branching. mlir::Value shift = builder.createIntegerConstant(loc, intType, intType.getWidth() - 1); - auto mask = builder.create<mlir::arith::ShRSIOp>(loc, arg, shift); - auto xored = builder.create<mlir::arith::XOrIOp>(loc, arg, mask); - return builder.create<mlir::arith::SubIOp>(loc, xored, mask); + auto mask = mlir::arith::ShRSIOp::create(builder, loc, arg, shift); + auto xored = mlir::arith::XOrIOp::create(builder, loc, arg, mask); + return mlir::arith::SubIOp::create(builder, loc, xored, mask); } llvm_unreachable("unexpected type in ABS argument"); } @@ -2671,7 +2673,7 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ADJUSTL & ADJUSTR @@ -2824,7 +2826,7 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ATAND, ATAN2D @@ -2838,8 +2840,8 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, // atand = atan * 180/pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2849,7 +2851,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } // ATANPI, ATAN2PI @@ -2863,8 +2865,8 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, // atanpi = atan / pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2874,7 +2876,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, @@ -2882,8 +2884,8 @@ static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, mlir::Value arg1) { auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); arg0 = builder.createConvert(loc, llvmPointerType, arg0); - return builder.create<mlir::LLVM::AtomicRMWOp>( - loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); + return mlir::LLVM::AtomicRMWOp::create(builder, loc, binOp, arg0, arg1, + mlir::LLVM::AtomicOrdering::seq_cst); } mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, @@ -2941,11 +2943,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, auto bitCastFloat = [&](mlir::Value arg) -> mlir::Value { if (mlir::isa<mlir::Float32Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI32Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI32Type(), + arg); if (mlir::isa<mlir::Float64Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI64Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI64Type(), + arg); return arg; }; @@ -2958,11 +2960,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, } auto address = - builder.create<mlir::UnrealizedConversionCastOp>(loc, llvmPtrTy, arg0) + mlir::UnrealizedConversionCastOp::create(builder, loc, llvmPtrTy, arg0) .getResult(0); - auto cmpxchg = builder.create<mlir::LLVM::AtomicCmpXchgOp>( - loc, address, arg1, arg2, successOrdering, failureOrdering); - return builder.create<mlir::LLVM::ExtractValueOp>(loc, cmpxchg, 1); + auto cmpxchg = mlir::LLVM::AtomicCmpXchgOp::create( + builder, loc, address, arg1, arg2, successOrdering, failureOrdering); + return mlir::LLVM::ExtractValueOp::create(builder, loc, cmpxchg, 1); } mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, @@ -3038,31 +3040,31 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::isa<fir::BoxProcType>(ptrTy))) { mlir::Value pointerBoxProc = fir::isBoxProcAddressType(ptrTy) - ? builder.create<fir::LoadOp>(loc, fir::getBase(args[0])) + ? fir::LoadOp::create(builder, loc, fir::getBase(args[0])) : fir::getBase(args[0]); mlir::Value pointerTarget = - builder.create<fir::BoxAddrOp>(loc, pointerBoxProc); + fir::BoxAddrOp::create(builder, loc, pointerBoxProc); if (isStaticallyAbsent(args[1])) return builder.genIsNotNullAddr(loc, pointerTarget); mlir::Value target = fir::getBase(args[1]); if (fir::isBoxProcAddressType(target.getType())) - target = builder.create<fir::LoadOp>(loc, target); + target = fir::LoadOp::create(builder, loc, target); if (mlir::isa<fir::BoxProcType>(target.getType())) - target = builder.create<fir::BoxAddrOp>(loc, target); + target = fir::BoxAddrOp::create(builder, loc, target); mlir::Type intPtrTy = builder.getIntPtrType(); mlir::Value pointerInt = builder.createConvert(loc, intPtrTy, pointerTarget); mlir::Value targetInt = builder.createConvert(loc, intPtrTy, target); - mlir::Value sameTarget = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); + mlir::Value sameTarget = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); mlir::Value zero = builder.createIntegerConstant(loc, intPtrTy, 0); - mlir::Value notNull = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); + mlir::Value notNull = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); // The not notNull test covers the following two cases: // - TARGET is a procedure that is OPTIONAL and absent at runtime. // - TARGET is a procedure pointer that is NULL. // In both cases, ASSOCIATED should be false if POINTER is NULL. - return builder.create<mlir::arith::AndIOp>(loc, sameTarget, notNull); + return mlir::arith::AndIOp::create(builder, loc, sameTarget, notNull); } auto *pointer = args[0].match([&](const fir::MutableBoxValue &x) { return &x; }, @@ -3075,7 +3077,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::Value targetBox = builder.createBox(loc, target); mlir::Value pointerBoxRef = fir::factory::getMutableIRBox(builder, loc, *pointer); - auto pointerBox = builder.create<fir::LoadOp>(loc, pointerBoxRef); + auto pointerBox = fir::LoadOp::create(builder, loc, pointerBoxRef); return fir::runtime::genAssociated(builder, loc, pointerBox, targetBox); } @@ -3106,12 +3108,12 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselJnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3123,7 +3125,7 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_JN(n2) and BESSEL_JN(n2 - 1) since they // are the anchors of the recursion. - mlir::Value n2_1 = builder.create<mlir::arith::SubIOp>(loc, n2, one); + mlir::Value n2_1 = mlir::arith::SubIOp::create(builder, loc, n2, one); mlir::Value bn2 = genRuntimeCall("bessel_jn", resultType, {n2, x}); mlir::Value bn2_1 = genRuntimeCall("bessel_jn", resultType, {n2_1, x}); fir::runtime::genBesselJn(builder, loc, resultBox, n1, n2, x, bn2, bn2_1); @@ -3191,12 +3193,12 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselYnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3208,7 +3210,7 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_YN(n1) and BESSEL_YN(n1 + 1) since they // are the anchors of the recursion. - mlir::Value n1_1 = builder.create<mlir::arith::AddIOp>(loc, n1, one); + mlir::Value n1_1 = mlir::arith::AddIOp::create(builder, loc, n1, one); mlir::Value bn1 = genRuntimeCall("bessel_yn", resultType, {n1, x}); mlir::Value bn1_1 = genRuntimeCall("bessel_yn", resultType, {n1_1, x}); fir::runtime::genBesselYn(builder, loc, resultBox, n1, n2, x, bn1, bn1_1); @@ -3280,12 +3282,12 @@ IntrinsicLibrary::genBitwiseCompare(mlir::Type resultType, if (arg0Ty.isUnsignedInteger()) arg0 = builder.createConvert(loc, signlessType, arg0); else if (bits0 < widest) - arg0 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg0); + arg0 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg0); if (arg1Ty.isUnsignedInteger()) arg1 = builder.createConvert(loc, signlessType, arg1); else if (bits1 < widest) - arg1 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg1); - return builder.create<mlir::arith::CmpIOp>(loc, pred, arg0, arg1); + arg1 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg1); + return mlir::arith::CmpIOp::create(builder, loc, pred, arg0, arg1); } // BTEST @@ -3304,9 +3306,9 @@ mlir::Value IntrinsicLibrary::genBtest(mlir::Type resultType, word = builder.createConvert(loc, signlessType, word); mlir::Value shiftCount = builder.createConvert(loc, signlessType, args[1]); mlir::Value shifted = - builder.create<mlir::arith::ShRUIOp>(loc, word, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, word, shiftCount); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); - mlir::Value bit = builder.create<mlir::arith::AndIOp>(loc, shifted, one); + mlir::Value bit = mlir::arith::AndIOp::create(builder, loc, shifted, one); return builder.createConvert(loc, resultType, bit); } @@ -3317,11 +3319,11 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder, mlir::Value addr{nullptr}; if (isFunc) { auto funcTy = mlir::cast<fir::BoxProcType>(argValue.getType()).getEleTy(); - addr = builder.create<fir::BoxAddrOp>(loc, funcTy, argValue); + addr = fir::BoxAddrOp::create(builder, loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf<fir::BoxValue>(); - addr = builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), - fir::getBase(*box)); + addr = fir::BoxAddrOp::create(builder, loc, box->getMemTy(), + fir::getBase(*box)); } return addr; } @@ -3331,7 +3333,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args, bool isFunc = false, bool isDevLoc = false) { assert(args.size() == 1); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Value resAddr; if (isDevLoc) resAddr = fir::factory::genCDevPtrAddr(builder, loc, res, resultType); @@ -3342,7 +3344,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value argAddrVal = builder.createConvert( loc, fir::unwrapRefType(resAddr.getType()), argAddr); - builder.create<fir::StoreOp>(loc, argAddrVal, resAddr); + fir::StoreOp::create(builder, loc, argAddrVal, resAddr); return res; } @@ -3355,8 +3357,8 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtrVal1 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr1); mlir::Value zero = builder.createIntegerConstant(loc, cPtrVal1.getType(), 0); - mlir::Value res = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); + mlir::Value res = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); if (isStaticallyPresent(args[1])) { mlir::Type i1Ty = builder.getI1Type(); @@ -3365,15 +3367,16 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, res = builder .genIfOp(loc, {i1Ty}, isDynamicallyAbsent, /*withElseRegion=*/true) - .genThen([&]() { builder.create<fir::ResultOp>(loc, res); }) + .genThen([&]() { fir::ResultOp::create(builder, loc, res); }) .genElse([&]() { mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); - mlir::Value cmpVal = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, cPtrVal2); + mlir::Value cmpVal = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, + cPtrVal2); mlir::Value newRes = - builder.create<mlir::arith::AndIOp>(loc, res, cmpVal); - builder.create<fir::ResultOp>(loc, newRes); + mlir::arith::AndIOp::create(builder, loc, res, cmpVal); + fir::ResultOp::create(builder, loc, newRes); }) .getResults()[0]; } @@ -3428,9 +3431,9 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type idxType = builder.getIndexType(); for (int i = 0; i < arrayRank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxType, i); - mlir::Value var = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(shapeElementType), shape, index); - mlir::Value load = builder.create<fir::LoadOp>(loc, var); + mlir::Value var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(shapeElementType), shape, index); + mlir::Value load = fir::LoadOp::create(builder, loc, var); extents.push_back(builder.createConvert(loc, idxType, load)); } } @@ -3474,8 +3477,8 @@ void IntrinsicLibrary::genCFProcPointer( mlir::Value cptrCast = builder.createConvert(loc, boxProcType.getEleTy(), cptr); mlir::Value cptrBox = - builder.create<fir::EmboxProcOp>(loc, boxProcType, cptrCast); - builder.create<fir::StoreOp>(loc, cptrBox, fptr); + fir::EmboxProcOp::create(builder, loc, boxProcType, cptrCast); + fir::StoreOp::create(builder, loc, cptrBox, fptr); } // C_FUNLOC @@ -3505,7 +3508,7 @@ IntrinsicLibrary::genCPtrCompare(mlir::Type resultType, mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); mlir::Value cmp = - builder.create<mlir::arith::CmpIOp>(loc, pred, cPtrVal1, cPtrVal2); + mlir::arith::CmpIOp::create(builder, loc, pred, cPtrVal1, cPtrVal2); return builder.createConvert(loc, resultType, cmp); } @@ -3604,7 +3607,7 @@ mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType, mlir::Value cplx = args[0]; auto imag = fir::factory::Complex{builder, loc}.extractComplexPart( cplx, /*isImagPart=*/true); - auto negImag = builder.create<mlir::arith::NegFOp>(loc, imag); + auto negImag = mlir::arith::NegFOp::create(builder, loc, imag); return fir::factory::Complex{builder, loc}.insertComplexPart( cplx, negImag, /*isImagPart=*/true); } @@ -3620,7 +3623,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3635,7 +3638,7 @@ mlir::Value IntrinsicLibrary::genCospi(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<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3696,7 +3699,7 @@ void IntrinsicLibrary::genCpuTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value res1 = fir::runtime::genCpuTime(builder, loc); mlir::Value res2 = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg->getType()), res1); - builder.create<fir::StoreOp>(loc, res2, *arg); + fir::StoreOp::create(builder, loc, res2, *arg); } // CSHIFT @@ -3723,7 +3726,7 @@ IntrinsicLibrary::genCshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar CSHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genCshiftVector(builder, loc, resultIrBox, array, shift); } else { @@ -3749,9 +3752,9 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, assert(args.size() == 1); mlir::Type resTy = fir::SequenceType::get(extent, resultType); mlir::Value arg = fir::getBase(args[0]); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resTy); + mlir::Value res = fir::AllocaOp::create(builder, loc, resTy); if (mlir::isa<fir::BaseBoxType>(arg.getType())) - arg = builder.create<fir::BoxAddrOp>(loc, arg); + arg = fir::BoxAddrOp::create(builder, loc, arg); mlir::Type refResTy = fir::ReferenceType::get(resTy); mlir::FunctionType ftype = mlir::FunctionType::get(arg.getContext(), {refResTy, refResTy}, {}); @@ -3759,7 +3762,7 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, llvm::SmallVector<mlir::Value> funcArgs; funcArgs.push_back(res); funcArgs.push_back(arg); - builder.create<fir::CallOp>(loc, funcOp, funcArgs); + fir::CallOp::create(builder, loc, funcOp, funcArgs); mlir::Value ext = builder.createIntegerConstant(loc, builder.getIndexType(), extent); return fir::ArrayBoxValue(res, {ext}); @@ -3775,8 +3778,8 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value values = fir::getBase(args[3]); if (!values) - values = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())); + values = fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())); fir::runtime::genDateAndTime(builder, loc, charArgs[0], charArgs[1], charArgs[2], values); @@ -3788,17 +3791,17 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, assert(args.size() == 2); if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto diff = builder.create<mlir::arith::SubIOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubIOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } assert(fir::isa_real(resultType) && "Only expects real and integer in DIM"); mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - auto diff = builder.create<mlir::arith::SubFOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubFOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } // DOT_PRODUCT @@ -3816,12 +3819,13 @@ IntrinsicLibrary::genDotProduct(mlir::Type resultType, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } // This operation is only used to pass the result type // information to the DotProduct generator. - auto resultBox = builder.create<fir::AbsentOp>(loc, fir::BoxType::get(eleTy)); + auto resultBox = + fir::AbsentOp::create(builder, loc, fir::BoxType::get(eleTy)); return fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, resultBox); } @@ -3833,7 +3837,7 @@ mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType, "Result must be double precision in DPROD"); mlir::Value a = builder.createConvert(loc, resultType, args[0]); mlir::Value b = builder.createConvert(loc, resultType, args[1]); - return builder.create<mlir::arith::MulFOp>(loc, a, b); + return mlir::arith::MulFOp::create(builder, loc, a, b); } // DSHIFTL @@ -3856,14 +3860,14 @@ mlir::Value IntrinsicLibrary::genDshiftl(mlir::Type resultType, // Per the standard, the value of DSHIFTL(I, J, SHIFT) is equal to // IOR (SHIFTL(I, SHIFT), SHIFTR(J, BIT_SIZE(J) - SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, shift}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, diff}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3889,14 +3893,14 @@ mlir::Value IntrinsicLibrary::genDshiftr(mlir::Type resultType, // Per the standard, the value of DSHIFTR(I, J, SHIFT) is equal to // IOR (SHIFTL(I, BIT_SIZE(I) - SHIFT), SHIFTR(J, SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, diff}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, shift}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3924,8 +3928,8 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle optional BOUNDARY argument mlir::Value boundary = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())) : builder.createBox(loc, args[2]); if (arrayRank == 1) { @@ -3933,7 +3937,7 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar EOSHIFT SHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genEoshiftVector(builder, loc, resultIrBox, array, shift, boundary); } else { @@ -3981,14 +3985,15 @@ void IntrinsicLibrary::genExecuteCommandLine( .genIfOp(loc, {i1Ty}, waitIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto waitLoad = builder.create<fir::LoadOp>(loc, waitAddr); + auto waitLoad = + fir::LoadOp::create(builder, loc, waitAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, waitLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -3996,15 +4001,15 @@ void IntrinsicLibrary::genExecuteCommandLine( mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdstatBox = isStaticallyPresent(cmdstat) ? fir::getBase(cmdstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdmsgBox = isStaticallyPresent(cmdmsg) ? fir::getBase(cmdmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); } @@ -4025,7 +4030,7 @@ IntrinsicLibrary::genEtime(std::optional<mlir::Type> resultType, auto timeAddr = builder.createTemporary(loc, *resultType); auto timeBox = builder.createBox(loc, timeAddr); fir::runtime::genEtime(builder, loc, values, timeBox); - return builder.create<fir::LoadOp>(loc, timeAddr); + return fir::LoadOp::create(builder, loc, timeAddr); } else { // subroutine form mlir::Value time = fir::getBase(args[1]); @@ -4098,8 +4103,8 @@ IntrinsicLibrary::genFindloc(mlir::Type resultType, // Handle optional mask argument auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); // Handle optional kind argument @@ -4288,15 +4293,15 @@ void IntrinsicLibrary::genGetCommand(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value commandBox = isStaticallyPresent(command) ? fir::getBase(command) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommand(builder, loc, commandBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4355,15 +4360,15 @@ void IntrinsicLibrary::genGetCommandArgument( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommandArgument( builder, loc, number, valBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4408,13 +4413,14 @@ void IntrinsicLibrary::genGetEnvironmentVariable( .genIfOp(loc, {i1Ty}, trimNameIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto trimLoad = builder.create<fir::LoadOp>(loc, trimNameAddr); + auto trimLoad = + fir::LoadOp::create(builder, loc, trimNameAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, trimLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -4423,15 +4429,15 @@ void IntrinsicLibrary::genGetEnvironmentVariable( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetEnvVariable(builder, loc, name, valBox, lenBox, trim, errBox); if (isStaticallyPresent(status)) { @@ -4516,8 +4522,8 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -4531,10 +4537,10 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } - auto resultBox = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + auto resultBox = fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())); return func(builder, loc, array, mask, resultBox); } // Handle Product/Sum cases that have an array result. @@ -4581,8 +4587,8 @@ mlir::Value IntrinsicLibrary::genIbclr(mlir::Type resultType, mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value bit = builder.create<mlir::arith::ShLIOp>(loc, one, pos); - mlir::Value mask = builder.create<mlir::arith::XOrIOp>(loc, ones, bit); + mlir::Value bit = mlir::arith::ShLIOp::create(builder, loc, one, pos); + mlir::Value mask = mlir::arith::XOrIOp::create(builder, loc, ones, bit); return builder.createUnsigned<mlir::arith::AndIOp>(loc, resultType, args[0], mask); } @@ -4610,18 +4616,18 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(resultType).getWidth()); mlir::Value shiftCount = - builder.create<mlir::arith::SubIOp>(loc, bitSize, len); + mlir::arith::SubIOp::create(builder, loc, bitSize, len); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value mask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); mlir::Value res1 = builder.createUnsigned<mlir::arith::ShRSIOp>( loc, signlessType, word, pos); - mlir::Value res2 = builder.create<mlir::arith::AndIOp>(loc, res1, mask); - mlir::Value lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::Value res2 = mlir::arith::AndIOp::create(builder, loc, res1, mask); + mlir::Value lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, zero, res2); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, zero, res2); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -4640,7 +4646,7 @@ mlir::Value IntrinsicLibrary::genIbset(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>(loc, one, pos); + mlir::Value mask = mlir::arith::ShLIOp::create(builder, loc, one, pos); return builder.createUnsigned<mlir::arith::OrIOp>(loc, resultType, args[0], mask); } @@ -4674,13 +4680,13 @@ IntrinsicLibrary::genIchar(mlir::Type resultType, fir::CharacterType::get(builder.getContext(), eleType.getFKind(), 1); mlir::Type toTy = builder.getRefType(charType); mlir::Value cast = builder.createConvert(loc, toTy, buffer); - charVal = builder.create<fir::LoadOp>(loc, cast); + charVal = fir::LoadOp::create(builder, loc, cast); } LLVM_DEBUG(llvm::dbgs() << "ichar(" << charVal << ")\n"); auto code = helper.extractCodeFromSingleton(charVal); if (code.getType() == resultType) return code; - return builder.create<mlir::arith::ExtUIOp>(loc, resultType, code); + return mlir::arith::ExtUIOp::create(builder, loc, resultType, code); } // llvm floating point class intrinsic test values @@ -4710,7 +4716,7 @@ mlir::Value IntrinsicLibrary::genIsFPClass(mlir::Type resultType, assert(args.size() == 1); mlir::Type i1Ty = builder.getI1Type(); mlir::Value isfpclass = - builder.create<mlir::LLVM::IsFPClass>(loc, i1Ty, args[0], fpclass); + mlir::LLVM::IsFPClass::create(builder, loc, i1Ty, args[0], fpclass); return builder.createConvert(loc, resultType, isfpclass); } @@ -4725,7 +4731,7 @@ mlir::Value IntrinsicLibrary::genQNan(mlir::Type resultType) { void IntrinsicLibrary::genRaiseExcept(int excepts, mlir::Value cond) { fir::IfOp ifOp; if (cond) { - ifOp = builder.create<fir::IfOp>(loc, cond, /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, cond, /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } mlir::Type i32Ty = builder.getIntegerType(32); @@ -4746,11 +4752,11 @@ getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec, mlir::dyn_cast<fir::RecordType>(fir::unwrapPassByRefType(rec.getType())); assert(index < recType.getTypeList().size() && "not enough components"); auto [fieldName, fieldTy] = recType.getTypeList()[index]; - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(recType.getContext()), fieldName, recType, - fir::getTypeParams(rec)); - return {builder.create<fir::CoordinateOp>(loc, builder.getRefType(fieldTy), - rec, field), + mlir::Value field = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(recType.getContext()), fieldName, + recType, fir::getTypeParams(rec)); + return {fir::CoordinateOp::create(builder, loc, builder.getRefType(fieldTy), + rec, field), fieldTy}; } @@ -4763,9 +4769,9 @@ IntrinsicLibrary::genIeeeTypeCompare(mlir::Type resultType, assert(args.size() == 2); auto [leftRef, fieldTy] = getFieldRef(builder, loc, args[0]); auto [rightRef, ignore] = getFieldRef(builder, loc, args[1]); - mlir::Value left = builder.create<fir::LoadOp>(loc, fieldTy, leftRef); - mlir::Value right = builder.create<fir::LoadOp>(loc, fieldTy, rightRef); - return builder.create<mlir::arith::CmpIOp>(loc, pred, left, right); + mlir::Value left = fir::LoadOp::create(builder, loc, fieldTy, leftRef); + mlir::Value right = fir::LoadOp::create(builder, loc, fieldTy, rightRef); + return mlir::arith::CmpIOp::create(builder, loc, pred, left, right); } // IEEE_CLASS @@ -4796,7 +4802,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, const unsigned intWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(intWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); llvm::StringRef tableName = RTNAME_STRING(IeeeClassTable); uint64_t highSignificandSize = (realType.getWidth() == 80) + 1; @@ -4806,8 +4812,8 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, return builder.createIntegerConstant(loc, intType, k); }; auto createIntegerConstantAPI = [&](const llvm::APInt &apInt) { - return builder.create<mlir::arith::ConstantOp>( - loc, intType, builder.getIntegerAttr(intType, apInt)); + return mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr(intType, apInt)); }; auto getMasksAndShifts = [&](uint64_t totalSize, uint64_t exponentSize, uint64_t significandSize, @@ -4854,50 +4860,52 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, // [s] sign bit int pos = 3 + highSignificandSize; - mlir::Value index = builder.create<mlir::arith::AndIOp>( - loc, builder.create<mlir::arith::ShRUIOp>(loc, intVal, signShift), + mlir::Value index = mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, signShift), createIntegerConstant(1ULL << pos)); // [e] exponent != 0 mlir::Value exponent = - builder.create<mlir::arith::AndIOp>(loc, intVal, exponentMask); + mlir::arith::AndIOp::create(builder, loc, intVal, exponentMask); mlir::Value zero = createIntegerConstant(0); - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, exponent, zero), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, exponent, zero), createIntegerConstant(1ULL << --pos), zero)); // [m] exponent == 1..1 (max exponent) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, exponent, exponentMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, exponent, + exponentMask), createIntegerConstant(1ULL << --pos), zero)); // [l] low-order significand != 0 - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, intVal, - lowSignificandMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, intVal, + lowSignificandMask), zero), createIntegerConstant(1ULL << --pos), zero)); // [h] high-order significand (1 or 2 bits) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::AndIOp>( - loc, - builder.create<mlir::arith::ShRUIOp>(loc, intVal, - highSignificandShift), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, + highSignificandShift), createIntegerConstant((1 << highSignificandSize) - 1))); int tableSize = 1 << (4 + highSignificandSize); @@ -5025,10 +5033,10 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, mlir::RankedTensorType::get(tableSize, int8Ty), values)); } - return builder.create<fir::CoordinateOp>( - loc, builder.getRefType(resultType), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(resultType), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), index); } @@ -5055,34 +5063,36 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType, // Args have the same type. if (xRealType == yRealType) - return builder.create<mlir::math::CopySignOp>(loc, xRealVal, yRealVal); + return mlir::math::CopySignOp::create(builder, loc, xRealVal, yRealVal); // Args have different types. mlir::Type xIntType = builder.getIntegerType(xRealType.getWidth()); mlir::Type yIntType = builder.getIntegerType(yRealType.getWidth()); mlir::Value xIntVal = - builder.create<mlir::arith::BitcastOp>(loc, xIntType, xRealVal); + mlir::arith::BitcastOp::create(builder, loc, xIntType, xRealVal); mlir::Value yIntVal = - builder.create<mlir::arith::BitcastOp>(loc, yIntType, yRealVal); + mlir::arith::BitcastOp::create(builder, loc, yIntType, yRealVal); mlir::Value xZero = builder.createIntegerConstant(loc, xIntType, 0); mlir::Value yZero = builder.createIntegerConstant(loc, yIntType, 0); mlir::Value xOne = builder.createIntegerConstant(loc, xIntType, 1); - mlir::Value ySign = builder.create<mlir::arith::ShRUIOp>( - loc, yIntVal, + mlir::Value ySign = mlir::arith::ShRUIOp::create( + builder, loc, yIntVal, builder.createIntegerConstant(loc, yIntType, yRealType.getWidth() - 1)); - mlir::Value xAbs = builder.create<mlir::arith::ShRUIOp>( - loc, builder.create<mlir::arith::ShLIOp>(loc, xIntVal, xOne), xOne); - mlir::Value xSign = builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::eq, - ySign, yZero), + mlir::Value xAbs = mlir::arith::ShRUIOp::create( + builder, loc, mlir::arith::ShLIOp::create(builder, loc, xIntVal, xOne), + xOne); + mlir::Value xSign = mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::eq, + ySign, yZero), xZero, - builder.create<mlir::arith::ShLIOp>( - loc, xOne, + mlir::arith::ShLIOp::create( + builder, loc, xOne, builder.createIntegerConstant(loc, xIntType, xRealType.getWidth() - 1))); - return builder.create<mlir::arith::BitcastOp>( - loc, xRealType, builder.create<mlir::arith::OrIOp>(loc, xAbs, xSign)); + return mlir::arith::BitcastOp::create( + builder, loc, xRealType, + mlir::arith::OrIOp::create(builder, loc, xAbs, xSign)); } // IEEE_GET_FLAG @@ -5096,16 +5106,16 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value excepts = fir::runtime::genFetestexcept( builder, loc, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - excepts, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, flagValue); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + excepts, zero)); + fir::StoreOp::create(builder, loc, logicalResult, flagValue); } // IEEE_GET_HALTING_MODE @@ -5120,17 +5130,17 @@ void IntrinsicLibrary::genIeeeGetHaltingMode( mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value haltSet = fir::runtime::genFegetexcept(builder, loc); - mlir::Value intResult = builder.create<mlir::arith::AndIOp>( - loc, haltSet, + mlir::Value intResult = mlir::arith::AndIOp::create( + builder, loc, haltSet, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - intResult, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, halting); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + intResult, zero)); + fir::StoreOp::create(builder, loc, logicalResult, halting); } // IEEE_GET_MODES, IEEE_SET_MODES @@ -5155,34 +5165,34 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // allotment. Allocate data space from the heap. auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]), 1); - addr = builder.create<fir::BoxAddrOp>( - loc, builder.create<fir::LoadOp>(loc, fieldRef)); + addr = fir::BoxAddrOp::create(builder, loc, + fir::LoadOp::create(builder, loc, fieldRef)); mlir::Type heapTy = addr.getType(); - mlir::Value allocated = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, + mlir::Value allocated = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, builder.createConvert(loc, i64Ty, addr), builder.createIntegerConstant(loc, i64Ty, 0)); - auto ifOp = builder.create<fir::IfOp>(loc, heapTy, allocated, - /*withElseRegion=*/true); + auto ifOp = fir::IfOp::create(builder, loc, heapTy, allocated, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, addr); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value byteSize = isModes ? fir::runtime::genGetModesTypeSize(builder, loc) : fir::runtime::genGetStatusTypeSize(builder, loc); byteSize = builder.createConvert(loc, builder.getIndexType(), byteSize); - addr = builder.create<fir::AllocMemOp>(loc, extractSequenceType(heapTy), - /*typeparams=*/mlir::ValueRange(), - byteSize); - mlir::Value shape = builder.create<fir::ShapeOp>(loc, byteSize); - builder.create<fir::StoreOp>( - loc, builder.create<fir::EmboxOp>(loc, fieldTy, addr, shape), fieldRef); - builder.create<fir::ResultOp>(loc, addr); + addr = fir::AllocMemOp::create(builder, loc, extractSequenceType(heapTy), + /*typeparams=*/mlir::ValueRange(), byteSize); + mlir::Value shape = fir::ShapeOp::create(builder, loc, byteSize); + fir::StoreOp::create( + builder, loc, fir::EmboxOp::create(builder, loc, fieldTy, addr, shape), + fieldRef); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointAfter(ifOp); - addr = builder.create<fir::ConvertOp>(loc, ptrTy, ifOp.getResult(0)); + addr = fir::ConvertOp::create(builder, loc, ptrTy, ifOp.getResult(0)); } else { // Place floating point environment data in __data storage. - addr = builder.create<fir::ConvertOp>(loc, ptrTy, getBase(args[0])); + addr = fir::ConvertOp::create(builder, loc, ptrTy, getBase(args[0])); } llvm::StringRef func = isModes ? (isGet ? "fegetmode" : "fesetmode") : (isGet ? "fegetenv" : "fesetenv"); @@ -5193,11 +5203,11 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // Check that an explicit ieee_[get|set]_rounding_mode call radix value is 2. static void checkRadix(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value radix, std::string procName) { - mlir::Value notTwo = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, radix, + mlir::Value notTwo = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, radix, builder.createIntegerConstant(loc, radix.getType(), 2)); - auto ifOp = builder.create<fir::IfOp>(loc, notTwo, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, notTwo, + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError(builder, loc, procName + " radix argument must be 2"); @@ -5215,9 +5225,9 @@ void IntrinsicLibrary::genIeeeGetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_get_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mode = builder.createConvert(loc, fieldTy, mode); - builder.create<fir::StoreOp>(loc, mode, fieldRef); + fir::StoreOp::create(builder, loc, mode, fieldRef); } // IEEE_GET_UNDERFLOW_MODE @@ -5242,44 +5252,45 @@ mlir::Value IntrinsicLibrary::genIeeeInt(mlir::Type resultType, mlir::FloatType realType = mlir::cast<mlir::FloatType>(args[0].getType()); mlir::Value realResult = genIeeeRint(realType, {args[0], args[1]}); int intWidth = mlir::cast<mlir::IntegerType>(resultType).getWidth(); - mlir::Value intLBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intLBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/intWidth - 1, /*hi=*/intWidth))); - mlir::Value intUBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intUBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/0, /*hi=*/intWidth - 1))); mlir::Value realLBound = - builder.create<fir::ConvertOp>(loc, realType, intLBound); - mlir::Value realUBound = builder.create<mlir::arith::NegFOp>(loc, realLBound); - mlir::Value aGreaterThanLBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); - mlir::Value aLessThanUBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); - mlir::Value resultIsValid = builder.create<mlir::arith::AndIOp>( - loc, aGreaterThanLBound, aLessThanUBound); + fir::ConvertOp::create(builder, loc, realType, intLBound); + mlir::Value realUBound = + mlir::arith::NegFOp::create(builder, loc, realLBound); + mlir::Value aGreaterThanLBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); + mlir::Value aLessThanUBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); + mlir::Value resultIsValid = mlir::arith::AndIOp::create( + builder, loc, aGreaterThanLBound, aLessThanUBound); // Result is valid. It may be exact or inexact. mlir::Value result; - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, resultIsValid, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, resultIsValid, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); - result = builder.create<fir::ConvertOp>(loc, resultType, realResult); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, realResult); + fir::ResultOp::create(builder, loc, result); // Result is invalid. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - result = builder.create<mlir::arith::SelectOp>(loc, aGreaterThanLBound, - intUBound, intLBound); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, aGreaterThanLBound, + intUBound, intLBound); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); } @@ -5334,7 +5345,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(realType.getWidth()); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Type i1Ty = builder.getI1Type(); int exponentBias, significandSize, nonSignificandSize; @@ -5381,72 +5392,72 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, llvm_unreachable("unknown real type"); } - mlir::Value isZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, realVal, + mlir::Value isZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, realVal, builder.createRealZeroConstant(loc, resultType)); - auto outerIfOp = builder.create<fir::IfOp>(loc, resultType, isZero, - /*withElseRegion=*/true); + auto outerIfOp = fir::IfOp::create(builder, loc, resultType, isZero, + /*withElseRegion=*/true); // X is zero -- result is -infinity builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO); mlir::Value ones = builder.createAllOnesInteger(loc, intType); - mlir::Value result = builder.create<mlir::arith::ShLIOp>( - loc, ones, + mlir::Value result = mlir::arith::ShLIOp::create( + builder, loc, ones, builder.createIntegerConstant(loc, intType, // kind=10 high-order bit is explicit significandSize - (bitWidth == 80))); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); mlir::Value one = builder.createIntegerConstant(loc, intType, 1); mlir::Value shiftLeftOne = - builder.create<mlir::arith::ShLIOp>(loc, intVal, one); + mlir::arith::ShLIOp::create(builder, loc, intVal, one); mlir::Value isFinite = genIsFPClass(i1Ty, args, finiteTest); - auto innerIfOp = builder.create<fir::IfOp>(loc, resultType, isFinite, - /*withElseRegion=*/true); + auto innerIfOp = fir::IfOp::create(builder, loc, resultType, isFinite, + /*withElseRegion=*/true); // X is non-zero finite -- result is unbiased exponent of X builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value isNormal = genIsFPClass(i1Ty, args, normalTest); - auto normalIfOp = builder.create<fir::IfOp>(loc, resultType, isNormal, - /*withElseRegion=*/true); + auto normalIfOp = fir::IfOp::create(builder, loc, resultType, isNormal, + /*withElseRegion=*/true); // X is normal builder.setInsertionPointToStart(&normalIfOp.getThenRegion().front()); - mlir::Value biasedExponent = builder.create<mlir::arith::ShRUIOp>( - loc, shiftLeftOne, + mlir::Value biasedExponent = mlir::arith::ShRUIOp::create( + builder, loc, shiftLeftOne, builder.createIntegerConstant(loc, intType, significandSize + 1)); - result = builder.create<mlir::arith::SubIOp>( - loc, biasedExponent, + result = mlir::arith::SubIOp::create( + builder, loc, biasedExponent, builder.createIntegerConstant(loc, intType, exponentBias)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // X is denormal -- result is (-exponentBias - ctlz(significand)) builder.setInsertionPointToStart(&normalIfOp.getElseRegion().front()); - mlir::Value significand = builder.create<mlir::arith::ShLIOp>( - loc, intVal, + mlir::Value significand = mlir::arith::ShLIOp::create( + builder, loc, intVal, builder.createIntegerConstant(loc, intType, nonSignificandSize)); mlir::Value ctlz = - builder.create<mlir::math::CountLeadingZerosOp>(loc, significand); + mlir::math::CountLeadingZerosOp::create(builder, loc, significand); mlir::Type i32Ty = builder.getI32Type(); - result = builder.create<mlir::arith::SubIOp>( - loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), - builder.create<fir::ConvertOp>(loc, i32Ty, ctlz)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SubIOp::create( + builder, loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), + fir::ConvertOp::create(builder, loc, i32Ty, ctlz)); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToEnd(&innerIfOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, normalIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, normalIfOp.getResult(0)); // X is infinity or NaN -- result is +infinity or NaN builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - result = builder.create<mlir::arith::ShRUIOp>(loc, shiftLeftOne, one); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::ShRUIOp::create(builder, loc, shiftLeftOne, one); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointToEnd(&outerIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -5480,8 +5491,8 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, mlir::Value x1, y1; // X or ABS(X), Y or ABS(Y) if constexpr (isMag) { mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - x1 = builder.create<mlir::math::CopySignOp>(loc, x, zero); - y1 = builder.create<mlir::math::CopySignOp>(loc, y, zero); + x1 = mlir::math::CopySignOp::create(builder, loc, x, zero); + y1 = mlir::math::CopySignOp::create(builder, loc, y, zero); } else { x1 = x; y1 = y; @@ -5492,56 +5503,56 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, // X1 < Y1 -- MAX result is Y; MIN result is X. pred = mlir::arith::CmpFPredicate::OLT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp1 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp1 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); result = isMax ? y : x; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 > Y1 -- MAX result is X; MIN result is Y. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OGT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp2 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp2 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); result = isMax ? x : y; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 == Y1 -- MAX favors a positive result; MIN favors a negative result. builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OEQ; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp3 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp3 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp3.getThenRegion().front()); resultIsX = isMax ? genIsFPClass(i1Ty, x, positiveTest) : genIsFPClass(i1Ty, x, negativeTest); - result = builder.create<mlir::arith::SelectOp>(loc, resultIsX, x, y); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, resultIsX, x, y); + fir::ResultOp::create(builder, loc, result); // X or Y or both are NaNs -- result may be X, Y, or a qNaN builder.setInsertionPointToStart(&ifOp3.getElseRegion().front()); if constexpr (isNum) { pred = mlir::arith::CmpFPredicate::ORD; // check for a non-NaN - resultIsX = builder.create<mlir::arith::CmpFOp>(loc, pred, x, x); - resultIsY = builder.create<mlir::arith::CmpFOp>(loc, pred, y, y); + resultIsX = mlir::arith::CmpFOp::create(builder, loc, pred, x, x); + resultIsY = mlir::arith::CmpFOp::create(builder, loc, pred, y, y); } else { resultIsX = resultIsY = builder.createBool(loc, false); } - result = builder.create<mlir::arith::SelectOp>( - loc, resultIsX, x, - builder.create<mlir::arith::SelectOp>(loc, resultIsY, y, - genQNan(resultType))); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + result = mlir::arith::SelectOp::create( + builder, loc, resultIsX, x, + mlir::arith::SelectOp::create(builder, loc, resultIsY, y, + genQNan(resultType))); + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointAfter(ifOp3); - builder.create<fir::ResultOp>(loc, ifOp3.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp3.getResult(0)); builder.setInsertionPointAfter(ifOp2); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5554,13 +5565,13 @@ IntrinsicLibrary::genIeeeQuietCompare(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { // Compare X and Y with special case treatment of NaN operands. assert(args.size() == 2); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_REAL @@ -5612,14 +5623,14 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, // If the argument is an sNaN, raise an invalid exception and return a qNaN. // Otherwise return the argument. auto processSnan = [&](mlir::Value x) { - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, - genIsFPClass(i1Ty, x, snanTest), - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, + genIsFPClass(i1Ty, x, snanTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - builder.create<fir::ResultOp>(loc, genQNan(resultType)); + fir::ResultOp::create(builder, loc, genQNan(resultType)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); }; @@ -5635,7 +5646,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, a = builder.createConvert(loc, f32Ty, a); aType = f32Ty; } - r = builder.create<fir::ConvertOp>(loc, resultType, a); + r = fir::ConvertOp::create(builder, loc, resultType, a); mlir::IntegerType aIntType = mlir::dyn_cast<mlir::IntegerType>(aType); mlir::FloatType aFloatType = mlir::dyn_cast<mlir::FloatType>(aType); @@ -5647,142 +5658,144 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, return aIntType ? r : processSnan(r); // A possibly inexact conversion result may need to be rounded up or down. - mlir::Value b = builder.create<fir::ConvertOp>(loc, aType, r); + mlir::Value b = fir::ConvertOp::create(builder, loc, aType, r); mlir::Value aEqB; if (aIntType) - aEqB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, a, b); + aEqB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, a, b); else - aEqB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, a, b); + aEqB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::UEQ, a, b); // [a == b] a is a NaN or r is exact (a may be -0, +0, -inf, +inf) -- return r - fir::IfOp ifOp1 = builder.create<fir::IfOp>(loc, resultType, aEqB, - /*withElseRegion=*/true); + fir::IfOp ifOp1 = fir::IfOp::create(builder, loc, resultType, aEqB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, aIntType ? r : processSnan(r)); + fir::ResultOp::create(builder, loc, aIntType ? r : processSnan(r)); // Code common to (a < b) and (a > b) branches. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mlir::Value aIsNegative, aIsPositive; if (aIntType) { mlir::Value zero = builder.createIntegerConstant(loc, aIntType, 0); - aIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, zero); - aIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, a, zero); + aIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, a, zero); + aIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, a, zero); } else { mlir::Value zero = builder.createRealZeroConstant(loc, aFloatType); - aIsNegative = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, zero); - aIsPositive = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, a, zero); + aIsNegative = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, a, zero); + aIsPositive = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, a, zero); } mlir::Type resultIntType = builder.getIntegerType(resultFloatType.getWidth()); mlir::Value resultCast = - builder.create<mlir::arith::BitcastOp>(loc, resultIntType, r); + mlir::arith::BitcastOp::create(builder, loc, resultIntType, r); mlir::Value one = builder.createIntegerConstant(loc, resultIntType, 1); - mlir::Value rIsOdd = builder.create<fir::ConvertOp>( - loc, i1Ty, builder.create<mlir::arith::AndIOp>(loc, resultCast, one)); + mlir::Value rIsOdd = fir::ConvertOp::create( + builder, loc, i1Ty, + mlir::arith::AndIOp::create(builder, loc, resultCast, one)); // Check for a rounding mode match. auto match = [&](int m) { - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, mode, + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, mode, builder.createIntegerConstant(loc, mode.getType(), m)); }; - mlir::Value roundToNearestBit = builder.create<mlir::arith::OrIOp>( - loc, + mlir::Value roundToNearestBit = mlir::arith::OrIOp::create( + builder, loc, // IEEE_OTHER is an alias for IEEE_NEAREST. match(_FORTRAN_RUNTIME_IEEE_NEAREST), match(_FORTRAN_RUNTIME_IEEE_OTHER)); mlir::Value roundToNearest = - builder.create<mlir::arith::AndIOp>(loc, roundToNearestBit, rIsOdd); + mlir::arith::AndIOp::create(builder, loc, roundToNearestBit, rIsOdd); mlir::Value roundToZeroBit = match(_FORTRAN_RUNTIME_IEEE_TO_ZERO); mlir::Value roundAwayBit = match(_FORTRAN_RUNTIME_IEEE_AWAY); mlir::Value roundToZero, roundAway, mustAdjust; fir::IfOp adjustIfOp; mlir::Value aLtB; if (aIntType) - aLtB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, b); + aLtB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); else - aLtB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, b); + aLtB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OLT, a, b); mlir::Value upResult = - builder.create<mlir::arith::AddIOp>(loc, resultCast, one); + mlir::arith::AddIOp::create(builder, loc, resultCast, one); mlir::Value downResult = - builder.create<mlir::arith::SubIOp>(loc, resultCast, one); + mlir::arith::SubIOp::create(builder, loc, resultCast, one); // (a < b): r is inexact -- return r or ieee_next_down(r) - fir::IfOp ifOp2 = builder.create<fir::IfOp>(loc, resultType, aLtB, - /*withElseRegion=*/true); + fir::IfOp ifOp2 = fir::IfOp::create(builder, loc, resultType, aLtB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsPositive); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsNegative); mlir::Value roundDown = match(_FORTRAN_RUNTIME_IEEE_DOWN); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundDown); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundDown); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, false)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsNegative, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsNegative, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // (a > b): r is inexact -- return r or ieee_next_up(r) builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsNegative); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsPositive); mlir::Value roundUp = match(_FORTRAN_RUNTIME_IEEE_UP); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundUp); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundUp); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, true)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsPositive, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsPositive, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // Generate exceptions for (a < b) and (a > b) branches. builder.setInsertionPointAfter(ifOp2); r = ifOp2.getResult(0); - fir::IfOp exceptIfOp1 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, infiniteTest), /*withElseRegion=*/true); + fir::IfOp exceptIfOp1 = + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, r, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp1.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&exceptIfOp1.getElseRegion().front()); - fir::IfOp exceptIfOp2 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), + fir::IfOp exceptIfOp2 = fir::IfOp::create( + builder, loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp2.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | @@ -5790,7 +5803,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, builder.setInsertionPointToStart(&exceptIfOp2.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointAfter(exceptIfOp1); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5806,19 +5819,19 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType, mlir::Value y = args[1]; if (mlir::dyn_cast<mlir::FloatType>(resultType).getWidth() < 32) { mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext()); - x = builder.create<fir::ConvertOp>(loc, f32Ty, x); - y = builder.create<fir::ConvertOp>(loc, f32Ty, y); + x = fir::ConvertOp::create(builder, loc, f32Ty, x); + y = fir::ConvertOp::create(builder, loc, f32Ty, y); } else { - x = builder.create<fir::ConvertOp>(loc, resultType, x); - y = builder.create<fir::ConvertOp>(loc, resultType, y); + x = fir::ConvertOp::create(builder, loc, resultType, x); + y = fir::ConvertOp::create(builder, loc, resultType, y); } // remainder calls do not signal IEEE_UNDERFLOW. - mlir::Value underflow = builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), + mlir::Value underflow = mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), genIsFPClass(builder.getI1Type(), y, infiniteTest)); mlir::Value result = genRuntimeCall("remainder", x.getType(), {x, y}); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW, underflow); - return builder.create<fir::ConvertOp>(loc, resultType, result); + return fir::ConvertOp::create(builder, loc, resultType, result); } // IEEE_RINT @@ -5834,19 +5847,19 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType, mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); mlir::Value mode; if (isStaticallyPresent(args[1])) { - mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mode = fir::CallOp::create(builder, loc, getRound).getResult(0); genIeeeSetRoundingMode({args[1]}); } if (mlir::cast<mlir::FloatType>(resultType).getWidth() == 16) - a = builder.create<fir::ConvertOp>( - loc, mlir::Float32Type::get(builder.getContext()), a); - mlir::Value result = builder.create<fir::ConvertOp>( - loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); + a = fir::ConvertOp::create(builder, loc, + mlir::Float32Type::get(builder.getContext()), a); + mlir::Value result = fir::ConvertOp::create( + builder, loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); if (isStaticallyPresent(args[1])) { - builder.create<fir::CallOp>(loc, setRound, mode); + fir::CallOp::create(builder, loc, setRound, mode); } else { - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], result); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], result); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); } return result; @@ -5862,18 +5875,19 @@ void IntrinsicLibrary::genIeeeSetFlagOrHaltingMode( mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value except = fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field)); - auto ifOp = builder.create<fir::IfOp>( - loc, builder.create<fir::ConvertOp>(loc, i1Ty, getBase(args[1])), + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field)); + auto ifOp = fir::IfOp::create( + builder, loc, + fir::ConvertOp::create(builder, loc, i1Ty, getBase(args[1])), /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); (isFlag ? fir::runtime::genFeraiseexcept : fir::runtime::genFeenableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); (isFlag ? fir::runtime::genFeclearexcept : fir::runtime::genFedisableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointAfter(ifOp); } @@ -5890,7 +5904,7 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_set_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); static_assert( _FORTRAN_RUNTIME_IEEE_TO_ZERO >= 0 && _FORTRAN_RUNTIME_IEEE_TO_ZERO <= 3 && @@ -5898,28 +5912,28 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( _FORTRAN_RUNTIME_IEEE_NEAREST <= 3 && _FORTRAN_RUNTIME_IEEE_UP >= 0 && _FORTRAN_RUNTIME_IEEE_UP <= 3 && _FORTRAN_RUNTIME_IEEE_DOWN >= 0 && _FORTRAN_RUNTIME_IEEE_DOWN <= 3 && "unexpected rounding mode mapping"); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>( - loc, builder.createAllOnesInteger(loc, fieldTy), + mlir::Value mask = mlir::arith::ShLIOp::create( + builder, loc, builder.createAllOnesInteger(loc, fieldTy), builder.createIntegerConstant(loc, fieldTy, 2)); - mlir::Value modeIsSupported = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, - builder.create<mlir::arith::AndIOp>(loc, mode, mask), + mlir::Value modeIsSupported = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, + mlir::arith::AndIOp::create(builder, loc, mode, mask), builder.createIntegerConstant(loc, fieldTy, 0)); mlir::Value nearest = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_NEAREST); - mode = builder.create<mlir::arith::SelectOp>(loc, modeIsSupported, mode, - nearest); - mode = builder.create<fir::ConvertOp>( - loc, setRound.getFunctionType().getInput(0), mode); - builder.create<fir::CallOp>(loc, setRound, mode); + mode = mlir::arith::SelectOp::create(builder, loc, modeIsSupported, mode, + nearest); + mode = fir::ConvertOp::create(builder, loc, + setRound.getFunctionType().getInput(0), mode); + fir::CallOp::create(builder, loc, setRound, mode); } // IEEE_SET_UNDERFLOW_MODE void IntrinsicLibrary::genIeeeSetUnderflowMode( llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - mlir::Value gradual = builder.create<fir::ConvertOp>(loc, builder.getI1Type(), - getBase(args[0])); + mlir::Value gradual = fir::ConvertOp::create( + builder, loc, builder.getI1Type(), getBase(args[0])); fir::runtime::genSetUnderflowMode(builder, loc, {gradual}); } @@ -5933,9 +5947,9 @@ IntrinsicLibrary::genIeeeSignalingCompare(mlir::Type resultType, assert(args.size() == 2); mlir::Value hasNaNOp = genIeeeUnordered(mlir::Type{}, args); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_SIGNBIT @@ -5954,9 +5968,9 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType, } mlir::Type intType = builder.getIntegerType(bitWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Value shift = builder.createIntegerConstant(loc, intType, bitWidth - 1); - mlir::Value sign = builder.create<mlir::arith::ShRUIOp>(loc, intVal, shift); + mlir::Value sign = mlir::arith::ShRUIOp::create(builder, loc, intVal, shift); return builder.createConvert(loc, resultType, sign); } @@ -5969,21 +5983,21 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value flag = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value flag = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value standardFlagMask = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_INVALID | _FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO | _FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - mlir::Value isStandardFlag = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, flag, standardFlagMask), + mlir::Value isStandardFlag = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, flag, standardFlagMask), builder.createIntegerConstant(loc, fieldTy, 0)); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, i1Ty, isStandardFlag, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, i1Ty, isStandardFlag, + /*withElseRegion=*/true); // Standard flags are supported. builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, builder.createBool(loc, true)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, true)); // TargetCharacteristics information for the nonstandard ieee_denorm flag // is not available here. So use a runtime check restricted to possibly @@ -6007,17 +6021,17 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, } } if (mayBeSupported) { - mlir::Value isDenorm = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, flag, + mlir::Value isDenorm = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, flag, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DENORM)); - mlir::Value result = builder.create<mlir::arith::AndIOp>( - loc, isDenorm, + mlir::Value result = mlir::arith::AndIOp::create( + builder, loc, isDenorm, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, flag))); - builder.create<fir::ResultOp>(loc, result); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, flag))); + fir::ResultOp::create(builder, loc, result); } else { - builder.create<fir::ResultOp>(loc, builder.createBool(loc, false)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, false)); } builder.setInsertionPointAfter(ifOp); return builder.createConvert(loc, resultType, ifOp.getResult(0)); @@ -6032,11 +6046,11 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportHalting( assert(args.size() == 1); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); return builder.createConvert( loc, resultType, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); } // IEEE_SUPPORT_ROUNDING @@ -6053,16 +6067,16 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportRounding( // 4 - to nearest, ties away from zero [not supported] assert(args.size() == 1 || args.size() == 2); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); - mlir::Value lbOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, mode, + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); + mlir::Value lbOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_TO_ZERO)); - mlir::Value ubOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sle, mode, + mlir::Value ubOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sle, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DOWN)); return builder.createConvert( - loc, resultType, builder.create<mlir::arith::AndIOp>(loc, lbOk, ubOk)); + loc, resultType, mlir::arith::AndIOp::create(builder, loc, lbOk, ubOk)); } // IEEE_SUPPORT_STANDARD @@ -6086,15 +6100,15 @@ IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType, // If there is no result type return an i1 result. assert(args.size() == 2); if (args[0].getType() == args[1].getType()) { - mlir::Value res = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); + mlir::Value res = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); return resultType ? builder.createConvert(loc, resultType, res) : res; } assert(resultType && "expecting a (mixed arg type) unordered result type"); mlir::Type i1Ty = builder.getI1Type(); mlir::Value xIsNan = genIsFPClass(i1Ty, args[0], nanTest); mlir::Value yIsNan = genIsFPClass(i1Ty, args[1], nanTest); - mlir::Value res = builder.create<mlir::arith::OrIOp>(loc, xIsNan, yIsNan); + mlir::Value res = mlir::arith::OrIOp::create(builder, loc, xIsNan, yIsNan); return builder.createConvert(loc, resultType, res); } @@ -6219,22 +6233,22 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType, mlir::Value which; if (args.size() == 2) { // user call auto [index, ignore] = getFieldRef(builder, loc, args[1]); - which = builder.create<fir::LoadOp>(loc, index); + which = fir::LoadOp::create(builder, loc, index); } else { // compiler generated call which = args[0]; } - mlir::Value bits = builder.create<fir::LoadOp>( - loc, - builder.create<fir::CoordinateOp>( - loc, builder.getRefType(valueTy), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + mlir::Value bits = fir::LoadOp::create( + builder, loc, + fir::CoordinateOp::create( + builder, loc, builder.getRefType(valueTy), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), which)); if (bitWidth > 64) - bits = builder.create<mlir::arith::ShLIOp>( - loc, builder.createConvert(loc, intType, bits), + bits = mlir::arith::ShLIOp::create( + builder, loc, builder.createConvert(loc, intType, bits), builder.createIntegerConstant(loc, intType, bitWidth - 64)); - return builder.create<mlir::arith::BitcastOp>(loc, realType, bits); + return mlir::arith::BitcastOp::create(builder, loc, realType, bits); } // IEOR @@ -6276,13 +6290,14 @@ IntrinsicLibrary::genIndex(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value backOpt = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : makeRefThenEmbox(fir::getBase(args[2])); + mlir::Value backOpt = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : makeRefThenEmbox(fir::getBase(args[2])); mlir::Value kindVal = isStaticallyAbsent(args, 3) ? builder.createIntegerConstant( loc, builder.getIndexType(), @@ -6331,8 +6346,8 @@ mlir::Value IntrinsicLibrary::genIsIostatValue(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, args[0], + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, args[0], builder.createIntegerConstant(loc, args[0].getType(), value)); } @@ -6359,16 +6374,16 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - auto left = builder.create<mlir::arith::ShLIOp>(loc, word, absShift); - auto right = builder.create<mlir::arith::ShRUIOp>(loc, word, absShift); - auto shiftIsLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); - auto shiftIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); + auto left = mlir::arith::ShLIOp::create(builder, loc, word, absShift); + auto right = mlir::arith::ShRUIOp::create(builder, loc, word, absShift); + auto shiftIsLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); + auto shiftIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); auto sel = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNegative, right, left); + mlir::arith::SelectOp::create(builder, loc, shiftIsNegative, right, left); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsLarge, zero, sel); + mlir::arith::SelectOp::create(builder, loc, shiftIsLarge, zero, sel); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6409,42 +6424,42 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value absShift = genAbs(signlessType, {shift}); - auto elseSize = builder.create<mlir::arith::SubIOp>(loc, size, absShift); - auto shiftIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, shift, zero); - auto shiftEqualsSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, absShift, size); + auto elseSize = mlir::arith::SubIOp::create(builder, loc, size, absShift); + auto shiftIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, shift, zero); + auto shiftEqualsSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, absShift, size); auto shiftIsNop = - builder.create<mlir::arith::OrIOp>(loc, shiftIsZero, shiftEqualsSize); - auto shiftIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, shift, zero); - auto leftSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - absShift, elseSize); - auto rightSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - elseSize, absShift); - auto hasUnchanged = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, size, bitSize); - auto unchangedTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, word, size); + mlir::arith::OrIOp::create(builder, loc, shiftIsZero, shiftEqualsSize); + auto shiftIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, shift, zero); + auto leftSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + absShift, elseSize); + auto rightSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + elseSize, absShift); + auto hasUnchanged = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, size, bitSize); + auto unchangedTmp1 = mlir::arith::ShRUIOp::create(builder, loc, word, size); auto unchangedTmp2 = - builder.create<mlir::arith::ShLIOp>(loc, unchangedTmp1, size); - auto unchanged = builder.create<mlir::arith::SelectOp>(loc, hasUnchanged, - unchangedTmp2, zero); + mlir::arith::ShLIOp::create(builder, loc, unchangedTmp1, size); + auto unchanged = mlir::arith::SelectOp::create(builder, loc, hasUnchanged, + unchangedTmp2, zero); auto leftMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, leftSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, leftSize); auto leftMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, leftMaskShift); - auto leftTmp = builder.create<mlir::arith::ShRUIOp>(loc, word, rightSize); - auto left = builder.create<mlir::arith::AndIOp>(loc, leftTmp, leftMask); + mlir::arith::ShRUIOp::create(builder, loc, ones, leftMaskShift); + auto leftTmp = mlir::arith::ShRUIOp::create(builder, loc, word, rightSize); + auto left = mlir::arith::AndIOp::create(builder, loc, leftTmp, leftMask); auto rightMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, rightSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, rightSize); auto rightMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, rightMaskShift); - auto rightTmp = builder.create<mlir::arith::AndIOp>(loc, word, rightMask); - auto right = builder.create<mlir::arith::ShLIOp>(loc, rightTmp, leftSize); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, left); - auto res = builder.create<mlir::arith::OrIOp>(loc, resTmp, right); + mlir::arith::ShRUIOp::create(builder, loc, ones, rightMaskShift); + auto rightTmp = mlir::arith::AndIOp::create(builder, loc, word, rightMask); + auto right = mlir::arith::ShLIOp::create(builder, loc, rightTmp, leftSize); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, left); + auto res = mlir::arith::OrIOp::create(builder, loc, resTmp, right); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNop, word, res); + mlir::arith::SelectOp::create(builder, loc, shiftIsNop, word, res); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6456,7 +6471,7 @@ mlir::Value IntrinsicLibrary::genLeadz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountLeadingZerosOp>(loc, args); + mlir::math::CountLeadingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -6524,18 +6539,18 @@ IntrinsicLibrary::genLoc(mlir::Type resultType, // created when preparing the argument cases, but the box can be safely be // used for all those cases and the address will be null if absent. mlir::Value isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), box); + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), box); return builder .genIfOp(loc, {resultType}, isPresent, /*withElseRegion=*/true) .genThen([&]() { mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value cast = builder.createConvert(loc, resultType, argAddr); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } @@ -6568,12 +6583,12 @@ mlir::Value IntrinsicLibrary::genMask(mlir::Type resultType, // non-deterministic result. Other compilers don't produce a consistent result // in this case either, so we choose the most efficient implementation. mlir::Value shift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, bitsToSet); - mlir::Value shifted = builder.create<Shift>(loc, ones, shift); - mlir::Value isZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); + mlir::arith::SubIOp::create(builder, loc, bitSize, bitsToSet); + mlir::Value shifted = Shift::create(builder, loc, ones, shift); + mlir::Value isZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, isZero, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, isZero, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6591,8 +6606,8 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); mlir::Type retTy = mlir::LLVM::LLVMStructType::getLiteral(context, {resultType, i1Ty}); @@ -6601,10 +6616,10 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, .create<mlir::NVVM::MatchSyncOp>(loc, retTy, args[0], arg1, mlir::NVVM::MatchSyncKind::all) .getResult(); - auto value = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 0); - auto pred = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 1); - auto conv = builder.create<mlir::LLVM::ZExtOp>(loc, resultType, pred); - builder.create<fir::StoreOp>(loc, conv, args[2]); + auto value = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 0); + auto pred = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 1); + auto conv = mlir::LLVM::ZExtOp::create(builder, loc, resultType, pred); + fir::StoreOp::create(builder, loc, conv, args[2]); return value; } @@ -6614,14 +6629,14 @@ mlir::Value IntrinsicLibrary::genVoteSync(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 2); mlir::Value arg1 = - builder.create<fir::ConvertOp>(loc, builder.getI1Type(), args[1]); + fir::ConvertOp::create(builder, loc, builder.getI1Type(), args[1]); mlir::Type resTy = kind == mlir::NVVM::VoteSyncKind::ballot ? builder.getI32Type() : builder.getI1Type(); auto voteRes = - builder.create<mlir::NVVM::VoteSyncOp>(loc, resTy, args[0], arg1, kind) + mlir::NVVM::VoteSyncOp::create(builder, loc, resTy, args[0], arg1, kind) .getResult(); - return builder.create<fir::ConvertOp>(loc, resultType, voteRes); + return fir::ConvertOp::create(builder, loc, resultType, voteRes); } // MATCH_ANY_SYNC @@ -6633,8 +6648,8 @@ IntrinsicLibrary::genMatchAnySync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); return builder .create<mlir::NVVM::MatchSyncOp>(loc, resultType, args[0], arg1, @@ -6718,10 +6733,10 @@ IntrinsicLibrary::genMerge(mlir::Type, mlir::Value other) -> mlir::Value { mlir::Type otherType = other.getType(); if (mlir::isa<fir::BaseBoxType>(otherType)) - return builder.create<fir::ReboxOp>(loc, otherType, polymorphic, - /*shape*/ mlir::Value{}, - /*slice=*/mlir::Value{}); - return builder.create<fir::BoxAddrOp>(loc, otherType, polymorphic); + return fir::ReboxOp::create(builder, loc, otherType, polymorphic, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + return fir::BoxAddrOp::create(builder, loc, otherType, polymorphic); }; if (fir::isPolymorphicType(tsource.getType()) && !fir::isPolymorphicType(fsource.getType())) { @@ -6737,8 +6752,8 @@ IntrinsicLibrary::genMerge(mlir::Type, // fulfill mlir::SelectOp constraint that the MLIR types must be the same. fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); } - auto rslt = builder.create<mlir::arith::SelectOp>(loc, mask, tsourceCast, - fsourceCast); + auto rslt = mlir::arith::SelectOp::create(builder, loc, mask, tsourceCast, + fsourceCast); if (isCharRslt) { // Need a CharBoxValue for character results const fir::CharBoxValue *charBox = args[0].getCharBox(); @@ -6779,7 +6794,7 @@ mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, args[0], args[1]); } if (mlir::isa<mlir::IntegerType>(resultType)) - return builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); + return mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); // Use runtime. return builder.createConvert( @@ -6809,19 +6824,19 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, } if (mlir::isa<mlir::IntegerType>(resultType)) { auto remainder = - builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); - auto argXor = builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]); + mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); + auto argXor = mlir::arith::XOrIOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createIntegerConstant(loc, argXor.getType(), 0); - auto argSignDifferent = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, argXor, zero); - auto remainderIsNotZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, remainder, zero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); + auto argSignDifferent = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, argXor, zero); + auto remainderIsNotZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, remainder, zero); + auto mustAddP = mlir::arith::AndIOp::create( + builder, loc, remainderIsNotZero, argSignDifferent); auto remPlusP = - builder.create<mlir::arith::AddIOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::AddIOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } auto fastMathFlags = builder.getFastMathFlags(); @@ -6834,21 +6849,21 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, loc, resultType, fir::runtime::genModulo(builder, loc, args[0], args[1])); - auto remainder = builder.create<mlir::arith::RemFOp>(loc, args[0], args[1]); + auto remainder = mlir::arith::RemFOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createRealZeroConstant(loc, remainder.getType()); - auto remainderIsNotZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); - auto aLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); - auto pLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); + auto remainderIsNotZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); + auto aLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); + auto pLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); auto argSignDifferent = - builder.create<mlir::arith::XOrIOp>(loc, aLessThanZero, pLessThanZero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); - auto remPlusP = builder.create<mlir::arith::AddFOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::XOrIOp::create(builder, loc, aLessThanZero, pLessThanZero); + auto mustAddP = mlir::arith::AndIOp::create(builder, loc, remainderIsNotZero, + argSignDifferent); + auto remPlusP = mlir::arith::AddFOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { @@ -6863,7 +6878,7 @@ void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value errBox = isStaticallyPresent(errMsg) ? fir::getBase(errMsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); const fir::MutableBoxValue *fromBox = from.getBoxOf<fir::MutableBoxValue>(); const fir::MutableBoxValue *toBox = to.getBoxOf<fir::MutableBoxValue>(); @@ -6920,33 +6935,34 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type toType{fir::dyn_cast_ptrEleTy(toAddr.getType())}; assert(toType.getIntOrFloatBitWidth() == fromType.getIntOrFloatBitWidth() && "mismatched mvbits types"); - auto to = builder.create<fir::LoadOp>(loc, signlessType, toAddr); + auto to = fir::LoadOp::create(builder, loc, signlessType, toAddr); mlir::Value topos = builder.createConvert(loc, signlessType, unbox(args[4])); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(signlessType).getWidth()); - auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len); - auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); - auto unchangedTmp1 = builder.create<mlir::arith::ShLIOp>(loc, mask, topos); + auto shiftCount = mlir::arith::SubIOp::create(builder, loc, bitSize, len); + auto mask = mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); + auto unchangedTmp1 = mlir::arith::ShLIOp::create(builder, loc, mask, topos); auto unchangedTmp2 = - builder.create<mlir::arith::XOrIOp>(loc, unchangedTmp1, ones); - auto unchanged = builder.create<mlir::arith::AndIOp>(loc, unchangedTmp2, to); + mlir::arith::XOrIOp::create(builder, loc, unchangedTmp1, ones); + auto unchanged = mlir::arith::AndIOp::create(builder, loc, unchangedTmp2, to); if (fromType.isUnsignedInteger()) from = builder.createConvert(loc, signlessType, from); - auto frombitsTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, from, frompos); + auto frombitsTmp1 = mlir::arith::ShRUIOp::create(builder, loc, from, frompos); auto frombitsTmp2 = - builder.create<mlir::arith::AndIOp>(loc, frombitsTmp1, mask); - auto frombits = builder.create<mlir::arith::ShLIOp>(loc, frombitsTmp2, topos); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, frombits); - auto lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::arith::AndIOp::create(builder, loc, frombitsTmp1, mask); + auto frombits = + mlir::arith::ShLIOp::create(builder, loc, frombitsTmp2, topos); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, frombits); + auto lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value res = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, to, resTmp); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, to, resTmp); if (toType.isUnsignedInteger()) res = builder.createConvert(loc, toType, res); - builder.create<fir::StoreOp>(loc, res, toAddr); + fir::StoreOp::create(builder, loc, res, toAddr); } // NEAREST, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP @@ -6988,7 +7004,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, // If isNan(Y), set X to a qNaN that will propagate to the resultIsX result. mlir::Value qNan = genQNan(xType); mlir::Value isFPClass = genIsFPClass(i1Ty, args[1], nanTest); - x = builder.create<mlir::arith::SelectOp>(loc, isFPClass, qNan, x); + x = mlir::arith::SelectOp::create(builder, loc, isFPClass, qNan, x); } mlir::Value resultIsX = genIsFPClass(i1Ty, x, nanTest); mlir::Type intType = builder.getIntegerType(xBitWidth); @@ -6999,15 +7015,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if constexpr (proc == NearestProc::Nearest) { // Arg S must not be zero. fir::IfOp ifOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[1], zeroTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[1], zeroTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError( builder, loc, "intrinsic nearest S argument is zero"); builder.setInsertionPointAfter(ifOp); mlir::Value sSign = IntrinsicLibrary::genIeeeSignbit(intType, {args[1]}); - valueUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, sSign, one); + valueUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, sSign, one); } else if constexpr (proc == NearestProc::NextAfter) { // Convert X and Y to a common type to allow comparison. Direct conversions // between kinds 2, 3, 10, and 16 are not all supported. These conversions @@ -7028,58 +7044,58 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if (xBitWidth > 32 && xBitWidth > yBitWidth) y = builder.createConvert(loc, xType, y); } - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x1, y)); - valueUp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, x1, y); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OEQ, x1, y)); + valueUp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, x1, y); } else if constexpr (proc == NearestProc::NextDown) { valueUp = builder.createBool(loc, false); } else if constexpr (proc == NearestProc::NextUp) { valueUp = builder.createBool(loc, true); } - mlir::Value magnitudeUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, valueUp, + mlir::Value magnitudeUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, valueUp, IntrinsicLibrary::genIeeeSignbit(i1Ty, {args[0]})); - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); // Result is X. (For ieee_next_after with isNan(Y), X has been set to a NaN.) - fir::IfOp outerIfOp = builder.create<fir::IfOp>(loc, resultType, resultIsX, - /*withElseRegion=*/true); + fir::IfOp outerIfOp = fir::IfOp::create(builder, loc, resultType, resultIsX, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); if constexpr (proc == NearestProc::NextDown || proc == NearestProc::NextUp) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, genIsFPClass(i1Ty, x, snanTest)); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); // Result is minPositiveSubnormal or minNegativeSubnormal. (X is zero.) builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); - mlir::Value resultIsMinSubnormal = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x, + mlir::Value resultIsMinSubnormal = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, x, builder.createRealZeroConstant(loc, xType)); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, resultType, resultIsMinSubnormal, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultType, resultIsMinSubnormal, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value minPositiveSubnormal = - builder.create<mlir::arith::BitcastOp>(loc, resultType, one); - mlir::Value minNegativeSubnormal = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::ConstantOp>( - loc, intType, + mlir::arith::BitcastOp::create(builder, loc, resultType, one); + mlir::Value minNegativeSubnormal = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr( intType, llvm::APInt::getBitsSetWithWrap( xBitWidth, /*lo=*/xBitWidth - 1, /*hi=*/1)))); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Result is (X + minPositiveSubnormal) or (X - minPositiveSubnormal). builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); @@ -7105,15 +7121,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, genRuntimeCall("feraiseexcept", i32Ty, excepts); genRuntimeCall("feenableexcept", i32Ty, mask); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } else { // Kind 2, 3, 4, 8, 16. Increment or decrement X cast to integer. - mlir::Value intX = builder.create<mlir::arith::BitcastOp>(loc, intType, x); - mlir::Value add = builder.create<mlir::arith::AddIOp>(loc, intX, one); - mlir::Value sub = builder.create<mlir::arith::SubIOp>(loc, intX, one); - result = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, magnitudeUp, add, sub)); + mlir::Value intX = mlir::arith::BitcastOp::create(builder, loc, intType, x); + mlir::Value add = mlir::arith::AddIOp::create(builder, loc, intX, one); + mlir::Value sub = mlir::arith::SubIOp::create(builder, loc, intX, one); + result = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, magnitudeUp, add, sub)); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) { genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | @@ -7123,11 +7139,11 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, _FORTRAN_RUNTIME_IEEE_INEXACT, genIsFPClass(i1Ty, result, subnormalTest)); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } builder.setInsertionPointAfter(innerIfOp); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -7209,7 +7225,7 @@ IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value boxStorage = builder.createTemporary(loc, boxType); mlir::Value box = fir::factory::createUnallocatedBox( builder, loc, boxType, mold->nonDeferredLenParams()); - builder.create<fir::StoreOp>(loc, box, boxStorage); + fir::StoreOp::create(builder, loc, box, boxStorage); return fir::MutableBoxValue(boxStorage, mold->nonDeferredLenParams(), {}); } @@ -7218,7 +7234,7 @@ template <typename OpTy> mlir::Value IntrinsicLibrary::genNVVMTime(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 0 && "expect no arguments"); - return builder.create<OpTy>(loc, resultType).getResult(); + return OpTy::create(builder, loc, resultType).getResult(); } // PACK @@ -7235,10 +7251,11 @@ IntrinsicLibrary::genPack(mlir::Type resultType, mlir::Value mask = builder.createBox(loc, args[1]); // Handle optional vector argument - mlir::Value vector = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value vector = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 1); @@ -7298,7 +7315,7 @@ void IntrinsicLibrary::genPerror(llvm::ArrayRef<fir::ExtendedValue> args) { fir::ExtendedValue str = args[0]; const auto *box = str.getBoxOf<fir::BoxValue>(); mlir::Value addr = - builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), fir::getBase(*box)); + fir::BoxAddrOp::create(builder, loc, box->getMemTy(), fir::getBase(*box)); fir::runtime::genPerror(builder, loc, addr); } @@ -7307,7 +7324,7 @@ mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - mlir::Value count = builder.create<mlir::math::CtPopOp>(loc, args); + mlir::Value count = mlir::math::CtPopOp::create(builder, loc, args); return builder.createConvert(loc, resultType, count); } @@ -7320,7 +7337,7 @@ mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, mlir::Value count = genPopcnt(resultType, args); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - return builder.create<mlir::arith::AndIOp>(loc, count, one); + return mlir::arith::AndIOp::create(builder, loc, count, one); } // PRESENT @@ -7328,8 +7345,8 @@ fir::ExtendedValue IntrinsicLibrary::genPresent(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - return builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(args[0])); + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(args[0])); } // PRODUCT @@ -7394,7 +7411,7 @@ void IntrinsicLibrary::genRandomSeed(llvm::ArrayRef<fir::ExtendedValue> args) { auto getDesc = [&](int i) { return isStaticallyPresent(args[i]) ? fir::getBase(args[i]) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); }; mlir::Value size = getDesc(0); mlir::Value put = getDesc(1); @@ -7438,13 +7455,13 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, bool absentDim = isStaticallyAbsent(args[2]); auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); mlir::Value identity = isStaticallyAbsent(args[4]) - ? builder.create<fir::AbsentOp>(loc, fir::ReferenceType::get(eleTy)) + ? fir::AbsentOp::create(builder, loc, fir::ReferenceType::get(eleTy)) : fir::getBase(args[4]); mlir::Value ordered = isStaticallyAbsent(args[5]) @@ -7460,7 +7477,7 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, ordered, result, argByRef); if (fir::isa_derived(eleTy)) return result; - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } if (fir::isa_char(eleTy)) { auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(resultType); @@ -7510,7 +7527,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, auto statusAddr = builder.createTemporary(loc, *resultType); auto statusBox = builder.createBox(loc, statusAddr); fir::runtime::genRename(builder, loc, path1, path2, statusBox); - return builder.create<fir::LoadOp>(loc, statusAddr); + return fir::LoadOp::create(builder, loc, statusAddr); } else { // code-gen for the procedure form of RENAME mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); @@ -7518,7 +7535,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, mlir::Value statusBox = isStaticallyPresent(status) ? fir::getBase(status) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genRename(builder, loc, path1, path2, statusBox); return {}; } @@ -7563,16 +7580,18 @@ IntrinsicLibrary::genReshape(mlir::Type resultType, TODO(loc, "intrinsic: reshape requires computing rank of result"); // Handle optional pad argument - mlir::Value pad = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value pad = + isStaticallyAbsent(args[2]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Handle optional order argument - mlir::Value order = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[3]); + mlir::Value order = + isStaticallyAbsent(args[3]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[3]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type type = builder.getVarLenSeqTy(resultType, resultRank); @@ -7643,26 +7662,27 @@ mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType, // If X is finite and result is infinite, signal IEEE_OVERFLOW // If X is finite and scale(result, -I) != X, signal IEEE_UNDERFLOW fir::IfOp outerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[0], finiteTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[0], finiteTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, result, infiniteTest), - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, result, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - mlir::Value minusI = builder.create<mlir::arith::MulIOp>( - loc, args[1], builder.createAllOnesInteger(loc, args[1].getType())); + mlir::Value minusI = mlir::arith::MulIOp::create( + builder, loc, args[1], + builder.createAllOnesInteger(loc, args[1].getType())); mlir::Value reverseResult = builder.createConvert( loc, resultType, fir::runtime::genScale( builder, loc, builder.createConvert(loc, f32Ty, result), minusI)); genRaiseExcept( _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT, - builder.create<mlir::arith::CmpFOp>(loc, mlir::arith::CmpFPredicate::ONE, - args[0], reverseResult)); + mlir::arith::CmpFOp::create(builder, loc, mlir::arith::CmpFPredicate::ONE, + args[0], reverseResult)); builder.setInsertionPointAfter(outerIfOp); return result; } @@ -7714,13 +7734,14 @@ IntrinsicLibrary::genScan(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -7761,7 +7782,7 @@ IntrinsicLibrary::genSecond(std::optional<mlir::Type> resultType, genCpuTime(subroutineArgs); if (resultType) - return builder.create<fir::LoadOp>(loc, fir::getBase(result)); + return fir::LoadOp::create(builder, loc, fir::getBase(result)); return {}; } @@ -7808,22 +7829,22 @@ IntrinsicLibrary::genSelectedRealKind(mlir::Type resultType, // Handle optional precision(P) argument mlir::Value precision = isStaticallyAbsent(args[0]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[0]); // Handle optional range(R) argument mlir::Value range = isStaticallyAbsent(args[1]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[1]); // Handle optional radix(RADIX) argument mlir::Value radix = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[2]); return builder.createConvert( @@ -7861,9 +7882,9 @@ createBoxForRuntimeBoundInquiry(mlir::Location loc, fir::FirOpBuilder &builder, // shape information. mlir::Value localShape = builder.createShape(loc, array); mlir::Value oldBox = boxValue.getAddr(); - return builder.create<fir::ReboxOp>(loc, oldBox.getType(), oldBox, - localShape, - /*slice=*/mlir::Value{}); + return fir::ReboxOp::create(builder, loc, oldBox.getType(), oldBox, + localShape, + /*slice=*/mlir::Value{}); }, [&](const auto &) -> mlir::Value { // This is a pointer/allocatable, or an entity not yet tracked with a @@ -7909,7 +7930,7 @@ genBoundInquiry(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value resultBase = builder.createConvert(loc, baseType, resultStorage); mlir::Value rankValue = - builder.create<fir::BoxRankOp>(loc, builder.getIndexType(), arrayBox); + fir::BoxRankOp::create(builder, loc, builder.getIndexType(), arrayBox); return fir::ArrayBoxValue{resultBase, {rankValue}}; } // Result extent is a compile time constant in the other cases. @@ -7939,9 +7960,9 @@ IntrinsicLibrary::genShape(mlir::Type resultType, mlir::Value extent = fir::factory::readExtent(builder, loc, array, dim); extent = builder.createConvert(loc, extentType, extent); auto index = builder.createIntegerConstant(loc, indexType, dim); - auto shapeAddr = builder.create<fir::CoordinateOp>(loc, shapeAddrType, - shapeArray, index); - builder.create<fir::StoreOp>(loc, extent, shapeAddr); + auto shapeAddr = fir::CoordinateOp::create(builder, loc, shapeAddrType, + shapeArray, index); + fir::StoreOp::create(builder, loc, extent, shapeAddr); } mlir::Value shapeArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -7967,18 +7988,18 @@ mlir::Value IntrinsicLibrary::genShift(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value tooSmall = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); - mlir::Value tooLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); + mlir::Value tooSmall = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); + mlir::Value tooLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); mlir::Value outOfBounds = - builder.create<mlir::arith::OrIOp>(loc, tooSmall, tooLarge); + mlir::arith::OrIOp::create(builder, loc, tooSmall, tooLarge); mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value shifted = builder.create<Shift>(loc, word, shift); + mlir::Value shifted = Shift::create(builder, loc, word, shift); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, outOfBounds, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, outOfBounds, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -7993,8 +8014,8 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value bitSize = builder.createIntegerConstant(loc, signlessType, bits); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value shiftGeBitSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); + mlir::Value shiftGeBitSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); // Lowering of mlir::arith::ShRSIOp is using `ashr`. `ashr` is undefined when // the shift amount is equal to the element size. @@ -8006,13 +8027,13 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value valueIsNeg = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, word, zero); + mlir::Value valueIsNeg = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, word, zero); mlir::Value specialRes = - builder.create<mlir::arith::SelectOp>(loc, valueIsNeg, minusOne, zero); - mlir::Value shifted = builder.create<mlir::arith::ShRSIOp>(loc, word, shift); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, shiftGeBitSize, specialRes, shifted); + mlir::arith::SelectOp::create(builder, loc, valueIsNeg, minusOne, zero); + mlir::Value shifted = mlir::arith::ShRSIOp::create(builder, loc, word, shift); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, shiftGeBitSize, specialRes, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -8037,10 +8058,10 @@ mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto neg = builder.create<mlir::arith::SubIOp>(loc, zero, abs); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, args[1], zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, neg, abs); + auto neg = mlir::arith::SubIOp::create(builder, loc, zero, abs); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, args[1], zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, neg, abs); } return genRuntimeCall("sign", resultType, args); } @@ -8056,6 +8077,21 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); + return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); +} + +// SINPI +mlir::Value IntrinsicLibrary::genSinpi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi); + 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<mlir::arith::MulFOp>(loc, args[0], factor); return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); } @@ -8100,14 +8136,14 @@ IntrinsicLibrary::genSize(mlir::Type resultType, .genThen([&]() { mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, array)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .genElse([&]() { - mlir::Value dimValue = builder.create<fir::LoadOp>(loc, dim); + mlir::Value dimValue = fir::LoadOp::create(builder, loc, dim); mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSizeDim(builder, loc, array, dimValue)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .getResults()[0]; } @@ -8118,12 +8154,13 @@ IntrinsicLibrary::genSizeOf(mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); mlir::Value box = fir::getBase(args[0]); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, resultType, box); + mlir::Value eleSize = + fir::BoxEleSizeOp::create(builder, loc, resultType, box); if (!fir::isArray(args[0])) return eleSize; mlir::Value arraySize = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, box)); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, arraySize); + return mlir::arith::MulIOp::create(builder, loc, eleSize, arraySize); } // TAND @@ -8137,6 +8174,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); + return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); +} + +// TANPI +mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi); + 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<mlir::arith::MulFOp>(loc, args[0], factor); return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); } @@ -8147,81 +8199,83 @@ mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); - mlir::Value blockIdX = builder.create<mlir::NVVM::BlockIdXOp>(loc, i32Ty); - mlir::Value blockIdY = builder.create<mlir::NVVM::BlockIdYOp>(loc, i32Ty); - mlir::Value blockIdZ = builder.create<mlir::NVVM::BlockIdZOp>(loc, i32Ty); + mlir::Value blockIdX = mlir::NVVM::BlockIdXOp::create(builder, loc, i32Ty); + mlir::Value blockIdY = mlir::NVVM::BlockIdYOp::create(builder, loc, i32Ty); + mlir::Value blockIdZ = mlir::NVVM::BlockIdZOp::create(builder, loc, i32Ty); - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); - mlir::Value gridDimX = builder.create<mlir::NVVM::GridDimXOp>(loc, i32Ty); - mlir::Value gridDimY = builder.create<mlir::NVVM::GridDimYOp>(loc, i32Ty); - mlir::Value gridDimZ = builder.create<mlir::NVVM::GridDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); + mlir::Value gridDimX = mlir::NVVM::GridDimXOp::create(builder, loc, i32Ty); + mlir::Value gridDimY = mlir::NVVM::GridDimYOp::create(builder, loc, i32Ty); + mlir::Value gridDimZ = mlir::NVVM::GridDimZOp::create(builder, loc, i32Ty); // this_grid.size = ((blockDim.z * gridDim.z) * (blockDim.y * gridDim.y)) * // (blockDim.x * gridDim.x); mlir::Value resZ = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, gridDimZ); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, gridDimZ); mlir::Value resY = - builder.create<mlir::arith::MulIOp>(loc, blockDimY, gridDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimY, gridDimY); mlir::Value resX = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, gridDimX); - mlir::Value resZY = builder.create<mlir::arith::MulIOp>(loc, resZ, resY); - mlir::Value size = builder.create<mlir::arith::MulIOp>(loc, resZY, resX); + mlir::arith::MulIOp::create(builder, loc, blockDimX, gridDimX); + mlir::Value resZY = mlir::arith::MulIOp::create(builder, loc, resZ, resY); + mlir::Value size = mlir::arith::MulIOp::create(builder, loc, resZY, resX); // tmp = ((blockIdx.z * gridDim.y * gridDim.x) + (blockIdx.y * gridDim.x)) + // blockIdx.x; // this_group.rank = tmp * ((blockDim.x * blockDim.y) * blockDim.z) + // ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value r1 = builder.create<mlir::arith::MulIOp>(loc, blockIdZ, gridDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, gridDimX); - mlir::Value r3 = builder.create<mlir::arith::MulIOp>(loc, blockIdY, gridDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value tmp = builder.create<mlir::arith::AddIOp>(loc, r2r3, blockIdX); + mlir::Value r1 = + mlir::arith::MulIOp::create(builder, loc, blockIdZ, gridDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, gridDimX); + mlir::Value r3 = + mlir::arith::MulIOp::create(builder, loc, blockIdY, gridDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value tmp = mlir::arith::AddIOp::create(builder, loc, r2r3, blockIdX); mlir::Value bXbY = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, blockDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimX, blockDimY); mlir::Value bXbYbZ = - builder.create<mlir::arith::MulIOp>(loc, bXbY, blockDimZ); + mlir::arith::MulIOp::create(builder, loc, bXbY, blockDimZ); mlir::Value tZbY = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); mlir::Value tZbYbX = - builder.create<mlir::arith::MulIOp>(loc, tZbY, blockDimX); + mlir::arith::MulIOp::create(builder, loc, tZbY, blockDimX); mlir::Value tYbX = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value rank = builder.create<mlir::arith::MulIOp>(loc, tmp, bXbYbZ); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tZbYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value rank = mlir::arith::MulIOp::create(builder, loc, tmp, bXbYbZ); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tZbYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8232,50 +8286,50 @@ IntrinsicLibrary::genThisThreadBlock(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // this_thread_block%size = blockDim.z * blockDim.y * blockDim.x; - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); mlir::Value size = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, blockDimY); - size = builder.create<mlir::arith::MulIOp>(loc, size, blockDimX); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, blockDimY); + size = mlir::arith::MulIOp::create(builder, loc, size, blockDimX); // this_thread_block%rank = ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); mlir::Value r1 = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, blockDimX); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, blockDimX); mlir::Value r3 = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, r2r3, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, r2r3, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8285,7 +8339,7 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // coalesced_group%size = 32 @@ -8293,28 +8347,28 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); // coalesced_group%rank = threadIdx.x & 31 + 1 - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); mlir::Value mask = builder.createIntegerConstant(loc, i32Ty, 31); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); mlir::Value masked = - builder.create<mlir::arith::AndIOp>(loc, threadIdX, mask); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, masked, one); + mlir::arith::AndIOp::create(builder, loc, threadIdX, mask); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, masked, one); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8324,7 +8378,7 @@ mlir::Value IntrinsicLibrary::genTrailz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountTrailingZerosOp>(loc, args); + mlir::math::CountTrailingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -8352,10 +8406,10 @@ static mlir::Value computeLBOUND(fir::FirOpBuilder &builder, mlir::Location loc, zero = builder.createConvert(loc, extent.getType(), zero); // Note: for assumed size, the extent is -1, and the lower bound should // be returned. It is important to test extent == 0 and not extent > 0. - auto dimIsEmpty = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); + auto dimIsEmpty = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); one = builder.createConvert(loc, lb.getType(), one); - return builder.create<mlir::arith::SelectOp>(loc, dimIsEmpty, one, lb); + return mlir::arith::SelectOp::create(builder, loc, dimIsEmpty, one, lb); } // LBOUND @@ -8391,8 +8445,8 @@ IntrinsicLibrary::genLbound(mlir::Type resultType, lb = builder.createConvert(loc, lbType, lb); auto index = builder.createIntegerConstant(loc, indexType, dim); auto lbAddr = - builder.create<fir::CoordinateOp>(loc, lbAddrType, lbArray, index); - builder.create<fir::StoreOp>(loc, lb, lbAddr); + fir::CoordinateOp::create(builder, loc, lbAddrType, lbArray, index); + fir::StoreOp::create(builder, loc, lb, lbAddr); } mlir::Value lbArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -8431,8 +8485,8 @@ IntrinsicLibrary::genUbound(mlir::Type resultType, mlir::Value lbound = fir::getBase(genLbound(resultType, args)); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - mlir::Value ubound = builder.create<mlir::arith::SubIOp>(loc, lbound, one); - return builder.create<mlir::arith::AddIOp>(loc, ubound, extent); + mlir::Value ubound = mlir::arith::SubIOp::create(builder, loc, lbound, one); + return mlir::arith::AddIOp::create(builder, loc, ubound, extent); } // Handle calls to UBOUND without the DIM argument, which return an array int kindPos = args.size() == 2 ? 1 : 2; @@ -8526,9 +8580,9 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType, box = builder.createBox(loc, args[0], /*isPolymorphic=*/args[0].isPolymorphic()); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, kindTy, box); + mlir::Value eleSize = fir::BoxEleSizeOp::create(builder, loc, kindTy, box); mlir::Value c8 = builder.createIntegerConstant(loc, kindTy, 8); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, c8); + return mlir::arith::MulIOp::create(builder, loc, eleSize, c8); } // SUM @@ -8541,7 +8595,7 @@ IntrinsicLibrary::genSum(mlir::Type resultType, // SYNCTHREADS void IntrinsicLibrary::genSyncThreads(llvm::ArrayRef<fir::ExtendedValue> args) { - builder.create<mlir::NVVM::Barrier0Op>(loc); + mlir::NVVM::Barrier0Op::create(builder, loc); } // SYNCTHREADS_AND @@ -8553,7 +8607,7 @@ IntrinsicLibrary::genSyncThreadsAnd(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_COUNT @@ -8565,7 +8619,7 @@ IntrinsicLibrary::genSyncThreadsCount(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_OR @@ -8577,7 +8631,7 @@ IntrinsicLibrary::genSyncThreadsOr(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCWARP @@ -8589,7 +8643,7 @@ void IntrinsicLibrary::genSyncWarp(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {mask.getType()}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> argsList{mask}; - builder.create<fir::CallOp>(loc, funcOp, argsList); + fir::CallOp::create(builder, loc, funcOp, argsList); } // SYSTEM @@ -8615,25 +8669,26 @@ IntrinsicLibrary::genSystem(std::optional<mlir::Type> resultType, mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); // Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself // when cmdstat is assigned with a non-zero value but not present mlir::Value tempValue = builder.createIntegerConstant(loc, builder.getI16Type(), 0); mlir::Value temp = builder.createTemporary(loc, builder.getI16Type()); - builder.create<fir::StoreOp>(loc, tempValue, temp); + fir::StoreOp::create(builder, loc, tempValue, temp); mlir::Value cmdstatBox = builder.createBox(loc, temp); mlir::Value cmdmsgBox = - builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); if (resultType) { - mlir::Value exitstatAddr = builder.create<fir::BoxAddrOp>(loc, exitstatBox); - return builder.create<fir::LoadOp>(loc, fir::getBase(exitstatAddr)); + mlir::Value exitstatAddr = + fir::BoxAddrOp::create(builder, loc, exitstatBox); + return fir::LoadOp::create(builder, loc, fir::getBase(exitstatAddr)); } return {}; } @@ -8729,7 +8784,7 @@ void IntrinsicLibrary::genThreadFence(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_BLOCK @@ -8740,7 +8795,7 @@ void IntrinsicLibrary::genThreadFenceBlock( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_SYSTEM @@ -8751,7 +8806,7 @@ void IntrinsicLibrary::genThreadFenceSystem( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // TIME @@ -8803,29 +8858,30 @@ static mlir::Value createExtremumCompare(mlir::Location loc, // Return the number if one of the inputs is NaN and the other is // a number. auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto rightIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, right, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto rightIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, right, right); result = - builder.create<mlir::arith::OrIOp>(loc, leftIsResult, rightIsNan); + mlir::arith::OrIOp::create(builder, loc, leftIsResult, rightIsNan); } else if constexpr (behavior == ExtremumBehavior::IeeeMinMaximum) { // Always return NaNs if one the input is NaNs auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto leftIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, left, left); - result = builder.create<mlir::arith::OrIOp>(loc, leftIsResult, leftIsNan); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto leftIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, left, left); + result = + mlir::arith::OrIOp::create(builder, loc, leftIsResult, leftIsNan); } else if constexpr (behavior == ExtremumBehavior::MinMaxss) { // If the left is a NaN, return the right whatever it is. result = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); } else if constexpr (behavior == ExtremumBehavior::PgfortranLlvm) { // If one of the operand is a NaN, return left whatever it is. static constexpr auto unorderedCmp = extremum == Extremum::Max ? mlir::arith::CmpFPredicate::UGT : mlir::arith::CmpFPredicate::ULT; result = - builder.create<mlir::arith::CmpFOp>(loc, unorderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, unorderedCmp, left, right); } else { // TODO: ieeeMinNum/ieeeMaxNum static_assert(behavior == ExtremumBehavior::IeeeMinMaxNum, @@ -8839,8 +8895,8 @@ static mlir::Value createExtremumCompare(mlir::Location loc, left = builder.createConvert(loc, signlessType, left); right = builder.createConvert(loc, signlessType, right); } - result = - builder.create<mlir::arith::CmpIOp>(loc, integerPredicate, left, right); + result = mlir::arith::CmpIOp::create(builder, loc, integerPredicate, left, + right); } else if (fir::isa_char(type) || fir::isa_char(fir::unwrapRefType(type))) { // TODO: ! character min and max is tricky because the result // length is the length of the longest argument! @@ -8961,13 +9017,14 @@ IntrinsicLibrary::genVerify(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -9007,8 +9064,8 @@ IntrinsicLibrary::genExtremumloc(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); // Handle optional kind argument @@ -9090,8 +9147,8 @@ IntrinsicLibrary::genExtremumVal(FN func, FD funcDim, FC funcChar, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -9155,7 +9212,7 @@ mlir::Value IntrinsicLibrary::genExtremum(mlir::Type, for (auto arg : args.drop_front()) { mlir::Value mask = createExtremumCompare<extremum, behavior>(loc, builder, result, arg); - result = builder.create<mlir::arith::SelectOp>(loc, mask, result, arg); + result = mlir::arith::SelectOp::create(builder, loc, mask, result, arg); } return result; } diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp index 93abedc..50c945d 100644 --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -35,7 +35,7 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value shape; if (!extents.empty()) { if (lbounds.empty()) { - shape = builder.create<fir::ShapeOp>(loc, extents); + shape = fir::ShapeOp::create(builder, loc, extents); } else { llvm::SmallVector<mlir::Value> shapeShiftBounds; for (auto [lb, extent] : llvm::zip(lbounds, extents)) { @@ -44,8 +44,8 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, } auto shapeShiftType = fir::ShapeShiftType::get(builder.getContext(), extents.size()); - shape = builder.create<fir::ShapeShiftOp>(loc, shapeShiftType, - shapeShiftBounds); + shape = fir::ShapeShiftOp::create(builder, loc, shapeShiftType, + shapeShiftBounds); } } // Otherwise, this a scalar. Leave the shape empty. @@ -78,8 +78,8 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value emptySlice; auto boxType = fir::updateTypeWithVolatility( box.getBoxTy(), fir::isa_volatile_type(cleanedAddr.getType())); - return builder.create<fir::EmboxOp>(loc, boxType, cleanedAddr, shape, - emptySlice, cleanedLengths, tdesc); + return fir::EmboxOp::create(builder, loc, boxType, cleanedAddr, shape, + emptySlice, cleanedLengths, tdesc); } //===----------------------------------------------------------------------===// @@ -106,7 +106,7 @@ public: bool forceIRBoxRead = false) : builder{builder}, loc{loc}, box{box} { if (forceIRBoxRead || !box.isDescribedByVariables()) - irBox = builder.create<fir::LoadOp>(loc, box.getAddr()); + irBox = fir::LoadOp::create(builder, loc, box.getAddr()); } /// Get base address of allocated/associated entity. mlir::Value readBaseAddress() { @@ -114,10 +114,10 @@ public: auto memrefTy = box.getBoxTy().getEleTy(); if (!fir::isa_ref_type(memrefTy)) memrefTy = builder.getRefType(memrefTy); - return builder.create<fir::BoxAddrOp>(loc, memrefTy, irBox); + return fir::BoxAddrOp::create(builder, loc, memrefTy, irBox); } auto addrVar = box.getMutableProperties().addr; - return builder.create<fir::LoadOp>(loc, addrVar); + return fir::LoadOp::create(builder, loc, addrVar); } /// Return {lbound, extent} values read from the MutableBoxValue given /// the dimension. @@ -125,13 +125,14 @@ public: auto idxTy = builder.getIndexType(); if (irBox) { auto dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - irBox, dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + irBox, dimVal); return {dimInfo.getResult(0), dimInfo.getResult(1)}; } const auto &mutableProperties = box.getMutableProperties(); - auto lb = builder.create<fir::LoadOp>(loc, mutableProperties.lbounds[dim]); - auto ext = builder.create<fir::LoadOp>(loc, mutableProperties.extents[dim]); + auto lb = fir::LoadOp::create(builder, loc, mutableProperties.lbounds[dim]); + auto ext = + fir::LoadOp::create(builder, loc, mutableProperties.extents[dim]); return {lb, ext}; } @@ -146,7 +147,7 @@ public: const auto &deferred = box.getMutableProperties().deferredParams; if (deferred.empty()) fir::emitFatalError(loc, "allocatable entity has no length property"); - return builder.create<fir::LoadOp>(loc, deferred[0]); + return fir::LoadOp::create(builder, loc, deferred[0]); } /// Read and return all extents. If \p lbounds vector is provided, lbounds are @@ -223,7 +224,7 @@ public: /// all that can be described in the new fir.box (e.g. non contiguous entity). void updateWithIrBox(mlir::Value newBox) { assert(!box.isDescribedByVariables()); - builder.create<fir::StoreOp>(loc, newBox, box.getAddr()); + fir::StoreOp::create(builder, loc, newBox, box.getAddr()); } /// Set unallocated/disassociated status for the entity described by /// MutableBoxValue. Deallocation is not performed by this helper. @@ -231,8 +232,8 @@ public: if (box.isDescribedByVariables()) { auto addrVar = box.getMutableProperties().addr; auto nullTy = fir::dyn_cast_ptrEleTy(addrVar.getType()); - builder.create<fir::StoreOp>(loc, builder.createNullConstant(loc, nullTy), - addrVar); + fir::StoreOp::create(builder, loc, + builder.createNullConstant(loc, nullTy), addrVar); } else { // Note that the dynamic type of polymorphic entities must be reset to the // declaration type of the mutable box. See Fortran 2018 7.8.2 NOTE 1. @@ -246,7 +247,7 @@ public: auto deallocatedBox = fir::factory::createUnallocatedBox( builder, loc, box.getBoxTy(), box.nonDeferredLenParams(), typeSourceBox, allocator); - builder.create<fir::StoreOp>(loc, deallocatedBox, box.getAddr()); + fir::StoreOp::create(builder, loc, deallocatedBox, box.getAddr()); } } @@ -286,7 +287,7 @@ private: const bool valueTypeIsVolatile = fir::isa_volatile_type(fir::unwrapRefType(box.getAddr().getType())); irBox = builder.createVolatileCast(loc, valueTypeIsVolatile, irBox); - builder.create<fir::StoreOp>(loc, irBox, box.getAddr()); + fir::StoreOp::create(builder, loc, irBox, box.getAddr()); } /// Update the set of property variables of the MutableBoxValue. @@ -295,8 +296,8 @@ private: mlir::ValueRange lengths) { auto castAndStore = [&](mlir::Value val, mlir::Value addr) { auto type = fir::dyn_cast_ptrEleTy(addr.getType()); - builder.create<fir::StoreOp>(loc, builder.createConvert(loc, type, val), - addr); + fir::StoreOp::create(builder, loc, builder.createConvert(loc, type, val), + addr); }; const auto &mutableProperties = box.getMutableProperties(); castAndStore(addr, mutableProperties.addr); @@ -379,8 +380,8 @@ mlir::Value fir::factory::createUnallocatedBox( } } mlir::Value emptySlice; - auto embox = builder.create<fir::EmboxOp>( - loc, baseBoxType, nullAddr, shape, emptySlice, lenParams, typeSourceBox); + auto embox = fir::EmboxOp::create(builder, loc, baseBoxType, nullAddr, shape, + emptySlice, lenParams, typeSourceBox); if (allocator != 0) embox.setAllocatorIdx(allocator); if (isAssumedRank) @@ -459,7 +460,7 @@ fir::factory::genMutableBoxRead(fir::FirOpBuilder &builder, mlir::Location loc, } mlir::Value sourceBox; if (box.isPolymorphic()) - sourceBox = builder.create<fir::LoadOp>(loc, box.getAddr()); + sourceBox = fir::LoadOp::create(builder, loc, box.getAddr()); if (rank) return fir::ArrayBoxValue{addr, extents, lbounds, sourceBox}; if (box.isPolymorphic()) @@ -490,7 +491,7 @@ static void genFreemem(fir::FirOpBuilder &builder, mlir::Location loc, // so make sure the heap type is restored before deallocation. auto cast = builder.createConvert( loc, fir::HeapType::get(fir::dyn_cast_ptrEleTy(addr.getType())), addr); - builder.create<fir::FreeMemOp>(loc, cast); + fir::FreeMemOp::create(builder, loc, cast); } void fir::factory::genFreememIfAllocated(fir::FirOpBuilder &builder, @@ -498,8 +499,8 @@ void fir::factory::genFreememIfAllocated(fir::FirOpBuilder &builder, const fir::MutableBoxValue &box) { auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress(); auto isAllocated = builder.genIsNotNullAddr(loc, addr); - auto ifOp = builder.create<fir::IfOp>(loc, isAllocated, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, isAllocated, + /*withElseRegion=*/false); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); ::genFreemem(builder, loc, addr); @@ -553,15 +554,15 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder, if (box.hasAssumedRank()) { assert(arr.hasAssumedRank() && "expect both arr and box to be assumed-rank"); - mlir::Value reboxed = builder.create<fir::ReboxAssumedRankOp>( - loc, box.getBoxTy(), arr.getAddr(), + mlir::Value reboxed = fir::ReboxAssumedRankOp::create( + builder, loc, box.getBoxTy(), arr.getAddr(), fir::LowerBoundModifierAttribute::Preserve); writer.updateWithIrBox(reboxed); } else if (box.isDescribedByVariables()) { // LHS is a contiguous pointer described by local variables. Open RHS // fir.box to update the LHS. - auto rawAddr = builder.create<fir::BoxAddrOp>(loc, arr.getMemTy(), - arr.getAddr()); + auto rawAddr = fir::BoxAddrOp::create(builder, loc, arr.getMemTy(), + arr.getAddr()); auto extents = fir::factory::getExtents(loc, builder, source); llvm::SmallVector<mlir::Value> lenParams; if (arr.isCharacter()) { @@ -576,11 +577,11 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder, if (!newLbounds.empty()) { auto shiftType = fir::ShiftType::get(builder.getContext(), newLbounds.size()); - shift = builder.create<fir::ShiftOp>(loc, shiftType, newLbounds); + shift = fir::ShiftOp::create(builder, loc, shiftType, newLbounds); } auto reboxed = - builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(), - shift, /*slice=*/mlir::Value()); + fir::ReboxOp::create(builder, loc, box.getBoxTy(), arr.getAddr(), + shift, /*slice=*/mlir::Value()); writer.updateWithIrBox(reboxed); } }, @@ -608,9 +609,9 @@ void fir::factory::associateMutableBoxWithRemap( for (auto [lb, ub] : llvm::zip(lbounds, ubounds)) { auto lbi = builder.createConvert(loc, idxTy, lb); auto ubi = builder.createConvert(loc, idxTy, ub); - auto diff = builder.create<mlir::arith::SubIOp>(loc, idxTy, ubi, lbi); + auto diff = mlir::arith::SubIOp::create(builder, loc, idxTy, ubi, lbi); extents.emplace_back( - builder.create<mlir::arith::AddIOp>(loc, idxTy, diff, one)); + mlir::arith::AddIOp::create(builder, loc, idxTy, diff, one)); } } else { // lbounds are default. Upper bounds and extents are the same. @@ -657,8 +658,8 @@ void fir::factory::associateMutableBoxWithRemap( if (box.isDescribedByVariables()) { // LHS is a contiguous pointer described by local variables. Open RHS // fir.box to update the LHS. - auto rawAddr = builder.create<fir::BoxAddrOp>(loc, arr.getMemTy(), - arr.getAddr()); + auto rawAddr = fir::BoxAddrOp::create(builder, loc, arr.getMemTy(), + arr.getAddr()); llvm::SmallVector<mlir::Value> lenParams; if (arr.isCharacter()) { lenParams.emplace_back( @@ -678,10 +679,10 @@ void fir::factory::associateMutableBoxWithRemap( shapeArgs.push_back(ext); } auto shape = - builder.create<fir::ShapeShiftOp>(loc, shapeType, shapeArgs); + fir::ShapeShiftOp::create(builder, loc, shapeType, shapeArgs); auto reboxed = - builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(), - shape, /*slice=*/mlir::Value()); + fir::ReboxOp::create(builder, loc, box.getBoxTy(), arr.getAddr(), + shape, /*slice=*/mlir::Value()); writer.updateWithIrBox(reboxed); } }, @@ -748,8 +749,8 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder, mlir::ValueRange lenParams, llvm::StringRef allocName) { auto lengths = getNewLengths(builder, loc, box, lenParams); - auto newStorage = builder.create<fir::AllocMemOp>( - loc, box.getBaseTy(), allocName, lengths, extents); + auto newStorage = fir::AllocMemOp::create(builder, loc, box.getBaseTy(), + allocName, lengths, extents); if (mlir::isa<fir::RecordType>(box.getEleTy())) { // TODO: skip runtime initialization if this is not required. Currently, // there is no way to know here if a derived type needs it or not. But the @@ -771,8 +772,8 @@ void fir::factory::genInlinedAllocation( llvm::SmallVector<mlir::Value> safeExtents; for (mlir::Value extent : extents) safeExtents.push_back(fir::factory::genMaxWithZero(builder, loc, extent)); - auto heap = builder.create<fir::AllocMemOp>(loc, box.getBaseTy(), allocName, - lengths, safeExtents); + auto heap = fir::AllocMemOp::create(builder, loc, box.getBaseTy(), allocName, + lengths, safeExtents); MutablePropertyWriter{builder, loc, box}.updateMutableBox( heap, lbounds, safeExtents, lengths); if (mlir::isa<fir::RecordType>(box.getEleTy())) { @@ -841,10 +842,11 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( mlir::Value required) { auto castPrevious = builder.createConvert(loc, required.getType(), previous); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, castPrevious, required); - mustReallocate = builder.create<mlir::arith::SelectOp>( - loc, cmp, cmp, mustReallocate); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, castPrevious, + required); + mustReallocate = mlir::arith::SelectOp::create( + builder, loc, cmp, cmp, mustReallocate); }; llvm::SmallVector<mlir::Value> previousExtents = reader.readShape(); if (!shape.empty()) @@ -879,17 +881,17 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( ".auto.alloc"); if (storageHandler) storageHandler(getExtValForStorage(heap)); - builder.create<fir::ResultOp>(loc, heap); + fir::ResultOp::create(builder, loc, heap); }) .genElse([&]() { if (storageHandler) storageHandler(getExtValForStorage(addr)); - builder.create<fir::ResultOp>(loc, addr); + fir::ResultOp::create(builder, loc, addr); }); ifOp.end(); auto newAddr = ifOp.getResults()[0]; - builder.create<fir::ResultOp>( - loc, mlir::ValueRange{mustReallocate, newAddr}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{mustReallocate, newAddr}); }) .genElse([&]() { auto trueValue = builder.createBool(loc, true); @@ -900,15 +902,15 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( builder, loc, "array left hand side must be allocated when the right hand " "side is a scalar"); - builder.create<fir::ResultOp>(loc, - mlir::ValueRange{trueValue, addr}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{trueValue, addr}); } else { auto heap = allocateAndInitNewStorage( builder, loc, box, shape, lengthParams, ".auto.alloc"); if (storageHandler) storageHandler(getExtValForStorage(heap)); - builder.create<fir::ResultOp>(loc, - mlir::ValueRange{trueValue, heap}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{trueValue, heap}); } }); ifOp.end(); @@ -976,7 +978,7 @@ mlir::Value fir::factory::genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( builder, loc, boxTy, /*nonDeferredParams=*/{}); - builder.create<fir::StoreOp>(loc, nullBox, boxStorage); + fir::StoreOp::create(builder, loc, nullBox, boxStorage); return boxStorage; } @@ -988,11 +990,11 @@ mlir::Value fir::factory::getAndEstablishBoxStorage( mlir::Value nullAddr = builder.createNullConstant(loc, boxTy.getBaseAddressType()); mlir::Value box = - builder.create<fir::EmboxOp>(loc, boxTy, nullAddr, shape, - /*emptySlice=*/mlir::Value{}, - fir::factory::elideLengthsAlreadyInType( - boxTy.unwrapInnerType(), typeParams), - polymorphicMold); - builder.create<fir::StoreOp>(loc, box, boxStorage); + fir::EmboxOp::create(builder, loc, boxTy, nullAddr, shape, + /*emptySlice=*/mlir::Value{}, + fir::factory::elideLengthsAlreadyInType( + boxTy.unwrapInnerType(), typeParams), + polymorphicMold); + fir::StoreOp::create(builder, loc, box, boxStorage); return boxStorage; } diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp index 0094ce89..03952da 100644 --- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp @@ -17,6 +17,7 @@ #include "flang/Evaluate/common.h" #include "flang/Optimizer/Builder/FIRBuilder.h" #include "flang/Optimizer/Builder/MutableBox.h" +#include "mlir/Dialect/Index/IR/IndexOps.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" namespace fir { @@ -1090,7 +1091,7 @@ void PPCIntrinsicLibrary::genMtfsf(llvm::ArrayRef<fir::ExtendedValue> args) { builder.getContext(), builder); funcOp = builder.createFunction(loc, "llvm.ppc.mtfsf", libFuncType); } - builder.create<fir::CallOp>(loc, funcOp, scalarArgs); + fir::CallOp::create(builder, loc, funcOp, scalarArgs); } // VEC_ABS @@ -1117,7 +1118,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, } funcOp = builder.createFunction(loc, fname, ftype); - auto callOp{builder.create<fir::CallOp>(loc, funcOp, argBases[0])}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, argBases[0])}; return callOp.getResult(0); } else if (auto eleTy = mlir::dyn_cast<mlir::IntegerType>(vTypeInfo.eleTy)) { // vec_abs(arg1) = max(0 - arg1, arg1) @@ -1127,8 +1128,8 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, // construct vector(0,..) auto zeroVal{builder.createIntegerConstant(loc, eleTy, 0)}; auto vZero{ - builder.create<mlir::vector::BroadcastOp>(loc, newVecTy, zeroVal)}; - auto zeroSubVarg1{builder.create<mlir::arith::SubIOp>(loc, vZero, varg1)}; + mlir::vector::BroadcastOp::create(builder, loc, newVecTy, zeroVal)}; + auto zeroSubVarg1{mlir::arith::SubIOp::create(builder, loc, vZero, varg1)}; mlir::func::FuncOp funcOp{nullptr}; switch (eleTy.getWidth()) { @@ -1158,7 +1159,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, funcOp = builder.createFunction(loc, fname, ftype); mlir::Value args[] = {zeroSubVarg1, varg1}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, args)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, args)}; return builder.createConvert(loc, argBases[0].getType(), callOp.getResult(0)); } @@ -1188,21 +1189,21 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( switch (vop) { case VecOp::Add: if (isInteger) - r = builder.create<mlir::arith::AddIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::AddIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::AddFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::AddFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::Mul: if (isInteger) - r = builder.create<mlir::arith::MulIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::MulIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::MulFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::MulFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::Sub: if (isInteger) - r = builder.create<mlir::arith::SubIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::SubIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::SubFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::SubFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::And: case VecOp::Xor: { @@ -1216,16 +1217,16 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( auto wd{mlir::dyn_cast<mlir::FloatType>(vecTyInfo.eleTy).getWidth()}; auto ftype{builder.getIntegerType(wd)}; auto bcVecTy{mlir::VectorType::get(vecTyInfo.len, ftype)}; - arg1 = builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[0]); - arg2 = builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[1]); + arg1 = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[0]); + arg2 = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[1]); } if (vop == VecOp::And) - r = builder.create<mlir::arith::AndIOp>(loc, arg1, arg2); + r = mlir::arith::AndIOp::create(builder, loc, arg1, arg2); else if (vop == VecOp::Xor) - r = builder.create<mlir::arith::XOrIOp>(loc, arg1, arg2); + r = mlir::arith::XOrIOp::create(builder, loc, arg1, arg2); if (isFloat) - r = builder.create<mlir::vector::BitCastOp>(loc, vargs[0].getType(), r); + r = mlir::vector::BitCastOp::create(builder, loc, vargs[0].getType(), r); break; } @@ -1341,7 +1342,7 @@ PPCIntrinsicLibrary::genVecAnyCompare(mlir::Type resultType, assert((!fname.empty() && ftype) && "invalid type"); mlir::func::FuncOp funcOp{builder.createFunction(loc, fname, ftype)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, cmpArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, cmpArgs)}; return callOp.getResult(0); } @@ -1472,7 +1473,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, // arg1 < arg2 --> vcmpgt(arg2, arg1) mlir::Value vargs[]{argBases[argOrder[vop][0]], argBases[argOrder[vop][1]]}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; res = callOp.getResult(0); break; } @@ -1486,14 +1487,15 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, // Construct a constant vector(-1) auto negOneVal{builder.createIntegerConstant( loc, getConvertedElementType(context, eTy), -1)}; - auto vNegOne{builder.create<mlir::vector::BroadcastOp>( - loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; + auto vNegOne{mlir::vector::BroadcastOp::create( + builder, loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; mlir::Value callRes{callOp.getResult(0)}; auto vargs2{ convertVecArgs(builder, loc, vecTyInfo, mlir::ValueRange{callRes})}; - auto xorRes{builder.create<mlir::arith::XOrIOp>(loc, vargs2[0], vNegOne)}; + auto xorRes{ + mlir::arith::XOrIOp::create(builder, loc, vargs2[0], vNegOne)}; res = builder.createConvert(loc, returnType, xorRes); break; @@ -1518,7 +1520,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, default: llvm_unreachable("Invalid vector operation for generator"); } - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; res = callOp.getResult(0); } else llvm_unreachable("invalid vector type"); @@ -1534,13 +1536,13 @@ static inline mlir::Value swapVectorWordPairs(fir::FirOpBuilder &builder, auto vtype{mlir::VectorType::get(16, mlir::IntegerType::get(context, 8))}; if (ty != vtype) - arg = builder.create<mlir::LLVM::BitcastOp>(loc, vtype, arg).getResult(); + arg = mlir::LLVM::BitcastOp::create(builder, loc, vtype, arg).getResult(); llvm::SmallVector<int64_t, 16> mask{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}; - arg = builder.create<mlir::vector::ShuffleOp>(loc, arg, arg, mask); + arg = mlir::vector::ShuffleOp::create(builder, loc, arg, arg, mask); if (ty != vtype) - arg = builder.create<mlir::LLVM::BitcastOp>(loc, ty, arg); + arg = mlir::LLVM::BitcastOp::create(builder, loc, ty, arg); return arg; } @@ -1575,7 +1577,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, : "llvm.ppc.altivec.vcfsx"}; auto funcOp{builder.createFunction(loc, fname, ftype)}; mlir::Value newArgs[] = {argBases[0], convArg}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } else if (width == 64) { @@ -1584,8 +1586,8 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, // vec_vtf(arg1, arg2) = fmul(1.0 / (1 << arg2), llvm.sitofp(arg1)) auto convOp{(isUnsigned) - ? builder.create<mlir::LLVM::UIToFPOp>(loc, ty, vArg1) - : builder.create<mlir::LLVM::SIToFPOp>(loc, ty, vArg1)}; + ? mlir::LLVM::UIToFPOp::create(builder, loc, ty, vArg1) + : mlir::LLVM::SIToFPOp::create(builder, loc, ty, vArg1)}; // construct vector<1./(1<<arg1), 1.0/(1<<arg1)> auto constInt{mlir::dyn_cast_or_null<mlir::IntegerAttr>( @@ -1594,11 +1596,11 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, assert(constInt && "expected integer constant argument"); double f{1.0 / (1 << constInt.getInt())}; llvm::SmallVector<double> vals{f, f}; - auto constOp{builder.create<mlir::arith::ConstantOp>( - loc, ty, builder.getF64VectorAttr(vals))}; + auto constOp{mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getF64VectorAttr(vals))}; - auto mulOp{builder.create<mlir::LLVM::FMulOp>( - loc, ty, convOp->getResult(0), constOp)}; + auto mulOp{mlir::LLVM::FMulOp::create(builder, loc, ty, + convOp->getResult(0), constOp)}; return builder.createConvert(loc, fir::VectorType::get(2, fTy), mulOp); } @@ -1612,7 +1614,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, auto firTy{resTyInfo.toFirVectorType()}; // vec_convert(v, mold) = bitcast v to "type of mold" - auto conv{builder.create<mlir::LLVM::BitcastOp>(loc, moldTy, vArg1)}; + auto conv{mlir::LLVM::BitcastOp::create(builder, loc, moldTy, vArg1)}; return builder.createConvert(loc, firTy, conv); } @@ -1628,7 +1630,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, auto ftype{ genFuncType<Ty::RealVector<8>, Ty::RealVector<4>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } else if (vecTyInfo.isFloat64()) { @@ -1637,7 +1639,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, genFuncType<Ty::RealVector<4>, Ty::RealVector<8>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; newArgs[0] = - builder.create<fir::CallOp>(loc, funcOp, newArgs).getResult(0); + fir::CallOp::create(builder, loc, funcOp, newArgs).getResult(0); auto fvf32Ty{newArgs[0].getType()}; auto f32type{mlir::Float32Type::get(context)}; auto mvf32Ty{mlir::VectorType::get(4, f32type)}; @@ -1661,7 +1663,7 @@ static mlir::Value convertVectorElementOrder(fir::FirOpBuilder &builder, mlir::Value idx) { mlir::Value numSub1{ builder.createIntegerConstant(loc, idx.getType(), vecInfo.len - 1)}; - return builder.create<mlir::LLVM::SubOp>(loc, idx.getType(), numSub1, idx); + return mlir::LLVM::SubOp::create(builder, loc, idx.getType(), numSub1, idx); } // VEC_EXTRACT @@ -1680,12 +1682,14 @@ PPCIntrinsicLibrary::genVecExtract(mlir::Type resultType, // position auto numEle{builder.createIntegerConstant(loc, argTypes[1], vecTyInfo.len)}; mlir::Value uremOp{ - builder.create<mlir::LLVM::URemOp>(loc, argBases[1], numEle)}; + mlir::LLVM::URemOp::create(builder, loc, argBases[1], numEle)}; if (!isNativeVecElemOrderOnLE()) uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp); - return builder.create<mlir::vector::ExtractElementOp>(loc, varg0, uremOp); + mlir::Value index = builder.createOrFold<mlir::index::CastUOp>( + loc, builder.getIndexType(), uremOp); + return mlir::vector::ExtractOp::create(builder, loc, varg0, index); } // VEC_INSERT @@ -1701,14 +1705,16 @@ PPCIntrinsicLibrary::genVecInsert(mlir::Type resultType, auto numEle{builder.createIntegerConstant(loc, argTypes[2], vecTyInfo.len)}; mlir::Value uremOp{ - builder.create<mlir::LLVM::URemOp>(loc, argBases[2], numEle)}; + mlir::LLVM::URemOp::create(builder, loc, argBases[2], numEle)}; if (!isNativeVecElemOrderOnLE()) uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp); - auto res{builder.create<mlir::vector::InsertElementOp>(loc, argBases[0], - varg1, uremOp)}; - return builder.create<fir::ConvertOp>(loc, vecTyInfo.toFirVectorType(), res); + mlir::Value index = builder.createOrFold<mlir::index::CastUOp>( + loc, builder.getIndexType(), uremOp); + mlir::Value res = + mlir::vector::InsertOp::create(builder, loc, argBases[0], varg1, index); + return fir::ConvertOp::create(builder, loc, vecTyInfo.toFirVectorType(), res); } // VEC_MERGEH, VEC_MERGEL @@ -1794,8 +1800,8 @@ PPCIntrinsicLibrary::genVecMerge(mlir::Type resultType, llvm::SmallVector<int64_t, 16> &mergeMask = (isBEVecElemOrderOnLE()) ? rMask : mMask; - auto callOp{builder.create<mlir::vector::ShuffleOp>(loc, vargs[0], vargs[1], - mergeMask)}; + auto callOp{mlir::vector::ShuffleOp::create(builder, loc, vargs[0], vargs[1], + mergeMask)}; return builder.createConvert(loc, resultType, callOp); } @@ -1807,9 +1813,9 @@ static mlir::Value addOffsetToAddress(fir::FirOpBuilder &builder, auto arrRefTy{builder.getRefType(fir::SequenceType::get( {typeExtent}, mlir::IntegerType::get(builder.getContext(), 8)))}; // Convert arg to !fir.ref<!ref.array<?xi8>> - auto resAddr{builder.create<fir::ConvertOp>(loc, arrRefTy, baseAddr)}; + auto resAddr{fir::ConvertOp::create(builder, loc, arrRefTy, baseAddr)}; - return builder.create<fir::CoordinateOp>(loc, arrRefTy, resAddr, offset); + return fir::CoordinateOp::create(builder, loc, arrRefTy, resAddr, offset); } static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder, @@ -1821,8 +1827,8 @@ static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder, for (int64_t i = 0; i < len; ++i) { mask.push_back(len - 1 - i); } - auto undefVec{builder.create<fir::UndefOp>(loc, v.getType())}; - return builder.create<mlir::vector::ShuffleOp>(loc, v, undefVec, mask); + auto undefVec{fir::UndefOp::create(builder, loc, v.getType())}; + return mlir::vector::ShuffleOp::create(builder, loc, v, undefVec, mask); } static mlir::NamedAttribute getAlignmentAttr(fir::FirOpBuilder &builder, @@ -1871,8 +1877,8 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecLdNoCallGrp( const auto triple{fir::getTargetTriple(builder.getModule())}; // Need to get align 1. - auto result{builder.create<fir::LoadOp>(loc, mlirTy, addr, - getAlignmentAttr(builder, 1))}; + auto result{fir::LoadOp::create(builder, loc, mlirTy, addr, + getAlignmentAttr(builder, 1))}; if ((vop == VecOp::Xl && isBEVecElemOrderOnLE()) || (vop == VecOp::Xlbe && triple.isLittleEndian())) return builder.createConvert( @@ -1965,13 +1971,13 @@ PPCIntrinsicLibrary::genVecLdCallGrp(mlir::Type resultType, mlir::FunctionType::get(context, {addr.getType()}, {intrinResTy})}; auto funcOp{builder.createFunction(loc, fname, funcType)}; auto result{ - builder.create<fir::CallOp>(loc, funcOp, parsedArgs).getResult(0)}; + fir::CallOp::create(builder, loc, funcOp, parsedArgs).getResult(0)}; if (vop == VecOp::Lxvp) return result; if (intrinResTy != mlirTy) - result = builder.create<mlir::vector::BitCastOp>(loc, mlirTy, result); + result = mlir::vector::BitCastOp::create(builder, loc, mlirTy, result); if (vop != VecOp::Xld2 && vop != VecOp::Xlw4 && isBEVecElemOrderOnLE()) return builder.createConvert( @@ -1998,13 +2004,13 @@ PPCIntrinsicLibrary::genVecLvsGrp(mlir::Type resultType, // Convert arg0 to i64 type if needed auto i64ty{mlir::IntegerType::get(context, 64)}; if (arg0.getType() != i64ty) - arg0 = builder.create<fir::ConvertOp>(loc, i64ty, arg0); + arg0 = fir::ConvertOp::create(builder, loc, i64ty, arg0); // offset is modulo 16, so shift left 56 bits and then right 56 bits to clear // upper 56 bit while preserving sign auto shiftVal{builder.createIntegerConstant(loc, i64ty, 56)}; - auto offset{builder.create<mlir::arith::ShLIOp>(loc, arg0, shiftVal)}; - auto offset2{builder.create<mlir::arith::ShRSIOp>(loc, offset, shiftVal)}; + auto offset{mlir::arith::ShLIOp::create(builder, loc, arg0, shiftVal)}; + auto offset2{mlir::arith::ShRSIOp::create(builder, loc, offset, shiftVal)}; // Add the offsetArg to %addr of arg1 auto addr{addOffsetToAddress(builder, loc, arg1, offset2)}; @@ -2024,7 +2030,7 @@ PPCIntrinsicLibrary::genVecLvsGrp(mlir::Type resultType, auto funcType{mlir::FunctionType::get(context, {addr.getType()}, {mlirTy})}; auto funcOp{builder.createFunction(loc, fname, funcType)}; auto result{ - builder.create<fir::CallOp>(loc, funcOp, parsedArgs).getResult(0)}; + fir::CallOp::create(builder, loc, funcOp, parsedArgs).getResult(0)}; if (isNativeVecElemOrderOnLE()) return builder.createConvert( @@ -2061,19 +2067,19 @@ PPCIntrinsicLibrary::genVecNmaddMsub(mlir::Type resultType, std::get<1>(fmaMap[width]))}; if (vop == VecOp::Nmadd) { // vec_nmadd(arg1, arg2, arg3) = -fma(arg1, arg2, arg3) - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; // We need to convert fir.vector to MLIR vector to use fneg and then back // to fir.vector to store. auto vCall{builder.createConvert(loc, vTypeInfo.toMlirVectorType(context), callOp.getResult(0))}; - auto neg{builder.create<mlir::arith::NegFOp>(loc, vCall)}; + auto neg{mlir::arith::NegFOp::create(builder, loc, vCall)}; return builder.createConvert(loc, vTypeInfo.toFirVectorType(), neg); } else if (vop == VecOp::Msub) { // vec_msub(arg1, arg2, arg3) = fma(arg1, arg2, -arg3) - newArgs[2] = builder.create<mlir::arith::NegFOp>(loc, newArgs[2]); + newArgs[2] = mlir::arith::NegFOp::create(builder, loc, newArgs[2]); - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } llvm_unreachable("Invalid vector operation for generator"); @@ -2104,10 +2110,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto mMask{builder.createConvert(loc, mlirMaskTy, argBases[2])}; if (mlirTy != vi32Ty) { - mArg0 = - builder.create<mlir::LLVM::BitcastOp>(loc, vi32Ty, mArg0).getResult(); - mArg1 = - builder.create<mlir::LLVM::BitcastOp>(loc, vi32Ty, mArg1).getResult(); + mArg0 = mlir::LLVM::BitcastOp::create(builder, loc, vi32Ty, mArg0) + .getResult(); + mArg1 = mlir::LLVM::BitcastOp::create(builder, loc, vi32Ty, mArg1) + .getResult(); } auto funcOp{builder.createFunction( @@ -2122,23 +2128,23 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto v8Ty{mlir::VectorType::get(16, i8Ty)}; auto negOne{builder.createMinusOneInteger(loc, i8Ty)}; auto vNegOne{ - builder.create<mlir::vector::BroadcastOp>(loc, v8Ty, negOne)}; + mlir::vector::BroadcastOp::create(builder, loc, v8Ty, negOne)}; - mMask = builder.create<mlir::arith::XOrIOp>(loc, mMask, vNegOne); + mMask = mlir::arith::XOrIOp::create(builder, loc, mMask, vNegOne); newArgs = {mArg1, mArg0, mMask}; } else { newArgs = {mArg0, mArg1, mMask}; } - auto res{builder.create<fir::CallOp>(loc, funcOp, newArgs).getResult(0)}; + auto res{fir::CallOp::create(builder, loc, funcOp, newArgs).getResult(0)}; if (res.getType() != argTypes[0]) { // fir.call llvm.ppc.altivec.vperm returns !fir.vector<i4:32> // convert the result back to the original type res = builder.createConvert(loc, vi32Ty, res); if (mlirTy != vi32Ty) - res = - builder.create<mlir::LLVM::BitcastOp>(loc, mlirTy, res).getResult(); + res = mlir::LLVM::BitcastOp::create(builder, loc, mlirTy, res) + .getResult(); } return builder.createConvert(loc, resultType, res); } @@ -2151,10 +2157,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto constInt{constIntOp.getInt()}; // arg1, arg2, and result type share same VecTypeInfo if (vecTyInfo.isFloat()) { - mArg0 = - builder.create<mlir::LLVM::BitcastOp>(loc, vf64Ty, mArg0).getResult(); - mArg1 = - builder.create<mlir::LLVM::BitcastOp>(loc, vf64Ty, mArg1).getResult(); + mArg0 = mlir::LLVM::BitcastOp::create(builder, loc, vf64Ty, mArg0) + .getResult(); + mArg1 = mlir::LLVM::BitcastOp::create(builder, loc, vf64Ty, mArg1) + .getResult(); } llvm::SmallVector<int64_t, 2> nMask; // native vector element order mask @@ -2183,9 +2189,9 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, llvm::SmallVector<int64_t, 2> mask = (isBEVecElemOrderOnLE()) ? rMask : nMask; - auto res{builder.create<mlir::vector::ShuffleOp>(loc, mArg0, mArg1, mask)}; + auto res{mlir::vector::ShuffleOp::create(builder, loc, mArg0, mArg1, mask)}; if (res.getType() != mlirTy) { - auto cast{builder.create<mlir::LLVM::BitcastOp>(loc, mlirTy, res)}; + auto cast{mlir::LLVM::BitcastOp::create(builder, loc, mlirTy, res)}; return builder.createConvert(loc, resultType, cast); } return builder.createConvert(loc, resultType, res); @@ -2212,22 +2218,23 @@ PPCIntrinsicLibrary::genVecSel(mlir::Type resultType, // construct a constant <16 x i8> vector with value -1 for bitcast auto bcVecTy{mlir::VectorType::get(16, i8Ty)}; - auto vNegOne{builder.create<mlir::vector::BroadcastOp>(loc, bcVecTy, negOne)}; + auto vNegOne{ + mlir::vector::BroadcastOp::create(builder, loc, bcVecTy, negOne)}; // bitcast arguments to bcVecTy - auto arg1{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[0])}; - auto arg2{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[1])}; - auto arg3{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[2])}; + auto arg1{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[0])}; + auto arg2{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[1])}; + auto arg3{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[2])}; // vec_sel(arg1, arg2, arg3) = // (arg2 and arg3) or (arg1 and (arg3 xor vector(-1,...))) - auto comp{builder.create<mlir::arith::XOrIOp>(loc, arg3, vNegOne)}; - auto a1AndComp{builder.create<mlir::arith::AndIOp>(loc, arg1, comp)}; - auto a1OrA2{builder.create<mlir::arith::AndIOp>(loc, arg2, arg3)}; - auto res{builder.create<mlir::arith::OrIOp>(loc, a1AndComp, a1OrA2)}; + auto comp{mlir::arith::XOrIOp::create(builder, loc, arg3, vNegOne)}; + auto a1AndComp{mlir::arith::AndIOp::create(builder, loc, arg1, comp)}; + auto a1OrA2{mlir::arith::AndIOp::create(builder, loc, arg2, arg3)}; + auto res{mlir::arith::OrIOp::create(builder, loc, a1AndComp, a1OrA2)}; auto bcRes{ - builder.create<mlir::vector::BitCastOp>(loc, vargs[0].getType(), res)}; + mlir::vector::BitCastOp::create(builder, loc, vargs[0].getType(), res)}; return builder.createConvert(loc, vecTyInfos[0].toFirVectorType(), bcRes); } @@ -2264,14 +2271,14 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto vecVal{builder.createIntegerConstant( loc, getConvertedElementType(context, vecTyInfoArgs[0].eleTy), width)}; auto mask{ - builder.create<mlir::vector::BroadcastOp>(loc, mlirTyArgs[1], vecVal)}; - auto shft{builder.create<mlir::arith::RemUIOp>(loc, mlirVecArgs[1], mask)}; + mlir::vector::BroadcastOp::create(builder, loc, mlirTyArgs[1], vecVal)}; + auto shft{mlir::arith::RemUIOp::create(builder, loc, mlirVecArgs[1], mask)}; mlir::Value res{nullptr}; if (vop == VecOp::Sr) - res = builder.create<mlir::arith::ShRUIOp>(loc, mlirVecArgs[0], shft); + res = mlir::arith::ShRUIOp::create(builder, loc, mlirVecArgs[0], shft); else if (vop == VecOp::Sl) - res = builder.create<mlir::arith::ShLIOp>(loc, mlirVecArgs[0], shft); + res = mlir::arith::ShLIOp::create(builder, loc, mlirVecArgs[0], shft); shftRes = builder.createConvert(loc, argTypes[0], res); } else if (vop == VecOp::Sll || vop == VecOp::Slo || vop == VecOp::Srl || @@ -2281,11 +2288,11 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, // Bitcast to vector<4xi32> auto bcVecTy{mlir::VectorType::get(4, builder.getIntegerType(32))}; if (mlirTyArgs[0] != bcVecTy) - mlirVecArgs[0] = - builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, mlirVecArgs[0]); + mlirVecArgs[0] = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, + mlirVecArgs[0]); if (mlirTyArgs[1] != bcVecTy) - mlirVecArgs[1] = - builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, mlirVecArgs[1]); + mlirVecArgs[1] = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, + mlirVecArgs[1]); llvm::StringRef funcName; switch (vop) { @@ -2307,13 +2314,13 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto funcTy{genFuncType<Ty::IntegerVector<4>, Ty::IntegerVector<4>, Ty::IntegerVector<4>>(context, builder)}; mlir::func::FuncOp funcOp{builder.createFunction(loc, funcName, funcTy)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, mlirVecArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, mlirVecArgs)}; // If the result vector type is different from the original type, need // to convert to mlir vector, bitcast and then convert back to fir vector. if (callOp.getResult(0).getType() != argTypes[0]) { auto res = builder.createConvert(loc, bcVecTy, callOp.getResult(0)); - res = builder.create<mlir::vector::BitCastOp>(loc, mlirTyArgs[0], res); + res = mlir::vector::BitCastOp::create(builder, loc, mlirTyArgs[0], res); shftRes = builder.createConvert(loc, argTypes[0], res); } else { shftRes = callOp.getResult(0); @@ -2329,10 +2336,10 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto vi8Ty{mlir::VectorType::get(16, builder.getIntegerType(8))}; if (mlirTyArgs[0] != vi8Ty) { mlirVecArgs[0] = - builder.create<mlir::LLVM::BitcastOp>(loc, vi8Ty, mlirVecArgs[0]) + mlir::LLVM::BitcastOp::create(builder, loc, vi8Ty, mlirVecArgs[0]) .getResult(); mlirVecArgs[1] = - builder.create<mlir::LLVM::BitcastOp>(loc, vi8Ty, mlirVecArgs[1]) + mlir::LLVM::BitcastOp::create(builder, loc, vi8Ty, mlirVecArgs[1]) .getResult(); } @@ -2347,19 +2354,19 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, if (triple.isLittleEndian()) { for (int i = 16; i < 32; ++i) mask.push_back(i - shiftVal); - shftRes = builder.create<mlir::vector::ShuffleOp>(loc, mlirVecArgs[1], - mlirVecArgs[0], mask); + shftRes = mlir::vector::ShuffleOp::create(builder, loc, mlirVecArgs[1], + mlirVecArgs[0], mask); } else { for (int i = 0; i < 16; ++i) mask.push_back(i + shiftVal); - shftRes = builder.create<mlir::vector::ShuffleOp>(loc, mlirVecArgs[0], - mlirVecArgs[1], mask); + shftRes = mlir::vector::ShuffleOp::create(builder, loc, mlirVecArgs[0], + mlirVecArgs[1], mask); } // Bitcast to the original type if (shftRes.getType() != mlirTyArgs[0]) shftRes = - builder.create<mlir::LLVM::BitcastOp>(loc, mlirTyArgs[0], shftRes); + mlir::LLVM::BitcastOp::create(builder, loc, mlirTyArgs[0], shftRes); return builder.createConvert(loc, resultType, shftRes); } else @@ -2384,8 +2391,9 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, auto vecTyInfo{getVecTypeFromFir(argBases[0])}; auto extractOp{genVecExtract(resultType, args)}; - splatOp = builder.create<mlir::vector::SplatOp>( - loc, *(extractOp.getUnboxed()), vecTyInfo.toMlirVectorType(context)); + splatOp = + mlir::vector::SplatOp::create(builder, loc, *(extractOp.getUnboxed()), + vecTyInfo.toMlirVectorType(context)); retTy = vecTyInfo.toFirVectorType(); break; } @@ -2393,8 +2401,8 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, assert(args.size() == 1); auto vecTyInfo{getVecTypeFromEle(argBases[0])}; - splatOp = builder.create<mlir::vector::SplatOp>( - loc, argBases[0], vecTyInfo.toMlirVectorType(context)); + splatOp = mlir::vector::SplatOp::create( + builder, loc, argBases[0], vecTyInfo.toMlirVectorType(context)); retTy = vecTyInfo.toFirVectorType(); break; } @@ -2404,8 +2412,8 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, auto intOp{builder.createConvert(loc, eleTy, argBases[0])}; // the intrinsic always returns vector(integer(4)) - splatOp = builder.create<mlir::vector::SplatOp>( - loc, intOp, mlir::VectorType::get(4, eleTy)); + splatOp = mlir::vector::SplatOp::create(builder, loc, intOp, + mlir::VectorType::get(4, eleTy)); retTy = fir::VectorType::get(4, eleTy); break; } @@ -2433,14 +2441,14 @@ PPCIntrinsicLibrary::genVecXlds(mlir::Type resultType, auto i64Ty{mlir::IntegerType::get(builder.getContext(), 64)}; auto i64VecTy{mlir::VectorType::get(2, i64Ty)}; auto i64RefTy{builder.getRefType(i64Ty)}; - auto addrConv{builder.create<fir::ConvertOp>(loc, i64RefTy, addr)}; + auto addrConv{fir::ConvertOp::create(builder, loc, i64RefTy, addr)}; - auto addrVal{builder.create<fir::LoadOp>(loc, addrConv)}; - auto splatRes{builder.create<mlir::vector::SplatOp>(loc, addrVal, i64VecTy)}; + auto addrVal{fir::LoadOp::create(builder, loc, addrConv)}; + auto splatRes{mlir::vector::SplatOp::create(builder, loc, addrVal, i64VecTy)}; mlir::Value result{nullptr}; if (mlirTy != splatRes.getType()) { - result = builder.create<mlir::vector::BitCastOp>(loc, mlirTy, splatRes); + result = mlir::vector::BitCastOp::create(builder, loc, mlirTy, splatRes); } else result = splatRes; @@ -2790,7 +2798,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { if (i == 0 && HandlerOp == MMAHandlerOp::FirstArgIsResult) { // First argument is passed in as an address. We need to load // the content to match the LLVM interface. - v = builder.create<fir::LoadOp>(loc, v); + v = fir::LoadOp::create(builder, loc, v); } auto vType{v.getType()}; mlir::Type targetType{intrFuncType.getInput(j)}; @@ -2801,7 +2809,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { auto len{mlir::dyn_cast<fir::VectorType>(vType).getLen()}; mlir::VectorType mlirType = mlir::VectorType::get(len, eleTy); auto v0{builder.createConvert(loc, mlirType, v)}; - auto v1{builder.create<mlir::vector::BitCastOp>(loc, targetType, v0)}; + auto v1{mlir::vector::BitCastOp::create(builder, loc, targetType, v0)}; intrArgs.push_back(v1); } else if (mlir::isa<mlir::IntegerType>(targetType) && mlir::isa<mlir::IntegerType>(vType)) { @@ -2817,7 +2825,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { intrArgs.push_back(v); } } - auto callSt{builder.create<fir::CallOp>(loc, funcOp, intrArgs)}; + auto callSt{fir::CallOp::create(builder, loc, funcOp, intrArgs)}; if (HandlerOp == MMAHandlerOp::SubToFunc || HandlerOp == MMAHandlerOp::SubToFuncReverseArgOnLE || HandlerOp == MMAHandlerOp::FirstArgIsResult) { @@ -2826,10 +2834,11 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value destPtr{fir::getBase(args[0])}; mlir::Type callResultPtrType{builder.getRefType(callResult.getType())}; if (destPtr.getType() != callResultPtrType) { - destPtr = builder.create<fir::ConvertOp>(loc, callResultPtrType, destPtr); + destPtr = + fir::ConvertOp::create(builder, loc, callResultPtrType, destPtr); } // Copy the result. - builder.create<fir::StoreOp>(loc, callResult, destPtr); + fir::StoreOp::create(builder, loc, callResult, destPtr); } } @@ -2896,7 +2905,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { if (vop == VecOp::Stxvp) { biArgs.push_back(argBases[0]); biArgs.push_back(addr); - builder.create<fir::CallOp>(loc, funcOp, biArgs); + fir::CallOp::create(builder, loc, funcOp, biArgs); return; } @@ -2906,7 +2915,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value newArg1{nullptr}; if (stTy != arg1TyInfo.toMlirVectorType(context)) - newArg1 = builder.create<mlir::vector::BitCastOp>(loc, stTy, cnv); + newArg1 = mlir::vector::BitCastOp::create(builder, loc, stTy, cnv); else newArg1 = cnv; @@ -2917,7 +2926,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { biArgs.push_back(newArg1); biArgs.push_back(addr); - builder.create<fir::CallOp>(loc, funcOp, biArgs); + fir::CallOp::create(builder, loc, funcOp, biArgs); } // VEC_XST, VEC_XST_BE, VEC_STXV, VEC_XSTD2, VEC_XSTW4 @@ -2966,7 +2975,7 @@ void PPCIntrinsicLibrary::genVecXStore( mlir::Type srcTy{nullptr}; if (numElem != arg1TyInfo.len) { - cnv = builder.create<mlir::vector::BitCastOp>(loc, mlirVecTy, cnv); + cnv = mlir::vector::BitCastOp::create(builder, loc, mlirVecTy, cnv); srcTy = firVecTy; } else { srcTy = arg1TyInfo.toFirVectorType(); @@ -2989,9 +2998,9 @@ void PPCIntrinsicLibrary::genVecXStore( default: assert(false && "Invalid vector operation for generator"); } - builder.create<fir::StoreOp>(loc, mlir::TypeRange{}, - mlir::ValueRange{src, trg}, - getAlignmentAttr(builder, 1)); + fir::StoreOp::create(builder, loc, mlir::TypeRange{}, + mlir::ValueRange{src, trg}, + getAlignmentAttr(builder, 1)); } } // namespace fir diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp index cd5f1f6..cc9f828 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -30,7 +30,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder, mlir::dyn_cast<fir::ClassType>(fir::dyn_cast_ptrEleTy(from.getType())); mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy()); declaredTypeDesc = - builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(derivedType)); + fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(derivedType)); } else { declaredTypeDesc = builder.createNullConstant(loc); } @@ -38,7 +38,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder, builder, loc, fTy, to, from, declaredTypeDesc, hasStat, errMsg, sourceFile, sourceLine)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genAllocatableApplyMold(fir::FirOpBuilder &builder, @@ -52,7 +52,7 @@ void fir::runtime::genAllocatableApplyMold(fir::FirOpBuilder &builder, builder.createIntegerConstant(loc, fTy.getInput(2), rank); llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, mold, rankVal)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAllocatableSetBounds(fir::FirOpBuilder &builder, @@ -66,7 +66,7 @@ void fir::runtime::genAllocatableSetBounds(fir::FirOpBuilder &builder, mlir::FunctionType fTy{func.getFunctionType()}; llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, dimIndex, lowerBound, upperBound)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAllocatableAllocate(fir::FirOpBuilder &builder, @@ -84,10 +84,10 @@ void fir::runtime::genAllocatableAllocate(fir::FirOpBuilder &builder, hasStat = builder.createBool(loc, false); if (!errMsg) { mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); - errMsg = builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + errMsg = fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); } llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, asyncObject, hasStat, errMsg, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index 0d56cd2..8c9825e 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -50,7 +50,7 @@ mlir::Value fir::runtime::genInitArrayConstructorVector( auto args = fir::runtime::createArguments(builder, loc, funcType, cookie, toBox, useValueLengthParameters, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return cookie; } @@ -63,7 +63,7 @@ void fir::runtime::genPushArrayConstructorValue( mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, arrayConstructorVector, fromBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genPushArrayConstructorSimpleScalar( @@ -75,5 +75,5 @@ void fir::runtime::genPushArrayConstructorSimpleScalar( mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments( builder, loc, funcType, arrayConstructorVector, fromAddress); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Assign.cpp b/flang/lib/Optimizer/Builder/Runtime/Assign.cpp index 62f03f7..336dbdc 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Assign.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Assign.cpp @@ -22,7 +22,7 @@ void fir::runtime::genAssign(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignPolymorphic(fir::FirOpBuilder &builder, @@ -36,7 +36,7 @@ void fir::runtime::genAssignPolymorphic(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignExplicitLengthCharacter(fir::FirOpBuilder &builder, @@ -52,7 +52,7 @@ void fir::runtime::genAssignExplicitLengthCharacter(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignTemporary(fir::FirOpBuilder &builder, @@ -66,7 +66,7 @@ void fir::runtime::genAssignTemporary(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genCopyInAssign(fir::FirOpBuilder &builder, @@ -79,7 +79,7 @@ void fir::runtime::genCopyInAssign(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genCopyOutAssign(fir::FirOpBuilder &builder, @@ -93,5 +93,5 @@ void fir::runtime::genCopyOutAssign(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp b/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp index 62a0652..a6ee986 100644 --- a/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp @@ -30,7 +30,7 @@ void fir::runtime::cuda::genSyncGlobalDescriptor(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, hostPtr, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } void fir::runtime::cuda::genDescriptorCheckSection(fir::FirOpBuilder &builder, @@ -45,7 +45,7 @@ void fir::runtime::cuda::genDescriptorCheckSection(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::cuda::genSetAllocatorIndex(fir::FirOpBuilder &builder, @@ -60,5 +60,5 @@ void fir::runtime::cuda::genSetAllocatorIndex(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, index, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Character.cpp b/flang/lib/Optimizer/Builder/Runtime/Character.cpp index b168199..57fb0cc 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Character.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Character.cpp @@ -34,7 +34,7 @@ static void genCharacterSearch(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, string1Box, string2Box, backBox, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Helper function to recover the KIND from the FIR type. @@ -72,7 +72,7 @@ static void genAdjust(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, stringBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, adjustFunc, args); + fir::CallOp::create(builder, loc, adjustFunc, args); } void fir::runtime::genAdjustL(fir::FirOpBuilder &builder, mlir::Location loc, @@ -114,9 +114,9 @@ fir::runtime::genCharCompare(fir::FirOpBuilder &builder, mlir::Location loc, auto fTy = beginFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, lhsBuff, rhsBuff, lhsLen, rhsLen); - auto tri = builder.create<fir::CallOp>(loc, beginFunc, args).getResult(0); + auto tri = fir::CallOp::create(builder, loc, beginFunc, args).getResult(0); auto zero = builder.createIntegerConstant(loc, tri.getType(), 0); - return builder.create<mlir::arith::CmpIOp>(loc, cmp, tri, zero); + return mlir::arith::CmpIOp::create(builder, loc, cmp, tri, zero); } mlir::Value fir::runtime::genCharCompare(fir::FirOpBuilder &builder, @@ -130,8 +130,8 @@ mlir::Value fir::runtime::genCharCompare(fir::FirOpBuilder &builder, if (fir::isa_ref_type(base.getType())) return base; auto mem = - builder.create<fir::AllocaOp>(loc, base.getType(), /*pinned=*/false); - builder.create<fir::StoreOp>(loc, base, mem); + fir::AllocaOp::create(builder, loc, base.getType(), /*pinned=*/false); + fir::StoreOp::create(builder, loc, base, mem); return mem; }; auto lhsBuffer = allocateIfNotInMemory(fir::getBase(lhs)); @@ -165,7 +165,7 @@ mlir::Value fir::runtime::genIndex(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, substringBase, substringLen, back); - return builder.create<fir::CallOp>(loc, indexFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, indexFunc, args).getResult(0); } void fir::runtime::genIndexDescriptor(fir::FirOpBuilder &builder, @@ -189,7 +189,7 @@ void fir::runtime::genRepeat(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, stringBox, ncopies, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, repeatFunc, args); + fir::CallOp::create(builder, loc, repeatFunc, args); } void fir::runtime::genTrim(fir::FirOpBuilder &builder, mlir::Location loc, @@ -202,7 +202,7 @@ void fir::runtime::genTrim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, stringBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, trimFunc, args); + fir::CallOp::create(builder, loc, trimFunc, args); } void fir::runtime::genScanDescriptor(fir::FirOpBuilder &builder, @@ -237,7 +237,7 @@ mlir::Value fir::runtime::genScan(fir::FirOpBuilder &builder, auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, setBase, setLen, back); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genVerifyDescriptor(fir::FirOpBuilder &builder, @@ -274,5 +274,5 @@ mlir::Value fir::runtime::genVerify(fir::FirOpBuilder &builder, auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, setBase, setLen, back); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Command.cpp b/flang/lib/Optimizer/Builder/Runtime/Command.cpp index 35aa529..e65e2b6d 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Command.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Command.cpp @@ -30,7 +30,7 @@ mlir::Value fir::runtime::genCommandArgumentCount(fir::FirOpBuilder &builder, mlir::Location loc) { auto argumentCountFunc = fir::runtime::getRuntimeFunc<mkRTKey(ArgumentCount)>(loc, builder); - return builder.create<fir::CallOp>(loc, argumentCountFunc).getResult(0); + return fir::CallOp::create(builder, loc, argumentCountFunc).getResult(0); } mlir::Value fir::runtime::genGetCommand(fir::FirOpBuilder &builder, @@ -46,7 +46,7 @@ mlir::Value fir::runtime::genGetCommand(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, command, length, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder, @@ -54,7 +54,7 @@ mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetPID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genGetCommandArgument( @@ -69,7 +69,7 @@ mlir::Value fir::runtime::genGetCommandArgument( llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, number, value, length, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetEnvVariable(fir::FirOpBuilder &builder, @@ -87,7 +87,7 @@ mlir::Value fir::runtime::genGetEnvVariable(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, name, value, length, trimName, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetCwd(fir::FirOpBuilder &builder, @@ -100,7 +100,7 @@ mlir::Value fir::runtime::genGetCwd(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, cwd, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genHostnm(fir::FirOpBuilder &builder, @@ -113,7 +113,7 @@ mlir::Value fir::runtime::genHostnm(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, res, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPerror(fir::FirOpBuilder &builder, mlir::Location loc, @@ -123,7 +123,7 @@ void fir::runtime::genPerror(fir::FirOpBuilder &builder, mlir::Location loc, mlir::FunctionType runtimeFuncTy = runtimeFunc.getFunctionType(); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, string); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } mlir::Value fir::runtime::genPutEnv(fir::FirOpBuilder &builder, @@ -137,7 +137,7 @@ mlir::Value fir::runtime::genPutEnv(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(1)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, str, strLength, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genUnlink(fir::FirOpBuilder &builder, @@ -151,5 +151,5 @@ mlir::Value fir::runtime::genUnlink(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(1)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, path, pathLength, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Derived.cpp b/flang/lib/Optimizer/Builder/Runtime/Derived.cpp index 25b4151..1b0457b 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Derived.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Derived.cpp @@ -26,7 +26,7 @@ void fir::runtime::genDerivedTypeInitialize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeInitializeClone(fir::FirOpBuilder &builder, @@ -41,7 +41,7 @@ void fir::runtime::genDerivedTypeInitializeClone(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, newBox, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeDestroy(fir::FirOpBuilder &builder, @@ -49,7 +49,7 @@ void fir::runtime::genDerivedTypeDestroy(fir::FirOpBuilder &builder, auto func = fir::runtime::getRuntimeFunc<mkRTKey(Destroy)>(loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeFinalize(fir::FirOpBuilder &builder, @@ -61,7 +61,7 @@ void fir::runtime::genDerivedTypeFinalize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeDestroyWithoutFinalization( @@ -70,7 +70,7 @@ void fir::runtime::genDerivedTypeDestroyWithoutFinalization( loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, @@ -78,7 +78,7 @@ void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, fir::RecordType derivedType, unsigned rank) { mlir::Value typeDesc = - builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(derivedType)); + fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(derivedType)); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(PointerNullifyDerived)>(loc, builder); @@ -90,7 +90,7 @@ void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, mlir::Value c0 = builder.createIntegerConstant(loc, inputTypes[3], 0); args.push_back(rankCst); args.push_back(c0); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } mlir::Value fir::runtime::genSameTypeAs(fir::FirOpBuilder &builder, @@ -100,7 +100,7 @@ mlir::Value fir::runtime::genSameTypeAs(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(SameTypeAs)>(loc, builder); auto fTy = sameTypeAsFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, a, b); - return builder.create<fir::CallOp>(loc, sameTypeAsFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sameTypeAsFunc, args).getResult(0); } mlir::Value fir::runtime::genExtendsTypeOf(fir::FirOpBuilder &builder, @@ -110,5 +110,6 @@ mlir::Value fir::runtime::genExtendsTypeOf(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(ExtendsTypeOf)>(loc, builder); auto fTy = extendsTypeOfFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, a, mold); - return builder.create<fir::CallOp>(loc, extendsTypeOfFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, extendsTypeOfFunc, args) + .getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp b/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp index bf5fd6a..fa3d00e 100755 --- a/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp @@ -44,7 +44,7 @@ mlir::Value fir::runtime::genEnvironmentDefaults( mlir::IntegerAttr one = builder.getIntegerAttr(idxTy, 1); std::string itemListName = envDefaultListPtrName + ".items"; auto listBuilder = [&](fir::FirOpBuilder &builder) { - mlir::Value list = builder.create<fir::UndefOp>(loc, itemListTy); + mlir::Value list = fir::UndefOp::create(builder, loc, itemListTy); llvm::SmallVector<mlir::Attribute, 2> idx = {mlir::Attribute{}, mlir::Attribute{}}; auto insertStringField = [&](const std::string &s, @@ -52,8 +52,8 @@ mlir::Value fir::runtime::genEnvironmentDefaults( mlir::Value stringAddress = fir::getBase( fir::factory::createStringLiteral(builder, loc, s + '\0')); mlir::Value addr = builder.createConvert(loc, charRefTy, stringAddress); - return builder.create<fir::InsertValueOp>(loc, itemListTy, list, addr, - builder.getArrayAttr(idx)); + return fir::InsertValueOp::create(builder, loc, itemListTy, list, addr, + builder.getArrayAttr(idx)); }; size_t n = 0; @@ -65,7 +65,7 @@ mlir::Value fir::runtime::genEnvironmentDefaults( list = insertStringField(def.defaultValue, idx); ++n; } - builder.create<fir::HasValueOp>(loc, list); + fir::HasValueOp::create(builder, loc, list); }; builder.createGlobalConstant(loc, itemListTy, itemListName, listBuilder, linkOnce); @@ -73,27 +73,27 @@ mlir::Value fir::runtime::genEnvironmentDefaults( // Define the EnviornmentDefaultList object. auto envDefaultListBuilder = [&](fir::FirOpBuilder &builder) { mlir::Value envDefaultList = - builder.create<fir::UndefOp>(loc, envDefaultListTy); + fir::UndefOp::create(builder, loc, envDefaultListTy); mlir::Value numItems = builder.createIntegerConstant(loc, intTy, envDefaults.size()); - envDefaultList = builder.create<fir::InsertValueOp>( - loc, envDefaultListTy, envDefaultList, numItems, - builder.getArrayAttr(zero)); + envDefaultList = fir::InsertValueOp::create(builder, loc, envDefaultListTy, + envDefaultList, numItems, + builder.getArrayAttr(zero)); fir::GlobalOp itemList = builder.getNamedGlobal(itemListName); assert(itemList && "missing environment default list"); - mlir::Value listAddr = builder.create<fir::AddrOfOp>( - loc, itemList.resultType(), itemList.getSymbol()); - envDefaultList = builder.create<fir::InsertValueOp>( - loc, envDefaultListTy, envDefaultList, listAddr, - builder.getArrayAttr(one)); - builder.create<fir::HasValueOp>(loc, envDefaultList); + mlir::Value listAddr = fir::AddrOfOp::create( + builder, loc, itemList.resultType(), itemList.getSymbol()); + envDefaultList = fir::InsertValueOp::create(builder, loc, envDefaultListTy, + envDefaultList, listAddr, + builder.getArrayAttr(one)); + fir::HasValueOp::create(builder, loc, envDefaultList); }; fir::GlobalOp envDefaultList = builder.createGlobalConstant( loc, envDefaultListTy, envDefaultListPtrName + ".list", envDefaultListBuilder, linkOnce); // Define the pointer to the list used by the runtime. - mlir::Value addr = builder.create<fir::AddrOfOp>( - loc, envDefaultList.resultType(), envDefaultList.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, envDefaultList.resultType(), envDefaultList.getSymbol()); return addr; } diff --git a/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp b/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp index 0f66315..0256644 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp @@ -18,21 +18,21 @@ mlir::Value fir::runtime::genMapExcept(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(MapException)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } void fir::runtime::genFeclearexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feclearexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } void fir::runtime::genFeraiseexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feraiseexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } mlir::Value fir::runtime::genFetestexcept(fir::FirOpBuilder &builder, @@ -40,28 +40,28 @@ mlir::Value fir::runtime::genFetestexcept(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fetestexcept)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } void fir::runtime::genFedisableexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fedisableexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } void fir::runtime::genFeenableexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feenableexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } mlir::Value fir::runtime::genFegetexcept(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fegetexcept)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } mlir::Value fir::runtime::genSupportHalting(fir::FirOpBuilder &builder, @@ -69,33 +69,33 @@ mlir::Value fir::runtime::genSupportHalting(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(SupportHalting)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } mlir::Value fir::runtime::genGetUnderflowMode(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetUnderflowMode)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } void fir::runtime::genSetUnderflowMode(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value flag) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(SetUnderflowMode)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, flag); + fir::CallOp::create(builder, loc, func, flag); } mlir::Value fir::runtime::genGetModesTypeSize(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetModesTypeSize)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } mlir::Value fir::runtime::genGetStatusTypeSize(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetStatusTypeSize)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Execute.cpp b/flang/lib/Optimizer/Builder/Runtime/Execute.cpp index 71ee399..2f85fb4 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Execute.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Execute.cpp @@ -40,5 +40,5 @@ void fir::runtime::genExecuteCommandLine(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, command, wait, exitstat, cmdstat, cmdmsg, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp b/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp index 718c353..5e3f022 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp @@ -26,7 +26,7 @@ mlir::Value fir::runtime::genLboundDim(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, lboundFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, lboundFunc, args).getResult(0); } void fir::runtime::genLbound(fir::FirOpBuilder &builder, mlir::Location loc, @@ -40,7 +40,7 @@ void fir::runtime::genLbound(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultAddr, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Ubound` runtime routine. Calls to UBOUND with a DIM @@ -57,7 +57,7 @@ void fir::runtime::genUbound(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, uboundFunc, args); + fir::CallOp::create(builder, loc, uboundFunc, args); } /// Generate call to `Size` runtime routine. This routine is a version when @@ -73,7 +73,7 @@ mlir::Value fir::runtime::genSizeDim(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, sizeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sizeFunc, args).getResult(0); } /// Generate call to `Size` runtime routine. This routine is a version when @@ -88,7 +88,7 @@ mlir::Value fir::runtime::genSize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, sizeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sizeFunc, args).getResult(0); } /// Generate call to `IsContiguous` runtime routine. @@ -99,7 +99,7 @@ mlir::Value fir::runtime::genIsContiguous(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsContiguous)>(loc, builder); auto fTy = isContiguousFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, array); - return builder.create<fir::CallOp>(loc, isContiguousFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, isContiguousFunc, args).getResult(0); } /// Generate call to `IsContiguousUpTo` runtime routine. @@ -111,7 +111,7 @@ mlir::Value fir::runtime::genIsContiguousUpTo(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsContiguousUpTo)>(loc, builder); auto fTy = isContiguousFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim); - return builder.create<fir::CallOp>(loc, isContiguousFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, isContiguousFunc, args).getResult(0); } void fir::runtime::genShape(fir::FirOpBuilder &builder, mlir::Location loc, @@ -125,5 +125,5 @@ void fir::runtime::genShape(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultAddr, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp index 773d640..4b4954a 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp @@ -52,14 +52,15 @@ mlir::Value fir::runtime::genAssociated(fir::FirOpBuilder &builder, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), pointer, target); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genCpuTime(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey(CpuTime)>(loc, builder); - return builder.create<fir::CallOp>(loc, func, std::nullopt).getResult(0); + return fir::CallOp::create(builder, loc, func, mlir::ValueRange{}) + .getResult(0); } void fir::runtime::genDateAndTime(fir::FirOpBuilder &builder, @@ -102,7 +103,7 @@ void fir::runtime::genDateAndTime(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, dateBuffer, dateLen, timeBuffer, timeLen, zoneBuffer, zoneLen, sourceFile, sourceLine, values); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc, @@ -116,7 +117,7 @@ void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, values, time, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } void fir::runtime::genFree(fir::FirOpBuilder &builder, mlir::Location loc, @@ -124,8 +125,8 @@ void fir::runtime::genFree(fir::FirOpBuilder &builder, mlir::Location loc, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(Free)>(loc, builder); mlir::Type intPtrTy = builder.getIntPtrType(); - builder.create<fir::CallOp>(loc, runtimeFunc, - builder.createConvert(loc, intPtrTy, ptr)); + fir::CallOp::create(builder, loc, runtimeFunc, + builder.createConvert(loc, intPtrTy, ptr)); } mlir::Value fir::runtime::genFseek(fir::FirOpBuilder &builder, @@ -139,7 +140,7 @@ mlir::Value fir::runtime::genFseek(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, unit, offset, whence, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); ; } @@ -149,7 +150,7 @@ mlir::Value fir::runtime::genFtell(fir::FirOpBuilder &builder, mlir::FunctionType runtimeFuncTy = runtimeFunc.getFunctionType(); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, unit); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder, @@ -157,7 +158,7 @@ mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetGID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder, @@ -165,7 +166,7 @@ mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetUID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genMalloc(fir::FirOpBuilder &builder, @@ -186,7 +187,7 @@ void fir::runtime::genRandomInit(fir::FirOpBuilder &builder, mlir::Location loc, fir::runtime::getRuntimeFunc<mkRTKey(RandomInit)>(loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), repeatable, imageDistinct); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genRandomNumber(fir::FirOpBuilder &builder, @@ -206,7 +207,7 @@ void fir::runtime::genRandomNumber(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, harvest, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, @@ -223,7 +224,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, if (staticArgCount == 0) { func = fir::runtime::getRuntimeFunc<mkRTKey(RandomSeedDefaultPut)>(loc, builder); - builder.create<fir::CallOp>(loc, func); + fir::CallOp::create(builder, loc, func); return; } mlir::FunctionType funcTy; @@ -238,7 +239,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcTy.getInput(4)); args = fir::runtime::createArguments(builder, loc, funcTy, size, put, get, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return; } if (sizeIsPresent) { @@ -255,7 +256,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, sourceLine = fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2)); args = fir::runtime::createArguments(builder, loc, funcTy, argBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate rename runtime call @@ -273,14 +274,15 @@ void fir::runtime::genRename(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, path1, path2, status, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } /// generate runtime call to time intrinsic mlir::Value fir::runtime::genTime(fir::FirOpBuilder &builder, mlir::Location loc) { auto func = fir::runtime::getRuntimeFunc<mkRTKey(time)>(loc, builder); - return builder.create<fir::CallOp>(loc, func, std::nullopt).getResult(0); + return fir::CallOp::create(builder, loc, func, mlir::ValueRange{}) + .getResult(0); } /// generate runtime call to transfer intrinsic with no size argument @@ -296,7 +298,7 @@ void fir::runtime::genTransfer(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, fTy, resultBox, sourceBox, moldBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate runtime call to transfer intrinsic with size argument @@ -313,7 +315,7 @@ void fir::runtime::genTransferSize(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, moldBox, sourceFile, sourceLine, size); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate system_clock runtime call/s @@ -330,11 +332,12 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, mlir::dyn_cast<fir::HeapType>(type)) { // Check for a disassociated pointer or an unallocated allocatable. assert(!isOptionalArg && "invalid optional argument"); - ifOp = builder.create<fir::IfOp>(loc, builder.genIsNotNullAddr(loc, arg), - /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, builder.genIsNotNullAddr(loc, arg), + /*withElseRegion=*/false); } else if (isOptionalArg) { - ifOp = builder.create<fir::IfOp>( - loc, builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), arg), + ifOp = fir::IfOp::create( + builder, loc, + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), arg), /*withElseRegion=*/false); } if (ifOp) @@ -346,11 +349,11 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, integerKind = intType.getWidth() / 8; mlir::Value kind = builder.createIntegerConstant(loc, kindTy, integerKind); mlir::Value res = - builder.create<fir::CallOp>(loc, func, mlir::ValueRange{kind}) + fir::CallOp::create(builder, loc, func, mlir::ValueRange{kind}) .getResult(0); mlir::Value castRes = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(type), res); - builder.create<fir::StoreOp>(loc, castRes, arg); + fir::StoreOp::create(builder, loc, castRes, arg); if (ifOp) builder.setInsertionPointAfter(ifOp); }; @@ -371,24 +374,24 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value status) { assert(mlir::isa<mlir::IntegerType>(number.getType())); mlir::Type int64 = builder.getIntegerType(64); - number = builder.create<fir::ConvertOp>(loc, int64, number); + number = fir::ConvertOp::create(builder, loc, int64, number); mlir::Type handlerUnwrappedTy = fir::unwrapRefType(handler.getType()); if (mlir::isa_and_nonnull<mlir::IntegerType>(handlerUnwrappedTy)) { // pass the integer as a function pointer like one would to signal(2) - handler = builder.create<fir::LoadOp>(loc, handler); + handler = fir::LoadOp::create(builder, loc, handler); mlir::Type fnPtrTy = fir::LLVMPointerType::get( mlir::FunctionType::get(handler.getContext(), {}, {})); - handler = builder.create<fir::ConvertOp>(loc, fnPtrTy, handler); + handler = fir::ConvertOp::create(builder, loc, fnPtrTy, handler); } else { assert(mlir::isa<fir::BoxProcType>(handler.getType())); - handler = builder.create<fir::BoxAddrOp>(loc, handler); + handler = fir::BoxAddrOp::create(builder, loc, handler); } mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(Signal)>(loc, builder)}; mlir::Value stat = - builder.create<fir::CallOp>(loc, func, mlir::ValueRange{number, handler}) + fir::CallOp::create(builder, loc, func, mlir::ValueRange{number, handler}) ->getResult(0); // return status code via status argument (if present) @@ -396,12 +399,12 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, assert(mlir::isa<mlir::IntegerType>(fir::unwrapRefType(status.getType()))); // status might be dynamically optional, so test if it is present mlir::Value isPresent = - builder.create<IsPresentOp>(loc, builder.getI1Type(), status); + IsPresentOp::create(builder, loc, builder.getI1Type(), status); builder.genIfOp(loc, /*results=*/{}, isPresent, /*withElseRegion=*/false) .genThen([&]() { - stat = builder.create<fir::ConvertOp>( - loc, fir::unwrapRefType(status.getType()), stat); - builder.create<fir::StoreOp>(loc, stat, status); + stat = fir::ConvertOp::create( + builder, loc, fir::unwrapRefType(status.getType()), stat); + fir::StoreOp::create(builder, loc, stat, status); }) .end(); } @@ -410,10 +413,10 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, void fir::runtime::genSleep(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value seconds) { mlir::Type int64 = builder.getIntegerType(64); - seconds = builder.create<fir::ConvertOp>(loc, int64, seconds); + seconds = fir::ConvertOp::create(builder, loc, int64, seconds); mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(Sleep)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, seconds); + fir::CallOp::create(builder, loc, func, seconds); } /// generate chdir runtime call @@ -423,5 +426,5 @@ mlir::Value fir::runtime::genChdir(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(Chdir)>(loc, builder)}; llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, func.getFunctionType(), name); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Main.cpp b/flang/lib/Optimizer/Builder/Runtime/Main.cpp index 9737448..d35f687 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Main.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Main.cpp @@ -62,17 +62,17 @@ void fir::runtime::genMain( llvm::SmallVector<mlir::Value, 4> args(block->getArguments()); args.push_back(env); - builder.create<fir::CallOp>(loc, startFn, args); + fir::CallOp::create(builder, loc, startFn, args); if (initCuda) { auto initFn = builder.createFunction( loc, RTNAME_STRING(CUFInit), mlir::FunctionType::get(context, {}, {})); - builder.create<fir::CallOp>(loc, initFn); + fir::CallOp::create(builder, loc, initFn); } - builder.create<fir::CallOp>(loc, qqMainFn); - builder.create<fir::CallOp>(loc, stopFn); + fir::CallOp::create(builder, loc, qqMainFn); + fir::CallOp::create(builder, loc, stopFn); mlir::Value ret = builder.createIntegerConstant(loc, argcTy, 0); - builder.create<mlir::func::ReturnOp>(loc, ret); + mlir::func::ReturnOp::create(builder, loc, ret); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp index 4ff7c86..62d5e50 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp @@ -317,7 +317,7 @@ mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Fraction intrinsic runtime routine. @@ -340,7 +340,7 @@ mlir::Value fir::runtime::genFraction(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Mod intrinsic runtime routine. @@ -370,7 +370,7 @@ mlir::Value fir::runtime::genMod(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, funcTy, a, p, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Modulo intrinsic runtime routine. @@ -403,7 +403,7 @@ mlir::Value fir::runtime::genModulo(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, funcTy, a, p, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Nearest intrinsic or a "Next" intrinsic module procedure. @@ -427,7 +427,7 @@ mlir::Value fir::runtime::genNearest(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, valueUp); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to RRSpacing intrinsic runtime routine. @@ -451,7 +451,7 @@ mlir::Value fir::runtime::genRRSpacing(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to ErfcScaled intrinsic runtime routine. @@ -475,7 +475,7 @@ mlir::Value fir::runtime::genErfcScaled(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Scale intrinsic runtime routine. @@ -499,7 +499,7 @@ mlir::Value fir::runtime::genScale(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_char_kind intrinsic runtime routine. @@ -519,7 +519,7 @@ mlir::Value fir::runtime::genSelectedCharKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, name, length); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_int_kind intrinsic runtime routine. @@ -540,7 +540,7 @@ mlir::Value fir::runtime::genSelectedIntKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, x, xKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_logical_kind intrinsic runtime routine. @@ -561,7 +561,7 @@ mlir::Value fir::runtime::genSelectedLogicalKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, x, xKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_real_kind intrinsic runtime routine. @@ -593,7 +593,7 @@ mlir::Value fir::runtime::genSelectedRealKind(fir::FirOpBuilder &builder, sourceLine, precision, pKind, range, rKind, radix, dKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Set_exponent intrinsic runtime routine. @@ -617,7 +617,7 @@ mlir::Value fir::runtime::genSetExponent(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Spacing intrinsic runtime routine. @@ -649,6 +649,6 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - mlir::Value res = builder.create<fir::CallOp>(loc, func, args).getResult(0); + mlir::Value res = fir::CallOp::create(builder, loc, func, args).getResult(0); return builder.createConvert(loc, fltTy, res); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp b/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp index 160c651..c03ff58 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp @@ -23,5 +23,5 @@ void fir::runtime::genPointerAssociateScalar(fir::FirOpBuilder &builder, mlir::FunctionType fTy{func.getFunctionType()}; llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, target)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp index e5d0fb0..e5cf963 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp @@ -34,25 +34,25 @@ void fir::runtime::genRaggedArrayAllocate(mlir::Location loc, auto eleTy = fir::unwrapSequenceType(fir::unwrapRefType(header.getType())); auto ptrTy = builder.getRefType(mlir::cast<mlir::TupleType>(eleTy).getType(1)); - auto ptr = builder.create<fir::CoordinateOp>(loc, ptrTy, header, one); - auto heap = builder.create<fir::LoadOp>(loc, ptr); + auto ptr = fir::CoordinateOp::create(builder, loc, ptrTy, header, one); + auto heap = fir::LoadOp::create(builder, loc, ptr); auto cmp = builder.genIsNullAddr(loc, heap); builder.genIfThen(loc, cmp) .genThen([&]() { auto asHeadersVal = builder.createIntegerConstant(loc, i1Ty, asHeaders); auto rankVal = builder.createIntegerConstant(loc, i64Ty, rank); - auto buff = builder.create<fir::AllocMemOp>(loc, extentTy); + auto buff = fir::AllocMemOp::create(builder, loc, extentTy); // Convert all the extents to i64 and pack them in a buffer on the heap. for (auto i : llvm::enumerate(extents)) { auto offset = builder.createIntegerConstant(loc, i32Ty, i.index()); auto addr = - builder.create<fir::CoordinateOp>(loc, refTy, buff, offset); + fir::CoordinateOp::create(builder, loc, refTy, buff, offset); auto castVal = builder.createConvert(loc, i64Ty, i.value()); - builder.create<fir::StoreOp>(loc, castVal, addr); + fir::StoreOp::create(builder, loc, castVal, addr); } auto args = fir::runtime::createArguments( builder, loc, fTy, header, asHeadersVal, rankVal, eleSize, buff); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); }) .end(); } @@ -64,5 +64,5 @@ void fir::runtime::genRaggedArrayDeallocate(mlir::Location loc, loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, header); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp index f778b96..157d435 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp @@ -1155,7 +1155,7 @@ mlir::Value genSpecial2Args(FN func, fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, maskBox, sourceFile, sourceLine, dim); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate calls to reduction intrinsics such as All and Any. @@ -1171,7 +1171,7 @@ static void genReduction2Args(FN func, fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, maskBox, dim, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxval and Minval. @@ -1189,7 +1189,7 @@ static void genReduction3Args(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, dim, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxloc and Minloc. @@ -1206,7 +1206,7 @@ static void genReduction4Args(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, kind, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxloc and Minloc. @@ -1223,7 +1223,7 @@ genReduction5Args(FN func, fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, kind, dim, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `AllDim` runtime routine. @@ -1296,7 +1296,7 @@ void fir::runtime::genCountDim(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(5)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, maskBox, dim, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Findloc` intrinsic runtime routine. This is the version @@ -1313,7 +1313,7 @@ void fir::runtime::genFindloc(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, valBox, kind, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `FindlocDim` intrinsic runtime routine. This is the version @@ -1331,7 +1331,7 @@ void fir::runtime::genFindlocDim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, valBox, kind, dim, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Maxloc` intrinsic runtime routine. This is the version @@ -1392,7 +1392,7 @@ mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `MaxvalDim` intrinsic runtime routine. This is the version @@ -1417,7 +1417,7 @@ void fir::runtime::genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Minloc` intrinsic runtime routine. This is the version @@ -1476,7 +1476,7 @@ void fir::runtime::genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Minval` intrinsic runtime routine. This is the version @@ -1504,7 +1504,7 @@ mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `Norm2Dim` intrinsic runtime routine. This is the version @@ -1527,7 +1527,7 @@ void fir::runtime::genNorm2Dim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, dim, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Norm2` intrinsic runtime routine. This is the version @@ -1558,7 +1558,7 @@ mlir::Value fir::runtime::genNorm2(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `Parity` intrinsic runtime routine. This routine is @@ -1604,7 +1604,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, dim, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1613,7 +1613,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `DotProduct` intrinsic runtime routine. @@ -1645,7 +1645,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, vectorABox, vectorBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1653,7 +1653,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, vectorABox, vectorBBox, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `SumDim` intrinsic runtime routine. This is the version /// that handles any rank array with the dim argument specified. @@ -1688,7 +1688,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, dim, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1697,7 +1697,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } // The IAll, IAny and IParity intrinsics have essentially the same @@ -1733,7 +1733,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( \ builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); \ \ - return builder.create<fir::CallOp>(loc, func, args).getResult(0); \ + return fir::CallOp::create(builder, loc, func, args).getResult(0); \ } /// Generate call to `IAllDim` intrinsic runtime routine. This is the version @@ -1819,11 +1819,12 @@ void fir::runtime::genReduce(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(2), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(2), operation); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Reduce` intrinsic runtime routine. This is the version @@ -1864,11 +1865,12 @@ mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(1), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(1), operation); auto args = fir::runtime::createArguments(builder, loc, fTy, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genReduceDim(fir::FirOpBuilder &builder, mlir::Location loc, @@ -1912,9 +1914,10 @@ void fir::runtime::genReduceDim(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(2), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(2), operation); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp index 411181c..5629371 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp @@ -19,13 +19,13 @@ void fir::runtime::genExit(fir::FirOpBuilder &builder, mlir::Location loc, auto exitFunc = fir::runtime::getRuntimeFunc<mkRTKey(Exit)>(loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, exitFunc.getFunctionType(), status); - builder.create<fir::CallOp>(loc, exitFunc, args); + fir::CallOp::create(builder, loc, exitFunc, args); } void fir::runtime::genAbort(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp abortFunc = fir::runtime::getRuntimeFunc<mkRTKey(Abort)>(loc, builder); - builder.create<fir::CallOp>(loc, abortFunc, std::nullopt); + fir::CallOp::create(builder, loc, abortFunc, mlir::ValueRange{}); } void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder, @@ -41,5 +41,5 @@ void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder, mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, msgVal, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, crashFunc, args); + fir::CallOp::create(builder, loc, crashFunc, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Support.cpp b/flang/lib/Optimizer/Builder/Runtime/Support.cpp index b5e9ddb..d0d48ad 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Support.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Support.cpp @@ -42,7 +42,7 @@ void fir::runtime::genCopyAndUpdateDescriptor(fir::FirOpBuilder &builder, func.setArgAttr(0, noCapture, unitAttr); func.setArgAttr(1, noCapture, unitAttr); } - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } mlir::Value fir::runtime::genIsAssumedSize(fir::FirOpBuilder &builder, @@ -52,5 +52,5 @@ mlir::Value fir::runtime::genIsAssumedSize(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsAssumedSize)>(loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp b/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp index 732152c..effd712 100644 --- a/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp @@ -23,7 +23,7 @@ mlir::Value fir::runtime::genCreateValueStack(mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcType.getInput(1)); auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPushValue(mlir::Location loc, fir::FirOpBuilder &builder, @@ -33,7 +33,7 @@ void fir::runtime::genPushValue(mlir::Location loc, fir::FirOpBuilder &builder, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, boxValue); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genValueAt(mlir::Location loc, fir::FirOpBuilder &builder, @@ -44,7 +44,7 @@ void fir::runtime::genValueAt(mlir::Location loc, fir::FirOpBuilder &builder, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, i, retValueBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDestroyValueStack(mlir::Location loc, @@ -54,7 +54,7 @@ void fir::runtime::genDestroyValueStack(mlir::Location loc, fir::runtime::getRuntimeFunc<mkRTKey(DestroyValueStack)>(loc, builder); mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } mlir::Value fir::runtime::genCreateDescriptorStack(mlir::Location loc, @@ -68,7 +68,7 @@ mlir::Value fir::runtime::genCreateDescriptorStack(mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcType.getInput(1)); auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPushDescriptor(mlir::Location loc, @@ -80,7 +80,7 @@ void fir::runtime::genPushDescriptor(mlir::Location loc, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, boxDescriptor); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDescriptorAt(mlir::Location loc, @@ -92,7 +92,7 @@ void fir::runtime::genDescriptorAt(mlir::Location loc, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, i, retDescriptorBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDestroyDescriptorStack(mlir::Location loc, @@ -103,5 +103,5 @@ void fir::runtime::genDestroyDescriptorStack(mlir::Location loc, builder); mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp index 47744b0..6251def 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp @@ -170,7 +170,7 @@ void fir::runtime::genBesselJn(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, x, bn2, bn2_1, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselJn` intrinsic. This is used when `x == 0.0`. @@ -196,7 +196,7 @@ void fir::runtime::genBesselJnX0(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselYn` intrinsic. @@ -225,7 +225,7 @@ void fir::runtime::genBesselYn(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, x, bn1, bn1_1, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselYn` intrinsic. This is used when `x == 0.0`. @@ -251,7 +251,7 @@ void fir::runtime::genBesselYnX0(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Cshift intrinsic @@ -266,7 +266,7 @@ void fir::runtime::genCshift(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, dimBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, cshiftFunc, args); + fir::CallOp::create(builder, loc, cshiftFunc, args); } /// Generate call to the vector version of the Cshift intrinsic @@ -282,7 +282,7 @@ void fir::runtime::genCshiftVector(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, shiftBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, cshiftFunc, args); + fir::CallOp::create(builder, loc, cshiftFunc, args); } /// Generate call to Eoshift intrinsic @@ -299,7 +299,7 @@ void fir::runtime::genEoshift(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, boundBox, dimBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, eoshiftFunc, args); + fir::CallOp::create(builder, loc, eoshiftFunc, args); } /// Generate call to the vector version of the Eoshift intrinsic @@ -318,7 +318,7 @@ void fir::runtime::genEoshiftVector(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, boundBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, eoshiftFunc, args); + fir::CallOp::create(builder, loc, eoshiftFunc, args); } /// Define ForcedMatmul<ACAT><AKIND><BCAT><BKIND> models. @@ -388,7 +388,7 @@ void fir::runtime::genMatmul(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, matrixABox, matrixBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Define ForcedMatmulTranspose<ACAT><AKIND><BCAT><BKIND> models. @@ -440,7 +440,7 @@ void fir::runtime::genMatmulTranspose(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, matrixABox, matrixBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Pack intrinsic runtime routine. @@ -455,7 +455,7 @@ void fir::runtime::genPack(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, maskBox, vectorBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, packFunc, args); + fir::CallOp::create(builder, loc, packFunc, args); } /// Generate call to Reshape intrinsic runtime routine. @@ -471,7 +471,7 @@ void fir::runtime::genReshape(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, shapeBox, padBox, orderBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to ShallowCopy[Direct] runtime routine. @@ -491,7 +491,7 @@ void fir::runtime::genShallowCopy(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, packFunc, args); + fir::CallOp::create(builder, loc, packFunc, args); } /// Generate call to Spread intrinsic runtime routine. @@ -506,7 +506,7 @@ void fir::runtime::genSpread(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, dim, ncopies, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Transpose intrinsic runtime routine. @@ -519,7 +519,7 @@ void fir::runtime::genTranspose(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Unpack intrinsic runtime routine. @@ -534,5 +534,5 @@ void fir::runtime::genUnpack(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, vectorBox, maskBox, fieldBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, unpackFunc, args); + fir::CallOp::create(builder, loc, unpackFunc, args); } diff --git a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp index 9d2e983..4c648df 100644 --- a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp +++ b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp @@ -28,7 +28,7 @@ fir::factory::Counter::Counter(mlir::Location loc, fir::FirOpBuilder &builder, one = builder.createIntegerConstant(loc, type, 1); if (canCountThroughLoops) { index = builder.createTemporary(loc, type); - builder.create<fir::StoreOp>(loc, initialValue, index); + fir::StoreOp::create(builder, loc, initialValue, index); } else { index = initialValue; } @@ -38,21 +38,21 @@ mlir::Value fir::factory::Counter::getAndIncrementIndex(mlir::Location loc, fir::FirOpBuilder &builder) { if (canCountThroughLoops) { - mlir::Value indexValue = builder.create<fir::LoadOp>(loc, index); + mlir::Value indexValue = fir::LoadOp::create(builder, loc, index); mlir::Value newValue = - builder.create<mlir::arith::AddIOp>(loc, indexValue, one); - builder.create<fir::StoreOp>(loc, newValue, index); + mlir::arith::AddIOp::create(builder, loc, indexValue, one); + fir::StoreOp::create(builder, loc, newValue, index); return indexValue; } mlir::Value indexValue = index; - index = builder.create<mlir::arith::AddIOp>(loc, indexValue, one); + index = mlir::arith::AddIOp::create(builder, loc, indexValue, one); return indexValue; } void fir::factory::Counter::reset(mlir::Location loc, fir::FirOpBuilder &builder) { if (canCountThroughLoops) - builder.create<fir::StoreOp>(loc, initialValue, index); + fir::StoreOp::create(builder, loc, initialValue, index); else index = initialValue; } @@ -103,7 +103,7 @@ void fir::factory::HomogeneousScalarStack::pushValue(mlir::Location loc, // below should not get hit but is added as a remainder/safety. if (!entity.hasIntrinsicType()) TODO(loc, "creating inlined temporary stack for derived types"); - builder.create<hlfir::AssignOp>(loc, value, tempElement); + hlfir::AssignOp::create(builder, loc, value, tempElement); } void fir::factory::HomogeneousScalarStack::resetFetchPosition( @@ -125,14 +125,14 @@ void fir::factory::HomogeneousScalarStack::destroy(mlir::Location loc, if (allocateOnHeap) { auto declare = temp.getDefiningOp<hlfir::DeclareOp>(); assert(declare && "temp must have been declared"); - builder.create<fir::FreeMemOp>(loc, declare.getMemref()); + fir::FreeMemOp::create(builder, loc, declare.getMemref()); } } hlfir::Entity fir::factory::HomogeneousScalarStack::moveStackAsArrayExpr( mlir::Location loc, fir::FirOpBuilder &builder) { mlir::Value mustFree = builder.createBool(loc, allocateOnHeap); - auto hlfirExpr = builder.create<hlfir::AsExprOp>(loc, temp, mustFree); + auto hlfirExpr = hlfir::AsExprOp::create(builder, loc, temp, mustFree); return hlfir::Entity{hlfirExpr}; } @@ -147,14 +147,14 @@ fir::factory::SimpleCopy::SimpleCopy(mlir::Location loc, // Use hlfir.as_expr and hlfir.associate to create a copy and leave // bufferization deals with how best to make the copy. if (source.isVariable()) - source = hlfir::Entity{builder.create<hlfir::AsExprOp>(loc, source)}; + source = hlfir::Entity{hlfir::AsExprOp::create(builder, loc, source)}; copy = hlfir::genAssociateExpr(loc, builder, source, source.getFortranElementType(), tempName); } void fir::factory::SimpleCopy::destroy(mlir::Location loc, fir::FirOpBuilder &builder) { - builder.create<hlfir::EndAssociateOp>(loc, copy); + hlfir::EndAssociateOp::create(builder, loc, copy); } //===----------------------------------------------------------------------===// @@ -279,7 +279,7 @@ mlir::Value fir::factory::AnyVariableStack::fetch(mlir::Location loc, mlir::Value indexValue = counter.getAndIncrementIndex(loc, builder); fir::runtime::genDescriptorAt(loc, builder, opaquePtr, indexValue, retValueBox); - hlfir::Entity retBox{builder.create<fir::LoadOp>(loc, retValueBox)}; + hlfir::Entity retBox{fir::LoadOp::create(builder, loc, retValueBox)}; // The runtime always tracks variable as address, but the form of the variable // that was saved may be different (raw address, fir.boxchar), ensure // the returned variable has the same form of the one that was saved. @@ -326,7 +326,7 @@ void fir::factory::AnyVectorSubscriptStack::pushShape( hlfir::getFortranElementOrSequenceType(*boxType)); mlir::Value null = builder.createNullConstant(loc, refType); mlir::Value descriptor = - builder.create<fir::EmboxOp>(loc, *boxType, null, shape); + fir::EmboxOp::create(builder, loc, *boxType, null, shape); shapeTemp->pushValue(loc, builder, descriptor); return; } @@ -372,7 +372,7 @@ void fir::factory::AnyAddressStack::pushValue(mlir::Location loc, mlir::Value cast = variable; if (auto boxProcType = llvm::dyn_cast<fir::BoxProcType>(variable.getType())) { cast = - builder.create<fir::BoxAddrOp>(loc, boxProcType.getEleTy(), variable); + fir::BoxAddrOp::create(builder, loc, boxProcType.getEleTy(), variable); } cast = builder.createConvert(loc, builder.getIntPtrType(), cast); static_cast<AnyValueStack *>(this)->pushValue(loc, builder, cast); @@ -383,7 +383,7 @@ mlir::Value fir::factory::AnyAddressStack::fetch(mlir::Location loc, mlir::Value addr = static_cast<AnyValueStack *>(this)->fetch(loc, builder); if (auto boxProcType = llvm::dyn_cast<fir::BoxProcType>(addressType)) { mlir::Value cast = builder.createConvert(loc, boxProcType.getEleTy(), addr); - return builder.create<fir::EmboxProcOp>(loc, boxProcType, cast); + return fir::EmboxProcOp::create(builder, loc, boxProcType, cast); } return builder.createConvert(loc, addressType, addr); } diff --git a/flang/lib/Optimizer/CodeGen/CMakeLists.txt b/flang/lib/Optimizer/CodeGen/CMakeLists.txt index 16c7944a..d5ea3c7 100644 --- a/flang/lib/Optimizer/CodeGen/CMakeLists.txt +++ b/flang/lib/Optimizer/CodeGen/CMakeLists.txt @@ -37,6 +37,7 @@ add_flang_library(FIRCodeGen MLIRComplexToROCDLLibraryCalls MLIRComplexToStandard MLIRGPUDialect + MLIRIndexToLLVM MLIRMathToFuncs MLIRMathToLLVM MLIRMathToLibm diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index d879382..609ba27 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -37,6 +37,7 @@ #include "mlir/Conversion/ComplexToStandard/ComplexToStandard.h" #include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h" #include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h" +#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h" #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Conversion/MathToFuncs/MathToFuncs.h" #include "mlir/Conversion/MathToLLVM/MathToLLVM.h" @@ -4224,6 +4225,7 @@ public: if (!isAMDGCN) mlir::populateMathToLibmConversionPatterns(pattern); mlir::populateComplexToLLVMConversionPatterns(typeConverter, pattern); + mlir::index::populateIndexToLLVMConversionPatterns(typeConverter, pattern); mlir::populateVectorToLLVMConversionPatterns(typeConverter, pattern); // Flang specific overloads for OpenMP operations, to allow for special diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp index 03cc92e..c5cf01e 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp @@ -405,7 +405,7 @@ void OrderedAssignmentRewriter::pre(hlfir::ForallMaskOp forallMaskOp) { mlir::Location loc = forallMaskOp.getLoc(); mlir::Value mask = generateYieldedScalarValue(forallMaskOp.getMaskRegion(), builder.getI1Type()); - auto ifOp = builder.create<fir::IfOp>(loc, std::nullopt, mask, false); + auto ifOp = builder.create<fir::IfOp>(loc, mlir::TypeRange{}, mask, false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); constructStack.push_back(ifOp); } @@ -530,7 +530,7 @@ void OrderedAssignmentRewriter::generateMaskIfOp(mlir::Value cdt) { mlir::Location loc = cdt.getLoc(); cdt = hlfir::loadTrivialScalar(loc, builder, hlfir::Entity{cdt}); cdt = builder.createConvert(loc, builder.getI1Type(), cdt); - auto ifOp = builder.create<fir::IfOp>(cdt.getLoc(), std::nullopt, cdt, + auto ifOp = builder.create<fir::IfOp>(cdt.getLoc(), mlir::TypeRange{}, cdt, /*withElseRegion=*/false); constructStack.push_back(ifOp.getOperation()); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp index 59e2eeb..391cfe3 100644 --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -137,9 +137,9 @@ public: auto buffer = saveResult.getMemref(); mlir::Value arg = buffer; if (mustEmboxResult(result.getType(), shouldBoxResult)) - arg = rewriter.create<fir::EmboxOp>( - loc, argType, buffer, saveResult.getShape(), /*slice*/ mlir::Value{}, - saveResult.getTypeparams()); + arg = fir::EmboxOp::create(rewriter, loc, argType, buffer, + saveResult.getShape(), /*slice*/ mlir::Value{}, + saveResult.getTypeparams()); llvm::SmallVector<mlir::Type> newResultTypes; bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType()); @@ -155,8 +155,8 @@ public: if (!isResultBuiltinCPtr) newOperands.emplace_back(arg); newOperands.append(op.getOperands().begin(), op.getOperands().end()); - newOp = rewriter.create<fir::CallOp>(loc, *op.getCallee(), - newResultTypes, newOperands); + newOp = fir::CallOp::create(rewriter, loc, *op.getCallee(), + newResultTypes, newOperands); } else { // Indirect calls. llvm::SmallVector<mlir::Type> newInputTypes; @@ -169,13 +169,13 @@ public: llvm::SmallVector<mlir::Value> newOperands; newOperands.push_back( - rewriter.create<fir::ConvertOp>(loc, newFuncTy, op.getOperand(0))); + fir::ConvertOp::create(rewriter, loc, newFuncTy, op.getOperand(0))); if (!isResultBuiltinCPtr) newOperands.push_back(arg); newOperands.append(op.getOperands().begin() + 1, op.getOperands().end()); - newOp = rewriter.create<fir::CallOp>(loc, mlir::SymbolRefAttr{}, - newResultTypes, newOperands); + newOp = fir::CallOp::create(rewriter, loc, mlir::SymbolRefAttr{}, + newResultTypes, newOperands); } } @@ -191,8 +191,8 @@ public: passArgPos = rewriter.getI32IntegerAttr(*op.getPassArgPos() + passArgShift); // TODO: propagate argument and result attributes (need to be shifted). - newOp = rewriter.create<fir::DispatchOp>( - loc, newResultTypes, rewriter.getStringAttr(op.getMethod()), + newOp = fir::DispatchOp::create( + rewriter, loc, newResultTypes, rewriter.getStringAttr(op.getMethod()), op.getOperands()[0], newOperands, passArgPos, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, op.getProcedureAttrsAttr()); @@ -280,7 +280,7 @@ processReturnLikeOp(OpTy ret, mlir::Value newArg, // register pass, this is possible for fir.box results, or fir.record // with no length parameters. Simply store the result in the result // storage. at the return point. - rewriter.create<fir::StoreOp>(loc, resultValue, newArg); + fir::StoreOp::create(rewriter, loc, resultValue, newArg); rewriter.replaceOpWithNewOp<OpTy>(ret); } // Delete result old local storage if unused. @@ -337,8 +337,8 @@ public: newFuncTy = getCPtrFunctionType(oldFuncTy); else newFuncTy = getNewFunctionType(oldFuncTy, shouldBoxResult); - auto newAddrOf = rewriter.create<fir::AddrOfOp>(addrOf.getLoc(), newFuncTy, - addrOf.getSymbol()); + auto newAddrOf = fir::AddrOfOp::create(rewriter, addrOf.getLoc(), newFuncTy, + addrOf.getSymbol()); // Rather than converting all op a function pointer might transit through // (e.g calls, stores, loads, converts...), cast new type to the abstract // type. A conversion will be added when calling indirect calls of abstract @@ -397,7 +397,7 @@ public: if (mustEmboxResult(resultType, shouldBoxResult)) { auto bufferType = fir::ReferenceType::get(resultType); rewriter.setInsertionPointToStart(&func.front()); - newArg = rewriter.create<fir::BoxAddrOp>(loc, bufferType, newArg); + newArg = fir::BoxAddrOp::create(rewriter, loc, bufferType, newArg); } patterns.insert<ReturnOpConversion>(context, newArg); target.addDynamicallyLegalOp<mlir::func::ReturnOp>( diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp index b27c1b2..85403ad 100644 --- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp +++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp @@ -48,12 +48,21 @@ static llvm::cl::opt<bool> llvm::cl::Hidden, llvm::cl::desc("Add TBAA tags to local allocations.")); +// Engineering option to triage TBAA tags attachment for accesses +// of allocatable entities. +static llvm::cl::opt<unsigned> localAllocsThreshold( + "local-alloc-tbaa-threshold", llvm::cl::init(0), llvm::cl::ReallyHidden, + llvm::cl::desc("If present, stops generating TBAA tags for accesses of " + "local allocations after N accesses in a module")); + namespace { /// Shared state per-module class PassState { public: - PassState(mlir::DominanceInfo &domInfo) : domInfo(domInfo) {} + PassState(mlir::DominanceInfo &domInfo, + std::optional<unsigned> localAllocsThreshold) + : domInfo(domInfo), localAllocsThreshold(localAllocsThreshold) {} /// memoised call to fir::AliasAnalysis::getSource inline const fir::AliasAnalysis::Source &getSource(mlir::Value value) { if (!analysisCache.contains(value)) @@ -84,6 +93,11 @@ public: // (e.g. !fir.ref<!fir.type<Derived{f:!fir.box<!fir.heap<f32>>}>>). bool typeReferencesDescriptor(mlir::Type type); + // Returns true if we can attach a TBAA tag to an access of an allocatable + // entities. It checks if localAllocsThreshold allows the next tag + // attachment. + bool attachLocalAllocTag(); + private: mlir::DominanceInfo &domInfo; fir::AliasAnalysis analysis; @@ -103,6 +117,8 @@ private: // Local pass cache for derived types that contain descriptor // member(s), to avoid the cost of isRecordWithDescriptorMember(). llvm::DenseSet<mlir::Type> typesContainingDescriptors; + + std::optional<unsigned> localAllocsThreshold; }; // Process fir.dummy_scope operations in the given func: @@ -169,6 +185,19 @@ bool PassState::typeReferencesDescriptor(mlir::Type type) { return false; } +bool PassState::attachLocalAllocTag() { + if (!localAllocsThreshold) + return true; + if (*localAllocsThreshold == 0) { + LLVM_DEBUG(llvm::dbgs().indent(2) + << "WARN: not assigning TBAA tag for an allocated entity access " + "due to the threshold\n"); + return false; + } + --*localAllocsThreshold; + return true; +} + class AddAliasTagsPass : public fir::impl::AddAliasTagsBase<AddAliasTagsPass> { public: void runOnOperation() override; @@ -335,16 +364,16 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op, LLVM_DEBUG(llvm::dbgs().indent(2) << "WARN: unknown defining op for SourceKind::Allocate " << *op << "\n"); - } else if (source.isPointer()) { + } else if (source.isPointer() && state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to allocation at " << *op << "\n"); tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag(); - } else if (name) { + } else if (name && state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to allocation " << name << " at " << *op << "\n"); tag = state.getFuncTreeWithScope(func, scopeOp) .allocatedDataTree.getTag(*name); - } else { + } else if (state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "WARN: couldn't find a name for allocation " << *op << "\n"); @@ -372,7 +401,9 @@ void AddAliasTagsPass::runOnOperation() { // thinks the pass operates on), then the real work of the pass is done in // runOnAliasInterface auto &domInfo = getAnalysis<mlir::DominanceInfo>(); - PassState state(domInfo); + PassState state(domInfo, localAllocsThreshold.getPosition() + ? std::optional<unsigned>(localAllocsThreshold) + : std::nullopt); mlir::ModuleOp mod = getOperation(); mod.walk( diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp index d45f855..f1c66a5 100644 --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -60,9 +60,10 @@ public: if (!maybeExpandedMap) return failure(); - auto coorOp = rewriter.create<fir::CoordinateOp>( - op.getLoc(), fir::ReferenceType::get(op.getResult().getType()), - adaptor.getMemref(), *maybeExpandedMap); + auto coorOp = fir::CoordinateOp::create( + rewriter, op.getLoc(), + fir::ReferenceType::get(op.getResult().getType()), adaptor.getMemref(), + *maybeExpandedMap); rewriter.replaceOpWithNewOp<fir::LoadOp>(op, coorOp.getResult()); return success(); @@ -83,8 +84,9 @@ public: if (!maybeExpandedMap) return failure(); - auto coorOp = rewriter.create<fir::CoordinateOp>( - op.getLoc(), fir::ReferenceType::get(op.getValueToStore().getType()), + auto coorOp = fir::CoordinateOp::create( + rewriter, op.getLoc(), + fir::ReferenceType::get(op.getValueToStore().getType()), adaptor.getMemref(), *maybeExpandedMap); rewriter.replaceOpWithNewOp<fir::StoreOp>(op, adaptor.getValue(), coorOp.getResult()); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index ef82e400..b032767 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -366,8 +366,9 @@ static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) { static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeOp shape, SmallVectorImpl<mlir::Value> &indexArgs, mlir::PatternRewriter &rewriter) { - auto one = rewriter.create<mlir::arith::ConstantOp>( - acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); + auto one = mlir::arith::ConstantOp::create(rewriter, acoOp.getLoc(), + rewriter.getIndexType(), + rewriter.getIndexAttr(1)); auto extents = shape.getExtents(); for (auto i = extents.begin(); i < extents.end(); i++) { indexArgs.push_back(one); @@ -379,8 +380,9 @@ static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeOp shape, static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeShiftOp shape, SmallVectorImpl<mlir::Value> &indexArgs, mlir::PatternRewriter &rewriter) { - auto one = rewriter.create<mlir::arith::ConstantOp>( - acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); + auto one = mlir::arith::ConstantOp::create(rewriter, acoOp.getLoc(), + rewriter.getIndexType(), + rewriter.getIndexAttr(1)); auto extents = shape.getPairs(); for (auto i = extents.begin(); i < extents.end();) { indexArgs.push_back(*i++); @@ -422,13 +424,13 @@ createAffineOps(mlir::Value arrayRef, mlir::PatternRewriter &rewriter) { populateIndexArgs(acoOp, indexArgs, rewriter); - auto affineApply = rewriter.create<affine::AffineApplyOp>( - acoOp.getLoc(), affineMap, indexArgs); + auto affineApply = affine::AffineApplyOp::create(rewriter, acoOp.getLoc(), + affineMap, indexArgs); auto arrayElementType = coordinateArrayElement(acoOp); auto newType = mlir::MemRefType::get({mlir::ShapedType::kDynamic}, arrayElementType); - auto arrayConvert = rewriter.create<fir::ConvertOp>(acoOp.getLoc(), newType, - acoOp.getMemref()); + auto arrayConvert = fir::ConvertOp::create(rewriter, acoOp.getLoc(), newType, + acoOp.getMemref()); return std::make_pair(affineApply, arrayConvert); } @@ -495,7 +497,7 @@ public: affineFor.getRegionIterArgs()); if (!results.empty()) { rewriter.setInsertionPointToEnd(affineFor.getBody()); - rewriter.create<affine::AffineYieldOp>(resultOp->getLoc(), results); + affine::AffineYieldOp::create(rewriter, resultOp->getLoc(), results); } rewriter.finalizeOpModification(affineFor.getOperation()); @@ -525,8 +527,8 @@ private: std::pair<affine::AffineForOp, mlir::Value> positiveConstantStep(fir::DoLoopOp op, int64_t step, mlir::PatternRewriter &rewriter) const { - auto affineFor = rewriter.create<affine::AffineForOp>( - op.getLoc(), ValueRange(op.getLowerBound()), + auto affineFor = affine::AffineForOp::create( + rewriter, op.getLoc(), ValueRange(op.getLowerBound()), mlir::AffineMap::get(0, 1, mlir::getAffineSymbolExpr(0, op.getContext())), ValueRange(op.getUpperBound()), @@ -543,24 +545,24 @@ private: auto step = mlir::getAffineSymbolExpr(2, op.getContext()); mlir::AffineMap upperBoundMap = mlir::AffineMap::get( 0, 3, (upperBound - lowerBound + step).floorDiv(step)); - auto genericUpperBound = rewriter.create<affine::AffineApplyOp>( - op.getLoc(), upperBoundMap, + auto genericUpperBound = affine::AffineApplyOp::create( + rewriter, op.getLoc(), upperBoundMap, ValueRange({op.getLowerBound(), op.getUpperBound(), op.getStep()})); auto actualIndexMap = mlir::AffineMap::get( 1, 2, (lowerBound + mlir::getAffineDimExpr(0, op.getContext())) * mlir::getAffineSymbolExpr(1, op.getContext())); - auto affineFor = rewriter.create<affine::AffineForOp>( - op.getLoc(), ValueRange(), + auto affineFor = affine::AffineForOp::create( + rewriter, op.getLoc(), ValueRange(), AffineMap::getConstantMap(0, op.getContext()), genericUpperBound.getResult(), mlir::AffineMap::get(0, 1, 1 + mlir::getAffineSymbolExpr(0, op.getContext())), 1, op.getIterOperands()); rewriter.setInsertionPointToStart(affineFor.getBody()); - auto actualIndex = rewriter.create<affine::AffineApplyOp>( - op.getLoc(), actualIndexMap, + auto actualIndex = affine::AffineApplyOp::create( + rewriter, op.getLoc(), actualIndexMap, ValueRange( {affineFor.getInductionVar(), op.getLowerBound(), op.getStep()})); return std::make_pair(affineFor, actualIndex.getResult()); @@ -588,8 +590,8 @@ public: << "AffineIfConversion: couldn't calculate affine condition\n";); return failure(); } - auto affineIf = rewriter.create<affine::AffineIfOp>( - op.getLoc(), affineCondition.getIntegerSet(), + auto affineIf = affine::AffineIfOp::create( + rewriter, op.getLoc(), affineCondition.getIntegerSet(), affineCondition.getAffineArgs(), !op.getElseRegion().empty()); rewriter.startOpModification(affineIf); affineIf.getThenBlock()->getOperations().splice( diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp index 8544d17..247ba95 100644 --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -856,7 +856,7 @@ static bool getAdjustedExtents(mlir::Location loc, auto idxTy = rewriter.getIndexType(); if (isAssumedSize(result)) { // Use slice information to compute the extent of the column. - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); mlir::Value size = one; if (mlir::Value sliceArg = arrLoad.getSlice()) { if (auto sliceOp = @@ -896,14 +896,14 @@ static mlir::Value getOrReadExtentsAndShapeOp( mlir::cast<SequenceType>(dyn_cast_ptrOrBoxEleTy(boxTy)).getDimension(); auto idxTy = rewriter.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { - auto dimVal = rewriter.create<mlir::arith::ConstantIndexOp>(loc, dim); - auto dimInfo = rewriter.create<BoxDimsOp>(loc, idxTy, idxTy, idxTy, - arrLoad.getMemref(), dimVal); + auto dimVal = mlir::arith::ConstantIndexOp::create(rewriter, loc, dim); + auto dimInfo = BoxDimsOp::create(rewriter, loc, idxTy, idxTy, idxTy, + arrLoad.getMemref(), dimVal); result.emplace_back(dimInfo.getResult(1)); } if (!arrLoad.getShape()) { auto shapeType = ShapeType::get(rewriter.getContext(), rank); - return rewriter.create<ShapeOp>(loc, shapeType, result); + return ShapeOp::create(rewriter, loc, shapeType, result); } auto shiftOp = arrLoad.getShape().getDefiningOp<ShiftOp>(); auto shapeShiftType = ShapeShiftType::get(rewriter.getContext(), rank); @@ -912,8 +912,8 @@ static mlir::Value getOrReadExtentsAndShapeOp( shapeShiftOperands.push_back(lb); shapeShiftOperands.push_back(extent); } - return rewriter.create<ShapeShiftOp>(loc, shapeShiftType, - shapeShiftOperands); + return ShapeShiftOp::create(rewriter, loc, shapeShiftType, + shapeShiftOperands); } copyUsingSlice = getAdjustedExtents(loc, rewriter, arrLoad, result, arrLoad.getShape()); @@ -952,13 +952,13 @@ static mlir::Value genCoorOp(mlir::PatternRewriter &rewriter, auto module = load->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); auto typeparams = getTypeParamsIfRawData(loc, builder, load, alloc.getType()); - mlir::Value result = rewriter.create<ArrayCoorOp>( - loc, eleTy, alloc, shape, slice, + mlir::Value result = ArrayCoorOp::create( + rewriter, loc, eleTy, alloc, shape, slice, llvm::ArrayRef<mlir::Value>{originated}.take_front(dimension), typeparams); if (dimension < originated.size()) - result = rewriter.create<fir::CoordinateOp>( - loc, resTy, result, + result = fir::CoordinateOp::create( + rewriter, loc, resTy, result, llvm::ArrayRef<mlir::Value>{originated}.drop_front(dimension)); return result; } @@ -971,13 +971,13 @@ static mlir::Value getCharacterLen(mlir::Location loc, FirOpBuilder &builder, // The loaded array is an emboxed value. Get the CHARACTER length from // the box value. auto eleSzInBytes = - builder.create<BoxEleSizeOp>(loc, charLenTy, load.getMemref()); + BoxEleSizeOp::create(builder, loc, charLenTy, load.getMemref()); auto kindSize = builder.getKindMap().getCharacterBitsize(charTy.getFKind()); auto kindByteSize = builder.createIntegerConstant(loc, charLenTy, kindSize / 8); - return builder.create<mlir::arith::DivSIOp>(loc, eleSzInBytes, - kindByteSize); + return mlir::arith::DivSIOp::create(builder, loc, eleSzInBytes, + kindByteSize); } // The loaded array is a (set of) unboxed values. If the CHARACTER's // length is not a constant, it must be provided as a type parameter to @@ -1003,11 +1003,11 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter, auto idxTy = rewriter.getIndexType(); // Build loop nest from column to row. for (auto sh : llvm::reverse(extents)) { - auto ubi = rewriter.create<ConvertOp>(loc, idxTy, sh); - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); - auto ub = rewriter.create<mlir::arith::SubIOp>(loc, idxTy, ubi, one); - auto loop = rewriter.create<DoLoopOp>(loc, zero, ub, one); + auto ubi = ConvertOp::create(rewriter, loc, idxTy, sh); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); + auto ub = mlir::arith::SubIOp::create(rewriter, loc, idxTy, ubi, one); + auto loop = DoLoopOp::create(rewriter, loc, zero, ub, one); rewriter.setInsertionPointToStart(loop.getBody()); indices.push_back(loop.getInductionVar()); } @@ -1015,13 +1015,13 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter, std::reverse(indices.begin(), indices.end()); auto module = arrLoad->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); - auto fromAddr = rewriter.create<ArrayCoorOp>( - loc, getEleTy(src.getType()), src, shapeOp, + auto fromAddr = ArrayCoorOp::create( + rewriter, loc, getEleTy(src.getType()), src, shapeOp, CopyIn && copyUsingSlice ? sliceOp : mlir::Value{}, factory::originateIndices(loc, rewriter, src.getType(), shapeOp, indices), getTypeParamsIfRawData(loc, builder, arrLoad, src.getType())); - auto toAddr = rewriter.create<ArrayCoorOp>( - loc, getEleTy(dst.getType()), dst, shapeOp, + auto toAddr = ArrayCoorOp::create( + rewriter, loc, getEleTy(dst.getType()), dst, shapeOp, !CopyIn && copyUsingSlice ? sliceOp : mlir::Value{}, factory::originateIndices(loc, rewriter, dst.getType(), shapeOp, indices), getTypeParamsIfRawData(loc, builder, arrLoad, dst.getType())); @@ -1093,15 +1093,16 @@ allocateArrayTemp(mlir::Location loc, mlir::PatternRewriter &rewriter, findNonconstantExtents(baseType, extents); llvm::SmallVector<mlir::Value> typeParams = genArrayLoadTypeParameters(loc, rewriter, load); - mlir::Value allocmem = rewriter.create<AllocMemOp>( - loc, dyn_cast_ptrOrBoxEleTy(baseType), typeParams, nonconstantExtents); + mlir::Value allocmem = + AllocMemOp::create(rewriter, loc, dyn_cast_ptrOrBoxEleTy(baseType), + typeParams, nonconstantExtents); mlir::Type eleType = fir::unwrapSequenceType(fir::unwrapPassByRefType(baseType)); if (fir::isRecordWithAllocatableMember(eleType)) { // The allocatable component descriptors need to be set to a clean // deallocated status before anything is done with them. - mlir::Value box = rewriter.create<fir::EmboxOp>( - loc, fir::BoxType::get(allocmem.getType()), allocmem, shape, + mlir::Value box = fir::EmboxOp::create( + rewriter, loc, fir::BoxType::get(allocmem.getType()), allocmem, shape, /*slice=*/mlir::Value{}, typeParams); auto module = load->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); @@ -1111,12 +1112,12 @@ allocateArrayTemp(mlir::Location loc, mlir::PatternRewriter &rewriter, auto cleanup = [=](mlir::PatternRewriter &r) { FirOpBuilder builder(r, module); runtime::genDerivedTypeDestroy(builder, loc, box); - r.create<FreeMemOp>(loc, allocmem); + FreeMemOp::create(r, loc, allocmem); }; return {allocmem, cleanup}; } auto cleanup = [=](mlir::PatternRewriter &r) { - r.create<FreeMemOp>(loc, allocmem); + FreeMemOp::create(r, loc, allocmem); }; return {allocmem, cleanup}; } @@ -1257,7 +1258,7 @@ public: if (auto inEleTy = dyn_cast_ptrEleTy(input.getType())) { emitFatalError(loc, "array_update on references not supported"); } else { - rewriter.create<fir::StoreOp>(loc, input, coor); + fir::StoreOp::create(rewriter, loc, input, coor); } }; auto lhsEltRefType = toRefType(update.getMerge().getType()); @@ -1368,7 +1369,7 @@ public: auto *op = amend.getOperation(); rewriter.setInsertionPoint(op); auto loc = amend.getLoc(); - auto undef = rewriter.create<UndefOp>(loc, amend.getType()); + auto undef = UndefOp::create(rewriter, loc, amend.getType()); rewriter.replaceOp(amend, undef.getResult()); return mlir::success(); } diff --git a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp index 6af1cb9..4c7b228 100644 --- a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp @@ -88,8 +88,8 @@ public: (fir::isPolymorphicType(oldBoxType) || (newEleType != oldBoxType.unwrapInnerType())) && !fir::isPolymorphicType(newBoxType)) { - newDtype = builder.create<fir::TypeDescOp>( - loc, mlir::TypeAttr::get(newDerivedType)); + newDtype = fir::TypeDescOp::create(builder, loc, + mlir::TypeAttr::get(newDerivedType)); } else { newDtype = builder.createNullConstant(loc); } @@ -103,7 +103,7 @@ public: rebox.getBox(), newDtype, newAttribute, lowerBoundModifier); - mlir::Value descValue = builder.create<fir::LoadOp>(loc, tempDesc); + mlir::Value descValue = fir::LoadOp::create(builder, loc, tempDesc); mlir::Value castDesc = builder.createConvert(loc, newBoxType, descValue); rewriter.replaceOp(rebox, castDesc); return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp b/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp index 2dd6950..baa8e59 100644 --- a/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp +++ b/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp @@ -68,25 +68,26 @@ struct CUFAddConstructor // Symbol reference to CUFRegisterAllocator. builder.setInsertionPointToEnd(mod.getBody()); - auto registerFuncOp = builder.create<mlir::LLVM::LLVMFuncOp>( - loc, RTNAME_STRING(CUFRegisterAllocator), funcTy); + auto registerFuncOp = mlir::LLVM::LLVMFuncOp::create( + builder, loc, RTNAME_STRING(CUFRegisterAllocator), funcTy); registerFuncOp.setVisibility(mlir::SymbolTable::Visibility::Private); auto cufRegisterAllocatorRef = mlir::SymbolRefAttr::get( mod.getContext(), RTNAME_STRING(CUFRegisterAllocator)); builder.setInsertionPointToEnd(mod.getBody()); // Create the constructor function that call CUFRegisterAllocator. - auto func = builder.create<mlir::LLVM::LLVMFuncOp>(loc, cudaFortranCtorName, - funcTy); + auto func = mlir::LLVM::LLVMFuncOp::create(builder, loc, + cudaFortranCtorName, funcTy); func.setLinkage(mlir::LLVM::Linkage::Internal); builder.setInsertionPointToStart(func.addEntryBlock(builder)); - builder.create<mlir::LLVM::CallOp>(loc, funcTy, cufRegisterAllocatorRef); + mlir::LLVM::CallOp::create(builder, loc, funcTy, cufRegisterAllocatorRef); auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(cudaDeviceModuleName); if (gpuMod) { auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(ctx); - auto registeredMod = builder.create<cuf::RegisterModuleOp>( - loc, llvmPtrTy, mlir::SymbolRefAttr::get(ctx, gpuMod.getName())); + auto registeredMod = cuf::RegisterModuleOp::create( + builder, loc, llvmPtrTy, + mlir::SymbolRefAttr::get(ctx, gpuMod.getName())); fir::LLVMTypeConverter typeConverter(mod, /*applyTBAA=*/false, /*forceUnifiedTBAATree=*/false, *dl); @@ -96,7 +97,8 @@ struct CUFAddConstructor auto kernelName = mlir::SymbolRefAttr::get( builder.getStringAttr(cudaDeviceModuleName), {mlir::SymbolRefAttr::get(builder.getContext(), func.getName())}); - builder.create<cuf::RegisterKernelOp>(loc, kernelName, registeredMod); + cuf::RegisterKernelOp::create(builder, loc, kernelName, + registeredMod); } } @@ -140,19 +142,19 @@ struct CUFAddConstructor auto sizeVal = builder.createIntegerConstant(loc, idxTy, *size); // Global variable address - mlir::Value addr = builder.create<fir::AddrOfOp>( - loc, globalOp.resultType(), globalOp.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, globalOp.resultType(), globalOp.getSymbol()); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, registeredMod, addr, gblName, sizeVal)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } break; default: break; } } } - builder.create<mlir::LLVM::ReturnOp>(loc, mlir::ValueRange{}); + mlir::LLVM::ReturnOp::create(builder, loc, mlir::ValueRange{}); // Create the llvm.global_ctor with the function. // TODO: We might want to have a utility that retrieve it if already @@ -165,8 +167,8 @@ struct CUFAddConstructor llvm::SmallVector<mlir::Attribute> data; priorities.push_back(0); data.push_back(mlir::LLVM::ZeroAttr::get(mod.getContext())); - builder.create<mlir::LLVM::GlobalCtorsOp>( - mod.getLoc(), builder.getArrayAttr(funcs), + mlir::LLVM::GlobalCtorsOp::create( + builder, mod.getLoc(), builder.getArrayAttr(funcs), builder.getI32ArrayAttr(priorities), builder.getArrayAttr(data)); } }; diff --git a/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp b/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp index f6381ef..5e910f7 100644 --- a/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp +++ b/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp @@ -93,10 +93,11 @@ struct CUFComputeSharedMemoryOffsetsAndSize mlir::Value dynSize = builder.createIntegerConstant(loc, idxTy, tySize); for (auto extent : sharedOp.getShape()) - dynSize = builder.create<mlir::arith::MulIOp>(loc, dynSize, extent); + dynSize = + mlir::arith::MulIOp::create(builder, loc, dynSize, extent); if (crtDynOffset) - crtDynOffset = - builder.create<mlir::arith::AddIOp>(loc, crtDynOffset, dynSize); + crtDynOffset = mlir::arith::AddIOp::create(builder, loc, + crtDynOffset, dynSize); else crtDynOffset = dynSize; @@ -142,9 +143,9 @@ struct CUFComputeSharedMemoryOffsetsAndSize fir::GlobalOp::getDataAttrAttrName(globalOpName), cuf::DataAttributeAttr::get(gpuMod.getContext(), cuf::DataAttribute::Shared))); - auto sharedMem = builder.create<fir::GlobalOp>( - funcOp.getLoc(), sharedMemGlobalName, false, false, sharedMemType, - init, linkage, attrs); + auto sharedMem = fir::GlobalOp::create( + builder, funcOp.getLoc(), sharedMemGlobalName, false, false, + sharedMemType, init, linkage, attrs); sharedMem.setAlignment(alignment); } } diff --git a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp index fe69ffa8..a40ed95 100644 --- a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp @@ -46,27 +46,28 @@ static mlir::Value createKernelArgArray(mlir::Location loc, auto structTy = mlir::LLVM::LLVMStructType::getLiteral(ctx, structTypes); auto ptrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext()); mlir::Type i32Ty = rewriter.getI32Type(); - auto zero = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); - auto one = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 1)); + auto zero = mlir::LLVM::ConstantOp::create(rewriter, loc, i32Ty, + rewriter.getIntegerAttr(i32Ty, 0)); + auto one = mlir::LLVM::ConstantOp::create(rewriter, loc, i32Ty, + rewriter.getIntegerAttr(i32Ty, 1)); mlir::Value argStruct = - rewriter.create<mlir::LLVM::AllocaOp>(loc, ptrTy, structTy, one); - auto size = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, structTypes.size())); + mlir::LLVM::AllocaOp::create(rewriter, loc, ptrTy, structTy, one); + auto size = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, structTypes.size())); mlir::Value argArray = - rewriter.create<mlir::LLVM::AllocaOp>(loc, ptrTy, ptrTy, size); + mlir::LLVM::AllocaOp::create(rewriter, loc, ptrTy, ptrTy, size); for (auto [i, arg] : llvm::enumerate(operands)) { - auto indice = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, i)); - mlir::Value structMember = rewriter.create<LLVM::GEPOp>( - loc, ptrTy, structTy, argStruct, - mlir::ArrayRef<mlir::Value>({zero, indice})); - rewriter.create<LLVM::StoreOp>(loc, arg, structMember); - mlir::Value arrayMember = rewriter.create<LLVM::GEPOp>( - loc, ptrTy, ptrTy, argArray, mlir::ArrayRef<mlir::Value>({indice})); - rewriter.create<LLVM::StoreOp>(loc, structMember, arrayMember); + auto indice = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, i)); + mlir::Value structMember = + LLVM::GEPOp::create(rewriter, loc, ptrTy, structTy, argStruct, + mlir::ArrayRef<mlir::Value>({zero, indice})); + LLVM::StoreOp::create(rewriter, loc, arg, structMember); + mlir::Value arrayMember = + LLVM::GEPOp::create(rewriter, loc, ptrTy, ptrTy, argArray, + mlir::ArrayRef<mlir::Value>({indice})); + LLVM::StoreOp::create(rewriter, loc, structMember, arrayMember); } return argArray; } @@ -94,8 +95,8 @@ struct GPULaunchKernelConversion mlir::Value dynamicMemorySize = op.getDynamicSharedMemorySize(); mlir::Type i32Ty = rewriter.getI32Type(); if (!dynamicMemorySize) - dynamicMemorySize = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); + dynamicMemorySize = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); mlir::Value kernelArgs = createKernelArgArray(loc, adaptor.getKernelOperands(), rewriter); @@ -108,17 +109,17 @@ struct GPULaunchKernelConversion if (!funcOp) return mlir::failure(); kernelPtr = - rewriter.create<LLVM::AddressOfOp>(loc, ptrTy, funcOp.getName()); + LLVM::AddressOfOp::create(rewriter, loc, ptrTy, funcOp.getName()); } else { kernelPtr = - rewriter.create<LLVM::AddressOfOp>(loc, ptrTy, kernel.getName()); + LLVM::AddressOfOp::create(rewriter, loc, ptrTy, kernel.getName()); } auto llvmIntPtrType = mlir::IntegerType::get( ctx, this->getTypeConverter()->getPointerBitwidth(0)); auto voidTy = mlir::LLVM::LLVMVoidType::get(ctx); - mlir::Value nullPtr = rewriter.create<LLVM::ZeroOp>(loc, ptrTy); + mlir::Value nullPtr = LLVM::ZeroOp::create(rewriter, loc, ptrTy); if (op.hasClusterSize()) { auto funcOp = mod.lookupSymbol<mlir::LLVM::LLVMFuncOp>( @@ -134,8 +135,8 @@ struct GPULaunchKernelConversion if (!funcOp) { mlir::OpBuilder::InsertionGuard insertGuard(rewriter); rewriter.setInsertionPointToStart(mod.getBody()); - auto launchKernelFuncOp = rewriter.create<mlir::LLVM::LLVMFuncOp>( - loc, RTNAME_STRING(CUFLaunchClusterKernel), funcTy); + auto launchKernelFuncOp = mlir::LLVM::LLVMFuncOp::create( + rewriter, loc, RTNAME_STRING(CUFLaunchClusterKernel), funcTy); launchKernelFuncOp.setVisibility( mlir::SymbolTable::Visibility::Private); } @@ -148,8 +149,8 @@ struct GPULaunchKernelConversion stream = adaptor.getAsyncDependencies().front(); } - rewriter.create<mlir::LLVM::CallOp>( - loc, funcTy, cufLaunchClusterKernel, + mlir::LLVM::CallOp::create( + rewriter, loc, funcTy, cufLaunchClusterKernel, mlir::ValueRange{kernelPtr, adaptor.getClusterSizeX(), adaptor.getClusterSizeY(), adaptor.getClusterSizeZ(), adaptor.getGridSizeX(), adaptor.getGridSizeY(), @@ -178,7 +179,7 @@ struct GPULaunchKernelConversion mlir::OpBuilder::InsertionGuard insertGuard(rewriter); rewriter.setInsertionPointToStart(mod.getBody()); auto launchKernelFuncOp = - rewriter.create<mlir::LLVM::LLVMFuncOp>(loc, fctName, funcTy); + mlir::LLVM::LLVMFuncOp::create(rewriter, loc, fctName, funcTy); launchKernelFuncOp.setVisibility( mlir::SymbolTable::Visibility::Private); } @@ -191,8 +192,8 @@ struct GPULaunchKernelConversion stream = adaptor.getAsyncDependencies().front(); } - rewriter.create<mlir::LLVM::CallOp>( - loc, funcTy, cufLaunchKernel, + mlir::LLVM::CallOp::create( + rewriter, loc, funcTy, cufLaunchKernel, mlir::ValueRange{kernelPtr, adaptor.getGridSizeX(), adaptor.getGridSizeY(), adaptor.getGridSizeZ(), adaptor.getBlockSizeX(), adaptor.getBlockSizeY(), @@ -222,11 +223,11 @@ static mlir::Value createAddressOfOp(mlir::ConversionPatternRewriter &rewriter, auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get( rewriter.getContext(), mlir::NVVM::NVVMMemorySpace::kSharedMemorySpace); if (auto g = gpuMod.lookupSymbol<fir::GlobalOp>(sharedGlobalName)) - return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy, - g.getSymName()); + return mlir::LLVM::AddressOfOp::create(rewriter, loc, llvmPtrTy, + g.getSymName()); if (auto g = gpuMod.lookupSymbol<mlir::LLVM::GlobalOp>(sharedGlobalName)) - return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy, - g.getSymName()); + return mlir::LLVM::AddressOfOp::create(rewriter, loc, llvmPtrTy, + g.getSymName()); return {}; } @@ -255,13 +256,13 @@ struct CUFSharedMemoryOpConversion if (!sharedGlobalAddr) mlir::emitError(loc, "Could not find the shared global operation\n"); - auto castPtr = rewriter.create<mlir::LLVM::AddrSpaceCastOp>( - loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), + auto castPtr = mlir::LLVM::AddrSpaceCastOp::create( + rewriter, loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), sharedGlobalAddr); mlir::Type baseType = castPtr->getResultTypes().front(); llvm::SmallVector<mlir::LLVM::GEPArg> gepArgs = {op.getOffset()}; - mlir::Value shmemPtr = rewriter.create<mlir::LLVM::GEPOp>( - loc, baseType, rewriter.getI8Type(), castPtr, gepArgs); + mlir::Value shmemPtr = mlir::LLVM::GEPOp::create( + rewriter, loc, baseType, rewriter.getI8Type(), castPtr, gepArgs); rewriter.replaceOp(op, {shmemPtr}); return mlir::success(); } diff --git a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp index 750569c..cd7d330 100644 --- a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp @@ -89,7 +89,7 @@ static mlir::Value createConvertOp(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Type toTy, mlir::Value val) { if (val.getType() != toTy) - return rewriter.create<fir::ConvertOp>(loc, toTy, val); + return fir::ConvertOp::create(rewriter, loc, toTy, val); return val; } @@ -118,7 +118,7 @@ static mlir::LogicalResult convertOpToCall(OpTy op, errmsg = op.getErrmsg(); } else { mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); - errmsg = builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + errmsg = fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); } llvm::SmallVector<mlir::Value> args; if constexpr (std::is_same_v<OpTy, cuf::AllocateOp>) { @@ -148,7 +148,7 @@ static mlir::LogicalResult convertOpToCall(OpTy op, fir::runtime::createArguments(builder, loc, fTy, op.getBox(), hasStat, errmsg, sourceFile, sourceLine); } - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); rewriter.replaceOp(op, callOp); return mlir::success(); } @@ -301,10 +301,11 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { if (inDeviceContext(op.getOperation())) { // In device context just replace the cuf.alloc operation with a fir.alloc // the cuf.free will be removed. - auto allocaOp = rewriter.create<fir::AllocaOp>( - loc, op.getInType(), op.getUniqName() ? *op.getUniqName() : "", - op.getBindcName() ? *op.getBindcName() : "", op.getTypeparams(), - op.getShape()); + auto allocaOp = + fir::AllocaOp::create(rewriter, loc, op.getInType(), + op.getUniqName() ? *op.getUniqName() : "", + op.getBindcName() ? *op.getBindcName() : "", + op.getTypeparams(), op.getShape()); allocaOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); rewriter.replaceOp(op, allocaOp); return mlir::success(); @@ -338,14 +339,15 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { assert(!op.getShape().empty() && "expect shape with dynamic arrays"); nbElem = builder.loadIfRef(loc, op.getShape()[0]); for (unsigned i = 1; i < op.getShape().size(); ++i) { - nbElem = rewriter.create<mlir::arith::MulIOp>( - loc, nbElem, builder.loadIfRef(loc, op.getShape()[i])); + nbElem = mlir::arith::MulIOp::create( + rewriter, loc, nbElem, + builder.loadIfRef(loc, op.getShape()[i])); } } else { nbElem = builder.createIntegerConstant(loc, builder.getIndexType(), seqTy.getConstantArraySize()); } - bytes = rewriter.create<mlir::arith::MulIOp>(loc, nbElem, width); + bytes = mlir::arith::MulIOp::create(rewriter, loc, nbElem, width); } else if (fir::isa_derived(op.getInType())) { mlir::Type structTy = typeConverter->convertType(op.getInType()); std::size_t structSize = dl->getTypeSizeInBits(structTy) / 8; @@ -363,7 +365,7 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { loc, builder.getI32Type(), getMemType(op.getDataAttr())); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, bytes, memTy, sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); auto convOp = builder.createConvert(loc, op.getResult().getType(), callOp.getResult(0)); @@ -386,7 +388,7 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, sizeInBytes, sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); auto convOp = builder.createConvert(loc, op.getResult().getType(), callOp.getResult(0)); @@ -414,8 +416,9 @@ struct CUFDeviceAddressOpConversion op.getHostSymbol().getRootReference().getValue())) { auto mod = op->getParentOfType<mlir::ModuleOp>(); mlir::Location loc = op.getLoc(); - auto hostAddr = rewriter.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(global.getType()), op.getHostSymbol()); + auto hostAddr = fir::AddrOfOp::create( + rewriter, loc, fir::ReferenceType::get(global.getType()), + op.getHostSymbol()); fir::FirOpBuilder builder(rewriter, mod); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(CUFGetDeviceAddress)>(loc, @@ -428,7 +431,7 @@ struct CUFDeviceAddressOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, conv, sourceFile, sourceLine)}; - auto call = rewriter.create<fir::CallOp>(loc, callee, args); + auto call = fir::CallOp::create(rewriter, loc, callee, args); mlir::Value addr = createConvertOp(rewriter, loc, hostAddr.getType(), call->getResult(0)); rewriter.replaceOp(op, addr.getDefiningOp()); @@ -456,8 +459,8 @@ struct DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> { addrOfOp.getSymbol().getRootReference().getValue())) { if (cuf::isRegisteredDeviceGlobal(global)) { rewriter.setInsertionPointAfter(addrOfOp); - mlir::Value devAddr = rewriter.create<cuf::DeviceAddressOp>( - op.getLoc(), addrOfOp.getType(), addrOfOp.getSymbol()); + mlir::Value devAddr = cuf::DeviceAddressOp::create( + rewriter, op.getLoc(), addrOfOp.getType(), addrOfOp.getSymbol()); rewriter.startOpModification(op); op.getMemrefMutable().assign(devAddr); rewriter.finalizeOpModification(op); @@ -502,7 +505,7 @@ struct CUFFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> { loc, builder.getI32Type(), getMemType(op.getDataAttr())); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, op.getDevptr(), memTy, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -515,7 +518,7 @@ struct CUFFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> { fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, op.getDevptr(), sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); rewriter.eraseOp(op); return mlir::success(); @@ -558,18 +561,18 @@ static mlir::Value emboxSrc(mlir::PatternRewriter &rewriter, srcTy = fir::LogicalType::get(rewriter.getContext(), 4); src = createConvertOp(rewriter, loc, srcTy, src); addr = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, addr); + fir::StoreOp::create(builder, loc, src, addr); } else { if (dstEleTy && fir::isa_trivial(dstEleTy) && srcTy != dstEleTy) { // Use dstEleTy and convert to avoid assign mismatch. addr = builder.createTemporary(loc, dstEleTy); - auto conv = builder.create<fir::ConvertOp>(loc, dstEleTy, src); - builder.create<fir::StoreOp>(loc, conv, addr); + auto conv = fir::ConvertOp::create(builder, loc, dstEleTy, src); + fir::StoreOp::create(builder, loc, conv, addr); srcTy = dstEleTy; } else { // Put constant in memory if it is not. addr = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, addr); + fir::StoreOp::create(builder, loc, src, addr); } } } else { @@ -582,7 +585,7 @@ static mlir::Value emboxSrc(mlir::PatternRewriter &rewriter, /*slice=*/nullptr, lenParams, /*tdesc=*/nullptr); mlir::Value src = builder.createTemporary(loc, box.getType()); - builder.create<fir::StoreOp>(loc, box, src); + fir::StoreOp::create(builder, loc, box, src); return src; } @@ -601,7 +604,7 @@ static mlir::Value emboxDst(mlir::PatternRewriter &rewriter, /*slice=*/nullptr, lenParams, /*tdesc=*/nullptr); mlir::Value dst = builder.createTemporary(loc, dstBox.getType()); - builder.create<fir::StoreOp>(loc, dstBox, dst); + fir::StoreOp::create(builder, loc, dstBox, dst); return dst; } @@ -660,7 +663,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -679,12 +682,12 @@ struct CUFDataTransferOpConversion extents.push_back(i.value()); } - nbElement = rewriter.create<fir::ConvertOp>(loc, i64Ty, extents[0]); + nbElement = fir::ConvertOp::create(rewriter, loc, i64Ty, extents[0]); for (unsigned i = 1; i < extents.size(); ++i) { auto operand = - rewriter.create<fir::ConvertOp>(loc, i64Ty, extents[i]); + fir::ConvertOp::create(rewriter, loc, i64Ty, extents[i]); nbElement = - rewriter.create<mlir::arith::MulIOp>(loc, nbElement, operand); + mlir::arith::MulIOp::create(rewriter, loc, nbElement, operand); } } else { if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(dstTy)) @@ -699,12 +702,11 @@ struct CUFDataTransferOpConversion } else { width = computeWidth(loc, dstTy, kindMap); } - mlir::Value widthValue = rewriter.create<mlir::arith::ConstantOp>( - loc, i64Ty, rewriter.getIntegerAttr(i64Ty, width)); - mlir::Value bytes = - nbElement - ? rewriter.create<mlir::arith::MulIOp>(loc, nbElement, widthValue) - : widthValue; + mlir::Value widthValue = mlir::arith::ConstantOp::create( + rewriter, loc, i64Ty, rewriter.getIntegerAttr(i64Ty, width)); + mlir::Value bytes = nbElement ? mlir::arith::MulIOp::create( + rewriter, loc, nbElement, widthValue) + : widthValue; mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey(CUFDataTransferPtrPtr)>(loc, @@ -719,13 +721,13 @@ struct CUFDataTransferOpConversion // Materialize the src if constant. if (matchPattern(src.getDefiningOp(), mlir::m_Constant())) { mlir::Value temp = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, temp); + fir::StoreOp::create(builder, loc, src, temp); src = temp; } llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, dst, src, bytes, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -734,7 +736,7 @@ struct CUFDataTransferOpConversion if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp())) { // Materialize the box to memory to be able to call the runtime. mlir::Value box = builder.createTemporary(loc, val.getType()); - builder.create<fir::StoreOp>(loc, val, box); + fir::StoreOp::create(builder, loc, val, box); return box; } return val; @@ -768,7 +770,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); } else { // Transfer from a descriptor. @@ -784,7 +786,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); } return mlir::success(); @@ -810,20 +812,21 @@ public: mlir::PatternRewriter &rewriter) const override { mlir::Location loc = op.getLoc(); auto idxTy = mlir::IndexType::get(op.getContext()); - mlir::Value zero = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getIntegerType(32), rewriter.getI32IntegerAttr(0)); + mlir::Value zero = mlir::arith::ConstantOp::create( + rewriter, loc, rewriter.getIntegerType(32), + rewriter.getI32IntegerAttr(0)); auto gridSizeX = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridX()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridX()); auto gridSizeY = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridY()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridY()); auto gridSizeZ = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridZ()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridZ()); auto blockSizeX = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockX()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockX()); auto blockSizeY = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockY()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockY()); auto blockSizeZ = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockZ()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockZ()); auto kernelName = mlir::SymbolRefAttr::get( rewriter.getStringAttr(cudaDeviceModuleName), {mlir::SymbolRefAttr::get( @@ -835,12 +838,12 @@ public: op.getCallee().getLeafReference())) { if (auto clusterDimsAttr = funcOp->getAttrOfType<cuf::ClusterDimsAttr>( cuf::getClusterDimsAttrName())) { - clusterDimX = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getX().getInt()); - clusterDimY = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getY().getInt()); - clusterDimZ = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getZ().getInt()); + clusterDimX = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getX().getInt()); + clusterDimY = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getY().getInt()); + clusterDimZ = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getZ().getInt()); } procAttr = funcOp->getAttrOfType<cuf::ProcAttributeAttr>(cuf::getProcAttrName()); @@ -870,8 +873,9 @@ public: args.push_back(arg); } mlir::Value dynamicShmemSize = op.getBytes() ? op.getBytes() : zero; - auto gpuLaunchOp = rewriter.create<mlir::gpu::LaunchFuncOp>( - loc, kernelName, mlir::gpu::KernelDim3{gridSizeX, gridSizeY, gridSizeZ}, + auto gpuLaunchOp = mlir::gpu::LaunchFuncOp::create( + rewriter, loc, kernelName, + mlir::gpu::KernelDim3{gridSizeX, gridSizeY, gridSizeZ}, mlir::gpu::KernelDim3{blockSizeX, blockSizeY, blockSizeZ}, dynamicShmemSize, args); if (clusterDimX && clusterDimY && clusterDimZ) { @@ -883,7 +887,7 @@ public: mlir::OpBuilder::InsertionGuard guard(rewriter); rewriter.setInsertionPoint(gpuLaunchOp); mlir::Value stream = - rewriter.create<cuf::StreamCastOp>(loc, op.getStream()); + cuf::StreamCastOp::create(rewriter, loc, op.getStream()); gpuLaunchOp.getAsyncDependenciesMutable().append(stream); } if (procAttr) @@ -916,8 +920,9 @@ struct CUFSyncDescriptorOpConversion if (!globalOp) return mlir::failure(); - auto hostAddr = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), op.getGlobalName()); + auto hostAddr = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + op.getGlobalName()); fir::runtime::cuda::genSyncGlobalDescriptor(builder, loc, hostAddr); op.erase(); return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp index aee7e8c..13da38e 100644 --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -48,12 +48,13 @@ public: << "running character conversion on " << conv << '\n'); // Establish a loop that executes count iterations. - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); auto idxTy = rewriter.getIndexType(); - auto castCnt = rewriter.create<fir::ConvertOp>(loc, idxTy, conv.getCount()); - auto countm1 = rewriter.create<mlir::arith::SubIOp>(loc, castCnt, one); - auto loop = rewriter.create<fir::DoLoopOp>(loc, zero, countm1, one); + auto castCnt = + fir::ConvertOp::create(rewriter, loc, idxTy, conv.getCount()); + auto countm1 = mlir::arith::SubIOp::create(rewriter, loc, castCnt, one); + auto loop = fir::DoLoopOp::create(rewriter, loc, zero, countm1, one); auto insPt = rewriter.saveInsertionPoint(); rewriter.setInsertionPointToStart(loop.getBody()); @@ -75,21 +76,22 @@ public: auto toTy = rewriter.getIntegerType(toBits); auto toPtrTy = pointerType(toBits); auto fromPtr = - rewriter.create<fir::ConvertOp>(loc, fromPtrTy, conv.getFrom()); - auto toPtr = rewriter.create<fir::ConvertOp>(loc, toPtrTy, conv.getTo()); + fir::ConvertOp::create(rewriter, loc, fromPtrTy, conv.getFrom()); + auto toPtr = fir::ConvertOp::create(rewriter, loc, toPtrTy, conv.getTo()); auto getEleTy = [&](unsigned bits) { return fir::ReferenceType::get(rewriter.getIntegerType(bits)); }; - auto fromi = rewriter.create<fir::CoordinateOp>( - loc, getEleTy(fromBits), fromPtr, - mlir::ValueRange{loop.getInductionVar()}); - auto toi = rewriter.create<fir::CoordinateOp>( - loc, getEleTy(toBits), toPtr, mlir::ValueRange{loop.getInductionVar()}); - auto load = rewriter.create<fir::LoadOp>(loc, fromi); + auto fromi = + fir::CoordinateOp::create(rewriter, loc, getEleTy(fromBits), fromPtr, + mlir::ValueRange{loop.getInductionVar()}); + auto toi = + fir::CoordinateOp::create(rewriter, loc, getEleTy(toBits), toPtr, + mlir::ValueRange{loop.getInductionVar()}); + auto load = fir::LoadOp::create(rewriter, loc, fromi); mlir::Value icast = (fromBits >= toBits) - ? rewriter.create<fir::ConvertOp>(loc, toTy, load).getResult() - : rewriter.create<mlir::arith::ExtUIOp>(loc, toTy, load) + ? fir::ConvertOp::create(rewriter, loc, toTy, load).getResult() + : mlir::arith::ExtUIOp::create(rewriter, loc, toTy, load) .getResult(); rewriter.replaceOpWithNewOp<fir::StoreOp>(conv, icast, toi); rewriter.restoreInsertionPoint(insPt); diff --git a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp index 239a7cd..afafbd8 100644 --- a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp +++ b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp @@ -111,11 +111,11 @@ public: builder.insert(cln); mlir::Value val = builder.createConvert(loc, varTy, cln->getResult(0)); - builder.create<fir::HasValueOp>(loc, val); + fir::HasValueOp::create(builder, loc, val); }, builder.createInternalLinkage()); - mlir::Value addr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, global.resultType(), global.getSymbol()); newOperands.push_back(addr); needUpdate = true; } @@ -125,11 +125,11 @@ public: llvm::SmallVector<mlir::Type> newResultTypes; newResultTypes.append(callOp.getResultTypes().begin(), callOp.getResultTypes().end()); - fir::CallOp newOp = builder.create<fir::CallOp>( - loc, - callOp.getCallee().has_value() ? callOp.getCallee().value() - : mlir::SymbolRefAttr{}, - newResultTypes, newOperands); + fir::CallOp newOp = fir::CallOp::create(builder, loc, + callOp.getCallee().has_value() + ? callOp.getCallee().value() + : mlir::SymbolRefAttr{}, + newResultTypes, newOperands); // Copy all the attributes from the old to new op. newOp->setAttrs(callOp->getAttrs()); rewriter.replaceOp(callOp, newOp); diff --git a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp index 3d35803..e466aed 100644 --- a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp +++ b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp @@ -83,17 +83,17 @@ public: // Initalization block rewriter.setInsertionPointToEnd(initBlock); - auto diff = rewriter.create<mlir::arith::SubIOp>(loc, high, low); - auto distance = rewriter.create<mlir::arith::AddIOp>(loc, diff, step); + auto diff = mlir::arith::SubIOp::create(rewriter, loc, high, low); + auto distance = mlir::arith::AddIOp::create(rewriter, loc, diff, step); mlir::Value iters = - rewriter.create<mlir::arith::DivSIOp>(loc, distance, step); + mlir::arith::DivSIOp::create(rewriter, loc, distance, step); if (forceLoopToExecuteOnce) { - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto cond = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, iters, zero); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); - iters = rewriter.create<mlir::arith::SelectOp>(loc, cond, one, iters); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto cond = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, iters, zero); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); + iters = mlir::arith::SelectOp::create(rewriter, loc, cond, one, iters); } llvm::SmallVector<mlir::Value> loopOperands; @@ -102,20 +102,20 @@ public: loopOperands.append(operands.begin(), operands.end()); loopOperands.push_back(iters); - rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopOperands); + mlir::cf::BranchOp::create(rewriter, loc, conditionalBlock, loopOperands); // Last loop block auto *terminator = lastBlock->getTerminator(); rewriter.setInsertionPointToEnd(lastBlock); auto iv = conditionalBlock->getArgument(0); mlir::Value steppedIndex = - rewriter.create<mlir::arith::AddIOp>(loc, iv, step, iofAttr); + mlir::arith::AddIOp::create(rewriter, loc, iv, step, iofAttr); assert(steppedIndex && "must be a Value"); auto lastArg = conditionalBlock->getNumArguments() - 1; auto itersLeft = conditionalBlock->getArgument(lastArg); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); mlir::Value itersMinusOne = - rewriter.create<mlir::arith::SubIOp>(loc, itersLeft, one); + mlir::arith::SubIOp::create(rewriter, loc, itersLeft, one); llvm::SmallVector<mlir::Value> loopCarried; loopCarried.push_back(steppedIndex); @@ -123,8 +123,8 @@ public: : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); loopCarried.push_back(itersMinusOne); - auto backEdge = - rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopCarried); + auto backEdge = mlir::cf::BranchOp::create(rewriter, loc, conditionalBlock, + loopCarried); rewriter.eraseOp(terminator); // Copy loop annotations from the do loop to the loop back edge. @@ -133,13 +133,13 @@ public: // Conditional block rewriter.setInsertionPointToEnd(conditionalBlock); - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto comparison = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sgt, itersLeft, zero); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto comparison = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sgt, itersLeft, zero); - rewriter.create<mlir::cf::CondBranchOp>( - loc, comparison, firstBlock, llvm::ArrayRef<mlir::Value>(), endBlock, - llvm::ArrayRef<mlir::Value>()); + mlir::cf::CondBranchOp::create(rewriter, loc, comparison, firstBlock, + llvm::ArrayRef<mlir::Value>(), endBlock, + llvm::ArrayRef<mlir::Value>()); // The result of the loop operation is the values of the condition block // arguments except the induction variable on the last iteration. @@ -180,7 +180,7 @@ public: continueBlock = rewriter.createBlock( remainingOpsBlock, ifOp.getResultTypes(), llvm::SmallVector<mlir::Location>(ifOp.getNumResults(), loc)); - rewriter.create<mlir::cf::BranchOp>(loc, remainingOpsBlock); + mlir::cf::BranchOp::create(rewriter, loc, remainingOpsBlock); } // Move blocks from the "then" region to the region containing 'fir.if', @@ -190,8 +190,8 @@ public: auto *ifOpTerminator = ifOpRegion.back().getTerminator(); auto ifOpTerminatorOperands = ifOpTerminator->getOperands(); rewriter.setInsertionPointToEnd(&ifOpRegion.back()); - rewriter.create<mlir::cf::BranchOp>(loc, continueBlock, - ifOpTerminatorOperands); + mlir::cf::BranchOp::create(rewriter, loc, continueBlock, + ifOpTerminatorOperands); rewriter.eraseOp(ifOpTerminator); rewriter.inlineRegionBefore(ifOpRegion, continueBlock); @@ -205,16 +205,17 @@ public: auto *otherwiseTerm = otherwiseRegion.back().getTerminator(); auto otherwiseTermOperands = otherwiseTerm->getOperands(); rewriter.setInsertionPointToEnd(&otherwiseRegion.back()); - rewriter.create<mlir::cf::BranchOp>(loc, continueBlock, - otherwiseTermOperands); + mlir::cf::BranchOp::create(rewriter, loc, continueBlock, + otherwiseTermOperands); rewriter.eraseOp(otherwiseTerm); rewriter.inlineRegionBefore(otherwiseRegion, continueBlock); } rewriter.setInsertionPointToEnd(condBlock); - auto branchOp = rewriter.create<mlir::cf::CondBranchOp>( - loc, ifOp.getCondition(), ifOpBlock, llvm::ArrayRef<mlir::Value>(), - otherwiseBlock, llvm::ArrayRef<mlir::Value>()); + auto branchOp = mlir::cf::CondBranchOp::create( + rewriter, loc, ifOp.getCondition(), ifOpBlock, + llvm::ArrayRef<mlir::Value>(), otherwiseBlock, + llvm::ArrayRef<mlir::Value>()); llvm::ArrayRef<int32_t> weights = ifOp.getWeights(); if (!weights.empty()) branchOp.setWeights(weights); @@ -269,7 +270,7 @@ public: rewriter.setInsertionPointToEnd(lastBodyBlock); auto step = whileOp.getStep(); mlir::Value stepped = - rewriter.create<mlir::arith::AddIOp>(loc, iv, step, iofAttr); + mlir::arith::AddIOp::create(rewriter, loc, iv, step, iofAttr); assert(stepped && "must be a Value"); llvm::SmallVector<mlir::Value> loopCarried; @@ -278,7 +279,7 @@ public: ? std::next(terminator->operand_begin()) : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); - rewriter.create<mlir::cf::BranchOp>(loc, conditionBlock, loopCarried); + mlir::cf::BranchOp::create(rewriter, loc, conditionBlock, loopCarried); rewriter.eraseOp(terminator); // Compute loop bounds before branching to the condition. @@ -293,31 +294,31 @@ public: destOperands.push_back(lowerBound); auto iterOperands = whileOp.getIterOperands(); destOperands.append(iterOperands.begin(), iterOperands.end()); - rewriter.create<mlir::cf::BranchOp>(loc, conditionBlock, destOperands); + mlir::cf::BranchOp::create(rewriter, loc, conditionBlock, destOperands); // With the body block done, we can fill in the condition block. rewriter.setInsertionPointToEnd(conditionBlock); // The comparison depends on the sign of the step value. We fully expect // this expression to be folded by the optimizer or LLVM. This expression // is written this way so that `step == 0` always returns `false`. - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto compl0 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::slt, zero, step); - auto compl1 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, iv, upperBound); - auto compl2 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::slt, step, zero); - auto compl3 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, upperBound, iv); - auto cmp0 = rewriter.create<mlir::arith::AndIOp>(loc, compl0, compl1); - auto cmp1 = rewriter.create<mlir::arith::AndIOp>(loc, compl2, compl3); - auto cmp2 = rewriter.create<mlir::arith::OrIOp>(loc, cmp0, cmp1); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto compl0 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::slt, zero, step); + auto compl1 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, iv, upperBound); + auto compl2 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::slt, step, zero); + auto compl3 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, upperBound, iv); + auto cmp0 = mlir::arith::AndIOp::create(rewriter, loc, compl0, compl1); + auto cmp1 = mlir::arith::AndIOp::create(rewriter, loc, compl2, compl3); + auto cmp2 = mlir::arith::OrIOp::create(rewriter, loc, cmp0, cmp1); // Remember to AND in the early-exit bool. auto comparison = - rewriter.create<mlir::arith::AndIOp>(loc, iterateVar, cmp2); - rewriter.create<mlir::cf::CondBranchOp>( - loc, comparison, firstBodyBlock, llvm::ArrayRef<mlir::Value>(), - endBlock, llvm::ArrayRef<mlir::Value>()); + mlir::arith::AndIOp::create(rewriter, loc, iterateVar, cmp2); + mlir::cf::CondBranchOp::create(rewriter, loc, comparison, firstBodyBlock, + llvm::ArrayRef<mlir::Value>(), endBlock, + llvm::ArrayRef<mlir::Value>()); // The result of the loop operation is the values of the condition block // arguments except the induction variable on the last iteration. auto args = whileOp.getFinalValue() diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp index abad500..5dcb54e 100644 --- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp +++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp @@ -103,13 +103,14 @@ mlir::LLVM::DILocalVariableAttr DebugTypeGenerator::generateArtificialVariable( mlir::Type type = val.getType(); if (!mlir::isa<mlir::IntegerType>(type) || !type.isSignlessInteger()) { type = builder.getIntegerType(64); - val = builder.create<fir::ConvertOp>(declOp.getLoc(), type, val); + val = fir::ConvertOp::create(builder, declOp.getLoc(), type, val); } mlir::LLVM::DITypeAttr Ty = convertType(type, fileAttr, scope, declOp); auto lvAttr = mlir::LLVM::DILocalVariableAttr::get( context, scope, name, fileAttr, /*line=*/0, /*argNo=*/0, /*alignInBits=*/0, Ty, mlir::LLVM::DIFlags::Artificial); - builder.create<mlir::LLVM::DbgValueOp>(declOp.getLoc(), val, lvAttr, nullptr); + mlir::LLVM::DbgValueOp::create(builder, declOp.getLoc(), val, lvAttr, + nullptr); return lvAttr; } diff --git a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp index f06ad2d..d7d1865 100644 --- a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp +++ b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp @@ -49,13 +49,13 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> { // must be a positive value. // For easier conversion, we calculate the trip count and use a canonical // induction variable. - auto diff = rewriter.create<arith::SubIOp>(loc, high, low); - auto distance = rewriter.create<arith::AddIOp>(loc, diff, step); - auto tripCount = rewriter.create<arith::DivSIOp>(loc, distance, step); - auto zero = rewriter.create<arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<arith::ConstantIndexOp>(loc, 1); + auto diff = arith::SubIOp::create(rewriter, loc, high, low); + auto distance = arith::AddIOp::create(rewriter, loc, diff, step); + auto tripCount = arith::DivSIOp::create(rewriter, loc, distance, step); + auto zero = arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = arith::ConstantIndexOp::create(rewriter, loc, 1); auto scfForOp = - rewriter.create<scf::ForOp>(loc, zero, tripCount, one, iterArgs); + scf::ForOp::create(rewriter, loc, zero, tripCount, one, iterArgs); auto &loopOps = doLoopOp.getBody()->getOperations(); auto resultOp = cast<fir::ResultOp>(doLoopOp.getBody()->getTerminator()); @@ -68,12 +68,12 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> { rewriter.setInsertionPointToStart(loweredBody); Value iv = - rewriter.create<arith::MulIOp>(loc, scfForOp.getInductionVar(), step); - iv = rewriter.create<arith::AddIOp>(loc, low, iv); + arith::MulIOp::create(rewriter, loc, scfForOp.getInductionVar(), step); + iv = arith::AddIOp::create(rewriter, loc, low, iv); if (!results.empty()) { rewriter.setInsertionPointToEnd(loweredBody); - rewriter.create<scf::YieldOp>(resultOp->getLoc(), results); + scf::YieldOp::create(rewriter, resultOp->getLoc(), results); } doLoopOp.getInductionVar().replaceAllUsesWith(iv); rewriter.replaceAllUsesWith(doLoopOp.getRegionIterArgs(), diff --git a/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp b/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp index 7ea3b9c..699be12 100644 --- a/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp +++ b/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp @@ -91,8 +91,8 @@ void GenRuntimeCallsForTestPass::runOnOperation() { // Generate the wrapper function body that consists of a call and return. builder.setInsertionPointToStart(callerFunc.addEntryBlock()); mlir::Block::BlockArgListType args = callerFunc.front().getArguments(); - auto callOp = builder.create<fir::CallOp>(loc, funcOp, args); - builder.create<mlir::func::ReturnOp>(loc, callOp.getResults()); + auto callOp = fir::CallOp::create(builder, loc, funcOp, args); + mlir::func::ReturnOp::create(builder, loc, callOp.getResults()); newFuncs.push_back(callerFunc.getOperation()); builder.restoreInsertionPoint(insertPt); diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp index 056bdf6..0095159 100644 --- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp +++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp @@ -285,7 +285,7 @@ static mlir::Value getIndex(fir::FirOpBuilder &builder, mlir::Operation *op, // index_0 = index - lb; if (lb.getType() != index.getType()) lb = builder.createConvert(coop.getLoc(), index.getType(), lb); - return builder.create<mlir::arith::SubIOp>(coop.getLoc(), index, lb); + return mlir::arith::SubIOp::create(builder, coop.getLoc(), index, lb); } void LoopVersioningPass::runOnOperation() { @@ -483,26 +483,26 @@ void LoopVersioningPass::runOnOperation() { unsigned ndims = arg.rank; for (unsigned i = 0; i < ndims; i++) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - arg.dims[i] = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - arg.arg, dimIdx); + arg.dims[i] = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + arg.arg, dimIdx); } // We only care about lowest order dimension, here. mlir::Value elemSize = builder.createIntegerConstant(loc, idxTy, arg.size); - mlir::Value cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, arg.dims[0].getResult(2), - elemSize); + mlir::Value cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, + arg.dims[0].getResult(2), elemSize); if (!allCompares) { allCompares = cmp; } else { allCompares = - builder.create<mlir::arith::AndIOp>(loc, cmp, allCompares); + mlir::arith::AndIOp::create(builder, loc, cmp, allCompares); } } auto ifOp = - builder.create<fir::IfOp>(loc, op.op->getResultTypes(), allCompares, - /*withElse=*/true); + fir::IfOp::create(builder, loc, op.op->getResultTypes(), allCompares, + /*withElse=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); LLVM_DEBUG(llvm::dbgs() << "Creating cloned loop\n"); @@ -515,8 +515,8 @@ void LoopVersioningPass::runOnOperation() { mlir::Type arrTy = fir::SequenceType::get(newShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); mlir::Type refArrTy = builder.getRefType(arrTy); - auto carg = builder.create<fir::ConvertOp>(loc, boxArrTy, arg.arg); - auto caddr = builder.create<fir::BoxAddrOp>(loc, refArrTy, carg); + auto carg = fir::ConvertOp::create(builder, loc, boxArrTy, arg.arg); + auto caddr = fir::BoxAddrOp::create(builder, loc, refArrTy, carg); auto insPt = builder.saveInsertionPoint(); // Use caddr instead of arg. clonedLoop->walk([&](mlir::Operation *coop) { @@ -540,9 +540,9 @@ void LoopVersioningPass::runOnOperation() { mlir::Value scale = builder.createConvert(loc, idxTy, arg.dims[i].getResult(2)); curIndex = - builder.create<mlir::arith::MulIOp>(loc, scale, curIndex); - totalIndex = (totalIndex) ? builder.create<mlir::arith::AddIOp>( - loc, curIndex, totalIndex) + mlir::arith::MulIOp::create(builder, loc, scale, curIndex); + totalIndex = (totalIndex) ? mlir::arith::AddIOp::create( + builder, loc, curIndex, totalIndex) : curIndex; } // This is the lowest dimension - which doesn't need scaling @@ -554,16 +554,16 @@ void LoopVersioningPass::runOnOperation() { unsigned bits = llvm::Log2_32(arg.size); mlir::Value elemShift = builder.createIntegerConstant(loc, idxTy, bits); - totalIndex = builder.create<mlir::arith::AddIOp>( - loc, - builder.create<mlir::arith::ShRSIOp>(loc, totalIndex, - elemShift), + totalIndex = mlir::arith::AddIOp::create( + builder, loc, + mlir::arith::ShRSIOp::create(builder, loc, totalIndex, + elemShift), finalIndex); } else { totalIndex = finalIndex; } - auto newOp = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(elementType), caddr, + auto newOp = fir::CoordinateOp::create( + builder, loc, builder.getRefType(elementType), caddr, mlir::ValueRange{totalIndex}); LLVM_DEBUG(newOp->dump()); coop->getResult(0).replaceAllUsesWith(newOp->getResult(0)); @@ -582,7 +582,7 @@ void LoopVersioningPass::runOnOperation() { mlir::ResultRange results = clonedLoop->getResults(); bool hasResults = (results.size() > 0); if (hasResults) - builder.create<fir::ResultOp>(loc, results); + fir::ResultOp::create(builder, loc, results); // Add the original loop in the else-side of the if operation. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); @@ -591,7 +591,7 @@ void LoopVersioningPass::runOnOperation() { builder.insert(op.op); // Rely on "cloned loop has results, so original loop also has results". if (hasResults) { - builder.create<fir::ResultOp>(loc, op.op->getResults()); + fir::ResultOp::create(builder, loc, op.op->getResults()); } else { // Use an assert to check this. assert(op.op->getResults().size() == 0 && diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp index 3f308a8..9904089 100644 --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -68,9 +68,9 @@ static mlir::Value genAllocmem(mlir::OpBuilder &builder, fir::AllocaOp alloca, }; llvm::StringRef uniqName = unpackName(alloca.getUniqName()); llvm::StringRef bindcName = unpackName(alloca.getBindcName()); - auto heap = builder.create<fir::AllocMemOp>(alloca.getLoc(), varTy, uniqName, - bindcName, alloca.getTypeparams(), - alloca.getShape()); + auto heap = fir::AllocMemOp::create(builder, alloca.getLoc(), varTy, uniqName, + bindcName, alloca.getTypeparams(), + alloca.getShape()); LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: replaced " << alloca << " with " << heap << '\n'); return heap; @@ -78,7 +78,7 @@ static mlir::Value genAllocmem(mlir::OpBuilder &builder, fir::AllocaOp alloca, static void genFreemem(mlir::Location loc, mlir::OpBuilder &builder, mlir::Value allocmem) { - [[maybe_unused]] auto free = builder.create<fir::FreeMemOp>(loc, allocmem); + [[maybe_unused]] auto free = fir::FreeMemOp::create(builder, loc, allocmem); LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: add free " << free << " for " << allocmem << '\n'); } diff --git a/flang/lib/Optimizer/Transforms/MemoryUtils.cpp b/flang/lib/Optimizer/Transforms/MemoryUtils.cpp index 1f8edf8..789111c 100644 --- a/flang/lib/Optimizer/Transforms/MemoryUtils.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryUtils.cpp @@ -200,30 +200,30 @@ void AllocaReplaceImpl::genIndirectDeallocation( // and access it indirectly in the entry points that do not dominate. rewriter.setInsertionPointToStart(&owningRegion.front()); mlir::Type heapType = fir::HeapType::get(alloca.getInType()); - mlir::Value ptrVar = rewriter.create<fir::AllocaOp>(loc, heapType); - mlir::Value nullPtr = rewriter.create<fir::ZeroOp>(loc, heapType); - rewriter.create<fir::StoreOp>(loc, nullPtr, ptrVar); + mlir::Value ptrVar = fir::AllocaOp::create(rewriter, loc, heapType); + mlir::Value nullPtr = fir::ZeroOp::create(rewriter, loc, heapType); + fir::StoreOp::create(rewriter, loc, nullPtr, ptrVar); // TODO: introducing a pointer compare op in FIR would help // generating less IR here. mlir::Type intPtrTy = fir::getIntPtrType(rewriter); - mlir::Value c0 = rewriter.create<mlir::arith::ConstantOp>( - loc, intPtrTy, rewriter.getIntegerAttr(intPtrTy, 0)); + mlir::Value c0 = mlir::arith::ConstantOp::create( + rewriter, loc, intPtrTy, rewriter.getIntegerAttr(intPtrTy, 0)); // Store new storage address right after its creation. rewriter.restoreInsertionPoint(replacementInsertPoint); mlir::Value castReplacement = fir::factory::createConvert(rewriter, loc, heapType, replacement); - rewriter.create<fir::StoreOp>(loc, castReplacement, ptrVar); + fir::StoreOp::create(rewriter, loc, castReplacement, ptrVar); // Generate conditional deallocation at every deallocation point. auto genConditionalDealloc = [&](mlir::Location loc) { - mlir::Value ptrVal = rewriter.create<fir::LoadOp>(loc, ptrVar); + mlir::Value ptrVal = fir::LoadOp::create(rewriter, loc, ptrVar); mlir::Value ptrToInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, ptrVal); - mlir::Value isAllocated = rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, ptrToInt, c0); - auto ifOp = rewriter.create<fir::IfOp>(loc, std::nullopt, isAllocated, - /*withElseRegion=*/false); + fir::ConvertOp::create(rewriter, loc, intPtrTy, ptrVal); + mlir::Value isAllocated = mlir::arith::CmpIOp::create( + rewriter, loc, mlir::arith::CmpIPredicate::ne, ptrToInt, c0); + auto ifOp = fir::IfOp::create(rewriter, loc, mlir::TypeRange{}, isAllocated, + /*withElseRegion=*/false); rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front()); mlir::Value cast = fir::factory::createConvert( rewriter, loc, replacement.getType(), ptrVal); diff --git a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp index 57eae1f..2c6601d 100644 --- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp @@ -183,49 +183,51 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> { mlir::Type tdescType = fir::TypeDescType::get(mlir::NoneType::get(rewriter.getContext())); mlir::Value boxDesc = - rewriter.create<fir::BoxTypeDescOp>(loc, tdescType, passedObject); - boxDesc = rewriter.create<fir::ConvertOp>( - loc, fir::ReferenceType::get(typeDescTy), boxDesc); + fir::BoxTypeDescOp::create(rewriter, loc, tdescType, passedObject); + boxDesc = fir::ConvertOp::create( + rewriter, loc, fir::ReferenceType::get(typeDescTy), boxDesc); // Load the bindings descriptor. auto bindingsCompName = Fortran::semantics::bindingDescCompName; fir::RecordType typeDescRecTy = mlir::cast<fir::RecordType>(typeDescTy); - mlir::Value field = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, bindingsCompName, typeDescRecTy, mlir::ValueRange{}); + mlir::Value field = + fir::FieldIndexOp::create(rewriter, loc, fieldTy, bindingsCompName, + typeDescRecTy, mlir::ValueRange{}); mlir::Type coorTy = fir::ReferenceType::get(typeDescRecTy.getType(bindingsCompName)); mlir::Value bindingBoxAddr = - rewriter.create<fir::CoordinateOp>(loc, coorTy, boxDesc, field); - mlir::Value bindingBox = rewriter.create<fir::LoadOp>(loc, bindingBoxAddr); + fir::CoordinateOp::create(rewriter, loc, coorTy, boxDesc, field); + mlir::Value bindingBox = fir::LoadOp::create(rewriter, loc, bindingBoxAddr); // Load the correct binding. - mlir::Value bindings = rewriter.create<fir::BoxAddrOp>(loc, bindingBox); + mlir::Value bindings = fir::BoxAddrOp::create(rewriter, loc, bindingBox); fir::RecordType bindingTy = fir::unwrapIfDerived( mlir::cast<fir::BaseBoxType>(bindingBox.getType())); mlir::Type bindingAddrTy = fir::ReferenceType::get(bindingTy); - mlir::Value bindingIdxVal = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getIndexType(), rewriter.getIndexAttr(bindingIdx)); - mlir::Value bindingAddr = rewriter.create<fir::CoordinateOp>( - loc, bindingAddrTy, bindings, bindingIdxVal); + mlir::Value bindingIdxVal = + mlir::arith::ConstantOp::create(rewriter, loc, rewriter.getIndexType(), + rewriter.getIndexAttr(bindingIdx)); + mlir::Value bindingAddr = fir::CoordinateOp::create( + rewriter, loc, bindingAddrTy, bindings, bindingIdxVal); // Get the function pointer. auto procCompName = Fortran::semantics::procCompName; - mlir::Value procField = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); + mlir::Value procField = fir::FieldIndexOp::create( + rewriter, loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); fir::RecordType procTy = mlir::cast<fir::RecordType>(bindingTy.getType(procCompName)); mlir::Type procRefTy = fir::ReferenceType::get(procTy); - mlir::Value procRef = rewriter.create<fir::CoordinateOp>( - loc, procRefTy, bindingAddr, procField); + mlir::Value procRef = fir::CoordinateOp::create(rewriter, loc, procRefTy, + bindingAddr, procField); auto addressFieldName = Fortran::lower::builtin::cptrFieldName; - mlir::Value addressField = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, addressFieldName, procTy, mlir::ValueRange{}); + mlir::Value addressField = fir::FieldIndexOp::create( + rewriter, loc, fieldTy, addressFieldName, procTy, mlir::ValueRange{}); mlir::Type addressTy = procTy.getType(addressFieldName); mlir::Type addressRefTy = fir::ReferenceType::get(addressTy); - mlir::Value addressRef = rewriter.create<fir::CoordinateOp>( - loc, addressRefTy, procRef, addressField); - mlir::Value address = rewriter.create<fir::LoadOp>(loc, addressRef); + mlir::Value addressRef = fir::CoordinateOp::create( + rewriter, loc, addressRefTy, procRef, addressField); + mlir::Value address = fir::LoadOp::create(rewriter, loc, addressRef); // Get the function type. llvm::SmallVector<mlir::Type> argTypes; @@ -237,7 +239,7 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> { mlir::Type funTy = mlir::FunctionType::get(rewriter.getContext(), argTypes, resTypes); - mlir::Value funcPtr = rewriter.create<fir::ConvertOp>(loc, funTy, address); + mlir::Value funcPtr = fir::ConvertOp::create(rewriter, loc, funTy, address); // Make the call. llvm::SmallVector<mlir::Value> args{funcPtr}; @@ -398,12 +400,13 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( if (code == 0) return mlir::emitError(loc) << "type code unavailable for " << a.getType(); - mlir::Value typeCode = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getI8IntegerAttr(code)); - mlir::Value selectorTypeCode = rewriter.create<fir::BoxTypeCodeOp>( - loc, rewriter.getI8Type(), selector); - cmp = rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, selectorTypeCode, typeCode); + mlir::Value typeCode = mlir::arith::ConstantOp::create( + rewriter, loc, rewriter.getI8IntegerAttr(code)); + mlir::Value selectorTypeCode = fir::BoxTypeCodeOp::create( + rewriter, loc, rewriter.getI8Type(), selector); + cmp = mlir::arith::CmpIOp::create(rewriter, loc, + mlir::arith::CmpIPredicate::eq, + selectorTypeCode, typeCode); } else { // Flang inline the kind parameter in the type descriptor so we can // directly check if the type descriptor addresses are identical for @@ -418,16 +421,16 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( } else if (auto a = mlir::dyn_cast<fir::SubclassAttr>(attr)) { // Retrieve the type descriptor from the type guard statement record type. assert(mlir::isa<fir::RecordType>(a.getType()) && "expect fir.record type"); - mlir::Value typeDescAddr = - rewriter.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(a.getType())); + mlir::Value typeDescAddr = fir::TypeDescOp::create( + rewriter, loc, mlir::TypeAttr::get(a.getType())); mlir::Type refNoneType = ReferenceType::get(rewriter.getNoneType()); mlir::Value typeDesc = - rewriter.create<ConvertOp>(loc, refNoneType, typeDescAddr); + ConvertOp::create(rewriter, loc, refNoneType, typeDescAddr); // Prepare the selector descriptor for the runtime call. mlir::Type descNoneTy = fir::BoxType::get(rewriter.getNoneType()); mlir::Value descSelector = - rewriter.create<ConvertOp>(loc, descNoneTy, selector); + ConvertOp::create(rewriter, loc, descNoneTy, selector); // Generate runtime call. llvm::StringRef fctName = RTNAME_STRING(ClassIs); @@ -455,10 +458,10 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( rewriter.createBlock(dest->getParent(), mlir::Region::iterator(dest)); rewriter.setInsertionPointToEnd(thisBlock); if (destOps.has_value()) - rewriter.create<mlir::cf::CondBranchOp>(loc, cmp, dest, destOps.value(), - newBlock, std::nullopt); + mlir::cf::CondBranchOp::create(rewriter, loc, cmp, dest, destOps.value(), + newBlock, mlir::ValueRange{}); else - rewriter.create<mlir::cf::CondBranchOp>(loc, cmp, dest, newBlock); + mlir::cf::CondBranchOp::create(rewriter, loc, cmp, dest, newBlock); rewriter.setInsertionPointToEnd(newBlock); return mlir::success(); } @@ -470,16 +473,17 @@ SelectTypeConv::genTypeDescCompare(mlir::Location loc, mlir::Value selector, mlir::PatternRewriter &rewriter) const { assert(mlir::isa<fir::RecordType>(ty) && "expect fir.record type"); mlir::Value typeDescAddr = - rewriter.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(ty)); - mlir::Value selectorTdescAddr = rewriter.create<fir::BoxTypeDescOp>( - loc, typeDescAddr.getType(), selector); + fir::TypeDescOp::create(rewriter, loc, mlir::TypeAttr::get(ty)); + mlir::Value selectorTdescAddr = fir::BoxTypeDescOp::create( + rewriter, loc, typeDescAddr.getType(), selector); auto intPtrTy = rewriter.getIndexType(); auto typeDescInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, typeDescAddr); + fir::ConvertOp::create(rewriter, loc, intPtrTy, typeDescAddr); auto selectorTdescInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, selectorTdescAddr); - return rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, typeDescInt, selectorTdescInt); + fir::ConvertOp::create(rewriter, loc, intPtrTy, selectorTdescAddr); + return mlir::arith::CmpIOp::create(rewriter, loc, + mlir::arith::CmpIPredicate::eq, + typeDescInt, selectorTdescInt); } llvm::SmallSet<llvm::StringRef, 4> diff --git a/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp b/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp index 506c8e6..c6aec96 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp @@ -88,18 +88,18 @@ mlir::LogicalResult IsContiguousBoxCoversion::matchAndRewrite( // The scalar cases are supposed to be optimized by the canonicalization. if (rank == 1 || (op.getInnermost() && rank > 0)) { mlir::Type idxTy = builder.getIndexType(); - auto eleSize = builder.create<fir::BoxEleSizeOp>(loc, idxTy, box); + auto eleSize = fir::BoxEleSizeOp::create(builder, loc, idxTy, box); mlir::Value zero = fir::factory::createZeroValue(builder, loc, idxTy); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, zero); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, zero); mlir::Value stride = dimInfo.getByteStride(); - mlir::Value pred1 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, eleSize, stride); + mlir::Value pred1 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, eleSize, stride); mlir::Value extent = dimInfo.getExtent(); - mlir::Value pred2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); + mlir::Value pred2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); mlir::Value result = - builder.create<mlir::arith::OrIOp>(loc, pred1, pred2); + mlir::arith::OrIOp::create(builder, loc, pred1, pred2); result = builder.createConvert(loc, op.getType(), result); rewriter.replaceOp(op, result); return mlir::success(); @@ -192,7 +192,7 @@ public: // TODO Should this be a heap allocation instead? For now, we allocate // on the stack for each loop iteration. mlir::Value localAlloc = - rewriter.create<fir::AllocaOp>(loop.getLoc(), localizer.getType()); + fir::AllocaOp::create(rewriter, loop.getLoc(), localizer.getType()); auto cloneLocalizerRegion = [&](mlir::Region ®ion, mlir::ValueRange regionArgs, @@ -258,10 +258,10 @@ public: for (auto [lb, ub, st, iv] : llvm::zip_equal(loop.getLowerBound(), loop.getUpperBound(), loop.getStep(), *loop.getLoopInductionVars())) { - innermostUnorderdLoop = rewriter.create<fir::DoLoopOp>( - doConcurentOp.getLoc(), lb, ub, st, + innermostUnorderdLoop = fir::DoLoopOp::create( + rewriter, doConcurentOp.getLoc(), lb, ub, st, /*unordred=*/true, /*finalCountValue=*/false, - /*iterArgs=*/std::nullopt, loop.getReduceVars(), + /*iterArgs=*/mlir::ValueRange{}, loop.getReduceVars(), loop.getReduceAttrsAttr()); ivArgs.push_back(innermostUnorderdLoop.getInductionVar()); rewriter.setInsertionPointToStart(innermostUnorderdLoop.getBody()); diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index 4d25a02..49a085e 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -284,7 +284,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, fir::SequenceType::getUnknownExtent()); mlir::Type arrTy = fir::SequenceType::get(flatShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); - mlir::Value array = builder.create<fir::ConvertOp>(loc, boxArrTy, arg); + mlir::Value array = fir::ConvertOp::create(builder, loc, boxArrTy, arg); mlir::Type resultType = funcOp.getResultTypes()[0]; mlir::Value init = initVal(builder, loc, resultType); @@ -299,11 +299,11 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // should be able to optimize the redundancy. for (unsigned i = 0; i < rank; ++i) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array, dimIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array, + dimIdx); mlir::Value len = dims.getResult(1); // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); bounds.push_back(loopCount); } // Create a loop nest consisting of OP operations. @@ -316,9 +316,9 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, for (unsigned i = rank; 0 < i; --i) { mlir::Value step = one; mlir::Value loopCount = bounds[i - 1]; - auto loop = builder.create<OP>(loc, zeroIdx, loopCount, step, - unorderedOrInitialLoopCond, - /*finalCountValue=*/false, init); + auto loop = OP::create(builder, loc, zeroIdx, loopCount, step, + unorderedOrInitialLoopCond, + /*finalCountValue=*/false, init); init = loop.getRegionIterArgs()[resultIndex]; indices.push_back(loop.getInductionVar()); // Set insertion point to the loop body so that the next loop @@ -332,8 +332,8 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // We are in the innermost loop: generate the reduction body. mlir::Type eleRefTy = builder.getRefType(elementType); mlir::Value addr = - builder.create<fir::CoordinateOp>(loc, eleRefTy, array, indices); - mlir::Value elem = builder.create<fir::LoadOp>(loc, addr); + fir::CoordinateOp::create(builder, loc, eleRefTy, array, indices); + mlir::Value elem = fir::LoadOp::create(builder, loc, addr); mlir::Value reductionVal = genBody(builder, loc, elementType, elem, init); // Generate vector with condition to continue while loop at [0] and result // from current loop at [1] for IterWhileOp loops, just result at [0] for @@ -344,7 +344,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // to return the updated value of the reduction to the enclosing // loops. for (unsigned i = 0; i < rank; ++i) { - auto result = builder.create<fir::ResultOp>(loc, results); + auto result = fir::ResultOp::create(builder, loc, results); // Proceed to the outer loop. auto loop = mlir::cast<OP>(result->getParentOp()); results = loop.getResults(); @@ -354,7 +354,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, } // End of loop nest. The insertion point is after the outermost loop. // Return the reduction value from the function. - builder.create<mlir::func::ReturnOp>(loc, results[resultIndex]); + mlir::func::ReturnOp::create(builder, loc, results[resultIndex]); } static llvm::SmallVector<mlir::Value> nopLoopCond(fir::FirOpBuilder &builder, @@ -394,9 +394,9 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { if (mlir::isa<mlir::FloatType>(elementType)) - return builder.create<mlir::arith::AddFOp>(loc, elem1, elem2); + return mlir::arith::AddFOp::create(builder, loc, elem1, elem2); if (mlir::isa<mlir::IntegerType>(elementType)) - return builder.create<mlir::arith::AddIOp>(loc, elem1, elem2); + return mlir::arith::AddIOp::create(builder, loc, elem1, elem2); llvm_unreachable("unsupported type"); return {}; @@ -436,12 +436,12 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, // This libm function may not work properly for F128 arguments // on targets where long double is not F128. It is an LLVM issue, // but we just use normal select here to resolve all the cases. - auto compare = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2); - return builder.create<mlir::arith::SelectOp>(loc, compare, elem1, elem2); + auto compare = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2); + return mlir::arith::SelectOp::create(builder, loc, compare, elem1, elem2); } if (mlir::isa<mlir::IntegerType>(elementType)) - return builder.create<mlir::arith::MaxSIOp>(loc, elem1, elem2); + return mlir::arith::MaxSIOp::create(builder, loc, elem1, elem2); llvm_unreachable("unsupported type"); return {}; @@ -472,11 +472,11 @@ static void genRuntimeCountBody(fir::FirOpBuilder &builder, auto zero64 = builder.createIntegerConstant(loc, builder.getI64Type(), 0); auto one64 = builder.createIntegerConstant(loc, builder.getI64Type(), 1); - auto compare = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, elem1, zero32); + auto compare = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, elem1, zero32); auto select = - builder.create<mlir::arith::SelectOp>(loc, compare, zero64, one64); - return builder.create<mlir::arith::AddIOp>(loc, select, elem2); + mlir::arith::SelectOp::create(builder, loc, compare, zero64, one64); + return mlir::arith::AddIOp::create(builder, loc, select, elem2); }; // Count always gets I32 for elementType as it converts logical input to @@ -501,14 +501,14 @@ static void genRuntimeAnyBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { auto zero = builder.createIntegerConstant(loc, elementType, 0); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, elem1, zero); + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, elem1, zero); }; auto continueCond = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Value reductionVal) { auto one1 = builder.createIntegerConstant(loc, builder.getI1Type(), 1); - auto eor = builder.create<mlir::arith::XOrIOp>(loc, reductionVal, one1); + auto eor = mlir::arith::XOrIOp::create(builder, loc, reductionVal, one1); llvm::SmallVector<mlir::Value> results = {eor, reductionVal}; return results; }; @@ -534,8 +534,8 @@ static void genRuntimeAllBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { auto zero = builder.createIntegerConstant(loc, elementType, 0); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, elem1, zero); + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, elem1, zero); }; auto continueCond = [](fir::FirOpBuilder builder, mlir::Location loc, @@ -577,13 +577,13 @@ void fir::genMinMaxlocReductionLoop( fir::SequenceType::getUnknownExtent()); mlir::Type arrTy = fir::SequenceType::get(flatShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); - array = builder.create<fir::ConvertOp>(loc, boxArrTy, array); + array = fir::ConvertOp::create(builder, loc, boxArrTy, array); mlir::Type resultElemType = hlfir::getFortranElementType(resultArr.getType()); mlir::Value flagSet = builder.createIntegerConstant(loc, resultElemType, 1); mlir::Value zero = builder.createIntegerConstant(loc, resultElemType, 0); mlir::Value flagRef = builder.createTemporary(loc, resultElemType); - builder.create<fir::StoreOp>(loc, zero, flagRef); + fir::StoreOp::create(builder, loc, zero, flagRef); mlir::Value init = initVal(builder, loc, elementType); llvm::SmallVector<mlir::Value, Fortran::common::maxRank> bounds; @@ -597,11 +597,11 @@ void fir::genMinMaxlocReductionLoop( // should be able to optimize the redundancy. for (unsigned i = 0; i < rank; ++i) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array, dimIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array, + dimIdx); mlir::Value len = dims.getResult(1); // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); bounds.push_back(loopCount); } // Create a loop nest consisting of OP operations. @@ -615,8 +615,8 @@ void fir::genMinMaxlocReductionLoop( mlir::Value step = one; mlir::Value loopCount = bounds[i - 1]; auto loop = - builder.create<fir::DoLoopOp>(loc, zeroIdx, loopCount, step, false, - /*finalCountValue=*/false, init); + fir::DoLoopOp::create(builder, loc, zeroIdx, loopCount, step, false, + /*finalCountValue=*/false, init); init = loop.getRegionIterArgs()[0]; indices.push_back(loop.getInductionVar()); // Set insertion point to the loop body so that the next loop @@ -634,7 +634,7 @@ void fir::genMinMaxlocReductionLoop( // to return the updated value of the reduction to the enclosing // loops. for (unsigned i = 0; i < rank; ++i) { - auto result = builder.create<fir::ResultOp>(loc, reductionVal); + auto result = fir::ResultOp::create(builder, loc, reductionVal); // Proceed to the outer loop. auto loop = mlir::cast<fir::DoLoopOp>(result->getParentOp()); reductionVal = loop.getResult(0); @@ -646,7 +646,7 @@ void fir::genMinMaxlocReductionLoop( if (maskMayBeLogicalScalar) { if (fir::IfOp ifOp = mlir::dyn_cast<fir::IfOp>(builder.getBlock()->getParentOp())) { - builder.create<fir::ResultOp>(loc, reductionVal); + fir::ResultOp::create(builder, loc, reductionVal); builder.setInsertionPointAfter(ifOp); // Redefine flagSet to escape scope of ifOp flagSet = builder.createIntegerConstant(loc, resultElemType, 1); @@ -689,10 +689,11 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Value returnValue = builder.createIntegerConstant(loc, resultElemTy, 0); mlir::Value resultArrSize = builder.createIntegerConstant(loc, idxTy, rank); - mlir::Value resultArrInit = builder.create<fir::AllocMemOp>(loc, resultTy); - mlir::Value resultArrShape = builder.create<fir::ShapeOp>(loc, resultArrSize); - mlir::Value resultArr = builder.create<fir::EmboxOp>( - loc, resultBoxTy, resultArrInit, resultArrShape); + mlir::Value resultArrInit = fir::AllocMemOp::create(builder, loc, resultTy); + mlir::Value resultArrShape = + fir::ShapeOp::create(builder, loc, resultArrSize); + mlir::Value resultArr = fir::EmboxOp::create(builder, loc, resultBoxTy, + resultArrInit, resultArrShape); mlir::Type resultRefTy = builder.getRefType(resultElemTy); @@ -701,14 +702,14 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, fir::SequenceType::getUnknownExtent()); mlir::Type maskTy = fir::SequenceType::get(flatShape, maskElemType); mlir::Type boxMaskTy = fir::BoxType::get(maskTy); - mask = builder.create<fir::ConvertOp>(loc, boxMaskTy, mask); + mask = fir::ConvertOp::create(builder, loc, boxMaskTy, mask); } for (unsigned int i = 0; i < rank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxTy, i); mlir::Value resultElemAddr = - builder.create<fir::CoordinateOp>(loc, resultRefTy, resultArr, index); - builder.create<fir::StoreOp>(loc, returnValue, resultElemAddr); + fir::CoordinateOp::create(builder, loc, resultRefTy, resultArr, index); + fir::StoreOp::create(builder, loc, returnValue, resultElemAddr); } auto genBodyOp = @@ -720,29 +721,30 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (maskRank > 0) { mlir::Type logicalRef = builder.getRefType(maskElemType); mlir::Value maskAddr = - builder.create<fir::CoordinateOp>(loc, logicalRef, mask, indices); - mlir::Value maskElem = builder.create<fir::LoadOp>(loc, maskAddr); + fir::CoordinateOp::create(builder, loc, logicalRef, mask, indices); + mlir::Value maskElem = fir::LoadOp::create(builder, loc, maskAddr); // fir::IfOp requires argument to be I1 - won't accept logical or any // other Integer. mlir::Type ifCompatType = builder.getI1Type(); mlir::Value ifCompatElem = - builder.create<fir::ConvertOp>(loc, ifCompatType, maskElem); + fir::ConvertOp::create(builder, loc, ifCompatType, maskElem); llvm::SmallVector<mlir::Type> resultsTy = {elementType, elementType}; - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, ifCompatElem, - /*withElseRegion=*/true); + fir::IfOp ifOp = + fir::IfOp::create(builder, loc, elementType, ifCompatElem, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } // Set flag that mask was true at some point mlir::Value flagSet = builder.createIntegerConstant( loc, mlir::cast<fir::ReferenceType>(flagRef.getType()).getEleTy(), 1); - mlir::Value isFirst = builder.create<fir::LoadOp>(loc, flagRef); + mlir::Value isFirst = fir::LoadOp::create(builder, loc, flagRef); mlir::Type eleRefTy = builder.getRefType(elementType); mlir::Value addr = - builder.create<fir::CoordinateOp>(loc, eleRefTy, array, indices); - mlir::Value elem = builder.create<fir::LoadOp>(loc, addr); + fir::CoordinateOp::create(builder, loc, eleRefTy, array, indices); + mlir::Value elem = fir::LoadOp::create(builder, loc, addr); mlir::Value cmp; if (mlir::isa<mlir::FloatType>(elementType)) { @@ -750,38 +752,37 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, // is not NaN. A OGL/OLT condition will usually work for this unless all // the values are Nan or Inf. This follows the same logic as // NumericCompare for Minloc/Maxlox in extrema.cpp. - cmp = builder.create<mlir::arith::CmpFOp>( - loc, - isMax ? mlir::arith::CmpFPredicate::OGT - : mlir::arith::CmpFPredicate::OLT, - elem, reduction); - - mlir::Value cmpNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, reduction, reduction); - mlir::Value cmpNan2 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); - cmpNan = builder.create<mlir::arith::AndIOp>(loc, cmpNan, cmpNan2); - cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, cmpNan); + cmp = mlir::arith::CmpFOp::create(builder, loc, + isMax ? mlir::arith::CmpFPredicate::OGT + : mlir::arith::CmpFPredicate::OLT, + elem, reduction); + + mlir::Value cmpNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, reduction, reduction); + mlir::Value cmpNan2 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); + cmpNan = mlir::arith::AndIOp::create(builder, loc, cmpNan, cmpNan2); + cmp = mlir::arith::OrIOp::create(builder, loc, cmp, cmpNan); } else if (mlir::isa<mlir::IntegerType>(elementType)) { - cmp = builder.create<mlir::arith::CmpIOp>( - loc, - isMax ? mlir::arith::CmpIPredicate::sgt - : mlir::arith::CmpIPredicate::slt, - elem, reduction); + cmp = mlir::arith::CmpIOp::create(builder, loc, + isMax ? mlir::arith::CmpIPredicate::sgt + : mlir::arith::CmpIPredicate::slt, + elem, reduction); } else { llvm_unreachable("unsupported type"); } // The condition used for the loop is isFirst || <the condition above>. - isFirst = builder.create<fir::ConvertOp>(loc, cmp.getType(), isFirst); - isFirst = builder.create<mlir::arith::XOrIOp>( - loc, isFirst, builder.createIntegerConstant(loc, cmp.getType(), 1)); - cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, isFirst); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, cmp, - /*withElseRegion*/ true); + isFirst = fir::ConvertOp::create(builder, loc, cmp.getType(), isFirst); + isFirst = mlir::arith::XOrIOp::create( + builder, loc, isFirst, + builder.createIntegerConstant(loc, cmp.getType(), 1)); + cmp = mlir::arith::OrIOp::create(builder, loc, cmp, isFirst); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, elementType, cmp, + /*withElseRegion*/ true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::StoreOp>(loc, flagSet, flagRef); + fir::StoreOp::create(builder, loc, flagSet, flagRef); mlir::Type resultElemTy = hlfir::getFortranElementType(resultArr.getType()); mlir::Type returnRefTy = builder.getRefType(resultElemTy); mlir::IndexType idxTy = builder.getIndexType(); @@ -790,17 +791,17 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, for (unsigned int i = 0; i < rank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxTy, i); - mlir::Value resultElemAddr = - builder.create<fir::CoordinateOp>(loc, returnRefTy, resultArr, index); + mlir::Value resultElemAddr = fir::CoordinateOp::create( + builder, loc, returnRefTy, resultArr, index); mlir::Value convert = - builder.create<fir::ConvertOp>(loc, resultElemTy, indices[i]); + fir::ConvertOp::create(builder, loc, resultElemTy, indices[i]); mlir::Value fortranIndex = - builder.create<mlir::arith::AddIOp>(loc, convert, one); - builder.create<fir::StoreOp>(loc, fortranIndex, resultElemAddr); + mlir::arith::AddIOp::create(builder, loc, convert, one); + fir::StoreOp::create(builder, loc, fortranIndex, resultElemAddr); } - builder.create<fir::ResultOp>(loc, elem); + fir::ResultOp::create(builder, loc, elem); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, reduction); + fir::ResultOp::create(builder, loc, reduction); builder.setInsertionPointAfter(ifOp); mlir::Value reductionVal = ifOp.getResult(0); @@ -808,9 +809,9 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (maskRank > 0) { fir::IfOp ifOp = mlir::dyn_cast<fir::IfOp>(builder.getBlock()->getParentOp()); - builder.create<fir::ResultOp>(loc, reductionVal); + fir::ResultOp::create(builder, loc, reductionVal); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, reduction); + fir::ResultOp::create(builder, loc, reduction); reductionVal = ifOp.getResult(0); builder.setInsertionPointAfter(ifOp); } @@ -825,12 +826,12 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Type logical = maskElemType; mlir::Type logicalRefTy = builder.getRefType(logical); mlir::Value condAddr = - builder.create<fir::BoxAddrOp>(loc, logicalRefTy, mask); - mlir::Value cond = builder.create<fir::LoadOp>(loc, condAddr); - mlir::Value condI1 = builder.create<fir::ConvertOp>(loc, i1Type, cond); + fir::BoxAddrOp::create(builder, loc, logicalRefTy, mask); + mlir::Value cond = fir::LoadOp::create(builder, loc, condAddr); + mlir::Value condI1 = fir::ConvertOp::create(builder, loc, i1Type, cond); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, condI1, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, elementType, condI1, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value basicValue; @@ -839,7 +840,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, } else { basicValue = builder.createRealConstant(loc, elementType, 0); } - builder.create<fir::ResultOp>(loc, basicValue); + fir::ResultOp::create(builder, loc, basicValue); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } @@ -847,8 +848,8 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, const mlir::Type &resultElemType, mlir::Value resultArr, mlir::Value index) { mlir::Type resultRefTy = builder.getRefType(resultElemType); - return builder.create<fir::CoordinateOp>(loc, resultRefTy, resultArr, - index); + return fir::CoordinateOp::create(builder, loc, resultRefTy, resultArr, + index); }; genMinMaxlocReductionLoop(builder, funcOp.front().getArgument(1), init, @@ -859,25 +860,26 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (isDim) { mlir::Type resultBoxTy = fir::BoxType::get(fir::HeapType::get(resultElemTy)); - mlir::Value outputArr = builder.create<fir::ConvertOp>( - loc, builder.getRefType(resultBoxTy), funcOp.front().getArgument(0)); - mlir::Value resultArrScalar = builder.create<fir::ConvertOp>( - loc, fir::HeapType::get(resultElemTy), resultArrInit); + mlir::Value outputArr = + fir::ConvertOp::create(builder, loc, builder.getRefType(resultBoxTy), + funcOp.front().getArgument(0)); + mlir::Value resultArrScalar = fir::ConvertOp::create( + builder, loc, fir::HeapType::get(resultElemTy), resultArrInit); mlir::Value resultBox = - builder.create<fir::EmboxOp>(loc, resultBoxTy, resultArrScalar); - builder.create<fir::StoreOp>(loc, resultBox, outputArr); + fir::EmboxOp::create(builder, loc, resultBoxTy, resultArrScalar); + fir::StoreOp::create(builder, loc, resultBox, outputArr); } else { fir::SequenceType::Shape resultShape(1, rank); mlir::Type outputArrTy = fir::SequenceType::get(resultShape, resultElemTy); mlir::Type outputHeapTy = fir::HeapType::get(outputArrTy); mlir::Type outputBoxTy = fir::BoxType::get(outputHeapTy); mlir::Type outputRefTy = builder.getRefType(outputBoxTy); - mlir::Value outputArr = builder.create<fir::ConvertOp>( - loc, outputRefTy, funcOp.front().getArgument(0)); - builder.create<fir::StoreOp>(loc, resultArr, outputArr); + mlir::Value outputArr = fir::ConvertOp::create( + builder, loc, outputRefTy, funcOp.front().getArgument(0)); + fir::StoreOp::create(builder, loc, resultArr, outputArr); } - builder.create<mlir::func::ReturnOp>(loc); + mlir::func::ReturnOp::create(builder, loc); } /// Generate function type for the simplified version of RTNAME(DotProduct) @@ -929,10 +931,10 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, fir::SequenceType::Shape flatShape = {fir::SequenceType::getUnknownExtent()}; mlir::Type arrTy1 = fir::SequenceType::get(flatShape, arg1ElementTy); mlir::Type boxArrTy1 = fir::BoxType::get(arrTy1); - mlir::Value array1 = builder.create<fir::ConvertOp>(loc, boxArrTy1, arg1); + mlir::Value array1 = fir::ConvertOp::create(builder, loc, boxArrTy1, arg1); mlir::Type arrTy2 = fir::SequenceType::get(flatShape, arg2ElementTy); mlir::Type boxArrTy2 = fir::BoxType::get(arrTy2); - mlir::Value array2 = builder.create<fir::ConvertOp>(loc, boxArrTy2, arg2); + mlir::Value array2 = fir::ConvertOp::create(builder, loc, boxArrTy2, arg2); // This version takes the loop trip count from the first argument. // If the first argument's box has unknown (at compilation time) // extent, then it may be better to take the extent from the second @@ -941,17 +943,17 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, // function and some analysis at the call site to choose which version // is more profitable to call. // Note that we can assume that both arguments have the same extent. - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array1, zeroIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array1, + zeroIdx); mlir::Value len = dims.getResult(1); mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); mlir::Value step = one; // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); - auto loop = builder.create<fir::DoLoopOp>(loc, zeroIdx, loopCount, step, - /*unordered=*/false, - /*finalCountValue=*/false, zero); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); + auto loop = fir::DoLoopOp::create(builder, loc, zeroIdx, loopCount, step, + /*unordered=*/false, + /*finalCountValue=*/false, zero); mlir::Value sumVal = loop.getRegionIterArgs()[0]; // Begin loop code @@ -961,33 +963,35 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, mlir::Type eleRef1Ty = builder.getRefType(arg1ElementTy); mlir::Value index = loop.getInductionVar(); mlir::Value addr1 = - builder.create<fir::CoordinateOp>(loc, eleRef1Ty, array1, index); - mlir::Value elem1 = builder.create<fir::LoadOp>(loc, addr1); + fir::CoordinateOp::create(builder, loc, eleRef1Ty, array1, index); + mlir::Value elem1 = fir::LoadOp::create(builder, loc, addr1); // Convert to the result type. - elem1 = builder.create<fir::ConvertOp>(loc, resultElementType, elem1); + elem1 = fir::ConvertOp::create(builder, loc, resultElementType, elem1); mlir::Type eleRef2Ty = builder.getRefType(arg2ElementTy); mlir::Value addr2 = - builder.create<fir::CoordinateOp>(loc, eleRef2Ty, array2, index); - mlir::Value elem2 = builder.create<fir::LoadOp>(loc, addr2); + fir::CoordinateOp::create(builder, loc, eleRef2Ty, array2, index); + mlir::Value elem2 = fir::LoadOp::create(builder, loc, addr2); // Convert to the result type. - elem2 = builder.create<fir::ConvertOp>(loc, resultElementType, elem2); + elem2 = fir::ConvertOp::create(builder, loc, resultElementType, elem2); if (mlir::isa<mlir::FloatType>(resultElementType)) - sumVal = builder.create<mlir::arith::AddFOp>( - loc, builder.create<mlir::arith::MulFOp>(loc, elem1, elem2), sumVal); + sumVal = mlir::arith::AddFOp::create( + builder, loc, mlir::arith::MulFOp::create(builder, loc, elem1, elem2), + sumVal); else if (mlir::isa<mlir::IntegerType>(resultElementType)) - sumVal = builder.create<mlir::arith::AddIOp>( - loc, builder.create<mlir::arith::MulIOp>(loc, elem1, elem2), sumVal); + sumVal = mlir::arith::AddIOp::create( + builder, loc, mlir::arith::MulIOp::create(builder, loc, elem1, elem2), + sumVal); else llvm_unreachable("unsupported type"); - builder.create<fir::ResultOp>(loc, sumVal); + fir::ResultOp::create(builder, loc, sumVal); // End of loop. builder.restoreInsertionPoint(loopEndPt); mlir::Value resultVal = loop.getResult(0); - builder.create<mlir::func::ReturnOp>(loc, resultVal); + mlir::func::ReturnOp::create(builder, loc, resultVal); } mlir::func::FuncOp SimplifyIntrinsicsPass::getOrCreateFunction( @@ -1229,8 +1233,8 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction( mlir::func::FuncOp newFunc = getOrCreateFunction(builder, funcName, typeGenerator, bodyGenerator); - builder.create<fir::CallOp>(loc, newFunc, - mlir::ValueRange{args[0], args[1], mask}); + fir::CallOp::create(builder, loc, newFunc, + mlir::ValueRange{args[0], args[1], mask}); call->dropAllReferences(); call->erase(); } @@ -1259,7 +1263,7 @@ void SimplifyIntrinsicsPass::simplifyReductionBody( mlir::func::FuncOp newFunc = getOrCreateFunction(builder, funcName, typeGenerator, bodyGenerator); auto newCall = - builder.create<fir::CallOp>(loc, newFunc, mlir::ValueRange{args[0]}); + fir::CallOp::create(builder, loc, newFunc, mlir::ValueRange{args[0]}); call->replaceAllUsesWith(newCall.getResults()); call->dropAllReferences(); call->erase(); @@ -1344,8 +1348,8 @@ void SimplifyIntrinsicsPass::runOnOperation() { mlir::func::FuncOp newFunc = getOrCreateFunction( builder, typedFuncName, typeGenerator, bodyGenerator); - auto newCall = builder.create<fir::CallOp>(loc, newFunc, - mlir::ValueRange{v1, v2}); + auto newCall = fir::CallOp::create(builder, loc, newFunc, + mlir::ValueRange{v1, v2}); call->replaceAllUsesWith(newCall.getResults()); call->dropAllReferences(); call->erase(); diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp index bc8a949..0d13129 100644 --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -569,7 +569,7 @@ static mlir::Value convertAllocationType(mlir::PatternRewriter &rewriter, auto insertionPoint = rewriter.saveInsertionPoint(); rewriter.setInsertionPointAfter(stack.getDefiningOp()); mlir::Value conv = - rewriter.create<fir::ConvertOp>(loc, firHeapTy, stack).getResult(); + fir::ConvertOp::create(rewriter, loc, firHeapTy, stack).getResult(); rewriter.restoreInsertionPoint(insertionPoint); return conv; } @@ -758,9 +758,9 @@ AllocMemConversion::insertAlloca(fir::AllocMemOp &oldAlloc, llvm::StringRef uniqName = unpackName(oldAlloc.getUniqName()); llvm::StringRef bindcName = unpackName(oldAlloc.getBindcName()); - auto alloca = rewriter.create<fir::AllocaOp>(loc, varTy, uniqName, bindcName, - oldAlloc.getTypeparams(), - oldAlloc.getShape()); + auto alloca = + fir::AllocaOp::create(rewriter, loc, varTy, uniqName, bindcName, + oldAlloc.getTypeparams(), oldAlloc.getShape()); if (emitLifetimeMarkers) insertLifetimeMarkers(oldAlloc, alloca, rewriter); diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 76c9499..d349d8c 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -274,6 +274,10 @@ TYPE_PARSER( // construct<OmpTypeSpecifier>(Parser<DeclarationTypeSpec>{}) || construct<OmpTypeSpecifier>(Parser<TypeSpec>{})) +// 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list) +TYPE_PARSER(construct<OmpReductionIdentifier>(Parser<DefinedOperator>{}) || + construct<OmpReductionIdentifier>(Parser<ProcedureDesignator>{})) + TYPE_PARSER(construct<OmpReductionSpecifier>( // Parser<OmpReductionIdentifier>{}, ":"_tok >> nonemptyList(Parser<OmpTypeSpecifier>{}), @@ -442,9 +446,18 @@ TYPE_PARSER(construct<OmpAllocatorComplexModifier>( TYPE_PARSER(construct<OmpAllocatorSimpleModifier>(scalarIntExpr)) +TYPE_PARSER(construct<OmpAlwaysModifier>( // + "ALWAYS" >> pure(OmpAlwaysModifier::Value::Always))) + TYPE_PARSER(construct<OmpChunkModifier>( // "SIMD" >> pure(OmpChunkModifier::Value::Simd))) +TYPE_PARSER(construct<OmpCloseModifier>( // + "CLOSE" >> pure(OmpCloseModifier::Value::Close))) + +TYPE_PARSER(construct<OmpDeleteModifier>( // + "DELETE" >> pure(OmpDeleteModifier::Value::Delete))) + TYPE_PARSER(construct<OmpDependenceType>( "SINK" >> pure(OmpDependenceType::Value::Sink) || "SOURCE" >> pure(OmpDependenceType::Value::Source))) @@ -502,26 +515,16 @@ TYPE_PARSER(construct<OmpLinearModifier>( // TYPE_PARSER(construct<OmpMapper>( // "MAPPER"_tok >> parenthesized(Parser<ObjectName>{}))) -// map-type -> ALLOC | DELETE | FROM | RELEASE | TO | TOFROM +// map-type -> ALLOC | DELETE | FROM | RELEASE | STORAGE | TO | TOFROM TYPE_PARSER(construct<OmpMapType>( // "ALLOC" >> pure(OmpMapType::Value::Alloc) || - "DELETE" >> pure(OmpMapType::Value::Delete) || + // Parse "DELETE" as OmpDeleteModifier "FROM" >> pure(OmpMapType::Value::From) || "RELEASE" >> pure(OmpMapType::Value::Release) || + "STORAGE" >> pure(OmpMapType::Value::Storage) || "TO"_id >> pure(OmpMapType::Value::To) || "TOFROM" >> pure(OmpMapType::Value::Tofrom))) -// map-type-modifier -> ALWAYS | CLOSE | OMPX_HOLD | PRESENT -TYPE_PARSER(construct<OmpMapTypeModifier>( - "ALWAYS" >> pure(OmpMapTypeModifier::Value::Always) || - "CLOSE" >> pure(OmpMapTypeModifier::Value::Close) || - "OMPX_HOLD" >> pure(OmpMapTypeModifier::Value::Ompx_Hold) || - "PRESENT" >> pure(OmpMapTypeModifier::Value::Present))) - -// 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list) -TYPE_PARSER(construct<OmpReductionIdentifier>(Parser<DefinedOperator>{}) || - construct<OmpReductionIdentifier>(Parser<ProcedureDesignator>{})) - TYPE_PARSER(construct<OmpOrderModifier>( "REPRODUCIBLE" >> pure(OmpOrderModifier::Value::Reproducible) || "UNCONSTRAINED" >> pure(OmpOrderModifier::Value::Unconstrained))) @@ -534,11 +537,22 @@ TYPE_PARSER(construct<OmpOrderingModifier>( TYPE_PARSER(construct<OmpPrescriptiveness>( "STRICT" >> pure(OmpPrescriptiveness::Value::Strict))) +TYPE_PARSER(construct<OmpPresentModifier>( // + "PRESENT" >> pure(OmpPresentModifier::Value::Present))) + TYPE_PARSER(construct<OmpReductionModifier>( "INSCAN" >> pure(OmpReductionModifier::Value::Inscan) || "TASK" >> pure(OmpReductionModifier::Value::Task) || "DEFAULT" >> pure(OmpReductionModifier::Value::Default))) +TYPE_PARSER(construct<OmpRefModifier>( // + "REF_PTEE" >> pure(OmpRefModifier::Value::Ref_Ptee) || + "REF_PTR"_id >> pure(OmpRefModifier::Value::Ref_Ptr) || + "REF_PTR_PTEE" >> pure(OmpRefModifier::Value::Ref_Ptr_Ptee))) + +TYPE_PARSER(construct<OmpSelfModifier>( // + "SELF" >> pure(OmpSelfModifier::Value::Self))) + TYPE_PARSER(construct<OmpStepComplexModifier>( // "STEP" >> parenthesized(scalarIntExpr))) @@ -559,6 +573,9 @@ TYPE_PARSER(construct<OmpVariableCategory>( "POINTER" >> pure(OmpVariableCategory::Value::Pointer) || "SCALAR" >> pure(OmpVariableCategory::Value::Scalar))) +TYPE_PARSER(construct<OmpxHoldModifier>( // + "OMPX_HOLD" >> pure(OmpxHoldModifier::Value::Ompx_Hold))) + // This could be auto-generated. TYPE_PARSER( sourced(construct<OmpAffinityClause::Modifier>(Parser<OmpIterator>{}))) @@ -611,10 +628,16 @@ TYPE_PARSER(sourced( construct<OmpLinearClause::Modifier>(Parser<OmpStepSimpleModifier>{}))) TYPE_PARSER(sourced(construct<OmpMapClause::Modifier>( - sourced(construct<OmpMapClause::Modifier>(Parser<OmpMapTypeModifier>{}) || + sourced(construct<OmpMapClause::Modifier>(Parser<OmpAlwaysModifier>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpCloseModifier>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpDeleteModifier>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpPresentModifier>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpRefModifier>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpSelfModifier>{}) || construct<OmpMapClause::Modifier>(Parser<OmpMapper>{}) || construct<OmpMapClause::Modifier>(Parser<OmpIterator>{}) || - construct<OmpMapClause::Modifier>(Parser<OmpMapType>{}))))) + construct<OmpMapClause::Modifier>(Parser<OmpMapType>{}) || + construct<OmpMapClause::Modifier>(Parser<OmpxHoldModifier>{}))))) TYPE_PARSER( sourced(construct<OmpOrderClause::Modifier>(Parser<OmpOrderModifier>{}))) diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index fbe89c6..8ed1690 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -3007,8 +3007,15 @@ public: WALK_NESTED_ENUM(OmpPrescriptiveness, Value) // OMP prescriptiveness WALK_NESTED_ENUM(OmpMapType, Value) // OMP map-type WALK_NESTED_ENUM(OmpMapTypeModifier, Value) // OMP map-type-modifier + WALK_NESTED_ENUM(OmpAlwaysModifier, Value) + WALK_NESTED_ENUM(OmpCloseModifier, Value) + WALK_NESTED_ENUM(OmpDeleteModifier, Value) + WALK_NESTED_ENUM(OmpPresentModifier, Value) + WALK_NESTED_ENUM(OmpRefModifier, Value) + WALK_NESTED_ENUM(OmpSelfModifier, Value) WALK_NESTED_ENUM(OmpTraitSelectorName, Value) WALK_NESTED_ENUM(OmpTraitSetSelectorName, Value) + WALK_NESTED_ENUM(OmpxHoldModifier, Value) #undef WALK_NESTED_ENUM void Unparse(const ReductionOperator::Operator x) { diff --git a/flang/lib/Semantics/canonicalize-omp.cpp b/flang/lib/Semantics/canonicalize-omp.cpp index cf05d84..9722eca 100644 --- a/flang/lib/Semantics/canonicalize-omp.cpp +++ b/flang/lib/Semantics/canonicalize-omp.cpp @@ -9,6 +9,7 @@ #include "canonicalize-omp.h" #include "flang/Parser/parse-tree-visitor.h" #include "flang/Parser/parse-tree.h" +#include "flang/Semantics/semantics.h" // After Loop Canonicalization, rewrite OpenMP parse tree to make OpenMP // Constructs more structured which provide explicit scopes for later @@ -27,7 +28,8 @@ class CanonicalizationOfOmp { public: template <typename T> bool Pre(T &) { return true; } template <typename T> void Post(T &) {} - CanonicalizationOfOmp(parser::Messages &messages) : messages_{messages} {} + CanonicalizationOfOmp(SemanticsContext &context) + : context_{context}, messages_{context.messages()} {} void Post(parser::Block &block) { for (auto it{block.begin()}; it != block.end(); ++it) { @@ -88,6 +90,8 @@ public: CanonicalizeUtilityConstructs(spec); } + void Post(parser::OmpMapClause &map) { CanonicalizeMapModifiers(map); } + private: template <typename T> T *GetConstructIf(parser::ExecutionPartConstruct &x) { if (auto *y{std::get_if<parser::ExecutableConstruct>(&x.u)}) { @@ -390,16 +394,58 @@ private: omps.erase(rlast.base(), omps.end()); } + // Map clause modifiers are parsed as per OpenMP 6.0 spec. That spec has + // changed properties of some of the modifiers, for example it has expanded + // map-type-modifier into 3 individual modifiers (one for each of the + // possible values of the original modifier), and the "map-type" modifier + // is no longer ultimate. + // To utilize the modifier validation framework for semantic checks, + // if the specified OpenMP version is less than 6.0, rewrite the affected + // modifiers back into the pre-6.0 forms. + void CanonicalizeMapModifiers(parser::OmpMapClause &map) { + unsigned version{context_.langOptions().OpenMPVersion}; + if (version >= 60) { + return; + } + + // Omp{Always, Close, Present, xHold}Modifier -> OmpMapTypeModifier + // OmpDeleteModifier -> OmpMapType + using Modifier = parser::OmpMapClause::Modifier; + using Modifiers = std::optional<std::list<Modifier>>; + auto &modifiers{std::get<Modifiers>(map.t)}; + if (!modifiers) { + return; + } + + using MapTypeModifier = parser::OmpMapTypeModifier; + using MapType = parser::OmpMapType; + + for (auto &mod : *modifiers) { + if (std::holds_alternative<parser::OmpAlwaysModifier>(mod.u)) { + mod.u = MapTypeModifier(MapTypeModifier::Value::Always); + } else if (std::holds_alternative<parser::OmpCloseModifier>(mod.u)) { + mod.u = MapTypeModifier(MapTypeModifier::Value::Close); + } else if (std::holds_alternative<parser::OmpPresentModifier>(mod.u)) { + mod.u = MapTypeModifier(MapTypeModifier::Value::Present); + } else if (std::holds_alternative<parser::OmpxHoldModifier>(mod.u)) { + mod.u = MapTypeModifier(MapTypeModifier::Value::Ompx_Hold); + } else if (std::holds_alternative<parser::OmpDeleteModifier>(mod.u)) { + mod.u = MapType(MapType::Value::Delete); + } + } + } + // Mapping from the specification parts to the blocks that follow in the // same construct. This is for converting utility constructs to executable // constructs. std::map<parser::SpecificationPart *, parser::Block *> blockForSpec_; + SemanticsContext &context_; parser::Messages &messages_; }; -bool CanonicalizeOmp(parser::Messages &messages, parser::Program &program) { - CanonicalizationOfOmp omp{messages}; +bool CanonicalizeOmp(SemanticsContext &context, parser::Program &program) { + CanonicalizationOfOmp omp{context}; Walk(program, omp); - return !messages.AnyFatalError(); + return !context.messages().AnyFatalError(); } } // namespace Fortran::semantics diff --git a/flang/lib/Semantics/canonicalize-omp.h b/flang/lib/Semantics/canonicalize-omp.h index c45d6bb..3251218 100644 --- a/flang/lib/Semantics/canonicalize-omp.h +++ b/flang/lib/Semantics/canonicalize-omp.h @@ -11,11 +11,12 @@ namespace Fortran::parser { struct Program; -class Messages; -} // namespace Fortran::parser +} namespace Fortran::semantics { -bool CanonicalizeOmp(parser::Messages &messages, parser::Program &program); -} +class SemanticsContext; + +bool CanonicalizeOmp(SemanticsContext &context, parser::Program &program); +} // namespace Fortran::semantics #endif // FORTRAN_SEMANTICS_CANONICALIZE_OMP_H_ diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp index cc1d4bf..e258df8 100644 --- a/flang/lib/Semantics/check-do-forall.cpp +++ b/flang/lib/Semantics/check-do-forall.cpp @@ -1180,7 +1180,9 @@ void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) { void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) { const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)}; const parser::Name &name{control.name.thing.thing}; - context_.CheckIndexVarRedefine(name.source, *name.symbol); + if (name.symbol) { + context_.CheckIndexVarRedefine(name.source, *name.symbol); + } } void DoForallChecker::Leave(const parser::StatVariable &statVariable) { diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index e4a94ef..8264e1d 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -37,6 +37,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Frontend/OpenMP/OMP.h" @@ -3398,23 +3399,22 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Detach &x) { } } -void OmpStructureChecker::CheckAllowedMapTypes( - const parser::OmpMapType::Value &type, - const std::list<parser::OmpMapType::Value> &allowedMapTypeList) { - if (!llvm::is_contained(allowedMapTypeList, type)) { - std::string commaSeparatedMapTypes; - llvm::interleave( - allowedMapTypeList.begin(), allowedMapTypeList.end(), - [&](const parser::OmpMapType::Value &mapType) { - commaSeparatedMapTypes.append(parser::ToUpperCaseLetters( - parser::OmpMapType::EnumToString(mapType))); - }, - [&] { commaSeparatedMapTypes.append(", "); }); - context_.Say(GetContext().clauseSource, - "Only the %s map types are permitted " - "for MAP clauses on the %s directive"_err_en_US, - commaSeparatedMapTypes, ContextDirectiveAsFortran()); +void OmpStructureChecker::CheckAllowedMapTypes(parser::OmpMapType::Value type, + llvm::ArrayRef<parser::OmpMapType::Value> allowed) { + if (llvm::is_contained(allowed, type)) { + return; } + + llvm::SmallVector<std::string> names; + llvm::transform( + allowed, std::back_inserter(names), [](parser::OmpMapType::Value val) { + return parser::ToUpperCaseLetters( + parser::OmpMapType::EnumToString(val)); + }); + llvm::sort(names); + context_.Say(GetContext().clauseSource, + "Only the %s map types are permitted for MAP clauses on the %s directive"_err_en_US, + llvm::join(names, ", "), ContextDirectiveAsFortran()); } void OmpStructureChecker::Enter(const parser::OmpClause::Map &x) { @@ -3435,27 +3435,62 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Map &x) { CheckIteratorModifier(*iter); } if (auto *type{OmpGetUniqueModifier<parser::OmpMapType>(modifiers)}) { + using Directive = llvm::omp::Directive; using Value = parser::OmpMapType::Value; - switch (GetContext().directive) { - case llvm::omp::Directive::OMPD_target: - case llvm::omp::Directive::OMPD_target_teams: - case llvm::omp::Directive::OMPD_target_teams_distribute: - case llvm::omp::Directive::OMPD_target_teams_distribute_simd: - case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do: - case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do_simd: - case llvm::omp::Directive::OMPD_target_data: - CheckAllowedMapTypes( - type->v, {Value::To, Value::From, Value::Tofrom, Value::Alloc}); - break; - case llvm::omp::Directive::OMPD_target_enter_data: - CheckAllowedMapTypes(type->v, {Value::To, Value::Alloc}); - break; - case llvm::omp::Directive::OMPD_target_exit_data: - CheckAllowedMapTypes( - type->v, {Value::From, Value::Release, Value::Delete}); - break; - default: - break; + + static auto isValidForVersion{ + [](parser::OmpMapType::Value t, unsigned version) { + switch (t) { + case parser::OmpMapType::Value::Alloc: + case parser::OmpMapType::Value::Delete: + case parser::OmpMapType::Value::Release: + return version < 60; + case parser::OmpMapType::Value::Storage: + return version >= 60; + default: + return true; + } + }}; + + llvm::SmallVector<parser::OmpMapType::Value> mapEnteringTypes{[&]() { + llvm::SmallVector<parser::OmpMapType::Value> result; + for (size_t i{0}; i != parser::OmpMapType::Value_enumSize; ++i) { + auto t{static_cast<parser::OmpMapType::Value>(i)}; + if (isValidForVersion(t, version) && IsMapEnteringType(t)) { + result.push_back(t); + } + } + return result; + }()}; + llvm::SmallVector<parser::OmpMapType::Value> mapExitingTypes{[&]() { + llvm::SmallVector<parser::OmpMapType::Value> result; + for (size_t i{0}; i != parser::OmpMapType::Value_enumSize; ++i) { + auto t{static_cast<parser::OmpMapType::Value>(i)}; + if (isValidForVersion(t, version) && IsMapExitingType(t)) { + result.push_back(t); + } + } + return result; + }()}; + + llvm::omp::Directive dir{GetContext().directive}; + llvm::ArrayRef<llvm::omp::Directive> leafs{ + llvm::omp::getLeafConstructsOrSelf(dir)}; + + if (llvm::is_contained(leafs, Directive::OMPD_target) || + llvm::is_contained(leafs, Directive::OMPD_target_data)) { + if (version >= 60) { + // Map types listed in the decay table. [6.0:276] + CheckAllowedMapTypes( + type->v, {Value::Storage, Value::From, Value::To, Value::Tofrom}); + } else { + CheckAllowedMapTypes( + type->v, {Value::Alloc, Value::From, Value::To, Value::Tofrom}); + } + } else if (llvm::is_contained(leafs, Directive::OMPD_target_enter_data)) { + CheckAllowedMapTypes(type->v, mapEnteringTypes); + } else if (llvm::is_contained(leafs, Directive::OMPD_target_exit_data)) { + CheckAllowedMapTypes(type->v, mapExitingTypes); } } diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h index 6a877a5..f4a291d 100644 --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -179,8 +179,8 @@ private: void HasInvalidDistributeNesting(const parser::OpenMPLoopConstruct &x); void HasInvalidLoopBinding(const parser::OpenMPLoopConstruct &x); // specific clause related - void CheckAllowedMapTypes(const parser::OmpMapType::Value &, - const std::list<parser::OmpMapType::Value> &); + void CheckAllowedMapTypes( + parser::OmpMapType::Value, llvm::ArrayRef<parser::OmpMapType::Value>); const std::list<parser::OmpTraitProperty> &GetTraitPropertyList( const parser::OmpTraitSelector &); diff --git a/flang/lib/Semantics/openmp-modifiers.cpp b/flang/lib/Semantics/openmp-modifiers.cpp index c84e832..336ce4b 100644 --- a/flang/lib/Semantics/openmp-modifiers.cpp +++ b/flang/lib/Semantics/openmp-modifiers.cpp @@ -141,6 +141,22 @@ OmpGetDescriptor<parser::OmpAllocatorSimpleModifier>() { } template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAlwaysModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"always-modifier", + /*props=*/ + { + {45, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {45, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpChunkModifier>() { static const OmpModifierDescriptor desc{ /*name=*/"chunk-modifier", @@ -157,6 +173,22 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpChunkModifier>() { } template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpCloseModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"close-modifier", + /*props=*/ + { + {50, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {50, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpContextSelector>() { static const OmpModifierDescriptor desc{ /*name=*/"context-selector", @@ -174,6 +206,23 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpContextSelector>() { } template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpDeleteModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"delete-modifier", + /*props=*/ + { + {45, {OmpProperty::Unique, OmpProperty::Ultimate}}, + {60, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {45, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpDependenceType>() { static const OmpModifierDescriptor desc{ /*name=*/"dependence-type", @@ -347,6 +396,7 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpMapType>() { /*props=*/ { {45, {OmpProperty::Ultimate}}, + {60, {OmpProperty::Unique}}, }, /*clauses=*/ { @@ -367,6 +417,7 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpMapTypeModifier>() { /*clauses=*/ { {45, {Clause::OMPC_map}}, + {60, {}}, }, }; return desc; @@ -421,6 +472,22 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpPrescriptiveness>() { } template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpPresentModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"present-modifier", + /*props=*/ + { + {51, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {51, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> const OmpModifierDescriptor & OmpGetDescriptor<parser::OmpReductionIdentifier>() { static const OmpModifierDescriptor desc{ @@ -457,6 +524,38 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpReductionModifier>() { } template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpRefModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"ref-modifier", + /*props=*/ + { + {60, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {60, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpSelfModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"self-modifier", + /*props=*/ + { + {60, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {60, {Clause::OMPC_map}}, + }, + }; + return desc; +} + +template <> const OmpModifierDescriptor & OmpGetDescriptor<parser::OmpStepComplexModifier>() { static const OmpModifierDescriptor desc{ @@ -522,4 +621,20 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpVariableCategory>() { }; return desc; } + +template <> +const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpxHoldModifier>() { + static const OmpModifierDescriptor desc{ + /*name=*/"ompx-hold-modifier", + /*props=*/ + { + {45, {OmpProperty::Unique}}, + }, + /*clauses=*/ + { + {45, {Clause::OMPC_map}}, + }, + }; + return desc; +} } // namespace Fortran::semantics diff --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp index f43d2cc..da14507 100644 --- a/flang/lib/Semantics/openmp-utils.cpp +++ b/flang/lib/Semantics/openmp-utils.cpp @@ -143,6 +143,31 @@ bool IsVarOrFunctionRef(const MaybeExpr &expr) { } } +bool IsMapEnteringType(parser::OmpMapType::Value type) { + switch (type) { + case parser::OmpMapType::Value::Alloc: + case parser::OmpMapType::Value::Storage: + case parser::OmpMapType::Value::To: + case parser::OmpMapType::Value::Tofrom: + return true; + default: + return false; + } +} + +bool IsMapExitingType(parser::OmpMapType::Value type) { + switch (type) { + case parser::OmpMapType::Value::Delete: + case parser::OmpMapType::Value::From: + case parser::OmpMapType::Value::Release: + case parser::OmpMapType::Value::Storage: + case parser::OmpMapType::Value::Tofrom: + return true; + default: + return false; + } +} + std::optional<SomeExpr> GetEvaluateExpr(const parser::Expr &parserExpr) { const parser::TypedExpr &typedExpr{parserExpr.typedExpr}; // ForwardOwningPointer typedExpr diff --git a/flang/lib/Semantics/openmp-utils.h b/flang/lib/Semantics/openmp-utils.h index a96c008..001fbeb 100644 --- a/flang/lib/Semantics/openmp-utils.h +++ b/flang/lib/Semantics/openmp-utils.h @@ -59,6 +59,9 @@ bool IsExtendedListItem(const Symbol &sym); bool IsVariableListItem(const Symbol &sym); bool IsVarOrFunctionRef(const MaybeExpr &expr); +bool IsMapEnteringType(parser::OmpMapType::Value type); +bool IsMapExitingType(parser::OmpMapType::Value type); + std::optional<SomeExpr> GetEvaluateExpr(const parser::Expr &parserExpr); std::optional<evaluate::DynamicType> GetDynamicType( const parser::Expr &parserExpr); diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 151f4cc..4c3e509 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -138,6 +138,9 @@ public: void Post(const parser::OpenACCBlockConstruct &) { PopContext(); } bool Pre(const parser::OpenACCCombinedConstruct &); void Post(const parser::OpenACCCombinedConstruct &) { PopContext(); } + void Post(const parser::AccBeginCombinedDirective &) { + GetContext().withinConstruct = true; + } bool Pre(const parser::OpenACCDeclarativeConstruct &); void Post(const parser::OpenACCDeclarativeConstruct &) { PopContext(); } @@ -160,6 +163,18 @@ public: GetContext().withinConstruct = true; } + // TODO: We should probably also privatize ConcurrentBounds. + template <typename A> + bool Pre(const parser::LoopBounds<parser::ScalarName, A> &x) { + if (!dirContext_.empty() && GetContext().withinConstruct) { + if (auto *symbol{ResolveAcc( + x.name.thing, Symbol::Flag::AccPrivate, currScope())}) { + AddToContextObjectWithDSA(*symbol, Symbol::Flag::AccPrivate); + } + } + return true; + } + bool Pre(const parser::OpenACCStandaloneConstruct &); void Post(const parser::OpenACCStandaloneConstruct &) { PopContext(); } void Post(const parser::AccStandaloneDirective &) { @@ -712,7 +727,9 @@ public: void Post(const parser::EorLabel &eorLabel) { CheckSourceLabel(eorLabel.v); } void Post(const parser::OmpMapClause &x) { - Symbol::Flag ompFlag = Symbol::Flag::OmpMapToFrom; + unsigned version{context_.langOptions().OpenMPVersion}; + std::optional<Symbol::Flag> ompFlag; + auto &mods{OmpGetModifiers(x)}; if (auto *mapType{OmpGetUniqueModifier<parser::OmpMapType>(mods)}) { switch (mapType->v) { @@ -726,16 +743,33 @@ public: ompFlag = Symbol::Flag::OmpMapToFrom; break; case parser::OmpMapType::Value::Alloc: - ompFlag = Symbol::Flag::OmpMapAlloc; - break; case parser::OmpMapType::Value::Release: - ompFlag = Symbol::Flag::OmpMapRelease; + case parser::OmpMapType::Value::Storage: + ompFlag = Symbol::Flag::OmpMapStorage; break; case parser::OmpMapType::Value::Delete: ompFlag = Symbol::Flag::OmpMapDelete; break; } } + if (!ompFlag) { + if (version >= 60) { + // [6.0:275:12-15] + // When a map-type is not specified for a clause on which it may be + // specified, the map-type defaults to storage if the delete-modifier + // is present on the clause or if the list item for which the map-type + // is not specified is an assumed-size array. + if (OmpGetUniqueModifier<parser::OmpDeleteModifier>(mods)) { + ompFlag = Symbol::Flag::OmpMapStorage; + } + // Otherwise, if delete-modifier is absent, leave ompFlag unset. + } else { + // [5.2:151:10] + // If a map-type is not specified, the map-type defaults to tofrom. + ompFlag = Symbol::Flag::OmpMapToFrom; + } + } + const auto &ompObjList{std::get<parser::OmpObjectList>(x.t)}; for (const auto &ompObj : ompObjList.v) { common::visit( @@ -744,15 +778,15 @@ public: if (const auto *name{ semantics::getDesignatorNameIfDataRef(designator)}) { if (name->symbol) { - name->symbol->set(ompFlag); - AddToContextObjectWithDSA(*name->symbol, ompFlag); - } - if (name->symbol && - semantics::IsAssumedSizeArray(*name->symbol)) { - context_.Say(designator.source, - "Assumed-size whole arrays may not appear on the %s " - "clause"_err_en_US, - "MAP"); + name->symbol->set( + ompFlag.value_or(Symbol::Flag::OmpMapStorage)); + AddToContextObjectWithDSA(*name->symbol, *ompFlag); + if (semantics::IsAssumedSizeArray(*name->symbol)) { + context_.Say(designator.source, + "Assumed-size whole arrays may not appear on the %s " + "clause"_err_en_US, + "MAP"); + } } } }, @@ -760,7 +794,7 @@ public: }, ompObj.u); - ResolveOmpObject(ompObj, ompFlag); + ResolveOmpObject(ompObj, ompFlag.value_or(Symbol::Flag::OmpMapStorage)); } } @@ -2759,9 +2793,8 @@ void OmpAttributeVisitor::ResolveOmpObject( } Symbol::Flag dataMappingAttributeFlags[] = { Symbol::Flag::OmpMapTo, Symbol::Flag::OmpMapFrom, - Symbol::Flag::OmpMapToFrom, Symbol::Flag::OmpMapAlloc, - Symbol::Flag::OmpMapRelease, Symbol::Flag::OmpMapDelete, - Symbol::Flag::OmpIsDevicePtr, + Symbol::Flag::OmpMapToFrom, Symbol::Flag::OmpMapStorage, + Symbol::Flag::OmpMapDelete, Symbol::Flag::OmpIsDevicePtr, Symbol::Flag::OmpHasDeviceAddr}; Symbol::Flag dataSharingAttributeFlags[] = { diff --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp index 27e259f..9454ef9 100644 --- a/flang/lib/Semantics/resolve-labels.cpp +++ b/flang/lib/Semantics/resolve-labels.cpp @@ -492,10 +492,9 @@ public: // Uppercase the name of the main program, so that its symbol name // would be unique from similarly named non-main-program symbols. auto upperCaseCharBlock = [](const parser::CharBlock &cb) { - char *ch{const_cast<char *>(cb.begin())}; - char *endCh{ch + cb.size()}; - while (ch != endCh) { - *ch++ = parser::ToUpperCaseLetter(*ch); + auto ch{const_cast<char *>(cb.begin())}; + for (char *endCh{ch + cb.size()}; ch != endCh; ++ch) { + *ch = parser::ToUpperCaseLetter(*ch); } }; const parser::CharBlock *progName{nullptr}; diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp index b15ed05..6db11aa 100644 --- a/flang/lib/Semantics/semantics.cpp +++ b/flang/lib/Semantics/semantics.cpp @@ -642,8 +642,7 @@ bool Semantics::Perform() { return ValidateLabels(context_, program_) && parser::CanonicalizeDo(program_) && // force line break CanonicalizeAcc(context_.messages(), program_) && - CanonicalizeOmp(context_.messages(), program_) && - CanonicalizeCUDA(program_) && + CanonicalizeOmp(context_, program_) && CanonicalizeCUDA(program_) && PerformStatementSemantics(context_, program_) && CanonicalizeDirectives(context_.messages(), program_) && ModFileWriter{context_} diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp index 0380207..2259cfc 100644 --- a/flang/lib/Semantics/symbol.cpp +++ b/flang/lib/Semantics/symbol.cpp @@ -861,8 +861,7 @@ std::string Symbol::OmpFlagToClauseName(Symbol::Flag ompFlag) { case Symbol::Flag::OmpMapTo: case Symbol::Flag::OmpMapFrom: case Symbol::Flag::OmpMapToFrom: - case Symbol::Flag::OmpMapAlloc: - case Symbol::Flag::OmpMapRelease: + case Symbol::Flag::OmpMapStorage: case Symbol::Flag::OmpMapDelete: clauseName = "MAP"; break; |