Skip to content

[mlir][NFC] update flang/Lower create APIs (8/n) #149912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions flang/lib/Lower/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -433,9 +433,9 @@ class AllocateStmtHelper {
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);
}
Expand All @@ -461,7 +461,7 @@ class AllocateStmtHelper {
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,
Expand Down Expand Up @@ -557,7 +557,7 @@ class AllocateStmtHelper {
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
Expand Down Expand Up @@ -597,13 +597,14 @@ class AllocateStmtHelper {
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);
}
Expand Down Expand Up @@ -668,7 +669,7 @@ class AllocateStmtHelper {
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
Expand Down Expand Up @@ -697,7 +698,7 @@ class AllocateStmtHelper {
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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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));
}
54 changes: 28 additions & 26 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,12 @@ class TypeInfoConverter {
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
Expand All @@ -360,11 +361,11 @@ class TypeInfoConverter {
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);
}

Expand Down Expand Up @@ -4829,18 +4830,18 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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;
}
Expand All @@ -4849,8 +4850,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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;
}

Expand All @@ -4859,8 +4860,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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");
Expand Down Expand Up @@ -4906,8 +4907,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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;
}
}
Expand Down Expand Up @@ -4996,27 +4998,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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;
}
// Assignments inside Forall, Where, or assignments to a vector subscripted
// 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(&regionAssignOp.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.
Expand All @@ -5025,7 +5027,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
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;
Expand Down Expand Up @@ -5054,7 +5056,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
builder.createBlock(&regionAssignOp.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()};
Expand Down
Loading
Loading