2019-07-19 19:47:27 +08:00
|
|
|
//===- TestLoopMapping.cpp --- Parametric loop mapping pass ---------------===//
|
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-07-19 19:47:27 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-07-19 19:47:27 +08:00
|
|
|
//
|
2020-05-13 18:12:30 +08:00
|
|
|
// This file implements a pass to parametrically map scf.for loops to virtual
|
2019-07-19 19:47:27 +08:00
|
|
|
// processing element dimensions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-05-11 21:00:48 +08:00
|
|
|
#include "mlir/Dialect/SCF/SCF.h"
|
2019-07-19 19:47:27 +08:00
|
|
|
#include "mlir/IR/Builders.h"
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
#include "mlir/Transforms/LoopUtils.h"
|
|
|
|
#include "mlir/Transforms/Passes.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
namespace {
|
2020-04-08 04:56:16 +08:00
|
|
|
class TestLoopMappingPass
|
|
|
|
: public PassWrapper<TestLoopMappingPass, FunctionPass> {
|
2019-07-19 19:47:27 +08:00
|
|
|
public:
|
|
|
|
explicit TestLoopMappingPass() {}
|
|
|
|
|
|
|
|
void runOnFunction() override {
|
|
|
|
FuncOp func = getFunction();
|
|
|
|
|
|
|
|
// SSA values for the transformation are created out of thin air by
|
|
|
|
// unregistered "new_processor_id_and_range" operations. This is enough to
|
|
|
|
// emulate mapping conditions.
|
2019-12-24 06:45:01 +08:00
|
|
|
SmallVector<Value, 8> processorIds, numProcessors;
|
2019-07-19 19:47:27 +08:00
|
|
|
func.walk([&processorIds, &numProcessors](Operation *op) {
|
|
|
|
if (op->getName().getStringRef() != "new_processor_id_and_range")
|
|
|
|
return;
|
|
|
|
processorIds.push_back(op->getResult(0));
|
|
|
|
numProcessors.push_back(op->getResult(1));
|
|
|
|
});
|
|
|
|
|
2020-05-11 21:00:48 +08:00
|
|
|
func.walk([&processorIds, &numProcessors](scf::ForOp op) {
|
2019-07-19 19:47:27 +08:00
|
|
|
// Ignore nested loops.
|
2020-05-11 21:00:48 +08:00
|
|
|
if (op.getParentRegion()->getParentOfType<scf::ForOp>())
|
2019-07-19 19:47:27 +08:00
|
|
|
return;
|
|
|
|
mapLoopToProcessorIds(op, processorIds, numProcessors);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2020-11-05 05:18:26 +08:00
|
|
|
} // namespace
|
2019-07-19 19:47:27 +08:00
|
|
|
|
2020-02-12 17:03:40 +08:00
|
|
|
namespace mlir {
|
2020-11-05 05:18:26 +08:00
|
|
|
namespace test {
|
2020-02-12 17:03:40 +08:00
|
|
|
void registerTestLoopMappingPass() {
|
|
|
|
PassRegistration<TestLoopMappingPass>(
|
|
|
|
"test-mapping-to-processing-elements",
|
|
|
|
"test mapping a single loop on a virtual processor grid");
|
|
|
|
}
|
2020-11-05 05:18:26 +08:00
|
|
|
} // namespace test
|
2020-02-12 17:03:40 +08:00
|
|
|
} // namespace mlir
|