@@ -270,11 +270,13 @@ bool mlir::getInnermostParallelLoops(Operation *rootOp,
270
270
static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
271
271
int64_t divisor) {
272
272
assert (divisor > 0 && " expected positive divisor" );
273
- assert (dividend.getType ().isIndex () && " expected index-typed value" );
273
+ assert (dividend.getType ().isIntOrIndex () &&
274
+ " expected integer or index-typed value" );
274
275
275
- Value divisorMinusOneCst =
276
- builder.create <arith::ConstantIndexOp>(loc, divisor - 1 );
277
- Value divisorCst = builder.create <arith::ConstantIndexOp>(loc, divisor);
276
+ Value divisorMinusOneCst = builder.create <arith::ConstantOp>(
277
+ loc, builder.getIntegerAttr (dividend.getType (), divisor - 1 ));
278
+ Value divisorCst = builder.create <arith::ConstantOp>(
279
+ loc, builder.getIntegerAttr (dividend.getType (), divisor));
278
280
Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOneCst);
279
281
return builder.create <arith::DivUIOp>(loc, sum, divisorCst);
280
282
}
@@ -285,9 +287,10 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
285
287
// where divis is rounding-to-zero division.
286
288
static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
287
289
Value divisor) {
288
- assert (dividend.getType ().isIndex () && " expected index-typed value" );
289
-
290
- Value cstOne = builder.create <arith::ConstantIndexOp>(loc, 1 );
290
+ assert (dividend.getType ().isIntOrIndex () &&
291
+ " expected integer or index-typed value" );
292
+ Value cstOne = builder.create <arith::ConstantOp>(
293
+ loc, builder.getOneAttr (dividend.getType ()));
291
294
Value divisorMinusOne = builder.create <arith::SubIOp>(loc, divisor, cstOne);
292
295
Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOne);
293
296
return builder.create <arith::DivUIOp>(loc, sum, divisor);
@@ -409,16 +412,18 @@ LogicalResult mlir::loopUnrollByFactor(
409
412
// Create constant for 'upperBoundUnrolled' and set epilogue loop flag.
410
413
generateEpilogueLoop = upperBoundUnrolledCst < ubCst;
411
414
if (generateEpilogueLoop)
412
- upperBoundUnrolled = boundsBuilder.create <arith::ConstantIndexOp>(
413
- loc, upperBoundUnrolledCst);
415
+ upperBoundUnrolled = boundsBuilder.create <arith::ConstantOp>(
416
+ loc, boundsBuilder.getIntegerAttr (forOp.getUpperBound ().getType (),
417
+ upperBoundUnrolledCst));
414
418
else
415
419
upperBoundUnrolled = forOp.getUpperBound ();
416
420
417
421
// Create constant for 'stepUnrolled'.
418
422
stepUnrolled = stepCst == stepUnrolledCst
419
423
? step
420
- : boundsBuilder.create <arith::ConstantIndexOp>(
421
- loc, stepUnrolledCst);
424
+ : boundsBuilder.create <arith::ConstantOp>(
425
+ loc, boundsBuilder.getIntegerAttr (
426
+ step.getType (), stepUnrolledCst));
422
427
} else {
423
428
// Dynamic loop bounds computation.
424
429
// TODO: Add dynamic asserts for negative lb/ub/step, or
@@ -428,8 +433,8 @@ LogicalResult mlir::loopUnrollByFactor(
428
433
Value diff =
429
434
boundsBuilder.create <arith::SubIOp>(loc, upperBound, lowerBound);
430
435
Value tripCount = ceilDivPositive (boundsBuilder, loc, diff, step);
431
- Value unrollFactorCst =
432
- boundsBuilder.create <arith::ConstantIndexOp>(loc , unrollFactor);
436
+ Value unrollFactorCst = boundsBuilder. create <arith::ConstantOp>(
437
+ loc, boundsBuilder.getIntegerAttr (tripCount. getType () , unrollFactor) );
433
438
Value tripCountRem =
434
439
boundsBuilder.create <arith::RemSIOp>(loc, tripCount, unrollFactorCst);
435
440
// Compute tripCountEvenMultiple = tripCount - (tripCount % unrollFactor)
@@ -476,7 +481,9 @@ LogicalResult mlir::loopUnrollByFactor(
476
481
[&](unsigned i, Value iv, OpBuilder b) {
477
482
// iv' = iv + step * i;
478
483
auto stride = b.create <arith::MulIOp>(
479
- loc, step, b.create <arith::ConstantIndexOp>(loc, i));
484
+ loc, step,
485
+ b.create <arith::ConstantOp>(loc,
486
+ b.getIntegerAttr (iv.getType (), i)));
480
487
return b.create <arith::AddIOp>(loc, iv, stride);
481
488
},
482
489
annotateFn, iterArgs, yieldedValues);
0 commit comments