1 //===- TestLoopParametricTiling.cpp --- Parametric loop tiling pass -------===// 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 a pass to parametrically tile nests of standard loops. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/Dialect/SCF/SCF.h" 14 #include "mlir/IR/Builders.h" 15 #include "mlir/Pass/Pass.h" 16 #include "mlir/Transforms/LoopUtils.h" 17 #include "mlir/Transforms/Passes.h" 18 19 using namespace mlir; 20 21 namespace { 22 23 // Extracts fixed-range loops for top-level loop nests with ranges defined in 24 // the pass constructor. Assumes loops are permutable. 25 class SimpleParametricLoopTilingPass 26 : public PassWrapper<SimpleParametricLoopTilingPass, FunctionPass> { 27 public: 28 SimpleParametricLoopTilingPass() = default; SimpleParametricLoopTilingPass(const SimpleParametricLoopTilingPass &)29 SimpleParametricLoopTilingPass(const SimpleParametricLoopTilingPass &) {} SimpleParametricLoopTilingPass(ArrayRef<int64_t> outerLoopSizes)30 explicit SimpleParametricLoopTilingPass(ArrayRef<int64_t> outerLoopSizes) { 31 sizes = outerLoopSizes; 32 } 33 runOnFunction()34 void runOnFunction() override { 35 FuncOp func = getFunction(); 36 func.walk([this](scf::ForOp op) { 37 // Ignore nested loops. 38 if (op->getParentRegion()->getParentOfType<scf::ForOp>()) 39 return; 40 extractFixedOuterLoops(op, sizes); 41 }); 42 } 43 44 ListOption<int64_t> sizes{ 45 *this, "test-outer-loop-sizes", llvm::cl::MiscFlags::CommaSeparated, 46 llvm::cl::desc( 47 "fixed number of iterations that the outer loops should have")}; 48 }; 49 } // namespace 50 51 namespace mlir { 52 namespace test { registerSimpleParametricTilingPass()53void registerSimpleParametricTilingPass() { 54 PassRegistration<SimpleParametricLoopTilingPass>( 55 "test-extract-fixed-outer-loops", 56 "test application of parametric tiling to the outer loops so that the " 57 "ranges of outer loops become static"); 58 } 59 } // namespace test 60 } // namespace mlir 61