Skip to content

Commit e4d3dc6

Browse files
authored
[flang][NFC] Update HLFIR ops creation to the new APIs (#152075)
See #147168
1 parent 0885740 commit e4d3dc6

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
13161316
auto copyData = [&](hlfir::Entity l, hlfir::Entity r) {
13171317
// Dereference RHS and load it if trivial scalar.
13181318
r = hlfir::loadTrivialScalar(loc, *builder, r);
1319-
builder->create<hlfir::AssignOp>(loc, r, l, isAllocatable);
1319+
hlfir::AssignOp::create(*builder, loc, r, l, isAllocatable);
13201320
};
13211321

13221322
if (isPointer) {
@@ -3057,11 +3057,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
30573057
exprVal = builder->createConvert(loc, builder->getI1Type(), exprVal);
30583058
if (innerInsertionPoint.isSet())
30593059
builder->restoreInsertionPoint(innerInsertionPoint);
3060-
builder->create<hlfir::YieldOp>(loc, exprVal);
3060+
hlfir::YieldOp::create(*builder, loc, exprVal);
30613061
};
30623062
for (const Fortran::parser::ConcurrentControl &control :
30633063
std::get<std::list<Fortran::parser::ConcurrentControl>>(header.t)) {
3064-
auto forallOp = builder->create<hlfir::ForallOp>(loc);
3064+
auto forallOp = hlfir::ForallOp::create(*builder, loc);
30653065
if (isOutterForall && !outerForall)
30663066
outerForall = forallOp;
30673067
evaluateControl(std::get<1>(control.t), forallOp.getLbRegion());
@@ -3078,8 +3078,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
30783078
mlir::Type controlVarType = genType(*controlVar);
30793079
mlir::Block *forallBody = builder->createBlock(&forallOp.getBody(), {},
30803080
{controlVarType}, {loc});
3081-
auto forallIndex = builder->create<hlfir::ForallIndexOp>(
3082-
loc, fir::ReferenceType::get(controlVarType),
3081+
auto forallIndex = hlfir::ForallIndexOp::create(
3082+
*builder, loc, fir::ReferenceType::get(controlVarType),
30833083
forallBody->getArguments()[0],
30843084
builder->getStringAttr(controlVar->name().ToString()));
30853085
localSymbols.addVariableDefinition(*controlVar, forallIndex,
@@ -3092,7 +3092,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
30923092
std::get<std::optional<Fortran::parser::ScalarLogicalExpr>>(
30933093
header.t)) {
30943094
// Create hlfir.forall_mask and set insertion point in its body.
3095-
auto forallMaskOp = builder->create<hlfir::ForallMaskOp>(loc);
3095+
auto forallMaskOp = hlfir::ForallMaskOp::create(*builder, loc);
30963096
evaluateControl(*maskExpr, forallMaskOp.getMaskRegion(), /*isMask=*/true);
30973097
builder->createBlock(&forallMaskOp.getBody());
30983098
auto end = fir::FirEndOp::create(*builder, loc);
@@ -4573,14 +4573,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
45734573
// descriptor address/value and later implemented with a store.
45744574
// The RHS is fully prepared in lowering, so that all that is left
45754575
// in hlfir.region_assign code generation is the store.
4576-
auto regionAssignOp = builder->create<hlfir::RegionAssignOp>(loc);
4576+
auto regionAssignOp = hlfir::RegionAssignOp::create(*builder, loc);
45774577

45784578
// Lower LHS in its own region.
45794579
builder->createBlock(&regionAssignOp.getLhsRegion());
45804580
Fortran::lower::StatementContext lhsContext;
45814581
hlfir::Entity lhs = Fortran::lower::convertExprToHLFIR(
45824582
loc, *this, assign.lhs, localSymbols, lhsContext);
4583-
auto lhsYieldOp = builder->create<hlfir::YieldOp>(loc, lhs);
4583+
auto lhsYieldOp = hlfir::YieldOp::create(*builder, loc, lhs);
45844584
Fortran::lower::genCleanUpInRegionIfAny(
45854585
loc, *builder, lhsYieldOp.getCleanup(), lhsContext);
45864586

@@ -4589,7 +4589,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
45894589
Fortran::lower::StatementContext rhsContext;
45904590
mlir::Value rhs =
45914591
genForallPointerAssignmentRhs(loc, lhs, assign, rhsContext);
4592-
auto rhsYieldOp = builder->create<hlfir::YieldOp>(loc, rhs);
4592+
auto rhsYieldOp = hlfir::YieldOp::create(*builder, loc, rhs);
45934593
Fortran::lower::genCleanUpInRegionIfAny(
45944594
loc, *builder, rhsYieldOp.getCleanup(), rhsContext);
45954595

@@ -5360,7 +5360,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
53605360
if (!lowerToHighLevelFIR()) {
53615361
implicitIterSpace.growStack();
53625362
} else {
5363-
whereOp = builder->create<hlfir::WhereOp>(loc);
5363+
whereOp = hlfir::WhereOp::create(*builder, loc);
53645364
builder->createBlock(&whereOp.getMaskRegion());
53655365
}
53665366

@@ -5422,7 +5422,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
54225422
hlfir::Entity mask = Fortran::lower::convertExprToHLFIR(
54235423
loc, *this, *maskExpr, localSymbols, maskContext);
54245424
mask = hlfir::loadTrivialScalar(loc, *builder, mask);
5425-
auto yieldOp = builder->create<hlfir::YieldOp>(loc, mask);
5425+
auto yieldOp = hlfir::YieldOp::create(*builder, loc, mask);
54265426
Fortran::lower::genCleanUpInRegionIfAny(loc, *builder, yieldOp.getCleanup(),
54275427
maskContext);
54285428
}
@@ -5438,7 +5438,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
54385438
mlir::Location loc = getCurrentLocation();
54395439
hlfir::ElseWhereOp elsewhereOp;
54405440
if (lowerToHighLevelFIR()) {
5441-
elsewhereOp = builder->create<hlfir::ElseWhereOp>(loc);
5441+
elsewhereOp = hlfir::ElseWhereOp::create(*builder, loc);
54425442
// Lower mask in the mask region.
54435443
builder->createBlock(&elsewhereOp.getMaskRegion());
54445444
}
@@ -5466,7 +5466,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
54665466
void genFIR(const Fortran::parser::WhereConstruct::Elsewhere &ew) {
54675467
if (lowerToHighLevelFIR()) {
54685468
auto elsewhereOp =
5469-
builder->create<hlfir::ElseWhereOp>(getCurrentLocation());
5469+
hlfir::ElseWhereOp::create(*builder, getCurrentLocation());
54705470
builder->createBlock(&elsewhereOp.getBody());
54715471
}
54725472
genNestedStatement(
@@ -5492,7 +5492,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
54925492
std::get<Fortran::parser::LogicalExpr>(stmt.t));
54935493
if (lowerToHighLevelFIR()) {
54945494
mlir::Location loc = getCurrentLocation();
5495-
auto whereOp = builder->create<hlfir::WhereOp>(loc);
5495+
auto whereOp = hlfir::WhereOp::create(*builder, loc);
54965496
builder->createBlock(&whereOp.getMaskRegion());
54975497
lowerWhereMaskToHlfir(loc, mask);
54985498
builder->createBlock(&whereOp.getBody());

flang/lib/Lower/ConvertArrayConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ hlfir::EntityWithAttributes Fortran::lower::ArrayConstructorBuilder<T>::gen(
795795
// Insert the clean-up for the created hlfir.expr.
796796
fir::FirOpBuilder *bldr = &builder;
797797
stmtCtx.attachCleanup(
798-
[=]() { bldr->create<hlfir::DestroyOp>(loc, hlfirExpr); });
798+
[=]() { hlfir::DestroyOp::create(*bldr, loc, hlfirExpr); });
799799
return hlfir::EntityWithAttributes{hlfirExpr};
800800
}
801801

flang/lib/Lower/ConvertCall.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,8 @@ Fortran::lower::genCallOpAndResult(
702702
fir::FirOpBuilder *bldr = &converter.getFirOpBuilder();
703703
if (!isElemental)
704704
stmtCtx.attachCleanup([bldr, loc, expr, mustFinalizeResult]() {
705-
bldr->create<hlfir::DestroyOp>(loc, expr,
706-
/*finalize=*/mustFinalizeResult);
705+
hlfir::DestroyOp::create(*bldr, loc, expr,
706+
/*finalize=*/mustFinalizeResult);
707707
});
708708
return {LoweredResult{hlfir::EntityWithAttributes{expr}},
709709
mustFinalizeResult};
@@ -2244,8 +2244,9 @@ class ElementalCallBuilder {
22442244
if (hlfir::AssociateOp associate =
22452245
preparedActual->associateIfArrayExpr(loc, builder)) {
22462246
fir::FirOpBuilder *bldr = &builder;
2247-
callContext.stmtCtx.attachCleanup(
2248-
[=]() { bldr->create<hlfir::EndAssociateOp>(loc, associate); });
2247+
callContext.stmtCtx.attachCleanup([=]() {
2248+
hlfir::EndAssociateOp::create(*bldr, loc, associate);
2249+
});
22492250
}
22502251
}
22512252
}
@@ -2314,7 +2315,7 @@ class ElementalCallBuilder {
23142315
bool mustFinalizeExpr = impl().resultMayRequireFinalization(callContext);
23152316
fir::FirOpBuilder *bldr = &builder;
23162317
callContext.stmtCtx.attachCleanup([=]() {
2317-
bldr->create<hlfir::DestroyOp>(loc, elemental, mustFinalizeExpr);
2318+
hlfir::DestroyOp::create(*bldr, loc, elemental, mustFinalizeExpr);
23182319
});
23192320
return hlfir::EntityWithAttributes{elemental};
23202321
}
@@ -2739,7 +2740,7 @@ genIntrinsicRef(const Fortran::evaluate::SpecificIntrinsic *intrinsic,
27392740
if (result && mlir::isa<hlfir::ExprType>(result->getType())) {
27402741
fir::FirOpBuilder *bldr = &callContext.getBuilder();
27412742
callContext.stmtCtx.attachCleanup(
2742-
[=]() { bldr->create<hlfir::DestroyOp>(loc, *result); });
2743+
[=]() { hlfir::DestroyOp::create(*bldr, loc, *result); });
27432744
}
27442745
return result;
27452746
}

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ class HlfirDesignatorBuilder {
911911
setVectorSubscriptElementAddrOp(std::nullopt);
912912
fir::FirOpBuilder *bldr = &builder;
913913
getStmtCtx().attachCleanup(
914-
[=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
914+
[=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
915915
return hlfir::EntityWithAttributes{elemental};
916916
}
917917

@@ -1579,7 +1579,7 @@ class HlfirBuilder {
15791579
}
15801580

15811581
hlfir::EntityWithAttributes gen(const Fortran::evaluate::NullPointer &expr) {
1582-
auto nullop = getBuilder().create<hlfir::NullOp>(getLoc());
1582+
auto nullop = hlfir::NullOp::create(getBuilder(), getLoc());
15831583
return mlir::cast<fir::FortranVariableOpInterface>(nullop.getOperation());
15841584
}
15851585

@@ -1685,7 +1685,7 @@ class HlfirBuilder {
16851685
/*isUnordered=*/true, left.isPolymorphic() ? left : mlir::Value{});
16861686
fir::FirOpBuilder *bldr = &builder;
16871687
getStmtCtx().attachCleanup(
1688-
[=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
1688+
[=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
16891689
return hlfir::EntityWithAttributes{elemental};
16901690
}
16911691

@@ -1736,7 +1736,7 @@ class HlfirBuilder {
17361736
builder.setIntegerOverflowFlags(iofBackup);
17371737
fir::FirOpBuilder *bldr = &builder;
17381738
getStmtCtx().attachCleanup(
1739-
[=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
1739+
[=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
17401740
return hlfir::EntityWithAttributes{elemental};
17411741
}
17421742

flang/lib/Optimizer/Builder/HLFIRTools.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
12221222
loc, builder, entity, entity.getType(), "", byRefAttr);
12231223
auto *bldr = &builder;
12241224
hlfir::CleanupFunction cleanup = [bldr, loc, associate]() -> void {
1225-
bldr->create<hlfir::EndAssociateOp>(loc, associate);
1225+
hlfir::EndAssociateOp::create(*bldr, loc, associate);
12261226
};
12271227
hlfir::Entity temp{associate.getBase()};
12281228
return {translateToExtendedValue(loc, builder, temp).first, cleanup};
@@ -1502,15 +1502,15 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
15021502
mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation());
15031503
fir::FirOpBuilder *bldr = &builder;
15041504
auto cleanup = [loc, bldr, convertedRhs, associate]() {
1505-
bldr->create<hlfir::EndAssociateOp>(loc, associate);
1506-
bldr->create<hlfir::DestroyOp>(loc, convertedRhs);
1505+
hlfir::EndAssociateOp::create(*bldr, loc, associate);
1506+
hlfir::DestroyOp::create(*bldr, loc, convertedRhs);
15071507
};
15081508
return {castWithLbounds, cleanup};
15091509
}
15101510

15111511
fir::FirOpBuilder *bldr = &builder;
15121512
auto cleanup = [loc, bldr, convertedRhs]() {
1513-
bldr->create<hlfir::DestroyOp>(loc, convertedRhs);
1513+
hlfir::DestroyOp::create(*bldr, loc, convertedRhs);
15141514
};
15151515
return {hlfir::Entity{convertedRhs}, cleanup};
15161516
}

flang/lib/Optimizer/Builder/TemporaryStorage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ fir::factory::HomogeneousScalarStack::HomogeneousScalarStack(
8181
builder.createTemporary(loc, declaredType, tempName, extents, lengths);
8282

8383
mlir::Value shape = builder.genShape(loc, extents);
84-
temp = builder
85-
.create<hlfir::DeclareOp>(loc, tempStorage, tempName, shape,
86-
lengths, /*dummy_scope=*/nullptr,
87-
fir::FortranVariableFlagsAttr{})
84+
temp = hlfir::DeclareOp::create(builder, loc, tempStorage, tempName, shape,
85+
lengths, /*dummy_scope=*/nullptr,
86+
fir::FortranVariableFlagsAttr{})
8887
.getBase();
8988
}
9089

flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,15 @@ convertToMoldType(mlir::Location loc, fir::FirOpBuilder &builder,
438438
mlir::Value asExpr = hlfir::AsExprOp::create(builder, loc, input);
439439
if (asExpr.getType() != mold.getType())
440440
TODO(loc, "hlfir.expr conversion");
441-
cleanups.emplace_back([=]() { b->create<hlfir::DestroyOp>(loc, asExpr); });
441+
cleanups.emplace_back([=]() { hlfir::DestroyOp::create(*b, loc, asExpr); });
442442
return hlfir::Entity{asExpr};
443443
}
444444
if (input.isValue() && mold.isVariable()) {
445445
// T to fir.ref<T>, or hlfir.expr<T> to fir.ref<T>.
446446
hlfir::AssociateOp associate = hlfir::genAssociateExpr(
447447
loc, builder, input, mold.getFortranElementType(), ".tmp.val2ref");
448448
cleanups.emplace_back(
449-
[=]() { b->create<hlfir::EndAssociateOp>(loc, associate); });
449+
[=]() { hlfir::EndAssociateOp::create(*b, loc, associate); });
450450
return hlfir::Entity{associate.getBase()};
451451
}
452452
// Variable to Variable mismatch (e.g., fir.heap<T> vs fir.ref<T>), or value

0 commit comments

Comments
 (0)