Skip to content

Commit c280535

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

File tree

15 files changed

+158
-158
lines changed

15 files changed

+158
-158
lines changed

flang/include/flang/Lower/DirectivesCommon.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,26 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
193193
mlir::Value box =
194194
!fir::isBoxAddress(info.addr.getType())
195195
? info.addr
196-
: builder.create<fir::LoadOp>(loc, info.addr);
196+
: fir::LoadOp::create(builder, loc, info.addr);
197197
mlir::Value d =
198198
builder.createIntegerConstant(loc, idxTy, dimension);
199-
auto dimInfo = builder.create<fir::BoxDimsOp>(
199+
auto dimInfo = fir::BoxDimsOp::create(builder,
200200
loc, idxTy, idxTy, idxTy, box, d);
201-
builder.create<fir::ResultOp>(loc, dimInfo.getByteStride());
201+
fir::ResultOp::create(builder, loc, dimInfo.getByteStride());
202202
})
203203
.genElse([&] {
204204
mlir::Value zero =
205205
builder.createIntegerConstant(loc, idxTy, 0);
206-
builder.create<fir::ResultOp>(loc, zero);
206+
fir::ResultOp::create(builder, loc, zero);
207207
})
208208
.getResults()[0];
209209
} else {
210210
mlir::Value box = !fir::isBoxAddress(info.addr.getType())
211211
? info.addr
212-
: builder.create<fir::LoadOp>(loc, info.addr);
212+
: fir::LoadOp::create(builder, loc, info.addr);
213213
mlir::Value d = builder.createIntegerConstant(loc, idxTy, dimension);
214214
auto dimInfo =
215-
builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, d);
215+
fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, d);
216216
stride = dimInfo.getByteStride();
217217
}
218218
strideInBytes = true;
@@ -242,14 +242,14 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
242242
lbound = builder.createIntegerConstant(loc, idxTy, *lval - 1);
243243
} else {
244244
mlir::Value lb = builder.createIntegerConstant(loc, idxTy, *lval);
245-
lbound = builder.create<mlir::arith::SubIOp>(loc, lb, baseLb);
245+
lbound = mlir::arith::SubIOp::create(builder, loc, lb, baseLb);
246246
}
247247
asFortran << *lval;
248248
} else {
249249
mlir::Value lb =
250250
fir::getBase(converter.genExprValue(loc, *lower, stmtCtx));
251251
lb = builder.createConvert(loc, baseLb.getType(), lb);
252-
lbound = builder.create<mlir::arith::SubIOp>(loc, lb, baseLb);
252+
lbound = mlir::arith::SubIOp::create(builder, loc, lb, baseLb);
253253
asFortran << detail::peelOuterConvert(*lower).AsFortran();
254254
}
255255
} else {
@@ -276,14 +276,14 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
276276
ubound = builder.createIntegerConstant(loc, idxTy, *uval - 1);
277277
} else {
278278
mlir::Value ub = builder.createIntegerConstant(loc, idxTy, *uval);
279-
ubound = builder.create<mlir::arith::SubIOp>(loc, ub, baseLb);
279+
ubound = mlir::arith::SubIOp::create(builder, loc, ub, baseLb);
280280
}
281281
asFortran << *uval;
282282
} else {
283283
mlir::Value ub =
284284
fir::getBase(converter.genExprValue(loc, *upper, stmtCtx));
285285
ub = builder.createConvert(loc, baseLb.getType(), ub);
286-
ubound = builder.create<mlir::arith::SubIOp>(loc, ub, baseLb);
286+
ubound = mlir::arith::SubIOp::create(builder, loc, ub, baseLb);
287287
asFortran << detail::peelOuterConvert(*upper).AsFortran();
288288
}
289289
}
@@ -310,12 +310,12 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
310310
.genThen([&]() {
311311
mlir::Value ext = fir::factory::readExtent(
312312
builder, loc, dataExv, dimension);
313-
builder.create<fir::ResultOp>(loc, ext);
313+
fir::ResultOp::create(builder, loc, ext);
314314
})
315315
.genElse([&] {
316316
mlir::Value zero =
317317
builder.createIntegerConstant(loc, idxTy, 0);
318-
builder.create<fir::ResultOp>(loc, zero);
318+
fir::ResultOp::create(builder, loc, zero);
319319
})
320320
.getResults()[0];
321321
} else {
@@ -326,16 +326,16 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
326326
extent = zero;
327327
if (ubound && lbound) {
328328
mlir::Value diff =
329-
builder.create<mlir::arith::SubIOp>(loc, ubound, lbound);
330-
extent = builder.create<mlir::arith::AddIOp>(loc, diff, one);
329+
mlir::arith::SubIOp::create(builder, loc, ubound, lbound);
330+
extent = mlir::arith::AddIOp::create(builder, loc, diff, one);
331331
}
332332
if (!ubound)
333333
ubound = lbound;
334334
}
335335

