1 //===- Tiling.cpp - Implementation of linalg Tiling -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the linalg dialect Tiling pass.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Dialect/AffineOps/EDSC/Intrinsics.h"
14 #include "mlir/Dialect/Linalg/EDSC/Intrinsics.h"
15 #include "mlir/Dialect/Linalg/IR/LinalgTypes.h"
16 #include "mlir/Dialect/Linalg/Passes.h"
17 #include "mlir/Dialect/Linalg/Utils/Utils.h"
18 #include "mlir/Dialect/LoopOps/EDSC/Builders.h"
19 #include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
20 #include "mlir/IR/AffineExpr.h"
21 #include "mlir/IR/AffineExprVisitor.h"
22 #include "mlir/IR/AffineMap.h"
23 #include "mlir/IR/OpImplementation.h"
24 #include "mlir/Pass/Pass.h"
25 #include "mlir/Support/LLVM.h"
26 #include "mlir/Support/STLExtras.h"
27 #include "mlir/Transforms/FoldUtils.h"
28 
29 #include "llvm/Support/CommandLine.h"
30 
31 using namespace mlir;
32 using namespace mlir::edsc;
33 using namespace mlir::edsc::intrinsics;
34 using namespace mlir::linalg;
35 using namespace mlir::loop;
36 
37 using folded_affine_min = folded::ValueBuilder<AffineMinOp>;
38 
39 #define DEBUG_TYPE "linalg-tiling"
40 
41 static llvm::cl::OptionCategory clOptionsCategory(DEBUG_TYPE " options");
42 static llvm::cl::list<unsigned>
43     clTileSizes("linalg-tile-sizes",
44                 llvm::cl::desc("Tile sizes by which to tile linalg operations"),
45                 llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated,
46                 llvm::cl::cat(clOptionsCategory));
47 
48 static bool isZero(Value v) {
49   return isa_and_nonnull<ConstantIndexOp>(v.getDefiningOp()) &&
50          cast<ConstantIndexOp>(v.getDefiningOp()).getValue() == 0;
51 }
52 
53 using LoopIndexToRangeIndexMap = DenseMap<int, int>;
54 
55 // Creates a number of ranges equal to the number of non-zero in `tileSizes`.
56 // One for each loop of the LinalgOp that is tiled. The `tileSizes` argument has
57 // one entry per surrounding loop. It uses zero as the convention that a
58 // particular loop is not tiled. This convention simplifies implementations by
59 // avoiding affine map manipulations.
60 // The returned ranges correspond to the loop ranges, in the proper order, that
61 // are tiled and for which new loops will be created. Also the function returns
62 // a map from loop indices of the LinalgOp to the corresponding non-empty range
63 // indices of newly created loops.
64 static std::tuple<SmallVector<SubViewOp::Range, 4>, LoopIndexToRangeIndexMap>
65 makeTiledLoopRanges(OpBuilder &b, Location loc, AffineMap map,
66                     ArrayRef<Value> allViewSizes, ArrayRef<Value> allTileSizes,
67                     OperationFolder *folder) {
68   assert(allTileSizes.size() == map.getNumResults());
69   // Apply `map` to get view sizes in loop order.
70   auto viewSizes = applyMapToValues(b, loc, map, allViewSizes, folder);
71   SmallVector<Value, 4> tileSizes(allTileSizes.begin(), allTileSizes.end());
72 
73   // Traverse the tile sizes, which are in loop order, erase zeros everywhere.
74   LoopIndexToRangeIndexMap loopIndexToRangeIndex;
75   for (int idx = 0, e = tileSizes.size(), zerosCount = 0; idx < e; ++idx) {
76     if (isZero(tileSizes[idx - zerosCount])) {
77       viewSizes.erase(viewSizes.begin() + idx - zerosCount);
78       tileSizes.erase(tileSizes.begin() + idx - zerosCount);
79       ++zerosCount;
80       continue;
81     }
82     loopIndexToRangeIndex[idx] = idx - zerosCount;
83   }
84 
85   // Create a new range with the applied tile sizes.
86   SmallVector<SubViewOp::Range, 4> res;
87   for (unsigned idx = 0, e = tileSizes.size(); idx < e; ++idx) {
88     res.push_back(SubViewOp::Range{folded_std_constant_index(folder, 0),
89                                    viewSizes[idx], tileSizes[idx]});
90   }
91   return std::make_tuple(res, loopIndexToRangeIndex);
92 }
93 
94 namespace {
95 
96 // Helper visitor to determine whether an AffineExpr is tiled.
97 // This is achieved by traversing every AffineDimExpr with position `pos` and
98 // checking whether the corresponding `tileSizes[pos]` is non-zero.
99 // This also enforces only positive coefficients occur in multiplications.
100 //
101 // Example:
102 //   `d0 + 2 * d1 + d3` is tiled by [0, 0, 0, 2] but not by [0, 0, 2, 0]
103 //
104 struct TileCheck : public AffineExprVisitor<TileCheck> {
105   TileCheck(ArrayRef<Value> tileSizes) : isTiled(false), tileSizes(tileSizes) {}
106 
107   void visitDimExpr(AffineDimExpr expr) {
108     isTiled |= !isZero(tileSizes[expr.getPosition()]);
109   }
110   void visitAffineBinaryOpExpr(AffineBinaryOpExpr expr) {
111     visit(expr.getLHS());
112     visit(expr.getRHS());
113     if (expr.getKind() == mlir::AffineExprKind::Mul)
114       assert(expr.getRHS().cast<AffineConstantExpr>().getValue() > 0 &&
115              "nonpositive multiplying coefficient");
116   }
117   bool isTiled;
118   ArrayRef<Value> tileSizes;
119 };
120 
121 } // namespace
122 
123 // IndexedGenericOp explicitly uses induction variables in the loop body. The
124 // values of the indices that are used in the loop body for any given access of
125 // input/output memref before `subview` op was applied should be invariant with
126 // respect to tiling.
127 //
128 // Therefore, if the operation is tiled, we have to transform the indices
129 // accordingly, i.e. offset them by the values of the corresponding induction
130 // variables that are captured implicitly in the body of the op.
131 //
132 // Example. `linalg.indexed_generic` before tiling:
133 //
134 // #id_2d = (i, j) -> (i, j)
135 // #pointwise_2d_trait = {
136 //   indexing_maps = [#id_2d, #id_2d],
137 //   iterator_types = ["parallel", "parallel"],
138 //   n_views = [1, 1]
139 // }
140 // linalg.indexed_generic #pointwise_2d_trait %operand, %result {
141 //   ^bb0(%i: index, %j: index, %operand_in: f32, %result_in: f32):
142 //     <some operations that use %i, %j>
143 // }: memref<50x100xf32>, memref<50x100xf32>
144 //
145 // After tiling pass with tiles sizes 10 and 25:
146 //
147 // #strided = (i, j)[s0, s1, s2] -> (i * s1 + s0 + j * s2)
148 //
149 // %c1 = constant 1 : index
150 // %c0 = constant 0 : index
151 // %c25 = constant 25 : index
152 // %c10 = constant 10 : index
153 // operand_dim_0 = dim %operand, 0 : memref<50x100xf32>
154 // operand_dim_1 = dim %operand, 1 : memref<50x100xf32>
155 // loop.for %k = %c0 to operand_dim_0 step %c10 {
156 //   loop.for %l = %c0 to operand_dim_1 step %c25 {
157 //     %4 = std.subview %operand[%k, %l][%c10, %c25][%c1, %c1]
158 //       : memref<50x100xf32> to memref<?x?xf32, #strided>
159 //     %5 = std.subview %result[%k, %l][%c10, %c25][%c1, %c1]
160 //       : memref<50x100xf32> to memref<?x?xf32, #strided>
161 //     linalg.indexed_generic pointwise_2d_trait %4, %5 {
162 //     ^bb0(%i: index, %j: index, %operand_in: f32, %result_in: f32):
163 //       // Indices `k` and `l` are implicitly captured in the body.
164 //       %transformed_i = addi %i, %k : index // index `i` is offset by %k
165 //       %transformed_j = addi %j, %l : index // index `j` is offset by %l
166 //       // Every use of %i, %j is replaced with %transformed_i, %transformed_j
167 //       <some operations that use %transformed_i, %transformed_j>
168 //     }: memref<?x?xf32, #strided>, memref<?x?xf32, #strided>
169 //   }
170 // }
171 //
172 // TODO(pifon, ntv): Investigate whether mixing implicit and explicit indices
173 // does not lead to losing information.
174 static void transformIndexedGenericOpIndices(
175     OpBuilder &b, LinalgOp op, ArrayRef<ValueHandle *> pivs,
176     const LoopIndexToRangeIndexMap &loopIndexToRangeIndex) {
177   assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
178   auto indexedGenericOp = dyn_cast<IndexedGenericOp>(op.getOperation());
179   if (!indexedGenericOp)
180     return;
181 
182   // `linalg.indexed_generic` comes in two flavours. One has a region with a
183   // single block that defines the loop body. The other has a `fun` attribute
184   // that refers to an existing function symbol. The `fun` function call will be
185   // inserted in the loop body in that case.
186   //
187   // TODO(pifon): Add support for `linalg.indexed_generic` with `fun` attribute.
188   auto &region = indexedGenericOp.region();
189   if (region.empty()) {
190     indexedGenericOp.emitOpError("expected a region");
191     return;
192   }
193   auto &block = region.getBlocks().front();
194 
195   OpBuilder::InsertionGuard g(b);
196   b.setInsertionPointToStart(&block);
197   for (unsigned i = 0; i < indexedGenericOp.getNumLoops(); ++i) {
198     auto rangeIndex = loopIndexToRangeIndex.find(i);
199     if (rangeIndex == loopIndexToRangeIndex.end())
200       continue;
201     Value oldIndex = block.getArgument(i);
202     // Offset the index argument `i` by the value of the corresponding induction
203     // variable and replace all uses of the previous value.
204     Value newIndex = b.create<AddIOp>(indexedGenericOp.getLoc(), oldIndex,
205                                       pivs[rangeIndex->second]->getValue());
206     for (auto &use : oldIndex.getUses()) {
207       if (use.getOwner() == newIndex.getDefiningOp())
208         continue;
209       use.set(newIndex);
210     }
211   }
212 }
213 
214 static bool isTiled(AffineExpr expr, ArrayRef<Value> tileSizes) {
215   if (!expr)
216     return false;
217   TileCheck t(tileSizes);
218   t.visit(expr);
219   return t.isTiled;
220 }
221 
222 // Checks whether the view with index `viewIndex` within `linalgOp` varies with
223 // respect to a non-zero `tileSize`.
224 static bool isTiled(AffineMap map, ArrayRef<Value> tileSizes) {
225   if (!map)
226     return false;
227   for (unsigned r = 0; r < map.getNumResults(); ++r)
228     if (isTiled(map.getResult(r), tileSizes))
229       return true;
230   return false;
231 }
232 
233 static SmallVector<Value, 4>
234 makeTiledViews(OpBuilder &b, Location loc, LinalgOp linalgOp,
235                ArrayRef<Value> ivs, ArrayRef<Value> tileSizes,
236                ArrayRef<Value> viewSizes, OperationFolder *folder) {
237   assert(linalgOp.hasBufferSemantics() &&
238          "expected linalg op with buffer semantics");
239   assert(ivs.size() == static_cast<size_t>(llvm::count_if(
240                            llvm::make_range(tileSizes.begin(), tileSizes.end()),
241                            [](Value v) { return !isZero(v); })) &&
242          "expected as many ivs as non-zero sizes");
243 
244   using namespace edsc::op;
245 
246   // Construct (potentially temporary) mins and maxes on which to apply maps
247   // that define tile subviews.
248   SmallVector<Value, 8> lbs, subViewSizes;
249   for (unsigned idx = 0, idxIvs = 0, e = tileSizes.size(); idx < e; ++idx) {
250     bool isTiled = !isZero(tileSizes[idx]);
251     lbs.push_back(isTiled ? ivs[idxIvs++]
252                           : (Value)folded_std_constant_index(folder, 0));
253     subViewSizes.push_back(isTiled ? tileSizes[idx] : viewSizes[idx]);
254   }
255 
256   auto *op = linalgOp.getOperation();
257 
258   SmallVector<Value, 4> res;
259   res.reserve(op->getNumOperands());
260   auto viewIteratorBegin = linalgOp.getInputsAndOutputBuffers().begin();
261   for (unsigned viewIndex = 0; viewIndex < linalgOp.getNumInputsAndOutputs();
262        ++viewIndex) {
263     Value view = *(viewIteratorBegin + viewIndex);
264     auto viewType = view.getType().cast<MemRefType>();
265     unsigned rank = viewType.getRank();
266     auto map = loopToOperandRangesMaps(linalgOp)[viewIndex];
267     // If the view is not tiled, we can use it as is.
268     if (!isTiled(map, tileSizes)) {
269       res.push_back(view);
270       continue;
271     }
272 
273     // Construct a new subview for the tile.
274     SmallVector<Value, 4> offsets, sizes, strides;
275     offsets.reserve(rank);
276     sizes.reserve(rank);
277     strides.reserve(rank);
278     for (unsigned r = 0; r < rank; ++r) {
279       if (!isTiled(map.getSubMap({r}), tileSizes)) {
280         offsets.push_back(folded_std_constant_index(folder, 0));
281         sizes.push_back(std_dim(view, r));
282         strides.push_back(folded_std_constant_index(folder, 1));
283         continue;
284       }
285 
286       // Tiling creates a new slice at the proper index, the slice step is 1
287       // (i.e. the slice view does not subsample, stepping occurs in the loop).
288       auto m = map.getSubMap({r});
289       auto offset = applyMapToValues(b, loc, m, lbs, folder).front();
290       offsets.push_back(offset);
291       auto size = applyMapToValues(b, loc, m, subViewSizes, folder).front();
292 
293       // The size of the subview should be trimmed to avoid out-of-bounds
294       // accesses, unless we statically know the subview size divides the view
295       // size evenly.
296       int64_t viewSize = viewType.getDimSize(r);
297       auto sizeCst = dyn_cast_or_null<ConstantIndexOp>(size.getDefiningOp());
298       if (ShapedType::isDynamic(viewSize) || !sizeCst ||
299           (viewSize % sizeCst.getValue()) != 0) {
300         // Compute min(size, dim - offset) to avoid out-of-bounds accesses.
301         auto minMap = AffineMap::get(
302             /*dimCount=*/3, /*symbolCount=*/0,
303             {getAffineDimExpr(/*position=*/0, b.getContext()),
304              getAffineDimExpr(/*position=*/1, b.getContext()) -
305                  getAffineDimExpr(/*position=*/2, b.getContext())});
306         auto d = folded_std_dim(folder, view, r);
307         size = folded_affine_min(folder, b.getIndexType(), minMap,
308                                  ValueRange{size, d, offset});
309       }
310 
311       sizes.push_back(size);
312       strides.push_back(folded_std_constant_index(folder, 1));
313     }
314 
315     res.push_back(b.create<SubViewOp>(loc, view, offsets, sizes, strides));
316   }
317 
318   // Traverse the mins/maxes and erase those that don't have uses left.
319   // This is a special type of folding that we only apply when `folder` is
320   // defined.
321   if (folder)
322     for (auto v : llvm::concat<Value>(lbs, subViewSizes))
323       if (v.use_empty())
324         v.getDefiningOp()->erase();
325 
326   return res;
327 }
328 
329 template <typename LoopTy>
330 Optional<TiledLinalgOp>
331 tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes,
332                  ArrayRef<unsigned> permutation, OperationFolder *folder) {
333   assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
334   // 1. Enforce the convention that "tiling by zero" skips tiling a particular
335   // dimension. This convention is significantly simpler to handle instead of
336   // adjusting affine maps to account for missing dimensions.
337   assert(op.getNumParallelLoops() + op.getNumReductionLoops() +
338                  op.getNumWindowLoops() ==
339              tileSizes.size() &&
340          "expected matching number of tile sizes and loops");
341 
342   // If permutation is empty, use the identity. Build the permutation map
343   // otherwise.
344   auto invPermutationMap = AffineMap::getMultiDimIdentityMap(
345       tileSizes.size(), ScopedContext::getContext());
346   if (!permutation.empty())
347     invPermutationMap = inversePermutation(
348         AffineMap::getPermutationMap(permutation, ScopedContext::getContext()));
349 
350   OpBuilder::InsertionGuard g(b);
351   b.setInsertionPoint(op);
352   ScopedContext scope(b, op.getLoc());
353   // 2. Build the tiled loop ranges.
354   auto viewSizes = getViewSizes(b, op);
355   // The flattened loopToOperandRangesMaps is expected to be an invertible
356   // permutation map (asserted in the inverse calculation).
357   auto viewSizesToLoopsMap =
358       inversePermutation(concatAffineMaps(loopToOperandRangesMaps(op)));
359   assert(viewSizesToLoopsMap && "expected invertible map");
360 
361   SmallVector<SubViewOp::Range, 4> loopRanges;
362   LoopIndexToRangeIndexMap loopIndexToRangeIndex;
363   std::tie(loopRanges, loopIndexToRangeIndex) =
364       makeTiledLoopRanges(b, scope.getLocation(), viewSizesToLoopsMap,
365                           viewSizes, tileSizes, folder);
366   if (!permutation.empty())
367     applyPermutationToVector(loopRanges, permutation);
368 
369   // 3. Create the tiled loops.
370   LinalgOp res = op;
371   auto ivs = ValueHandle::makeIndexHandles(loopRanges.size());
372   auto pivs = makeHandlePointers(MutableArrayRef<ValueHandle>(ivs));
373   // Convert SubViewOp::Range to linalg_range.
374   SmallVector<Value, 4> linalgRanges;
375   for (auto &range : loopRanges) {
376     linalgRanges.push_back(
377         linalg_range(range.offset, range.size, range.stride));
378   }
379   GenericLoopNestRangeBuilder<LoopTy>(pivs, linalgRanges)([&] {
380     auto b = ScopedContext::getBuilder();
381     auto loc = ScopedContext::getLocation();
382     SmallVector<Value, 4> ivValues(ivs.begin(), ivs.end());
383 
384     // If we have to apply a permutation to the tiled loop nest, we have to
385     // reorder the induction variables This permutation is the right one
386     // assuming that loopRanges have previously been permuted by
387     // (i,j,k)->(k,i,j) So this permutation should be the inversePermutation of
388     // that one: (d0,d1,d2)->(d2,d0,d1)
389     if (!permutation.empty())
390       ivValues = applyMapToValues(b, loc, invPermutationMap, ivValues, folder);
391 
392     auto views =
393         makeTiledViews(b, loc, op, ivValues, tileSizes, viewSizes, folder);
394     auto operands = getAssumedNonViewOperands(op);
395     views.append(operands.begin(), operands.end());
396     res = op.clone(b, loc, views);
397   });
398 
399   // 4. Transforms index arguments of `linalg.generic` w.r.t. to the tiling.
400   transformIndexedGenericOpIndices(b, res, pivs, loopIndexToRangeIndex);
401 
402   // 5. Gather the newly created loops and return them with the new op.
403   SmallVector<Operation *, 8> loops;
404   loops.reserve(ivs.size());
405   for (auto iv : ivs)
406     loops.push_back(loop::getForInductionVarOwner(iv));
407 
408   return TiledLinalgOp{res, loops};
409 }
410 
411 template <typename LoopTy>
412 Optional<TiledLinalgOp>
413 tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
414                  ArrayRef<unsigned> permutation, OperationFolder *folder) {
415   assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
416   if (tileSizes.empty())
417     return llvm::None;
418 
419   // The following uses the convention that "tiling by zero" skips tiling a
420   // particular dimension. This convention is significantly simpler to handle
421   // instead of adjusting affine maps to account for missing dimensions.
422   auto nLoops = op.getNumParallelLoops() + op.getNumReductionLoops() +
423                 op.getNumWindowLoops();
424   tileSizes = tileSizes.take_front(nLoops);
425   // If only 0 tilings are left, then return.
426   if (llvm::all_of(tileSizes, [](int64_t v) { return v == 0; }))
427     return llvm::None;
428 
429   // Create a builder for tile size constants.
430   OpBuilder::InsertionGuard g(b);
431   b.setInsertionPoint(op);
432   ScopedContext scope(b, op.getLoc());
433 
434   // Materialize concrete tile size values to pass the generic tiling function.
435   SmallVector<Value, 8> tileSizeValues;
436   tileSizeValues.reserve(tileSizes.size());
437   for (auto ts : tileSizes)
438     tileSizeValues.push_back(folded_std_constant_index(folder, ts));
439   // Pad tile sizes with zero values to enforce our convention.
440   if (tileSizeValues.size() < nLoops) {
441     for (unsigned i = tileSizeValues.size(); i < nLoops; ++i)
442       tileSizeValues.push_back(folded_std_constant_index(folder, 0));
443   }
444 
445   return tileLinalgOpImpl<LoopTy>(b, op, tileSizeValues, permutation, folder);
446 }
447 
448 Optional<TiledLinalgOp>
449 mlir::linalg::tileLinalgOp(OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes,
450                            ArrayRef<unsigned> permutation,
451                            OperationFolder *folder) {
452   return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder);
453 }
454 
455 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops(
456     OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes,
457     ArrayRef<unsigned> permutation, OperationFolder *folder) {
458   return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation,
459                                             folder);
460 }
461 
462 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOp(
463     OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
464     ArrayRef<unsigned> permutation, OperationFolder *folder) {
465   return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder);
466 }
467 
468 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops(
469     OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
470     ArrayRef<unsigned> permutation, OperationFolder *folder) {
471   return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation,
472                                             folder);
473 }
474 
475 template <typename LoopTy>
476 static void tileLinalgOps(FuncOp f, ArrayRef<int64_t> tileSizes) {
477   OpBuilder b(f);
478   OperationFolder folder(f.getContext());
479   f.walk([tileSizes, &b, &folder](LinalgOp op) {
480     if (!op.hasBufferSemantics())
481       return;
482     auto opLoopsPair =
483         tileLinalgOpImpl<LoopTy>(b, op, tileSizes, /*permutation=*/{}, &folder);
484     // If tiling occurred successfully, erase old op.
485     if (opLoopsPair)
486       op.erase();
487   });
488   f.walk([](LinalgOp op) {
489     if (!op.getOperation()->hasNoSideEffect())
490       return;
491     if (op.getOperation()->use_empty())
492       op.erase();
493   });
494 }
495 
496 namespace {
497 
498 template <typename LoopTy>
499 struct LinalgTilingPass : public FunctionPass<LinalgTilingPass<LoopTy>> {
500   LinalgTilingPass() = default;
501   LinalgTilingPass(ArrayRef<int64_t> sizes) {
502     this->tileSizes.assign(sizes.begin(), sizes.end());
503   }
504 
505   void runOnFunction() override {
506     tileLinalgOps<LoopTy>(this->getFunction(), tileSizes);
507   }
508 
509   SmallVector<int64_t, 8> tileSizes;
510 };
511 
512 } // namespace
513 
514 std::unique_ptr<OpPassBase<FuncOp>>
515 mlir::createLinalgTilingPass(ArrayRef<int64_t> tileSizes) {
516   return std::make_unique<LinalgTilingPass<loop::ForOp>>(tileSizes);
517 }
518 
519 std::unique_ptr<OpPassBase<FuncOp>>
520 mlir::createLinalgTilingToParallelLoopsPass(ArrayRef<int64_t> tileSizes) {
521   return std::make_unique<LinalgTilingPass<loop::ParallelOp>>(tileSizes);
522 }
523 
524 static PassRegistration<LinalgTilingPass<loop::ForOp>>
525     tiling_pass("linalg-tile", "Tile operations in the linalg dialect", [] {
526       auto pass = std::make_unique<LinalgTilingPass<loop::ForOp>>();
527       pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
528       return pass;
529     });
530 
531 static PassRegistration<LinalgTilingPass<loop::ParallelOp>>
532     tiling_to_parallel_loops(
533         "linalg-tile-to-parallel-loops",
534         "Tile operations in the linalg dialect to parallel loops", [] {
535           auto pass = std::make_unique<LinalgTilingPass<loop::ParallelOp>>();
536           pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
537           return pass;
538         });
539