-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[flang][NFC] Update HLFIR ops creation to the new APIs #152075
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesSee #147168 Full diff: https://github.com/llvm/llvm-project/pull/152075.diff 7 Files Affected:
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 61476efbee1fc..e630841ca1a45 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -1316,7 +1316,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
auto copyData = [&](hlfir::Entity l, hlfir::Entity r) {
// Dereference RHS and load it if trivial scalar.
r = hlfir::loadTrivialScalar(loc, *builder, r);
- builder->create<hlfir::AssignOp>(loc, r, l, isAllocatable);
+ hlfir::AssignOp::create(*builder, loc, r, l, isAllocatable);
};
if (isPointer) {
@@ -3057,11 +3057,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
exprVal = builder->createConvert(loc, builder->getI1Type(), exprVal);
if (innerInsertionPoint.isSet())
builder->restoreInsertionPoint(innerInsertionPoint);
- builder->create<hlfir::YieldOp>(loc, exprVal);
+ hlfir::YieldOp::create(*builder, loc, exprVal);
};
for (const Fortran::parser::ConcurrentControl &control :
std::get<std::list<Fortran::parser::ConcurrentControl>>(header.t)) {
- auto forallOp = builder->create<hlfir::ForallOp>(loc);
+ auto forallOp = hlfir::ForallOp::create(*builder, loc);
if (isOutterForall && !outerForall)
outerForall = forallOp;
evaluateControl(std::get<1>(control.t), forallOp.getLbRegion());
@@ -3078,8 +3078,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
mlir::Type controlVarType = genType(*controlVar);
mlir::Block *forallBody = builder->createBlock(&forallOp.getBody(), {},
{controlVarType}, {loc});
- auto forallIndex = builder->create<hlfir::ForallIndexOp>(
- loc, fir::ReferenceType::get(controlVarType),
+ auto forallIndex = hlfir::ForallIndexOp::create(
+ *builder, loc, fir::ReferenceType::get(controlVarType),
forallBody->getArguments()[0],
builder->getStringAttr(controlVar->name().ToString()));
localSymbols.addVariableDefinition(*controlVar, forallIndex,
@@ -3092,7 +3092,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
std::get<std::optional<Fortran::parser::ScalarLogicalExpr>>(
header.t)) {
// Create hlfir.forall_mask and set insertion point in its body.
- auto forallMaskOp = builder->create<hlfir::ForallMaskOp>(loc);
+ auto forallMaskOp = hlfir::ForallMaskOp::create(*builder, loc);
evaluateControl(*maskExpr, forallMaskOp.getMaskRegion(), /*isMask=*/true);
builder->createBlock(&forallMaskOp.getBody());
auto end = fir::FirEndOp::create(*builder, loc);
@@ -4573,14 +4573,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// descriptor address/value and later implemented with a store.
// The RHS is fully prepared in lowering, so that all that is left
// in hlfir.region_assign code generation is the store.
- auto regionAssignOp = builder->create<hlfir::RegionAssignOp>(loc);
+ auto regionAssignOp = hlfir::RegionAssignOp::create(*builder, loc);
// Lower LHS in its own region.
builder->createBlock(®ionAssignOp.getLhsRegion());
Fortran::lower::StatementContext lhsContext;
hlfir::Entity lhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.lhs, localSymbols, 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);
@@ -4589,7 +4589,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
Fortran::lower::StatementContext rhsContext;
mlir::Value rhs =
genForallPointerAssignmentRhs(loc, lhs, assign, 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);
@@ -5360,7 +5360,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if (!lowerToHighLevelFIR()) {
implicitIterSpace.growStack();
} else {
- whereOp = builder->create<hlfir::WhereOp>(loc);
+ whereOp = hlfir::WhereOp::create(*builder, loc);
builder->createBlock(&whereOp.getMaskRegion());
}
@@ -5422,7 +5422,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
hlfir::Entity mask = Fortran::lower::convertExprToHLFIR(
loc, *this, *maskExpr, localSymbols, maskContext);
mask = hlfir::loadTrivialScalar(loc, *builder, mask);
- auto yieldOp = builder->create<hlfir::YieldOp>(loc, mask);
+ auto yieldOp = hlfir::YieldOp::create(*builder, loc, mask);
Fortran::lower::genCleanUpInRegionIfAny(loc, *builder, yieldOp.getCleanup(),
maskContext);
}
@@ -5438,7 +5438,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
mlir::Location loc = getCurrentLocation();
hlfir::ElseWhereOp elsewhereOp;
if (lowerToHighLevelFIR()) {
- elsewhereOp = builder->create<hlfir::ElseWhereOp>(loc);
+ elsewhereOp = hlfir::ElseWhereOp::create(*builder, loc);
// Lower mask in the mask region.
builder->createBlock(&elsewhereOp.getMaskRegion());
}
@@ -5466,7 +5466,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
void genFIR(const Fortran::parser::WhereConstruct::Elsewhere &ew) {
if (lowerToHighLevelFIR()) {
auto elsewhereOp =
- builder->create<hlfir::ElseWhereOp>(getCurrentLocation());
+ hlfir::ElseWhereOp::create(*builder, getCurrentLocation());
builder->createBlock(&elsewhereOp.getBody());
}
genNestedStatement(
@@ -5492,7 +5492,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
std::get<Fortran::parser::LogicalExpr>(stmt.t));
if (lowerToHighLevelFIR()) {
mlir::Location loc = getCurrentLocation();
- auto whereOp = builder->create<hlfir::WhereOp>(loc);
+ auto whereOp = hlfir::WhereOp::create(*builder, loc);
builder->createBlock(&whereOp.getMaskRegion());
lowerWhereMaskToHlfir(loc, mask);
builder->createBlock(&whereOp.getBody());
diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp
index 55c4b45554f78..87824110b4a0c 100644
--- a/flang/lib/Lower/ConvertArrayConstructor.cpp
+++ b/flang/lib/Lower/ConvertArrayConstructor.cpp
@@ -795,7 +795,7 @@ hlfir::EntityWithAttributes Fortran::lower::ArrayConstructorBuilder<T>::gen(
// Insert the clean-up for the created hlfir.expr.
fir::FirOpBuilder *bldr = &builder;
stmtCtx.attachCleanup(
- [=]() { bldr->create<hlfir::DestroyOp>(loc, hlfirExpr); });
+ [=]() { hlfir::DestroyOp::create(*bldr, loc, hlfirExpr); });
return hlfir::EntityWithAttributes{hlfirExpr};
}
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index 8c3648bcb0f35..bf713f5a0bc48 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -702,8 +702,8 @@ Fortran::lower::genCallOpAndResult(
fir::FirOpBuilder *bldr = &converter.getFirOpBuilder();
if (!isElemental)
stmtCtx.attachCleanup([bldr, loc, expr, mustFinalizeResult]() {
- bldr->create<hlfir::DestroyOp>(loc, expr,
- /*finalize=*/mustFinalizeResult);
+ hlfir::DestroyOp::create(*bldr, loc, expr,
+ /*finalize=*/mustFinalizeResult);
});
return {LoweredResult{hlfir::EntityWithAttributes{expr}},
mustFinalizeResult};
@@ -2244,8 +2244,9 @@ class ElementalCallBuilder {
if (hlfir::AssociateOp associate =
preparedActual->associateIfArrayExpr(loc, builder)) {
fir::FirOpBuilder *bldr = &builder;
- callContext.stmtCtx.attachCleanup(
- [=]() { bldr->create<hlfir::EndAssociateOp>(loc, associate); });
+ callContext.stmtCtx.attachCleanup([=]() {
+ hlfir::EndAssociateOp::create(*bldr, loc, associate);
+ });
}
}
}
@@ -2314,7 +2315,7 @@ class ElementalCallBuilder {
bool mustFinalizeExpr = impl().resultMayRequireFinalization(callContext);
fir::FirOpBuilder *bldr = &builder;
callContext.stmtCtx.attachCleanup([=]() {
- bldr->create<hlfir::DestroyOp>(loc, elemental, mustFinalizeExpr);
+ hlfir::DestroyOp::create(*bldr, loc, elemental, mustFinalizeExpr);
});
return hlfir::EntityWithAttributes{elemental};
}
@@ -2739,7 +2740,7 @@ genIntrinsicRef(const Fortran::evaluate::SpecificIntrinsic *intrinsic,
if (result && mlir::isa<hlfir::ExprType>(result->getType())) {
fir::FirOpBuilder *bldr = &callContext.getBuilder();
callContext.stmtCtx.attachCleanup(
- [=]() { bldr->create<hlfir::DestroyOp>(loc, *result); });
+ [=]() { hlfir::DestroyOp::create(*bldr, loc, *result); });
}
return result;
}
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 13cf4e2a5a19f..9930dd69e0c0a 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -911,7 +911,7 @@ class HlfirDesignatorBuilder {
setVectorSubscriptElementAddrOp(std::nullopt);
fir::FirOpBuilder *bldr = &builder;
getStmtCtx().attachCleanup(
- [=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
+ [=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
return hlfir::EntityWithAttributes{elemental};
}
@@ -1579,7 +1579,7 @@ class HlfirBuilder {
}
hlfir::EntityWithAttributes gen(const Fortran::evaluate::NullPointer &expr) {
- auto nullop = getBuilder().create<hlfir::NullOp>(getLoc());
+ auto nullop = hlfir::NullOp::create(getBuilder(), getLoc());
return mlir::cast<fir::FortranVariableOpInterface>(nullop.getOperation());
}
@@ -1685,7 +1685,7 @@ class HlfirBuilder {
/*isUnordered=*/true, left.isPolymorphic() ? left : mlir::Value{});
fir::FirOpBuilder *bldr = &builder;
getStmtCtx().attachCleanup(
- [=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
+ [=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
return hlfir::EntityWithAttributes{elemental};
}
@@ -1736,7 +1736,7 @@ class HlfirBuilder {
builder.setIntegerOverflowFlags(iofBackup);
fir::FirOpBuilder *bldr = &builder;
getStmtCtx().attachCleanup(
- [=]() { bldr->create<hlfir::DestroyOp>(loc, elemental); });
+ [=]() { hlfir::DestroyOp::create(*bldr, loc, elemental); });
return hlfir::EntityWithAttributes{elemental};
}
diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
index c3948f2caf67b..b6d692a0226cd 100644
--- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp
+++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
@@ -1222,7 +1222,7 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
loc, builder, entity, entity.getType(), "", byRefAttr);
auto *bldr = &builder;
hlfir::CleanupFunction cleanup = [bldr, loc, associate]() -> void {
- bldr->create<hlfir::EndAssociateOp>(loc, associate);
+ hlfir::EndAssociateOp::create(*bldr, loc, associate);
};
hlfir::Entity temp{associate.getBase()};
return {translateToExtendedValue(loc, builder, temp).first, cleanup};
@@ -1502,15 +1502,15 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation());
fir::FirOpBuilder *bldr = &builder;
auto cleanup = [loc, bldr, convertedRhs, associate]() {
- bldr->create<hlfir::EndAssociateOp>(loc, associate);
- bldr->create<hlfir::DestroyOp>(loc, convertedRhs);
+ hlfir::EndAssociateOp::create(*bldr, loc, associate);
+ hlfir::DestroyOp::create(*bldr, loc, convertedRhs);
};
return {castWithLbounds, cleanup};
}
fir::FirOpBuilder *bldr = &builder;
auto cleanup = [loc, bldr, convertedRhs]() {
- bldr->create<hlfir::DestroyOp>(loc, convertedRhs);
+ hlfir::DestroyOp::create(*bldr, loc, convertedRhs);
};
return {hlfir::Entity{convertedRhs}, cleanup};
}
diff --git a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
index 4c648df18b328..c0d6606b8d298 100644
--- a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
+++ b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
@@ -81,10 +81,9 @@ fir::factory::HomogeneousScalarStack::HomogeneousScalarStack(
builder.createTemporary(loc, declaredType, tempName, extents, lengths);
mlir::Value shape = builder.genShape(loc, extents);
- temp = builder
- .create<hlfir::DeclareOp>(loc, tempStorage, tempName, shape,
- lengths, /*dummy_scope=*/nullptr,
- fir::FortranVariableFlagsAttr{})
+ temp = hlfir::DeclareOp::create(builder, loc, tempStorage, tempName, shape,
+ lengths, /*dummy_scope=*/nullptr,
+ fir::FortranVariableFlagsAttr{})
.getBase();
}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
index 123e5e7a2425a..8e25298122411 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
@@ -438,7 +438,7 @@ convertToMoldType(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Value asExpr = hlfir::AsExprOp::create(builder, loc, input);
if (asExpr.getType() != mold.getType())
TODO(loc, "hlfir.expr conversion");
- cleanups.emplace_back([=]() { b->create<hlfir::DestroyOp>(loc, asExpr); });
+ cleanups.emplace_back([=]() { hlfir::DestroyOp::create(*b, loc, asExpr); });
return hlfir::Entity{asExpr};
}
if (input.isValue() && mold.isVariable()) {
@@ -446,7 +446,7 @@ convertToMoldType(mlir::Location loc, fir::FirOpBuilder &builder,
hlfir::AssociateOp associate = hlfir::genAssociateExpr(
loc, builder, input, mold.getFortranElementType(), ".tmp.val2ref");
cleanups.emplace_back(
- [=]() { b->create<hlfir::EndAssociateOp>(loc, associate); });
+ [=]() { hlfir::EndAssociateOp::create(*b, loc, associate); });
return hlfir::Entity{associate.getBase()};
}
// Variable to Variable mismatch (e.g., fir.heap<T> vs fir.ref<T>), or value
|
makslevental
approved these changes
Aug 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #147168