31
31
using namespace mlir ;
32
32
33
33
scf::SCFTilingOptions &
34
- scf::SCFTilingOptions::setTileSizes (ArrayRef<int64_t > ts) {
34
+ scf::SCFTilingOptions::setTileSizes (ArrayRef<OpFoldResult > ts) {
35
35
assert (!tileSizeComputationFunction && " tile sizes already set" );
36
- SmallVector< int64_t > tileSizes (ts. begin (), ts. end () );
36
+ auto tileSizes = llvm::to_vector (ts );
37
37
tileSizeComputationFunction = [tileSizes](OpBuilder &b, Operation *op) {
38
- OpBuilder::InsertionGuard guard (b);
39
- b.setInsertionPointToStart (
40
- &op->getParentWithTrait <OpTrait::IsIsolatedFromAbove>()
41
- ->getRegion (0 )
42
- .front ());
43
- return llvm::to_vector<4 >(map_range (tileSizes, [&](int64_t s) {
44
- Value v = b.create <arith::ConstantIndexOp>(op->getLoc (), s);
45
- return v;
46
- }));
38
+ return tileSizes;
47
39
};
48
40
return *this ;
49
41
}
@@ -108,17 +100,16 @@ static OpFoldResult getBoundedTileSize(OpBuilder &b, Location loc,
108
100
109
101
// / Generate an empty loop nest that represents the tiled loop nest shell.
110
102
// / - `loopRanges` specifies the lb, ub and step of the untiled iteration space.
111
- // / - `tileSizeVals ` is the tile sizes to use. Zero represent untiled loops.
103
+ // / - `tileSizes ` is the tile sizes to use. Zero represent untiled loops.
112
104
// / - In `offsets` and `sizes` return the multi-dimensional offset and size of
113
105
// / the
114
106
// / tile processed within the inner most loop.
115
- static SmallVector<scf::ForOp>
116
- generateTileLoopNest (OpBuilder &builder, Location loc,
117
- ArrayRef<Range> loopRanges, ArrayRef<Value> tileSizeVals,
118
- SmallVector<OpFoldResult> &offsets,
119
- SmallVector<OpFoldResult> &sizes) {
107
+ static SmallVector<scf::ForOp> generateTileLoopNest (
108
+ OpBuilder &builder, Location loc, ArrayRef<Range> loopRanges,
109
+ ArrayRef<OpFoldResult> tileSizes, SmallVector<OpFoldResult> &offsets,
110
+ SmallVector<OpFoldResult> &sizes) {
120
111
assert (!loopRanges.empty () && " expected at least one loop range" );
121
- assert (loopRanges.size () == tileSizeVals .size () &&
112
+ assert (loopRanges.size () == tileSizes .size () &&
122
113
" expected as many tile sizes as loop ranges" );
123
114
OpBuilder::InsertionGuard guard (builder);
124
115
SmallVector<scf::ForOp> loops;
@@ -130,7 +121,8 @@ generateTileLoopNest(OpBuilder &builder, Location loc,
130
121
getValueOrCreateConstantIndexOp (builder, loc, loopRange.value ().offset );
131
122
Value size =
132
123
getValueOrCreateConstantIndexOp (builder, loc, loopRange.value ().size );
133
- Value tileSize = tileSizeVals[loopRange.index ()];
124
+ Value tileSize = getValueOrCreateConstantIndexOp (
125
+ builder, loc, tileSizes[loopRange.index ()]);
134
126
// No loops if tile size is zero. Set offset and size to the loop
135
127
// offset and size.
136
128
if (matchPattern (tileSize, m_Zero ())) {
@@ -296,10 +288,10 @@ mlir::scf::tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op,
296
288
// skips tiling a particular dimension. This convention is significantly
297
289
// simpler to handle instead of adjusting affine maps to account for missing
298
290
// dimensions.
299
- SmallVector<Value > tileSizeVector =
291
+ SmallVector<OpFoldResult > tileSizeVector =
300
292
options.tileSizeComputationFunction (rewriter, op);
301
293
if (tileSizeVector.size () < iterationDomain.size ()) {
302
- auto zero = rewriter.create <arith::ConstantIndexOp>(op. getLoc (), 0 );
294
+ auto zero = rewriter.getIndexAttr ( 0 );
303
295
tileSizeVector.append (numLoops - tileSizeVector.size (), zero);
304
296
}
305
297
@@ -402,17 +394,17 @@ mlir::scf::tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op,
402
394
FailureOr<scf::SCFReductionTilingResult>
403
395
mlir::scf::tileReductionUsingScf (RewriterBase &b,
404
396
PartialReductionOpInterface op,
405
- ArrayRef<OpFoldResult> tileSize ) {
397
+ ArrayRef<OpFoldResult> tileSizes ) {
406
398
Location loc = op.getLoc ();
407
399
// Ops implementing PartialReductionOpInterface are expected to implement
408
400
// TilingInterface.
409
401
auto tilingInterfaceOp = cast<TilingInterface>(op.getOperation ());
410
402
SmallVector<Range> iterationDomain = tilingInterfaceOp.getIterationDomain (b);
411
- SmallVector<Value> tileSizeVector =
412
- getValueOrCreateConstantIndexOp (b, loc, tileSize);
413
- if (tileSizeVector. size () < iterationDomain. size ()) {
414
- auto zero = b. create <arith::ConstantIndexOp>(loc, 0 );
415
- tileSizeVector. append (iterationDomain. size () - tileSizeVector. size (), zero);
403
+ auto tileSizesVector = llvm::to_vector (tileSizes);
404
+ if (tileSizesVector. size () < iterationDomain. size ()) {
405
+ auto zero = b. getIndexAttr ( 0 );
406
+ tileSizesVector. append (iterationDomain. size () - tileSizesVector. size (),
407
+ zero);
416
408
}
417
409
if (op->getNumResults () != 1 )
418
410
return b.notifyMatchFailure (
@@ -429,15 +421,15 @@ mlir::scf::tileReductionUsingScf(RewriterBase &b,
429
421
430
422
// 1. create the inital tensor value.
431
423
FailureOr<Operation *> identityTensor =
432
- op.generateInitialTensorForPartialReduction (b, loc, tileSize ,
424
+ op.generateInitialTensorForPartialReduction (b, loc, tileSizesVector ,
433
425
reductionDims);
434
426
if (failed (identityTensor))
435
427
return b.notifyMatchFailure (op,
436
428
" cannot create a tensor of identity value." );
437
429
// 2. Create the nested loops.
438
430
SmallVector<OpFoldResult> offsets, sizes;
439
431
SmallVector<scf::ForOp> loops = generateTileLoopNest (
440
- b, loc, iterationDomain, tileSizeVector , offsets, sizes);
432
+ b, loc, iterationDomain, tileSizesVector , offsets, sizes);
441
433
442
434
// 3. Generate the tiled implementation within the inner most loop.
443
435
b.setInsertionPoint (loops.back ().getBody ()->getTerminator ());
0 commit comments