336336
if (!ubound) {
337337
// ub = extent - 1
338-
ubound = builder.create<mlir::arith::SubIOp>(loc, extent, one);
338+
ubound = mlir::arith::SubIOp::create(builder, loc, extent, one);
339339
}
340340
}
341341

@@ -347,7 +347,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
347347
loc, cumulativeExtent, extent);
348348
}
349349

350-
mlir::Value bound = builder.create<BoundsOp>(
350+
mlir::Value bound = BoundsOp::create(builder,
351351
loc, boundTy, lbound, ubound, extent, stride, strideInBytes, baseLb);
352352
bounds.push_back(bound);
353353
++dimension;
@@ -461,7 +461,7 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
461461
asFortran << designator.AsFortran();
462462

463463
if (semantics::IsOptional(compRef->GetLastSymbol())) {
464-
info.isPresent = builder.create<fir::IsPresentOp>(
464+
info.isPresent = fir::IsPresentOp::create(builder,
465465
operandLocation, builder.getI1Type(), info.rawInput);
466466
}
467467

@@ -472,7 +472,7 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
472472
fir::isPointerType(loadOp.getType())) {
473473
info.boxType = info.addr.getType();
474474
info.addr =
475-
builder.create<fir::BoxAddrOp>(operandLocation, info.addr);
475+
fir::BoxAddrOp::create(builder, operandLocation, info.addr);
476476
}
477477
info.rawInput = info.addr;
478478
}

flang/include/flang/Lower/Support/ReductionProcessor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ ReductionProcessor::getReductionOperation(fir::FirOpBuilder &builder,
142142
assert(type.isIntOrIndexOrFloat() &&
143143
"only integer, float and complex types are currently supported");
144144
if (type.isIntOrIndex())
145-
return builder.create<IntegerOp>(loc, op1, op2);
146-
return builder.create<FloatOp>(loc, op1, op2);
145+
return IntegerOp::create(builder, loc, op1, op2);
146+
return FloatOp::create(builder, loc, op1, op2);
147147
}
148148

149149
template <typename FloatOp, typename IntegerOp, typename ComplexOp>
@@ -154,10 +154,10 @@ ReductionProcessor::getReductionOperation(fir::FirOpBuilder &builder,
154154
assert((type.isIntOrIndexOrFloat() || fir::isa_complex(type)) &&
155155
"only integer, float and complex types are currently supported");
156156
if (type.isIntOrIndex())
157-
return builder.create<IntegerOp>(loc, op1, op2);
157+
return IntegerOp::create(builder, loc, op1, op2);
158158
if (fir::isa_real(type))
159-
return builder.create<FloatOp>(loc, op1, op2);
160-
return builder.create<ComplexOp>(loc, op1, op2);
159+
return FloatOp::create(builder, loc, op1, op2);
160+
return ComplexOp::create(builder, loc, op1, op2);
161161
}
162162

163163
} // namespace omp

