Skip to content

Commit 23ead47

Browse files
authored
[flang][mlir] Migrate to free create functions. NFC. (#164657)
See https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339. I plan to mark these as deprecated in #164649.
1 parent 322dd63 commit 23ead47

File tree

11 files changed

+132
-130
lines changed

11 files changed

+132
-130
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
17661766
// to a crash due to a block with no terminator. See issue #126452.
17671767
mlir::FunctionType funcType = builder->getFunction().getFunctionType();
17681768
mlir::Type resultType = funcType.getResult(0);
1769-
mlir::Value undefResult = builder->create<fir::UndefOp>(loc, resultType);
1769+
mlir::Value undefResult = fir::UndefOp::create(*builder, loc, resultType);
17701770
genExitRoutine(false, undefResult);
17711771
return;
17721772
}

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,37 +2059,38 @@ static void genCanonicalLoopNest(
20592059
// Start lowering
20602060
mlir::Value zero = firOpBuilder.createIntegerConstant(loc, loopVarType, 0);
20612061
mlir::Value one = firOpBuilder.createIntegerConstant(loc, loopVarType, 1);
2062-
mlir::Value isDownwards = firOpBuilder.create<mlir::arith::CmpIOp>(
2063-
loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero);
2062+
mlir::Value isDownwards = mlir::arith::CmpIOp::create(
2063+
firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero);
20642064

20652065
// Ensure we are counting upwards. If not, negate step and swap lb and ub.
20662066
mlir::Value negStep =
2067-
firOpBuilder.create<mlir::arith::SubIOp>(loc, zero, loopStepVar);
2068-
mlir::Value incr = firOpBuilder.create<mlir::arith::SelectOp>(
2069-
loc, isDownwards, negStep, loopStepVar);
2070-
mlir::Value lb = firOpBuilder.create<mlir::arith::SelectOp>(
2071-
loc, isDownwards, loopUBVar, loopLBVar);
2072-
mlir::Value ub = firOpBuilder.create<mlir::arith::SelectOp>(
2073-
loc, isDownwards, loopLBVar, loopUBVar);
2067+
mlir::arith::SubIOp::create(firOpBuilder, loc, zero, loopStepVar);
2068+
mlir::Value incr = mlir::arith::SelectOp::create(
2069+
firOpBuilder, loc, isDownwards, negStep, loopStepVar);
2070+
mlir::Value lb = mlir::arith::SelectOp::create(
2071+
firOpBuilder, loc, isDownwards, loopUBVar, loopLBVar);
2072+
mlir::Value ub = mlir::arith::SelectOp::create(
2073+
firOpBuilder, loc, isDownwards, loopLBVar, loopUBVar);
20742074

20752075
// Compute the trip count assuming lb <= ub. This guarantees that the result
20762076
// is non-negative and we can use unsigned arithmetic.
2077-
mlir::Value span = firOpBuilder.create<mlir::arith::SubIOp>(
2078-
loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw);
2077+
mlir::Value span = mlir::arith::SubIOp::create(
2078+
firOpBuilder, loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw);
20792079
mlir::Value tcMinusOne =
2080-
firOpBuilder.create<mlir::arith::DivUIOp>(loc, span, incr);
2081-
mlir::Value tcIfLooping = firOpBuilder.create<mlir::arith::AddIOp>(
2082-
loc, tcMinusOne, one, ::mlir::arith::IntegerOverflowFlags::nuw);
2080+
mlir::arith::DivUIOp::create(firOpBuilder, loc, span, incr);
2081+
mlir::Value tcIfLooping =
2082+
mlir::arith::AddIOp::create(firOpBuilder, loc, tcMinusOne, one,
2083+
::mlir::arith::IntegerOverflowFlags::nuw);
20832084

20842085
// Fall back to 0 if lb > ub
2085-
mlir::Value isZeroTC = firOpBuilder.create<mlir::arith::CmpIOp>(
2086-
loc, mlir::arith::CmpIPredicate::slt, ub, lb);
2087-
mlir::Value tripcount = firOpBuilder.create<mlir::arith::SelectOp>(
2088-
loc, isZeroTC, zero, tcIfLooping);
2086+
mlir::Value isZeroTC = mlir::arith::CmpIOp::create(
2087+
firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, ub, lb);
2088+
mlir::Value tripcount = mlir::arith::SelectOp::create(
2089+
firOpBuilder, loc, isZeroTC, zero, tcIfLooping);
20892090
tripcounts.push_back(tripcount);
20902091

20912092
// Create the CLI handle.
2092-
auto newcli = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
2093+
auto newcli = mlir::omp::NewCliOp::create(firOpBuilder, loc);
20932094
mlir::Value cli = newcli.getResult();
20942095
clis.push_back(cli);
20952096

@@ -2122,10 +2123,10 @@ static void genCanonicalLoopNest(
21222123
"Expecting all block args to have been collected by now");
21232124
for (auto j : llvm::seq<size_t>(numLoops)) {
21242125
mlir::Value natIterNum = fir::getBase(blockArgs[j]);
2125-
mlir::Value scaled = firOpBuilder.create<mlir::arith::MulIOp>(
2126-
loc, natIterNum, loopStepVars[j]);
2127-
mlir::Value userVal = firOpBuilder.create<mlir::arith::AddIOp>(
2128-
loc, loopLBVars[j], scaled);
2126+
mlir::Value scaled = mlir::arith::MulIOp::create(
2127+
firOpBuilder, loc, natIterNum, loopStepVars[j]);
2128+
mlir::Value userVal = mlir::arith::AddIOp::create(
2129+
firOpBuilder, loc, loopLBVars[j], scaled);
21292130

21302131
mlir::OpBuilder::InsertPoint insPt =
21312132
firOpBuilder.saveInsertionPoint();
@@ -2198,9 +2199,9 @@ static void genTileOp(Fortran::lower::AbstractConverter &converter,
21982199
gridGeneratees.reserve(numLoops);
21992200
intratileGeneratees.reserve(numLoops);
22002201
for ([[maybe_unused]] auto i : llvm::seq<int>(0, sizesClause.sizes.size())) {
2201-
auto gridCLI = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
2202+
auto gridCLI = mlir::omp::NewCliOp::create(firOpBuilder, loc);
22022203
gridGeneratees.push_back(gridCLI.getResult());
2203-
auto intratileCLI = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
2204+
auto intratileCLI = mlir::omp::NewCliOp::create(firOpBuilder, loc);
22042205
intratileGeneratees.push_back(intratileCLI.getResult());
22052206
}
22062207

@@ -2209,8 +2210,8 @@ static void genTileOp(Fortran::lower::AbstractConverter &converter,
22092210
generatees.append(gridGeneratees);
22102211
generatees.append(intratileGeneratees);
22112212

2212-
firOpBuilder.create<mlir::omp::TileOp>(loc, generatees, applyees,
2213-
sizesClause.sizes);
2213+
mlir::omp::TileOp::create(firOpBuilder, loc, generatees, applyees,
2214+
sizesClause.sizes);
22142215
}
22152216

22162217
static void genUnrollOp(Fortran::lower::AbstractConverter &converter,

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ struct AllocMemOpConversion : public fir::FIROpConversion<fir::AllocMemOp> {
11511151
mlir::Value size = genTypeSizeInBytes(loc, ity, rewriter, llvmObjectTy);
11521152
if (auto scaleSize =
11531153
fir::genAllocationScaleSize(loc, heap.getInType(), ity, rewriter))
1154-
size = rewriter.create<mlir::LLVM::MulOp>(loc, ity, size, scaleSize);
1154+
size = mlir::LLVM::MulOp::create(rewriter, loc, ity, size, scaleSize);
11551155
for (mlir::Value opnd : adaptor.getOperands())
11561156
size = mlir::LLVM::MulOp::create(rewriter, loc, ity, size,
11571157
integerCast(loc, rewriter, ity, opnd));

flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,11 @@ struct TargetAllocMemOpConversion
242242
loc, llvmObjectTy, ity, rewriter, lowerTy().getDataLayout());
243243
if (auto scaleSize = fir::genAllocationScaleSize(
244244
loc, allocmemOp.getInType(), ity, rewriter))
245-
size = rewriter.create<mlir::LLVM::MulOp>(loc, ity, size, scaleSize);
245+
size = mlir::LLVM::MulOp::create(rewriter, loc, ity, size, scaleSize);
246246
for (mlir::Value opnd : adaptor.getOperands().drop_front())
247-
size = rewriter.create<mlir::LLVM::MulOp>(
248-
loc, ity, size, integerCast(lowerTy(), loc, rewriter, ity, opnd));
247+
size = mlir::LLVM::MulOp::create(
248+
rewriter, loc, ity, size,
249+
integerCast(lowerTy(), loc, rewriter, ity, opnd));
249250
auto mallocTyWidth = lowerTy().getIndexTypeBitwidth();
250251
auto mallocTy =
251252
mlir::IntegerType::get(rewriter.getContext(), mallocTyWidth);

flang/lib/Optimizer/OpenACC/Transforms/ACCRecipeBufferization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class BufferizeInterface {
3939

4040
static mlir::Operation *load(mlir::OpBuilder &builder, mlir::Location loc,
4141
mlir::Value value) {
42-
return builder.create<fir::LoadOp>(loc, value);
42+
return fir::LoadOp::create(builder, loc, value);
4343
}
4444

4545
static mlir::Value placeInMemory(mlir::OpBuilder &builder, mlir::Location loc,
4646
mlir::Value value) {
47-
auto alloca = builder.create<fir::AllocaOp>(loc, value.getType());
48-
builder.create<fir::StoreOp>(loc, value, alloca);
47+
auto alloca = fir::AllocaOp::create(builder, loc, value.getType());
48+
fir::StoreOp::create(builder, loc, value, alloca);
4949
return alloca;
5050
}
5151
};

flang/lib/Optimizer/OpenMP/AutomapToTargetData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class AutomapToTargetDataPass
130130
builder.getBoolAttr(false));
131131
clauses.mapVars.push_back(mapInfo);
132132
isa<fir::StoreOp>(memOp)
133-
? builder.create<omp::TargetEnterDataOp>(memOp.getLoc(), clauses)
134-
: builder.create<omp::TargetExitDataOp>(memOp.getLoc(), clauses);
133+
? omp::TargetEnterDataOp::create(builder, memOp.getLoc(), clauses)
134+
: omp::TargetExitDataOp::create(builder, memOp.getLoc(), clauses);
135135
};
136136

137137
for (fir::GlobalOp globalOp : automapGlobals) {

flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ class DoConcurrentConversion
595595
mlir::omp::TargetOperands &clauseOps,
596596
mlir::omp::LoopNestOperands &loopNestClauseOps,
597597
const LiveInShapeInfoMap &liveInShapeInfoMap) const {
598-
auto targetOp = rewriter.create<mlir::omp::TargetOp>(loc, clauseOps);
598+
auto targetOp = mlir::omp::TargetOp::create(rewriter, loc, clauseOps);
599599
auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp);
600600

601601
mlir::Region &region = targetOp.getRegion();
@@ -672,7 +672,7 @@ class DoConcurrentConversion
672672
// temporary.
673673
Fortran::utils::openmp::cloneOrMapRegionOutsiders(builder, targetOp);
674674
rewriter.setInsertionPoint(
675-
rewriter.create<mlir::omp::TerminatorOp>(targetOp.getLoc()));
675+
mlir::omp::TerminatorOp::create(rewriter, targetOp.getLoc()));
676676

677677
return targetOp;
678678
}
@@ -715,8 +715,8 @@ class DoConcurrentConversion
715715

