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> static tileLinalgOpImpl(OpBuilder &b, LinalgOp op,
331                                                 ArrayRef<Value> tileSizes,
332                                                 ArrayRef<unsigned> permutation,
333                                                 OperationFolder *folder) {
334   assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
335   // 1. Enforce the convention that "tiling by zero" skips tiling a particular
336   // dimension. This convention is significantly simpler to handle instead of
337   // adjusting affine maps to account for missing dimensions.
338   assert(op.getNumParallelLoops() + op.getNumReductionLoops() +
339                  op.getNumWindowLoops() ==
340              tileSizes.size() &&
341          "expected matching number of tile sizes and loops");
342 
343   // If permutation is empty, use the identity. Build the permutation map
344   // otherwise.
345   auto invPermutationMap = AffineMap::getMultiDimIdentityMap(
346       tileSizes.size(), ScopedContext::getContext());
347   if (!permutation.empty())
348     invPermutationMap = inversePermutation(
349         AffineMap::getPermutationMap(permutation, ScopedContext::getContext()));
350 
351   OpBuilder::InsertionGuard g(b);
352   b.setInsertionPoint(op);
353   ScopedContext scope(b, op.getLoc());
354   // 2. Build the tiled loop ranges.
355   auto viewSizes = getViewSizes(b, op);
356   // The flattened loopToOperandRangesMaps is expected to be an invertible
357   // permutation map (asserted in the inverse calculation).
358   auto viewSizesToLoopsMap =
359       inversePermutation(concatAffineMaps(loopToOperandRangesMaps(op)));
360   assert(viewSizesToLoopsMap && "expected invertible map");
361 
362   SmallVector<SubViewOp::Range, 4> loopRanges;
363   LoopIndexToRangeIndexMap loopIndexToRangeIndex;
364   std::tie(loopRanges, loopIndexToRangeIndex) =
365       makeTiledLoopRanges(b, scope.getLocation(), viewSizesToLoopsMap,
366                           viewSizes, tileSizes, folder);
367   if (!permutation.empty())
368     applyPermutationToVector(loopRanges, permutation);
369 
370   // 3. Create the tiled loops.
371   LinalgOp res = op;
372   auto ivs = ValueHandle::makeIndexHandles(loopRanges.size());
373   auto pivs = makeHandlePointers(MutableArrayRef<ValueHandle>(ivs));
374   // Convert SubViewOp::Range to linalg_range.
375   SmallVector<Value, 4> linalgRanges;
376   for (auto &range : loopRanges) {
377     linalgRanges.push_back(
378         linalg_range(range.offset, range.size, range.stride));
379   }
380   GenericLoopNestRangeBuilder<LoopTy>(pivs, linalgRanges)([&] {
381     auto b = ScopedContext::getBuilder();
382     auto loc = ScopedContext::getLocation();
383     SmallVector<Value, 4> ivValues(ivs.begin(), ivs.end());
384 
385     // If we have to apply a permutation to the tiled loop nest, we have to
386     // reorder the induction variables This permutation is the right one
387     // assuming that loopRanges have previously been permuted by
388     // (i,j,k)->(k,i,j) So this permutation should be the inversePermutation of
389     // that one: (d0,d1,d2)->(d2,d0,d1)
390     if (!permutation.empty())
391       ivValues = applyMapToValues(b, loc, invPermutationMap, ivValues, folder);
392 
393     auto views =
394         makeTiledViews(b, loc, op, ivValues, tileSizes, viewSizes, folder);
395     auto operands = getAssumedNonViewOperands(op);
396     views.append(operands.begin(), operands.end());
397     res = op.clone(b, loc, views);
398   });
399 
400   // 4. Transforms index arguments of `linalg.generic` w.r.t. to the tiling.
401   transformIndexedGenericOpIndices(b, res, pivs, loopIndexToRangeIndex);
402 
403   // 5. Gather the newly created loops and return them with the new op.
404   SmallVector<Operation *, 8> loops;
405   loops.reserve(ivs.size());
406   for (auto iv : ivs)
407     loops.push_back(loop::getForInductionVarOwner(iv));
408 
409   return TiledLinalgOp{res, loops};
410 }
411 
412 template <typename LoopTy>
413 Optional<TiledLinalgOp>
414 tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
415                  ArrayRef<unsigned> permutation, OperationFolder *folder) {
416   assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
417   if (tileSizes.empty())
418     return llvm::None;
419 
420   // The following uses the convention that "tiling by zero" skips tiling a
421   // particular dimension. This convention is significantly simpler to handle
422   // instead of adjusting affine maps to account for missing dimensions.
423   auto nLoops = op.getNumParallelLoops() + op.getNumReductionLoops() +
424                 op.getNumWindowLoops();
425   tileSizes = tileSizes.take_front(nLoops);
426   // If only 0 tilings are left, then return.
427   if (llvm::all_of(tileSizes, [](int64_t v) { return v == 0; }))
428     return llvm::None;
429 
430   // Create a builder for tile size constants.
431   OpBuilder::InsertionGuard g(b);
432   b.setInsertionPoint(op);
433   ScopedContext scope(b, op.getLoc());
434 
435   // Materialize concrete tile size values to pass the generic tiling function.
436   SmallVector<Value, 8> tileSizeValues;
437   tileSizeValues.reserve(tileSizes.size());
438   for (auto ts : tileSizes)
439     tileSizeValues.push_back(folded_std_constant_index(folder, ts));
440   // Pad tile sizes with zero values to enforce our convention.
441   if (tileSizeValues.size() < nLoops) {
442     for (unsigned i = tileSizeValues.size(); i < nLoops; ++i)
443       tileSizeValues.push_back(folded_std_constant_index(folder, 0));
444   }
445 
446   return tileLinalgOpImpl<LoopTy>(b, op, tileSizeValues, permutation, folder);
447 }
448 
449 Optional<TiledLinalgOp>
450 mlir::linalg::tileLinalgOp(OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes,
451                            ArrayRef<unsigned> permutation,
452                            OperationFolder *folder) {
453   return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder);
454 }
455 
456 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops(
457     OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes,
458     ArrayRef<unsigned> permutation, OperationFolder *folder) {
459   return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation,
460                                             folder);
461 }
462 
463 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOp(
464     OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
465     ArrayRef<unsigned> permutation, OperationFolder *folder) {
466   return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder);
467 }
468 
469 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops(
470     OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes,
471     ArrayRef<unsigned> permutation, OperationFolder *folder) {
472   return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation,
473                                             folder);
474 }
475 
476 template <typename LoopTy>
477 static void tileLinalgOps(FuncOp f, ArrayRef<int64_t> tileSizes) {
478   OpBuilder b(f);
479   OperationFolder folder(f.getContext());
480   f.walk([tileSizes, &b, &folder](LinalgOp op) {
481     if (!op.hasBufferSemantics())
482       return;
483     auto opLoopsPair =
484         tileLinalgOpImpl<LoopTy>(b, op, tileSizes, /*permutation=*/{}, &folder);
485     // If tiling occurred successfully, erase old op.
486     if (opLoopsPair)
487       op.erase();
488   });
489   f.walk([](LinalgOp op) {
490     if (!op.getOperation()->hasNoSideEffect())
491       return;
492     if (op.getOperation()->use_empty())
493       op.erase();
494   });
495 }
496 
497 namespace {
498 
499 template <typename LoopTy>
500 struct LinalgTilingPass : public FunctionPass<LinalgTilingPass<LoopTy>> {
501   LinalgTilingPass() = default;
502   LinalgTilingPass(ArrayRef<int64_t> sizes) {
503     this->tileSizes.assign(sizes.begin(), sizes.end());
504   }
505 
506   void runOnFunction() override {
507     tileLinalgOps<LoopTy>(this->getFunction(), tileSizes);
508   }
509 
510   SmallVector<int64_t, 8> tileSizes;
511 };
512 
513 } // namespace
514 
515 std::unique_ptr<OpPassBase<FuncOp>>
516 mlir::createLinalgTilingPass(ArrayRef<int64_t> tileSizes) {
517   return std::make_unique<LinalgTilingPass<loop::ForOp>>(tileSizes);
518 }
519 
520 std::unique_ptr<OpPassBase<FuncOp>>
521 mlir::createLinalgTilingToParallelLoopsPass(ArrayRef<int64_t> tileSizes) {
522   return std::make_unique<LinalgTilingPass<loop::ParallelOp>>(tileSizes);
523 }
524 
525 static PassRegistration<LinalgTilingPass<loop::ForOp>>
526     tiling_pass("linalg-tile", "Tile operations in the linalg dialect", [] {
527       auto pass = std::make_unique<LinalgTilingPass<loop::ForOp>>();
528       pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
529       return pass;
530     });
531 
532 static PassRegistration<LinalgTilingPass<loop::ParallelOp>>
533     tiling_to_parallel_loops(
534         "linalg-tile-to-parallel-loops",
535         "Tile operations in the linalg dialect to parallel loops", [] {
536           auto pass = std::make_unique<LinalgTilingPass<loop::ParallelOp>>();
537           pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
538           return pass;
539         });
540