flang/include/flang/Optimizer/Builder/Complex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ class Complex {
5858
protected:
5959
template <Part partId>
6060
mlir::Value extract(mlir::Value cplx) {
61-
return builder.create<fir::ExtractValueOp>(
61+
return fir::ExtractValueOp::create(builder,
6262
loc, getComplexPartType(cplx), cplx,
6363
builder.getArrayAttr({builder.getIntegerAttr(
6464
builder.getIndexType(), static_cast<int>(partId))}));
6565
}
6666

6767
template <Part partId>
6868
mlir::Value insert(mlir::Value cplx, mlir::Value part) {
69-
return builder.create<fir::InsertValueOp>(
69+
return fir::InsertValueOp::create(builder,
7070
loc, cplx.getType(), cplx, part,
7171
builder.getArrayAttr({builder.getIntegerAttr(
7272
builder.getIndexType(), static_cast<int>(partId))}));

flang/include/flang/Optimizer/Builder/DirectivesCommon.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ inline AddrAndBoundsInfo getDataOperandBaseAddr(fir::FirOpBuilder &builder,
7171
mlir::Value isPresent;
7272
if (isOptional)
7373
isPresent =
74-
builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), rawInput);
74+
fir::IsPresentOp::create(builder, loc, builder.getI1Type(), rawInput);
7575

7676
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(
7777
fir::unwrapRefType(symAddr.getType()))) {
@@ -82,7 +82,7 @@ inline AddrAndBoundsInfo getDataOperandBaseAddr(fir::FirOpBuilder &builder,
8282
// if branches.
8383
if (unwrapFirBox && mlir::isa<fir::ReferenceType>(symAddr.getType()) &&
8484
!isOptional) {
85-
mlir::Value addr = builder.create<fir::LoadOp>(loc, symAddr);
85+
mlir::Value addr = fir::LoadOp::create(builder, loc, symAddr);
8686
return AddrAndBoundsInfo(addr, rawInput, isPresent, boxTy);
8787
}
8888

@@ -94,7 +94,7 @@ inline AddrAndBoundsInfo getDataOperandBaseAddr(fir::FirOpBuilder &builder,
9494
if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(
9595
fir::unwrapRefType((symAddr.getType())))) {
9696
if (!isOptional && mlir::isa<fir::ReferenceType>(symAddr.getType())) {
97-
mlir::Value boxChar = builder.create<fir::LoadOp>(loc, symAddr);
97+
mlir::Value boxChar = fir::LoadOp::create(builder, loc, symAddr);
9898
return AddrAndBoundsInfo(boxChar, rawInput, isPresent);
9999
}
100100
}
@@ -117,10 +117,10 @@ gatherBoundsOrBoundValues(fir::FirOpBuilder &builder, mlir::Location loc,
117117
mlir::Value baseLb =
118118
fir::factory::readLowerBound(builder, loc, dataExv, dim, one);
119119
auto dimInfo =
120-
builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, d);
120+
fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, d);
121121
mlir::Value lb = builder.createIntegerConstant(loc, idxTy, 0);
122122
mlir::Value ub =
123-
builder.create<mlir::arith::SubIOp>(loc, dimInfo.getExtent(), one);
123+
mlir::arith::SubIOp::create(builder, loc, dimInfo.getExtent(), one);
124124
if (dim == 0) // First stride is the element size.
125125
byteStride = dimInfo.getByteStride();
126126
if (collectValuesOnly) {
@@ -130,12 +130,12 @@ gatherBoundsOrBoundValues(fir::FirOpBuilder &builder, mlir::Location loc,
130130
values.push_back(byteStride);
131131
values.push_back(baseLb);
132132
} else {
133-
mlir::Value bound = builder.create<BoundsOp>(
133+
mlir::Value bound = BoundsOp::create(builder,
134134
loc, boundTy, lb, ub, dimInfo.getExtent(), byteStride, true, baseLb);
135135
values.push_back(bound);
136136
}
137137
// Compute the stride for the next dimension.
138-
byteStride = builder.create<mlir::arith::MulIOp>(loc, byteStride,
138+
byteStride = mlir::arith::MulIOp::create(builder, loc, byteStride,
139139
dimInfo.getExtent());
140140
}
141141
return values;
@@ -162,40 +162,40 @@ genBoundsOpFromBoxChar(fir::FirOpBuilder &builder, mlir::Location loc,
162162
.genThen([&]() {
163163
mlir::Value boxChar =
164164
fir::isa_ref_type(info.addr.getType())
165-
? builder.create<fir::LoadOp>(loc, info.addr)
165+
? fir::LoadOp::create(builder, loc, info.addr)
166166
: info.addr;
167167
fir::BoxCharType boxCharType =
168168
mlir::cast<fir::BoxCharType>(boxChar.getType());
169169
mlir::Type refType = builder.getRefType(boxCharType.getEleTy());
170-
auto unboxed = builder.create<fir::UnboxCharOp>(
170+
auto unboxed = fir::UnboxCharOp::create(builder,
171171
loc, refType, lenType, boxChar);
172172
mlir::SmallVector<mlir::Value> results = {unboxed.getResult(1),
173173
one};
174-
builder.create<fir::ResultOp>(loc, results);
174+
fir::ResultOp::create(builder, loc, results);
175175
})
176176
.genElse([&]() {
177177
mlir::SmallVector<mlir::Value> results = {zero, zero};
178-
builder.create<fir::ResultOp>(loc, results);
178+
fir::ResultOp::create(builder, loc, results);
179179
})
180180
.getResults();
181181
return {ifRes[0], ifRes[1]};
182182
}
183183
// We have already established that info.addr.getType() is a boxchar
184184
// or a boxchar address. If an address, load the boxchar.
185185
mlir::Value boxChar = fir::isa_ref_type(info.addr.getType())
186-
? builder.create<fir::LoadOp>(loc, info.addr)
186+
? fir::LoadOp::create(builder, loc, info.addr)
187187
: info.addr;
188188
fir::BoxCharType boxCharType =
189189
mlir::cast<fir::BoxCharType>(boxChar.getType());
190190
mlir::Type refType = builder.getRefType(boxCharType.getEleTy());
191191
auto unboxed =
192-
builder.create<fir::UnboxCharOp>(loc, refType, lenType, boxChar);
192+
fir::UnboxCharOp::create(builder, loc, refType, lenType, boxChar);
193193
return {unboxed.getResult(1), one};
194194
}();
195195

196-
mlir::Value ub = builder.create<mlir::arith::SubIOp>(loc, extent, one);
196+
mlir::Value ub = mlir::arith::SubIOp::create(builder, loc, extent, one);
197197
mlir::Type boundTy = builder.getType<BoundsType>();
198-
return builder.create<BoundsOp>(loc, boundTy,
198+
return BoundsOp::create(builder, loc, boundTy,
199199
/*lower_bound=*/zero,
200200
/*upper_bound=*/ub,
201201
/*extent=*/extent,
@@ -230,12 +230,12 @@ genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc,
230230
mlir::Value box =
231231
!fir::isBoxAddress(info.addr.getType())
232232
? info.addr
233-
: builder.create<fir::LoadOp>(loc, info.addr);
233+
: fir::LoadOp::create(builder, loc, info.addr);
234234
llvm::SmallVector<mlir::Value> boundValues =
235235
gatherBoundsOrBoundValues<BoundsOp, BoundsType>(
236236
builder, loc, dataExv, box,
237237
/*collectValuesOnly=*/true);
238-
builder.create<fir::ResultOp>(loc, boundValues);
238+
fir::ResultOp::create(builder, loc, boundValues);
239239
})
240240
.genElse([&] {
241241
// Box is not present. Populate bound values with default values.
@@ -249,21 +249,21 @@ genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc,
249249
boundValues.push_back(zero); // byteStride
250250
boundValues.push_back(zero); // baseLb
251251
}
252-
builder.create<fir::ResultOp>(loc, boundValues);
252+
fir::ResultOp::create(builder, loc, boundValues);
253253
})
254254
.getResults();
255255
// Create the bound operations outside the if-then-else with the if op
256256
// results.
257257
for (unsigned i = 0; i < ifRes.size(); i += nbValuesPerBound) {
258-
mlir::Value bound = builder.create<BoundsOp>(
258+
mlir::Value bound = BoundsOp::create(builder,
259259
loc, boundTy, ifRes[i], ifRes[i + 1], ifRes[i + 2], ifRes[i + 3],
260260
true, ifRes[i + 4]);
261261
bounds.push_back(bound);
262262
}
263263
} else {
264264
mlir::Value box = !fir::isBoxAddress(info.addr.getType())
265265
? info.addr
266-
: builder.create<fir::LoadOp>(loc, info.addr);
266+
: fir::LoadOp::create(builder, loc, info.addr);
267267
bounds = gatherBoundsOrBoundValues<BoundsOp, BoundsType>(builder, loc,
268268
dataExv, box);
269269
}
@@ -299,7 +299,7 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
299299
ub = lb;
300300
} else {
301301
// ub = extent - 1
302-
ub = builder.create<mlir::arith::SubIOp>(loc, extent, one);
302+
ub = mlir::arith::SubIOp::create(builder, loc, extent, one);
303303
}
304304
mlir::Value stride = one;
305305
if (strideIncludeLowerExtent) {
@@ -308,7 +308,7 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
308308
loc, cumulativeExtent, extent);
309309
}
310310

311-
mlir::Value bound = builder.create<BoundsOp>(loc, boundTy, lb, ub, extent,
311+
mlir::Value bound = BoundsOp::create(builder, loc, boundTy, lb, ub, extent,
312312
stride, false, baseLb);
313313
bounds.push_back(bound);
314314
}

flang/include/flang/Optimizer/CodeGen/FIROpPatterns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class ConvertFIRToLLVMPattern : public mlir::ConvertToLLVMPattern {
144144
llvm::SmallVector<mlir::LLVM::GEPArg> cv = {args...};
145145
auto llvmPtrTy =
146146
mlir::LLVM::LLVMPointerType::get(ty.getContext(), /*addressSpace=*/0);
147-
return rewriter.create<mlir::LLVM::GEPOp>(loc, llvmPtrTy, ty, base, cv);
147+
return mlir::LLVM::GEPOp::create(rewriter, loc, llvmPtrTy, ty, base, cv);
148148
}
149149

150150
// Find the Block in which the alloca should be inserted.

flang/unittests/Frontend/CodeGenActionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class LLVMConversionFailureCodeGenAction : public CodeGenAction {
7777
mlir::OpBuilder builder(mlirCtx.get());
7878
builder.setInsertionPointToStart(&mlirModule->getRegion().front());
7979
// Create a fake op to trip conversion to LLVM.
80-
builder.create<test::dummy::FakeOp>(loc);
80+
test::dummy::FakeOp::create(builder, loc);
8181

8282
llvmCtx = std::make_unique<llvm::LLVMContext>();
8383
}

flang/unittests/Optimizer/Builder/CharacterTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ struct CharacterTest : public testing::Test {
2626

2727
// Set up a Module with a dummy function operation inside.
2828
// Set the insertion point in the function entry block.
29-
moduleOp = builder.create<mlir::ModuleOp>(loc);
29+
moduleOp = mlir::ModuleOp::create(builder, loc);
3030
builder.setInsertionPointToStart(moduleOp->getBody());
31-
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
31+
mlir::func::FuncOp func = mlir::func::FuncOp::create(builder,
3232
loc, "func1", builder.getFunctionType({}, {}));
3333
auto *entryBlock = func.addEntryBlock();
3434
builder.setInsertionPointToStart(entryBlock);

flang/unittests/Optimizer/Builder/ComplexTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct ComplexTest : public testing::Test {
2222

2323
// Set up a Module with a dummy function operation inside.
2424
// Set the insertion point in the function entry block.
25-
moduleOp = builder.create<mlir::ModuleOp>(loc);
25+
moduleOp = mlir::ModuleOp::create(builder, loc);
2626
builder.setInsertionPointToStart(moduleOp->getBody());
27-
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
27+
mlir::func::FuncOp func = mlir::func::FuncOp::create(builder,
2828
loc, "func1", builder.getFunctionType({}, {}));
2929
auto *entryBlock = func.addEntryBlock();
3030
builder.setInsertionPointToStart(entryBlock);

0 commit comments

Comments
 (0)