This revision adds a helper function to hoist vector.transfer_read / vector.transfer_write pairs out of immediately enclosing scf::ForOp iteratively, if the following conditions are true: 1. The 2 ops access the same memref with the same indices. 2. All operands are invariant under the enclosing scf::ForOp. 3. No uses of the memref either dominate the transfer_read or are dominated by the transfer_write (i.e. no aliasing between the write and the read across the loop) To improve hoisting opportunities, call the `moveLoopInvariantCode` helper function on the candidate loop above which to hoist. Hoisting the transfers results in scf::ForOp yielding the value that originally transited through memory. This revision additionally exposes `moveLoopInvariantCode` as a helper in LoopUtils.h and updates SliceAnalysis to support return scf::For values and allow hoisting across multiple scf::ForOps. Differential Revision: https://reviews.llvm.org/D81199
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
//===- TestLinalgHoisting.cpp - Test Linalg hoisting functions ------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements logic for testing Linalg hoisting functions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
|
|
#include "mlir/Dialect/Linalg/Transforms/Hoisting.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::linalg;
|
|
|
|
namespace {
|
|
struct TestLinalgHoisting
|
|
: public PassWrapper<TestLinalgHoisting, FunctionPass> {
|
|
TestLinalgHoisting() = default;
|
|
TestLinalgHoisting(const TestLinalgHoisting &pass) {}
|
|
|
|
void runOnFunction() override;
|
|
|
|
Option<bool> testHoistViewAllocs{
|
|
*this, "test-hoist-view-allocs",
|
|
llvm::cl::desc("Test hoisting alloc used by view"),
|
|
llvm::cl::init(false)};
|
|
Option<bool> testHoistRedundantTransfers{
|
|
*this, "test-hoist-redundant-transfers",
|
|
llvm::cl::desc("Test hoisting transfer_read/transfer_write pairs"),
|
|
llvm::cl::init(false)};
|
|
};
|
|
} // end anonymous namespace
|
|
|
|
void TestLinalgHoisting::runOnFunction() {
|
|
if (testHoistViewAllocs) {
|
|
hoistViewAllocOps(getFunction());
|
|
return;
|
|
}
|
|
if (testHoistRedundantTransfers) {
|
|
hoistRedundantVectorTransfers(getFunction());
|
|
return;
|
|
}
|
|
}
|
|
|
|
namespace mlir {
|
|
void registerTestLinalgHoisting() {
|
|
PassRegistration<TestLinalgHoisting> testTestLinalgHoistingPass(
|
|
"test-linalg-hoisting", "Test Linalg hoisting functions.");
|
|
}
|
|
} // namespace mlir
|