Skip to content

Commit 64f5ec9

Browse files
committed
[mlir][NFC] update flang/Lower create APIs (8/n) (llvm#149687)
See llvm#147168 for more info.
1 parent b7e332d commit 64f5ec9

24 files changed

+892
-892
lines changed

flang/lib/Lower/Allocatable.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ErrorManager {
7878
statExpr && errMsgExpr
7979
? builder.createBox(loc,
8080
converter.genExprAddr(loc, errMsgExpr, stmtCtx))
81-
: builder.create<fir::AbsentOp>(
81+
: fir::AbsentOp::create(builder,
8282
loc,
8383
fir::BoxType::get(mlir::NoneType::get(builder.getContext())));
8484
sourceFile = fir::factory::locationToFilename(builder, loc);
@@ -92,9 +92,9 @@ struct ErrorManager {
9292
if (statValue) {
9393
mlir::Value zero =
9494
builder.createIntegerConstant(loc, statValue.getType(), 0);
95-
auto cmp = builder.create<mlir::arith::CmpIOp>(
95+
auto cmp = mlir::arith::CmpIOp::create(builder,
9696
loc, mlir::arith::CmpIPredicate::eq, statValue, zero);
97-
auto ifOp = builder.create<fir::IfOp>(loc, cmp,
97+
auto ifOp = fir::IfOp::create(builder, loc, cmp,
9898
/*withElseRegion=*/false);
9999
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
100100
}
@@ -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,13 @@ 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>(
600+
auto dimInfo = fir::BoxDimsOp::create(builder,
601601
loc, idxTy, idxTy, idxTy, 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(builder,
606+
loc, mlir::arith::AddIOp::create(builder, loc, extent, lb), one);
607607
mlir::Value dimIndex = builder.createIntegerConstant(loc, i32Ty, i);
608608
genRuntimeSetBounds(builder, loc, box, dimIndex, lb, ub);
609609
}
@@ -668,7 +668,7 @@ class AllocateStmtHelper {
668668
const auto args = fir::runtime::createArguments(
669669
builder, loc, callee.getFunctionType(), box.getAddr(), typeDescAddr,
670670
rankValue, corankValue);
671-
builder.create<fir::CallOp>(loc, callee, args);
671+
fir::CallOp::create(builder, loc, callee, args);
672672
}
673673

674674
/// Generate call to PointerNullifyIntrinsic or AllocatableInitIntrinsic to
@@ -697,7 +697,7 @@ class AllocateStmtHelper {
697697
const auto args = fir::runtime::createArguments(
698698
builder, loc, callee.getFunctionType(), box.getAddr(), categoryValue,
699699
kindValue, rankValue, corankValue);
700-
builder.create<fir::CallOp>(loc, callee, args);
700+
fir::CallOp::create(builder, loc, callee, args);
701701
}
702702

703703
/// Generate call to the AllocatableInitDerived to set up the type descriptor
@@ -909,7 +909,7 @@ void Fortran::lower::genDeallocateIfAllocated(
909909
.genThen([&]() {
910910
if (mlir::Type eleType = box.getEleTy();
911911
mlir::isa<fir::RecordType>(eleType) && box.isPolymorphic()) {
912-
mlir::Value declaredTypeDesc = builder.create<fir::TypeDescOp>(
912+
mlir::Value declaredTypeDesc = fir::TypeDescOp::create(builder,
913913
loc, mlir::TypeAttr::get(eleType));
914914
genDeallocateBox(converter, box, loc, sym, declaredTypeDesc);
915915
} else {
@@ -1151,7 +1151,7 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen(
11511151
// here).
11521152
auto readLength = [&]() {
11531153
fir::BoxValue boxLoad =
1154-
builder.create<fir::LoadOp>(loc, fir::getBase(box)).getResult();
1154+
fir::LoadOp::create(builder, loc, fir::getBase(box)).getResult();
11551155
return fir::factory::readCharLen(builder, loc, boxLoad);
11561156
};
11571157
if (Fortran::semantics::IsOptional(sym)) {
@@ -1160,15 +1160,15 @@ mlir::Value Fortran::lower::getAssumedCharAllocatableOrPointerLen(
11601160
// they are absents. According to 15.5.2.12 3 (9), it is illegal to
11611161
// inquire the length of absent optional, even if non deferred, so
11621162
// it's fine to use undefOp in this case.
1163-
auto isPresent = builder.create<fir::IsPresentOp>(loc, builder.getI1Type(),
1163+
auto isPresent = fir::IsPresentOp::create(builder, loc, builder.getI1Type(),
11641164
fir::getBase(box));
11651165
mlir::Value len =
11661166
builder.genIfOp(loc, {idxTy}, isPresent, true)
11671167
.genThen(
1168-
[&]() { builder.create<fir::ResultOp>(loc, readLength()); })
1168+
[&]() { fir::ResultOp::create(builder, loc, readLength()); })
11691169
.genElse([&]() {
1170-
auto undef = builder.create<fir::UndefOp>(loc, idxTy);
1171-
builder.create<fir::ResultOp>(loc, undef.getResult());
1170+
auto undef = fir::UndefOp::create(builder, loc, idxTy);
1171+
fir::ResultOp::create(builder, loc, undef.getResult());
11721172
})
11731173
.getResults()[0];
11741174
return len;
@@ -1183,5 +1183,5 @@ mlir::Value Fortran::lower::getTypeDescAddr(
11831183
mlir::Type typeDesc =
11841184
Fortran::lower::translateDerivedTypeToFIRType(converter, typeSpec);
11851185
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
1186-
return builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(typeDesc));
1186+
return fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(typeDesc));
11871187
}

flang/lib/Lower/Bridge.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ 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>(
336+
fir::DTEntryOp::create(builder,
337337
info.loc, mlir::StringAttr::get(builder.getContext(), tbpName),
338338
mlir::SymbolRefAttr::get(builder.getContext(), bindingName));
339339
}
340-
builder.create<fir::FirEndOp>(info.loc);
340+
fir::FirEndOp::create(builder, info.loc);
341341
}
342342
// Gather info about components that is not reflected in fir.type and may be
343343
// needed later: component initial values and array component non default
@@ -360,11 +360,11 @@ class TypeInfoConverter {
360360
componentInfo = builder.createBlock(&dt.getComponentInfo());
361361
auto compName = mlir::StringAttr::get(builder.getContext(),
362362
toStringRef(component.name()));
363-
builder.create<fir::DTComponentOp>(info.loc, compName, lbs, init_val);
363+
fir::DTComponentOp::create(builder, info.loc, compName, lbs, init_val);
364364
}
365365
}
366366
if (componentInfo)
367-
builder.create<fir::FirEndOp>(info.loc);
367+
fir::FirEndOp::create(builder, info.loc);
368368
builder.restoreInsertionPoint(insertPointIfCreated);
369369
}
370370

@@ -4829,17 +4829,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48294829
base = convertOp.getValue();
48304830
// Special case if the rhs is a constant.
48314831
if (matchPattern(base.getDefiningOp(), mlir::m_Constant())) {
4832-
builder.create<cuf::DataTransferOp>(loc, base, lhsVal, shape,
4832+
cuf::DataTransferOp::create(builder, loc, base, lhsVal, shape,
48334833
transferKindAttr);
48344834
} else {
48354835
auto associate = hlfir::genAssociateExpr(
48364836
loc, builder, rhs, rhs.getType(), ".cuf_host_tmp");
4837-
builder.create<cuf::DataTransferOp>(loc, associate.getBase(), lhsVal,
4837+
cuf::DataTransferOp::create(builder, loc, associate.getBase(), lhsVal,
48384838
shape, transferKindAttr);
4839-
builder.create<hlfir::EndAssociateOp>(loc, associate);
4839+
hlfir::EndAssociateOp::create(builder, loc, associate);
48404840
}
48414841
} else {
4842-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4842+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
48434843
transferKindAttr);
48444844
}
48454845
return;
@@ -4849,7 +4849,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48494849
if (!lhsIsDevice && rhsIsDevice) {
48504850
auto transferKindAttr = cuf::DataTransferKindAttr::get(
48514851
builder.getContext(), cuf::DataTransferKind::DeviceHost);
4852-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4852+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
48534853
transferKindAttr);
48544854
return;
48554855
}
@@ -4859,7 +4859,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
48594859
assert(rhs.isVariable() && "CUDA Fortran assignment rhs is not legal");
48604860
auto transferKindAttr = cuf::DataTransferKindAttr::get(
48614861
builder.getContext(), cuf::DataTransferKind::DeviceDevice);
4862-
builder.create<cuf::DataTransferOp>(loc, rhsVal, lhsVal, shape,
4862+
cuf::DataTransferOp::create(builder, loc, rhsVal, lhsVal, shape,
48634863
transferKindAttr);
48644864
return;
48654865
}
@@ -4906,7 +4906,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
49064906
addSymbol(sym,
49074907
hlfir::translateToExtendedValue(loc, builder, temp).first,
49084908
/*forced=*/true);
4909-
builder.create<cuf::DataTransferOp>(
4909+
cuf::DataTransferOp::create(builder,
49104910
loc, addr, temp, /*shape=*/mlir::Value{}, transferKindAttr);
49114911
++nbDeviceResidentObject;
49124912
}
@@ -4996,27 +4996,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
49964996
if (isCUDATransfer && !hasCUDAImplicitTransfer)
49974997
genCUDADataTransfer(builder, loc, assign, lhs, rhs);
49984998
else
4999-
builder.create<hlfir::AssignOp>(loc, rhs, lhs,
4999+
hlfir::AssignOp::create(builder, loc, rhs, lhs,
50005000
isWholeAllocatableAssignment,
50015001
keepLhsLengthInAllocatableAssignment);
50025002
if (hasCUDAImplicitTransfer && !isInDeviceContext) {
50035003
localSymbols.popScope();
50045004
for (mlir::Value temp : implicitTemps)
5005-
builder.create<fir::FreeMemOp>(loc, temp);
5005+
fir::FreeMemOp::create(builder, loc, temp);
50065006
}
50075007
return;
50085008
}
50095009
// Assignments inside Forall, Where, or assignments to a vector subscripted
50105010
// left-hand side requires using an hlfir.region_assign in HLFIR. The
50115011
// right-hand side and left-hand side must be evaluated inside the
50125012
// hlfir.region_assign regions.
5013-
auto regionAssignOp = builder.create<hlfir::RegionAssignOp>(loc);
5013+
auto regionAssignOp = hlfir::RegionAssignOp::create(builder, loc);
50145014

50155015
// Lower RHS in its own region.
50165016
builder.createBlock(&regionAssignOp.getRhsRegion());
50175017
Fortran::lower::StatementContext rhsContext;
50185018
hlfir::Entity rhs = evaluateRhs(rhsContext);
5019-
auto rhsYieldOp = builder.create<hlfir::YieldOp>(loc, rhs);
5019+
auto rhsYieldOp = hlfir::YieldOp::create(builder, loc, rhs);
50205020
Fortran::lower::genCleanUpInRegionIfAny(
50215021
loc, builder, rhsYieldOp.getCleanup(), rhsContext);
50225022
// Lower LHS in its own region.
@@ -5025,7 +5025,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
50255025
mlir::Value lhsYield = nullptr;
50265026
if (!lhsHasVectorSubscripts) {
50275027
hlfir::Entity lhs = evaluateLhs(lhsContext);
5028-
auto lhsYieldOp = builder.create<hlfir::YieldOp>(loc, lhs);
5028+
auto lhsYieldOp = hlfir::YieldOp::create(builder, loc, lhs);
50295029
Fortran::lower::genCleanUpInRegionIfAny(
50305030
loc, builder, lhsYieldOp.getCleanup(), lhsContext);
50315031
lhsYield = lhs;
@@ -5054,7 +5054,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
50545054
builder.createBlock(&regionAssignOp.getUserDefinedAssignment(),
50555055
mlir::Region::iterator{}, {rhsType, lhsType},
50565056
{loc, loc});
5057-
auto end = builder.create<fir::FirEndOp>(loc);
5057+
auto end = fir::FirEndOp::create(builder, loc);
50585058
builder.setInsertionPoint(end);
50595059
hlfir::Entity lhsBlockArg{regionAssignOp.getUserAssignmentLhs()};
50605060
hlfir::Entity rhsBlockArg{regionAssignOp.getUserAssignmentRhs()};

0 commit comments

Comments
 (0)