Skip to content

Commit a3a007a

Browse files
authored
[mlir][NFC] update flang/Lower create APIs (8/n) (#149912)
See #147168 for more info.
1 parent 6fa759b commit a3a007a

24 files changed

+1378
-1336
lines changed

flang/lib/Lower/Allocatable.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ struct ErrorManager {
7878
statExpr && errMsgExpr
7979
? builder.createBox(loc,
8080
converter.genExprAddr(loc, errMsgExpr, stmtCtx))
81-
: builder.create<fir::AbsentOp>(
82-
loc,
81+
: fir::AbsentOp::create(
82+
builder, loc,
8383
fir::BoxType::get(mlir::NoneType::get(builder.getContext())));
8484
sourceFile = fir::factory::locationToFilename(builder, loc);
8585
sourceLine = fir::factory::locationToLineNo(builder, loc,
@@ -92,10 +92,10 @@ struct ErrorManager {
9292
if (statValue) {
9393
mlir::Value zero =
9494
builder.createIntegerConstant(loc, statValue.getType(), 0);
95-
auto cmp = builder.create<mlir::arith::CmpIOp>(
96-
loc, mlir::arith::CmpIPredicate::eq, statValue, zero);
97-
auto ifOp = builder.create<fir::IfOp>(loc, cmp,
98-
/*withElseRegion=*/false);
95+
auto cmp = mlir::arith::CmpIOp::create(
96+
builder, loc, mlir::arith::CmpIPredicate::eq, statValue, zero);
97+
auto ifOp = fir::IfOp::create(builder, loc, cmp,
98+
/*withElseRegion=*/false);
9999
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
100100
}
101101
}
@@ -106,7 +106,7 @@ struct ErrorManager {
106106
assert(stat && "missing stat value");
107107
mlir::Value castStat = builder.createConvert(
108108
loc, fir::dyn_cast_ptrEleTy(statAddr.getType()), stat);
109-
builder.create<fir::StoreOp>(loc, castStat, statAddr);
109+
fir::StoreOp::create(builder, loc, castStat, statAddr);
110110
statValue = stat;
111111
}
112112
}
@@ -141,7 +141,7 @@ static void genRuntimeSetBounds(fir::FirOpBuilder &builder, mlir::Location loc,
141141
const auto args = fir::runtime::createArguments(
142142
builder, loc, callee.getFunctionType(), box.getAddr(), dimIndex,
143143
lowerBound, upperBound);
144-
builder.create<fir::CallOp>(loc, callee, args);
144+
fir::CallOp::create(builder, loc, callee, args);
145145
}
146146

147147
/// Generate runtime call to set the lengths of a character allocatable or
@@ -171,7 +171,7 @@ static void genRuntimeInitCharacter(fir::FirOpBuilder &builder,
171171
args.push_back(builder.createIntegerConstant(loc, inputTypes[4], corank));
172172
const auto convertedArgs = fir::runtime::createArguments(
173173
builder, loc, callee.getFunctionType(), args);
174-
builder.create<fir::CallOp>(loc, callee, convertedArgs);
174+
fir::CallOp::create(builder, loc, callee, convertedArgs);
175175
}
176176

177177
/// Generate a sequence of runtime calls to allocate memory.
@@ -194,7 +194,7 @@ static mlir::Value genRuntimeAllocate(fir::FirOpBuilder &builder,
194194
args.push_back(errorManager.sourceLine);
195195
const auto convertedArgs = fir::runtime::createArguments(
196196
builder, loc, callee.getFunctionType(), args);
197-
return builder.create<fir::CallOp>(loc, callee, convertedArgs).getResult(0);
197+
return fir::CallOp::create(builder, loc, callee, convertedArgs).getResult(0);
198198
}
199199

200200
/// Generate a sequence of runtime calls to allocate memory and assign with the
@@ -214,7 +214,7 @@ static mlir::Value genRuntimeAllocateSource(fir::FirOpBuilder &builder,
214214
builder, loc, callee.getFunctionType(), box.getAddr(),
215215
fir::getBase(source), errorManager.hasStat, errorManager.errMsgAddr,
216216
errorManager.sourceFile, errorManager.sourceLine);
217-
return builder.create<fir::CallOp>(loc, callee, args).getResult(0);
217+
return fir::CallOp::create(builder, loc, callee, args).getResult(0);
218218
}
219219

220220
/// Generate runtime call to apply mold to the descriptor.
@@ -233,7 +233,7 @@ static void genRuntimeAllocateApplyMold(fir::FirOpBuilder &builder,
233233
fir::factory::getMutableIRBox(builder, loc, box), fir::getBase(mold),
234234
builder.createIntegerConstant(
235235
loc, callee.getFunctionType().getInputs()[2], rank));
236-
builder.create<fir::CallOp>(loc, callee, args);
236+
fir::CallOp::create(builder, loc, callee, args);
237237
}
238238

239239
/// Generate a runtime call to deallocate memory.
@@ -270,7 +270,7 @@ static mlir::Value genRuntimeDeallocate(fir::FirOpBuilder &builder,
270270
errorManager.hasStat, errorManager.errMsgAddr, errorManager.sourceFile,
271271
errorManager.sourceLine);
272272
}
273-
return builder.create<fir::CallOp>(loc, callee, operands).getResult(0);
273+
return fir::CallOp::create(builder, loc, callee, operands).getResult(0);
274274
}
275275

