Files
clang-p2996/mlir/test/lib/Transforms/TestVectorToSCFConversion.cpp
Nicolas Vasilache 7c3c5b11b1 [mlir][Vector] Add option to fully unroll for VectorTransfer to SCF lowering
Summary:
Previously, the only support partial lowering from vector transfers to SCF was
going through loops. This requires a dedicated allocation and extra memory
roundtrips because LLVM aggregates cannot be indexed dynamically (for more
details see the [deep-dive](https://mlir.llvm.org/docs/Dialects/Vector/#deeperdive)).

This revision allows specifying full unrolling which removes this additional roundtrip.
This should be used carefully though because full unrolling will spill, negating the
benefits of removing the interim alloc in the first place.

Proper heuristics are left for a later time.

Differential Revision: https://reviews.llvm.org/D80100
2020-05-20 11:02:13 -04:00

49 lines
1.5 KiB
C++

//===- TestVectorToSCFConversion.cpp - Test VectorTransfers lowering ------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include <type_traits>
#include "mlir/Conversion/VectorToSCF/VectorToSCF.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/Passes.h"
using namespace mlir;
namespace {
struct TestVectorToSCFPass
: public PassWrapper<TestVectorToSCFPass, FunctionPass> {
TestVectorToSCFPass() = default;
TestVectorToSCFPass(const TestVectorToSCFPass &pass) {}
Option<bool> fullUnroll{
*this, "full-unroll",
llvm::cl::desc(
"Perform full unrolling when converting vector transfers to SCF"),
llvm::cl::init(false)};
void runOnFunction() override {
OwningRewritePatternList patterns;
auto *context = &getContext();
populateVectorToSCFConversionPatterns(
patterns, context, VectorTransferToSCFOptions().setUnroll(fullUnroll));
applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
} // end anonymous namespace
namespace mlir {
void registerTestVectorToSCFPass() {
PassRegistration<TestVectorToSCFPass> pass(
"test-convert-vector-to-scf",
"Converts vector transfer ops to loops over scalars and vector casts");
}
} // namespace mlir