716716
auto shapeShiftType = fir::ShapeShiftType::get(
717717
builder.getContext(), shapeShiftOperands.size() / 2);
718-
return builder.create<fir::ShapeShiftOp>(
719-
liveInArg.getLoc(), shapeShiftType, shapeShiftOperands);
718+
return fir::ShapeShiftOp::create(builder, liveInArg.getLoc(),
719+
shapeShiftType, shapeShiftOperands);
720720
}
721721

722722
llvm::SmallVector<mlir::Value> shapeOperands;
@@ -728,11 +728,11 @@ class DoConcurrentConversion
728728
++shapeIdx;
729729
}
730730

731-
return builder.create<fir::ShapeOp>(liveInArg.getLoc(), shapeOperands);
731+
return fir::ShapeOp::create(builder, liveInArg.getLoc(), shapeOperands);
732732
}();
733733

734-
return builder.create<hlfir::DeclareOp>(liveInArg.getLoc(), liveInArg,
735-
liveInName, shape);
734+
return hlfir::DeclareOp::create(builder, liveInArg.getLoc(), liveInArg,
735+
liveInName, shape);
736736
}
737737

738738
mlir::omp::TeamsOp genTeamsOp(mlir::ConversionPatternRewriter &rewriter,
@@ -742,13 +742,13 @@ class DoConcurrentConversion
742742
genReductions(rewriter, mapper, loop, teamsOps);
743743

744744
mlir::Location loc = loop.getLoc();
745-
auto teamsOp = rewriter.create<mlir::omp::TeamsOp>(loc, teamsOps);
745+
auto teamsOp = mlir::omp::TeamsOp::create(rewriter, loc, teamsOps);
746746
Fortran::common::openmp::EntryBlockArgs teamsArgs;
747747
teamsArgs.reduction.vars = teamsOps.reductionVars;
748748
Fortran::common::openmp::genEntryBlock(rewriter, teamsArgs,
749749
teamsOp.getRegion());
750750

751-
rewriter.setInsertionPoint(rewriter.create<mlir::omp::TerminatorOp>(loc));
751+
rewriter.setInsertionPoint(mlir::omp::TerminatorOp::create(rewriter, loc));
752752

753753
for (auto [loopVar, teamsArg] : llvm::zip_equal(
754754
loop.getReduceVars(), teamsOp.getRegion().getArguments())) {
@@ -761,8 +761,8 @@ class DoConcurrentConversion
761761
mlir::omp::DistributeOp
762762
genDistributeOp(mlir::Location loc,
763763
mlir::ConversionPatternRewriter &rewriter) const {
764-
auto distOp = rewriter.create<mlir::omp::DistributeOp>(
765-
loc, /*clauses=*/mlir::omp::DistributeOperands{});
764+
auto distOp = mlir::omp::DistributeOp::create(
765+
rewriter, loc, /*clauses=*/mlir::omp::DistributeOperands{});
766766

767767
rewriter.createBlock(&distOp.getRegion());
768768
return distOp;

0 commit comments

Comments
 (0)