276276
//===----------------------------------------------------------------------===//
@@ -433,9 +433,9 @@ class AllocateStmtHelper {
433433
loc, Fortran::semantics::GetExpr(std::get<1>(shapeSpec.t)), stmtCtx));
434434
ub = builder.createConvert(loc, idxTy, ub);
435435
if (lb) {
436-
mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, ub, lb);
436+
mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, ub, lb);
437437
extents.emplace_back(
438-
builder.create<mlir::arith::AddIOp>(loc, diff, one));
438+
mlir::arith::AddIOp::create(builder, loc, diff, one));
439439
} else {
440440
extents.emplace_back(ub);
441441
}
@@ -461,7 +461,7 @@ class AllocateStmtHelper {
461461
mlir::Value falseValue = builder.createBool(loc, false);
462462
mlir::Value falseConv = builder.createConvert(
463463
loc, fir::unwrapRefType(pinned.getType()), falseValue);
464-
builder.create<fir::StoreOp>(loc, falseConv, pinned);
464+
fir::StoreOp::create(builder, loc, falseConv, pinned);
465465
}
466466

467467
void genSimpleAllocation(const Allocation &alloc,
@@ -557,7 +557,7 @@ class AllocateStmtHelper {
557557
mlir::Value nullPointer = fir::factory::createUnallocatedBox(
558558
builder, loc, box.getBoxTy(), box.nonDeferredLenParams(),
559559
/*typeSourceBox=*/{}, allocatorIdx);
560-
builder.create<fir::StoreOp>(loc, nullPointer, box.getAddr());
560+
fir::StoreOp::create(builder, loc, nullPointer, box.getAddr());
561561
} else {
562562
assert(box.isAllocatable() && "must be an allocatable");
563563
// For allocatables, sync the MutableBoxValue and descriptor before the
@@ -597,13 +597,14 @@ class AllocateStmtHelper {
597597
assert(sourceBox && "source expression should be lowered to one box");
598598
for (int i = 0; i < sourceExpr->Rank(); ++i) {
599599
auto dimVal = builder.createIntegerConstant(loc, idxTy, i);
600-
auto dimInfo = builder.create<fir::BoxDimsOp>(
601-
loc, idxTy, idxTy, idxTy, sourceBox->getAddr(), dimVal);
600+
auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy,
601+
sourceBox->getAddr(), dimVal);
602602
mlir::Value lb =
603603
fir::factory::readLowerBound(builder, loc, sourceExv, i, one);
604604
mlir::Value extent = dimInfo.getResult(1);
605-
mlir::Value ub = builder.create<mlir::arith::SubIOp>(
606-
loc, builder.create<mlir::arith::AddIOp>(loc, extent, lb), one);
605+
mlir::Value ub = mlir::arith::SubIOp::create(
606+
builder, loc, mlir::arith::AddIOp::create(builder, loc, extent, lb),
607+
one);
607608
mlir::Value dimIndex = builder.createIntegerConstant(loc, i32Ty, i);
608609
genRuntimeSetBounds(builder, loc, box, dimIndex, lb, ub);
609610
}
@@ -668,7 +669,7 @@ class AllocateStmtHelper {
668669
const auto args = fir::runtime::createArguments(
669670
builder, loc, callee.getFunctionType(), box.getAddr(), typeDescAddr,
670671
rankValue, corankValue);
671-
builder.create<fir::CallOp>(loc, callee, args);
672+
fir::CallOp::create(builder, loc, callee, args);
672673
}
673674

674675
/// Generate call to PointerNullifyIntrinsic or AllocatableInitIntrinsic to
@@ -697,7 +698,7 @@ class AllocateStmtHelper {
697698
const auto args = fir::runtime::createArguments(
698699
builder, loc, callee.getFunctionType(), box.getAddr(), categoryValue,
699700
kindValue, rankValue, corankValue);
700-
builder.create<fir::CallOp>(loc, callee, args);
701+
fir::CallOp::create(builder, loc, callee, args);
701702
}
702703

703704
/// Generate call to the AllocatableInitDerived to set up the type descriptor
@@ -909,8 +910,8 @@ void Fortran::lower::genDeallocateIfAllocated(
909910
.genThen([&]() {
910911
if (mlir::Type eleType = box.getEleTy();
911912
mlir::isa<fir::RecordType>(eleType) && box.isPolymorphic()) {
912-
mlir::Value declaredTypeDesc = builder.create<fir::TypeDescOp>(
913-
loc, mlir::TypeAttr::get(eleType));
913+
mlir::Value declaredTypeDesc = fir::TypeDescOp::create(
914+
builder, loc, mlir::TypeAttr::get(eleType));
914915
genDeallocateBox(converter, box, loc, sym, declaredTypeDesc);
915916
} else {
916917
genDeallocateBox(converter, box, loc, sym);
@@ -1151,7 +1152,7 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen(
11511152
// here).
11521153
auto readLength = [&]() {
11531154
fir::BoxValue boxLoad =
1154-
builder.create<fir::LoadOp>(loc, fir::getBase(box)).getResult();
1155+
fir::LoadOp::create(builder, loc, fir::getBase(box)).getResult();
11551156
return fir::factory::readCharLen(builder, loc, boxLoad);
11561157
};
11571158
if (Fortran::semantics::IsOptional(sym)) {
@@ -1160,15 +1161,15 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen(
11601161
// they are absents. According to 15.5.2.12 3 (9), it is illegal to
11611162
// inquire the length of absent optional, even if non deferred, so
11621163
// it's fine to use undefOp in this case.
1163-
auto isPresent = builder.create<fir::IsPresentOp>(loc, builder.getI1Type(),
1164-
fir::getBase(box));
1164+
auto isPresent = fir::IsPresentOp::create(builder, loc, builder.getI1Type(),
1165+
fir::getBase(box));
11651166
mlir::Value len =
11661167
builder.genIfOp(loc, {idxTy}, isPresent, true)
11671168
.genThen(
1168-
[&]() { builder.create<fir::ResultOp>(loc, readLength()); })
1169+
[&]() { fir::ResultOp::create(builder, loc, readLength()); })
11691170
.genElse([&]() {
1170-
auto undef = builder.create<fir::UndefOp>(loc, idxTy);
1171-
builder.create<fir::ResultOp>(loc, undef.getResult());
1171+
auto undef = fir::UndefOp::create(builder, loc, idxTy);
1172+
fir::ResultOp::create(builder, loc, undef.getResult());
11721173
})
11731174
.getResults()[0];
11741175
return len;
@@ -1183,5 +1184,5 @@ mlir::Value Fortran::lower::getTypeDescAddr(
11831184
mlir::Type typeDesc =
11841185
Fortran::lower::translateDerivedTypeToFIRType(converter, typeSpec);
11851186
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
1186-
return builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(typeDesc));
1187+
return fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(typeDesc));
11871188
}

flang/lib/Lower/Bridge.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,12 @@ class TypeInfoConverter {
333333
if (details.numPrivatesNotOverridden() > 0)
334334
tbpName += "."s + std::to_string(details.numPrivatesNotOverridden());
335335
std::string bindingName = converter.mangleName(details.symbol());
336-
builder.create<fir::DTEntryOp>(
337-
info.loc, mlir::StringAttr::get(builder.getContext(), tbpName),
336+
fir::DTEntryOp::create(
337+
builder, info.loc,
338+
mlir::StringAttr::get(builder.getContext(), tbpName),
338339
mlir::SymbolRefAttr::get(builder.getContext(), bindingName));
339340
}
340-
builder.create<fir::FirEndOp>(info.loc);
341+
fir::FirEndOp::create(builder, info.loc);
341342
}
342343
// Gather info about components that is not reflected in fir.type and may be
343344
// needed later: component initial values and array component non default
@@ -360,11 +361,11 @@ class TypeInfoConverter {
360361
componentInfo = builder.createBlock(&dt.getComponentInfo());
361362
auto compName = mlir::StringAttr::get(builder.getContext(),
362363
toStringRef(component.name()));
363-
builder.create<fir::DTComponentOp>(info.loc, compName, lbs, init_val);
364+
fir::DTComponentOp::create(builder, info.loc, compName, lbs, init_val);
364365
}
365366
}
366367
if (componentInfo)
367-
builder.create<fir::FirEndOp>(info.loc);
368+
fir::FirEndOp::create(builder, info.loc);
368369
builder.restoreInsertionPoint(insertPointIfCreated);
369370
}
370371

@@ -4829,18 +4830,18 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48294830
base = convertOp.getValue();
48304831
// Special case if the rhs is a constant.
48314832
if (matchPattern(base.getDefiningOp(), mlir::m_Constant())) {
4832-
builder.create<cuf::DataTransferOp>(loc, base, lhsVal, shape,
4833-
transferKindAttr);
4833+
cuf::DataTransferOp::create(builder, loc, base, lhsVal, shape,
4834+
transferKindAttr);
48344835
} else {
48354836
auto associate = hlfir::genAssociateExpr(
48364837
loc, builder, rhs, rhs.getType(), ".cuf_host_tmp");
4837-
builder.create<cuf::DataTransferOp>(loc, associate.getBase(), lhsVal,
4838-
shape, transferKindAttr);
4839-
builder.create<hlfir::EndAssociateOp>(loc, associate);
4838+
cuf::DataTransferOp::create(builder, loc, associate.getBase(), lhsVal,
4839+
shape, transferKindAttr);
4840+
hlfir::EndAssociateOp::create(builder, loc, associate);
48404841
}
48414842
} else {
4842-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4843-
transferKindAttr);
4843+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
4844+
transferKindAttr);
48444845
}
48454846
return;
48464847
}
@@ -4849,8 +4850,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48494850
if (!lhsIsDevice && rhsIsDevice) {
48504851
auto transferKindAttr = cuf::DataTransferKindAttr::get(
48514852
builder.getContext(), cuf::DataTransferKind::DeviceHost);
4852-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4853-
transferKindAttr);
4853+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
4854+
transferKindAttr);
48544855
return;
48554856
}
48564857

