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