2019-07-22 04:30:50 -07:00
|
|
|
//===- TestLoopParametricTiling.cpp --- Parametric loop tiling pass -------===//
|
|
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-07-22 04:30:50 -07:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-07-22 04:30:50 -07:00
|
|
|
//
|
|
|
|
|
// This file implements a pass to parametrically tile nests of standard loops.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2020-05-11 15:00:48 +02:00
|
|
|
#include "mlir/Dialect/SCF/SCF.h"
|
2019-07-22 04:30:50 -07:00
|
|
|
#include "mlir/IR/Builders.h"
|
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
|
#include "mlir/Transforms/LoopUtils.h"
|
|
|
|
|
#include "mlir/Transforms/Passes.h"
|
|
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
|
|
namespace {
|
2019-10-08 18:23:13 -07:00
|
|
|
|
2019-07-22 04:30:50 -07:00
|
|
|
// Extracts fixed-range loops for top-level loop nests with ranges defined in
|
|
|
|
|
// the pass constructor. Assumes loops are permutable.
|
|
|
|
|
class SimpleParametricLoopTilingPass
|
2020-04-07 13:56:16 -07:00
|
|
|
: public PassWrapper<SimpleParametricLoopTilingPass, FunctionPass> {
|
2019-07-22 04:30:50 -07:00
|
|
|
public:
|
2019-12-23 15:54:55 -08:00
|
|
|
SimpleParametricLoopTilingPass() = default;
|
|
|
|
|
SimpleParametricLoopTilingPass(const SimpleParametricLoopTilingPass &) {}
|
|
|
|
|
explicit SimpleParametricLoopTilingPass(ArrayRef<int64_t> outerLoopSizes) {
|
|
|
|
|
sizes = outerLoopSizes;
|
2019-10-08 18:23:13 -07:00
|
|
|
}
|
2019-07-22 04:30:50 -07:00
|
|
|
|
|
|
|
|
void runOnFunction() override {
|
|
|
|
|
FuncOp func = getFunction();
|
2020-05-11 15:00:48 +02:00
|
|
|
func.walk([this](scf::ForOp op) {
|
2019-07-22 04:30:50 -07:00
|
|
|
// Ignore nested loops.
|
2020-05-11 15:00:48 +02:00
|
|
|
if (op.getParentRegion()->getParentOfType<scf::ForOp>())
|
2019-07-22 04:30:50 -07:00
|
|
|
return;
|
|
|
|
|
extractFixedOuterLoops(op, sizes);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 15:54:55 -08:00
|
|
|
ListOption<int64_t> sizes{
|
|
|
|
|
*this, "test-outer-loop-sizes", llvm::cl::MiscFlags::CommaSeparated,
|
|
|
|
|
llvm::cl::desc(
|
|
|
|
|
"fixed number of iterations that the outer loops should have")};
|
2019-07-22 04:30:50 -07:00
|
|
|
};
|
|
|
|
|
} // end namespace
|
|
|
|
|
|
2020-02-12 09:03:40 +00:00
|
|
|
namespace mlir {
|
|
|
|
|
void registerSimpleParametricTilingPass() {
|
|
|
|
|
PassRegistration<SimpleParametricLoopTilingPass>(
|
|
|
|
|
"test-extract-fixed-outer-loops",
|
|
|
|
|
"test application of parametric tiling to the outer loops so that the "
|
|
|
|
|
"ranges of outer loops become static");
|
2019-07-22 04:30:50 -07:00
|
|
|
}
|
2020-02-12 09:03:40 +00:00
|
|
|
} // namespace mlir
|