Skip to content

[flang][NFC] Move the rest of ops creation to new APIs #152079

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
Aug 5, 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
11 changes: 6 additions & 5 deletions flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,9 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
}

mlir::Value genNot(mlir::Location loc, mlir::Value boolean) {
return create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::eq,
boolean, createBool(loc, false));
return mlir::arith::CmpIOp::create(*this, loc,
mlir::arith::CmpIPredicate::eq, boolean,
createBool(loc, false));
}

/// Generate code testing \p addr is not a null address.
Expand Down Expand Up @@ -641,7 +642,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType,
mlir::Value left, mlir::Value right) {
if (!resultType.isIntOrFloat())
return create<OpTy>(loc, resultType, left, right);
return OpTy::create(*this, loc, resultType, left, right);
mlir::Type signlessType = mlir::IntegerType::get(
getContext(), resultType.getIntOrFloatBitWidth(),
mlir::IntegerType::SignednessSemantics::Signless);
Expand All @@ -654,7 +655,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
right = createConvert(loc, signlessType, right);
opResType = signlessType;
}
mlir::Value result = create<OpTy>(loc, opResType, left, right);
mlir::Value result = OpTy::create(*this, loc, opResType, left, right);
if (resultType.isUnsignedInteger())
result = createConvert(loc, resultType, result);
return result;
Expand All @@ -666,7 +667,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
mlir::Value ptr1, mlir::Value ptr2) {
ptr1 = createConvert(loc, getIndexType(), ptr1);
ptr2 = createConvert(loc, getIndexType(), ptr2);
return create<mlir::arith::CmpIOp>(loc, predicate, ptr1, ptr2);
return mlir::arith::CmpIOp::create(*this, loc, predicate, ptr1, ptr2);
}

private:
Expand Down
42 changes: 21 additions & 21 deletions flang/include/flang/Optimizer/Builder/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
fir::StoreOp::create(builder, loc, load, dst);
return;
}
auto zero = builder.template create<mlir::arith::ConstantIndexOp>(loc, 0);
auto one = builder.template create<mlir::arith::ConstantIndexOp>(loc, 1);
auto zero = mlir::arith::ConstantIndexOp::create(builder, loc, 0);
auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1);
auto toArrayTy = [&](fir::CharacterType ty) {
return fir::ReferenceType::get(fir::SequenceType::get(
fir::SequenceType::ShapeRef{fir::SequenceType::getUnknownExtent()},
Expand All @@ -68,8 +68,8 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
return fir::ReferenceType::get(toEleTy(ty));
};
if (!srcLen && !dstLen && srcTy.getLen() >= dstTy.getLen()) {
auto upper = builder.template create<mlir::arith::ConstantIndexOp>(
loc, dstTy.getLen() - 1);
auto upper =
mlir::arith::ConstantIndexOp::create(builder, loc, dstTy.getLen() - 1);
auto loop = fir::DoLoopOp::create(builder, loc, zero, upper, one);
auto insPt = builder.saveInsertionPoint();
builder.setInsertionPointToStart(loop.getBody());
Expand All @@ -92,26 +92,26 @@ void genCharacterCopy(mlir::Value src, mlir::Value srcLen, mlir::Value dst,
return;
}
auto minusOne = [&](mlir::Value v) -> mlir::Value {
return builder.template create<mlir::arith::SubIOp>(
loc, fir::ConvertOp::create(builder, loc, one.getType(), v), one);
return mlir::arith::SubIOp::create(
builder, loc, fir::ConvertOp::create(builder, loc, one.getType(), v),
one);
};
mlir::Value len = dstLen ? minusOne(dstLen)
: builder
.template create<mlir::arith::ConstantIndexOp>(
loc, dstTy.getLen() - 1)
: mlir::arith::ConstantIndexOp::create(
builder, loc, dstTy.getLen() - 1)
.getResult();
auto loop = fir::DoLoopOp::create(builder, loc, zero, len, one);
auto insPt = builder.saveInsertionPoint();
builder.setInsertionPointToStart(loop.getBody());
mlir::Value slen =
srcLen ? fir::ConvertOp::create(builder, loc, one.getType(), srcLen)
.getResult()
: builder
.template create<mlir::arith::ConstantIndexOp>(
loc, srcTy.getLen())
.getResult();
auto cond = builder.template create<mlir::arith::CmpIOp>(
loc, mlir::arith::CmpIPredicate::slt, loop.getInductionVar(), slen);
srcLen
? fir::ConvertOp::create(builder, loc, one.getType(), srcLen)
.getResult()
: mlir::arith::ConstantIndexOp::create(builder, loc, srcTy.getLen())
.getResult();
auto cond =
mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::slt,
loop.getInductionVar(), slen);
auto ifOp = fir::IfOp::create(builder, loc, cond, /*withElse=*/true);
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
auto csrcTy = toArrayTy(srcTy);
Expand Down Expand Up @@ -189,7 +189,7 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy,
auto ty = fir::dyn_cast_ptrOrBoxEleTy(memTy);
assert(ty && mlir::isa<fir::SequenceType>(ty));
auto seqTy = mlir::cast<fir::SequenceType>(ty);
auto one = builder.template create<mlir::arith::ConstantIndexOp>(loc, 1);
auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1);
const auto dimension = seqTy.getDimension();
if (shapeVal) {
assert(dimension == mlir::cast<fir::ShapeOp>(shapeVal.getDefiningOp())
Expand All @@ -200,7 +200,7 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy,
if (i.index() < dimension) {
assert(fir::isa_integer(i.value().getType()));
result.push_back(
builder.template create<mlir::arith::AddIOp>(loc, i.value(), one));
mlir::arith::AddIOp::create(builder, loc, i.value(), one));
} else {
result.push_back(i.value());
}
Expand All @@ -211,8 +211,8 @@ originateIndices(mlir::Location loc, B &builder, mlir::Type memTy,
unsigned origOff = 0;
for (auto i : llvm::enumerate(indices)) {
if (i.index() < dimension)
result.push_back(builder.template create<mlir::arith::AddIOp>(
loc, i.value(), origins[origOff++]));
result.push_back(mlir::arith::AddIOp::create(builder, loc, i.value(),
origins[origOff++]));
else
result.push_back(i.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def CombineConvertTruncOptPattern
(IntPred $arg, $irm), (SmallerWidthPred $arg, $irm)]>;

def createConstantOp
: NativeCodeCall<"$_builder.create<mlir::arith::ConstantOp>"
"($_loc, $_builder.getIndexType(), "
: NativeCodeCall<"mlir::arith::ConstantOp::create"
"($_builder, $_loc, $_builder.getIndexType(), "
"rewriter.getIndexAttr("
"mlir::dyn_cast<mlir::IntegerAttr>($1).getInt()))">;

Expand Down
Loading