@@ -4859,8 +4860,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48594860
assert(rhs.isVariable() && "CUDA Fortran assignment rhs is not legal");
48604861
auto transferKindAttr = cuf::DataTransferKindAttr::get(
48614862
builder.getContext(), cuf::DataTransferKind::DeviceDevice);
4862-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4863-
transferKindAttr);
4863+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
4864+
transferKindAttr);
48644865
return;
48654866
}
48664867
llvm_unreachable("Unhandled CUDA data transfer");
@@ -4906,8 +4907,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
49064907
addSymbol(sym,
49074908
hlfir::translateToExtendedValue(loc, builder, temp).first,
49084909
/*forced=*/true);
4909-
builder.create<cuf::DataTransferOp>(
4910-
loc, addr, temp, /*shape=*/mlir::Value{}, transferKindAttr);
4910+
cuf::DataTransferOp::create(builder, loc, addr, temp,
4911+
/*shape=*/mlir::Value{},
4912+
transferKindAttr);
49114913
++nbDeviceResidentObject;
49124914
}
49134915
}
@@ -4996,27 +4998,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
49964998
if (isCUDATransfer && !hasCUDAImplicitTransfer)
49974999
genCUDADataTransfer(builder, loc, assign, lhs, rhs);
49985000
else
4999-
builder.create<hlfir::AssignOp>(loc, rhs, lhs,
5000-
isWholeAllocatableAssignment,
5001-
keepLhsLengthInAllocatableAssignment);
5001+
hlfir::AssignOp::create(builder, loc, rhs, lhs,
5002+
isWholeAllocatableAssignment,
5003+
keepLhsLengthInAllocatableAssignment);
50025004
if (hasCUDAImplicitTransfer && !isInDeviceContext) {
50035005
localSymbols.popScope();
50045006
for (mlir::Value temp : implicitTemps)
5005-
builder.create<fir::FreeMemOp>(loc, temp);
5007+
fir::FreeMemOp::create(builder, loc, temp);
50065008
}
50075009
return;
50085010
}
50095011
// Assignments inside Forall, Where, or assignments to a vector subscripted
50105012
// left-hand side requires using an hlfir.region_assign in HLFIR. The
50115013
// right-hand side and left-hand side must be evaluated inside the
50125014
// hlfir.region_assign regions.
5013-
auto regionAssignOp = builder.create<hlfir::RegionAssignOp>(loc);
5015+
auto regionAssignOp = hlfir::RegionAssignOp::create(builder, loc);
50145016

