2019-12-10 11:54:00 -08:00
|
|
|
//===- TestVectorToVectorConversion.cpp - Test VectorTransfers lowering ---===//
|
2019-11-20 10:54:45 -08:00
|
|
|
//
|
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-11-20 10:54:45 -08:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-11-20 10:54:45 -08:00
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
2020-02-21 11:54:49 -08:00
|
|
|
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
2020-03-17 15:24:27 -07:00
|
|
|
#include "mlir/Dialect/Vector/VectorOps.h"
|
|
|
|
|
#include "mlir/Dialect/Vector/VectorTransforms.h"
|
2019-11-20 10:54:45 -08:00
|
|
|
#include "mlir/IR/PatternMatch.h"
|
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
|
|
|
|
|
|
using namespace mlir;
|
2019-12-10 11:54:00 -08:00
|
|
|
using namespace mlir::vector;
|
2019-11-20 10:54:45 -08:00
|
|
|
namespace {
|
2020-01-24 16:23:54 -08:00
|
|
|
|
2019-12-10 11:54:00 -08:00
|
|
|
#include "TestVectorTransformPatterns.h.inc"
|
2019-11-20 10:54:45 -08:00
|
|
|
|
|
|
|
|
struct TestVectorToVectorConversion
|
2020-04-07 13:56:16 -07:00
|
|
|
: public PassWrapper<TestVectorToVectorConversion, FunctionPass> {
|
2019-11-20 10:54:45 -08:00
|
|
|
void runOnFunction() override {
|
|
|
|
|
OwningRewritePatternList patterns;
|
|
|
|
|
auto *context = &getContext();
|
2019-12-10 11:54:00 -08:00
|
|
|
populateWithGenerated(context, &patterns);
|
|
|
|
|
populateVectorToVectorCanonicalizationPatterns(patterns, context);
|
2019-12-10 17:02:17 -08:00
|
|
|
populateVectorToVectorTransformationPatterns(patterns, context);
|
2020-04-05 06:54:16 +05:30
|
|
|
applyPatternsAndFoldGreedily(getFunction(), patterns);
|
2019-11-20 10:54:45 -08:00
|
|
|
}
|
|
|
|
|
};
|
2020-01-24 16:23:54 -08:00
|
|
|
|
|
|
|
|
struct TestVectorSlicesConversion
|
2020-04-07 13:56:16 -07:00
|
|
|
: public PassWrapper<TestVectorSlicesConversion, FunctionPass> {
|
2020-01-24 16:23:54 -08:00
|
|
|
void runOnFunction() override {
|
|
|
|
|
OwningRewritePatternList patterns;
|
|
|
|
|
populateVectorSlicesLoweringPatterns(patterns, &getContext());
|
2020-04-05 06:54:16 +05:30
|
|
|
applyPatternsAndFoldGreedily(getFunction(), patterns);
|
2020-01-24 16:23:54 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-13 14:50:07 -08:00
|
|
|
struct TestVectorContractionConversion
|
2020-04-07 13:56:16 -07:00
|
|
|
: public PassWrapper<TestVectorContractionConversion, FunctionPass> {
|
2020-03-17 22:51:21 -04:00
|
|
|
TestVectorContractionConversion() = default;
|
|
|
|
|
TestVectorContractionConversion(const TestVectorContractionConversion &pass) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Option<bool> lowerToLLVMMatrixIntrinsics{
|
|
|
|
|
*this, "vector-lower-matrix-intrinsics",
|
|
|
|
|
llvm::cl::desc("Lower vector.contract to llvm.intr.matrix.multiply"),
|
|
|
|
|
llvm::cl::init(false)};
|
|
|
|
|
|
2020-02-13 14:50:07 -08:00
|
|
|
void runOnFunction() override {
|
|
|
|
|
OwningRewritePatternList patterns;
|
2020-03-17 22:51:21 -04:00
|
|
|
VectorTransformsOptions options{
|
|
|
|
|
/*lowerToLLVMMatrixIntrinsics=*/lowerToLLVMMatrixIntrinsics};
|
|
|
|
|
populateVectorContractLoweringPatterns(patterns, &getContext(), options);
|
2020-04-05 06:54:16 +05:30
|
|
|
applyPatternsAndFoldGreedily(getFunction(), patterns);
|
2020-02-13 14:50:07 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-20 10:54:45 -08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
2020-02-12 09:03:40 +00:00
|
|
|
namespace mlir {
|
|
|
|
|
void registerTestVectorConversions() {
|
2020-02-13 14:50:07 -08:00
|
|
|
PassRegistration<TestVectorToVectorConversion> vectorToVectorPass(
|
2020-02-12 09:03:40 +00:00
|
|
|
"test-vector-to-vector-conversion",
|
|
|
|
|
"Test conversion patterns between ops in the vector dialect");
|
2020-01-24 16:23:54 -08:00
|
|
|
|
2020-02-13 14:50:07 -08:00
|
|
|
PassRegistration<TestVectorSlicesConversion> slicesPass(
|
2020-02-12 09:03:40 +00:00
|
|
|
"test-vector-slices-conversion",
|
|
|
|
|
"Test conversion patterns that lower slices ops in the vector dialect");
|
2020-02-13 14:50:07 -08:00
|
|
|
|
|
|
|
|
PassRegistration<TestVectorContractionConversion> contractionPass(
|
|
|
|
|
"test-vector-contraction-conversion",
|
|
|
|
|
"Test conversion patterns that lower contract ops in the vector dialect");
|
2020-02-12 09:03:40 +00:00
|
|
|
}
|
|
|
|
|
} // namespace mlir
|