[SplitFunction] support to further split sub-functions into multiple single-loop-function

This commit is contained in:
Hanchen Ye 2021-03-26 22:38:07 -05:00
parent 0cbc1d6bbf
commit dec53d8e36
2 changed files with 24 additions and 2 deletions

View File

@ -70,6 +70,12 @@ def SplitFunction : Pass<"split-function", "ModuleOp"> {
}];
let constructor = "mlir::scalehls::createSplitFunctionPass()";
let options = [
Option<"splitSubFunc", "split-sub-func", "bool", /*default=*/"false",
"Whether to further split the sub-functions so that each generated"
"function only contains one loop band">
];
}
//===----------------------------------------------------------------------===//

View File

@ -14,7 +14,7 @@ using namespace mlir;
using namespace scalehls;
static bool applySplitFunction(FuncOp func, ArrayRef<Operation *> ops,
StringRef name) {
StringRef name, bool splitSubFunc) {
Liveness liveness(func);
auto builder = OpBuilder(func);
@ -152,6 +152,22 @@ static bool applySplitFunction(FuncOp func, ArrayRef<Operation *> ops,
for (auto op : opsToErase)
op->erase();
// Further split each loop band into a function if required.
if (splitSubFunc) {
SmallVector<AffineForOp, 4> loops;
for (auto loop : subFunc.getOps<AffineForOp>())
loops.push_back(loop);
if (loops.size() > 1) {
unsigned index = 0;
for (auto loop : loops) {
auto loopName = std::string(name) + "_loop" + std::to_string(index);
applySplitFunction(subFunc, {loop}, loopName, splitSubFunc);
++index;
}
}
}
return true;
}
@ -172,7 +188,7 @@ struct SplitFunction : public SplitFunctionBase<SplitFunction> {
for (auto pair : dataflowOps) {
auto name = "dataflow" + std::to_string(pair.first);
applySplitFunction(func, pair.second, name);
applySplitFunction(func, pair.second, name, splitSubFunc);
}
}
}