50155017
// Lower RHS in its own region.
50165018
builder.createBlock(&regionAssignOp.getRhsRegion());
50175019
Fortran::lower::StatementContext rhsContext;
50185020
hlfir::Entity rhs = evaluateRhs(rhsContext);
5019-
auto rhsYieldOp = builder.create<hlfir::YieldOp>(loc, rhs);
5021+
auto rhsYieldOp = hlfir::YieldOp::create(builder, loc, rhs);
50205022
Fortran::lower::genCleanUpInRegionIfAny(
50215023
loc, builder, rhsYieldOp.getCleanup(), rhsContext);
50225024
// Lower LHS in its own region.
@@ -5025,7 +5027,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
50255027
mlir::Value lhsYield = nullptr;
50265028
if (!lhsHasVectorSubscripts) {
50275029
hlfir::Entity lhs = evaluateLhs(lhsContext);
5028-
auto lhsYieldOp = builder.create<hlfir::YieldOp>(loc, lhs);
5030+
auto lhsYieldOp = hlfir::YieldOp::create(builder, loc, lhs);
50295031
Fortran::lower::genCleanUpInRegionIfAny(
50305032
loc, builder, lhsYieldOp.getCleanup(), lhsContext);
50315033
lhsYield = lhs;
@@ -5054,7 +5056,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
50545056
builder.createBlock(&regionAssignOp.getUserDefinedAssignment(),
50555057
mlir::Region::iterator{}, {rhsType, lhsType},
50565058
{loc, loc});
5057-
auto end = builder.create<fir::FirEndOp>(loc);
5059+
auto end = fir::FirEndOp::create(builder, loc);
50585060
builder.setInsertionPoint(end);
50595061
hlfir::Entity lhsBlockArg{regionAssignOp.getUserAssignmentLhs()};
50605062
hlfir::Entity rhsBlockArg{regionAssignOp.getUserAssignmentRhs()};

0 commit comments

Comments
 (0)