Skip to content

Commit e71cb8a

Browse files
committed
Inline createIntOrIndexConstant
1 parent 92cf042 commit e71cb8a

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

mlir/include/mlir/Dialect/Arith/Utils/Utils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ Value createScalarOrSplatConstant(OpBuilder &builder, Location loc, Type type,
9494
Value createScalarOrSplatConstant(OpBuilder &builder, Location loc, Type type,
9595
const APFloat &value);
9696

97-
/// Create a constant of type `type` at location `loc` whose value is `value`.
98-
/// This works for integer type or the index type only.
99-
Value createIntOrIndexConstant(OpBuilder &builder, Location loc, Type type,
100-
int64_t value);
101-
10297
/// Returns the int type of the integer in ofr.
10398
/// Other attribute types are not supported.
10499
Type getType(OpFoldResult ofr);

mlir/lib/Dialect/Arith/Utils/Utils.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,6 @@ Value mlir::createScalarOrSplatConstant(OpBuilder &builder, Location loc,
302302
return builder.createOrFold<arith::ConstantOp>(loc, type, splat);
303303
}
304304

305-
Value mlir::createIntOrIndexConstant(OpBuilder &b, Location loc, Type type,
306-
int64_t value) {
307-
assert(type.isIntOrIndex() &&
308-
"unexpected type other than integers and index");
309-
return b.create<arith::ConstantOp>(loc, b.getIntegerAttr(type, value));
310-
}
311-
312305
Type mlir::getType(OpFoldResult ofr) {
313306
if (auto value = dyn_cast_if_present<Value>(ofr))
314307
return value.getType();

mlir/lib/Dialect/SCF/Utils/Utils.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
267267
assert(dividend.getType().isIntOrIndex() &&
268268
"expected integer or index-typed value");
269269

270-
Value divisorMinusOneCst =
271-
createIntOrIndexConstant(builder, loc, dividend.getType(), divisor - 1);
272-
Value divisorCst =
273-
createIntOrIndexConstant(builder, loc, dividend.getType(), divisor);
270+
Value divisorMinusOneCst = builder.create<arith::ConstantOp>(
271+
loc, builder.getIntegerAttr(dividend.getType(), divisor - 1));
272+
Value divisorCst = builder.create<arith::ConstantOp>(
273+
loc, builder.getIntegerAttr(dividend.getType(), divisor));
274274
Value sum = builder.create<arith::AddIOp>(loc, dividend, divisorMinusOneCst);
275275
return builder.create<arith::DivUIOp>(loc, sum, divisorCst);
276276
}
@@ -283,7 +283,8 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
283283
Value divisor) {
284284
assert(dividend.getType().isIntOrIndex() &&
285285
"expected integer or index-typed value");
286-
Value cstOne = createIntOrIndexConstant(builder, loc, dividend.getType(), 1);
286+
Value cstOne = builder.create<arith::ConstantOp>(
287+
loc, builder.getOneAttr(dividend.getType()));
287288
Value divisorMinusOne = builder.create<arith::SubIOp>(loc, divisor, cstOne);
288289
Value sum = builder.create<arith::AddIOp>(loc, dividend, divisorMinusOne);
289290
return builder.create<arith::DivUIOp>(loc, sum, divisor);
@@ -390,18 +391,18 @@ LogicalResult mlir::loopUnrollByFactor(
390391
// Create constant for 'upperBoundUnrolled' and set epilogue loop flag.
391392
generateEpilogueLoop = upperBoundUnrolledCst < ubCst;
392393
if (generateEpilogueLoop)
393-
upperBoundUnrolled = createIntOrIndexConstant(
394-
boundsBuilder, loc, forOp.getUpperBound().getType(),
395-
upperBoundUnrolledCst);
394+
upperBoundUnrolled = boundsBuilder.create<arith::ConstantOp>(
395+
loc, boundsBuilder.getIntegerAttr(forOp.getUpperBound().getType(),
396+
upperBoundUnrolledCst));
396397
else
397398
upperBoundUnrolled = forOp.getUpperBound();
398399

399400
// Create constant for 'stepUnrolled'.
400-
stepUnrolled =
401-
stepCst == stepUnrolledCst
402-
? step
403-
: createIntOrIndexConstant(boundsBuilder, loc, step.getType(),
404-
stepUnrolledCst);
401+
stepUnrolled = stepCst == stepUnrolledCst
402+
? step
403+
: boundsBuilder.create<arith::ConstantOp>(
404+
loc, boundsBuilder.getIntegerAttr(
405+
step.getType(), stepUnrolledCst));
405406
} else {
406407
// Dynamic loop bounds computation.
407408
// TODO: Add dynamic asserts for negative lb/ub/step, or
@@ -411,8 +412,8 @@ LogicalResult mlir::loopUnrollByFactor(
411412
Value diff =
412413
boundsBuilder.create<arith::SubIOp>(loc, upperBound, lowerBound);
413414
Value tripCount = ceilDivPositive(boundsBuilder, loc, diff, step);
414-
Value unrollFactorCst = createIntOrIndexConstant(
415-
boundsBuilder, loc, tripCount.getType(), unrollFactor);
415+
Value unrollFactorCst = boundsBuilder.create<arith::ConstantOp>(
416+
loc, boundsBuilder.getIntegerAttr(tripCount.getType(), unrollFactor));
416417
Value tripCountRem =
417418
boundsBuilder.create<arith::RemSIOp>(loc, tripCount, unrollFactorCst);
418419
// Compute tripCountEvenMultiple = tripCount - (tripCount % unrollFactor)
@@ -459,7 +460,9 @@ LogicalResult mlir::loopUnrollByFactor(
459460
[&](unsigned i, Value iv, OpBuilder b) {
460461
// iv' = iv + step * i;
461462
auto stride = b.create<arith::MulIOp>(
462-
loc, step, createIntOrIndexConstant(b, loc, iv.getType(), i));
463+
loc, step,
464+
b.create<arith::ConstantOp>(loc,
465+
b.getIntegerAttr(iv.getType(), i)));
463466
return b.create<arith::AddIOp>(loc, iv, stride);
464467
},
465468
annotateFn, iterArgs, yieldedValues);

0 commit comments

Comments
 (0)