MLIR-AIE
AIEVectorOpt.cpp
Go to the documentation of this file.
1//===- AIEVectorOpt.cpp -----------------------------------------*- C++ -*-===//
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7// (c) Copyright 2021 Xilinx Inc.
8//
9//===----------------------------------------------------------------------===//
10
13
14#include "mlir/Dialect/MemRef/IR/MemRef.h"
15#include "mlir/Dialect/Vector/IR/VectorOps.h"
16#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
17#include "mlir/Dialect/Vector/Transforms/VectorTransforms.h"
18#include "mlir/IR/PatternMatch.h"
19#include "mlir/Pass/Pass.h"
20#include "mlir/Transforms/DialectConversion.h"
21
22namespace xilinx::AIE {
23#define GEN_PASS_DEF_AIEVECTOROPT
24#include "aie/Dialect/AIE/Transforms/AIEPasses.h.inc"
25} // namespace xilinx::AIE
26
27#define DEBUG_TYPE "aie-vector-opt"
28
29using namespace mlir;
30using namespace xilinx;
31using namespace xilinx::AIE;
32
34 : xilinx::AIE::impl::AIEVectorOptBase<AIEVectorOptPass> {
35 void getDependentDialects(DialectRegistry &registry) const override {
36 registry.insert<func::FuncDialect>();
37 registry.insert<memref::MemRefDialect>();
38 }
39 void runOnOperation() override {
40 func::FuncOp f = getOperation();
41
42 // Initial store->load forwarding
43 IRRewriter rewriter(&getContext());
44 vector::transferOpflowOpt(rewriter, f);
45
46 ConversionTarget target(getContext());
47 target.addLegalDialect<memref::MemRefDialect>();
48 target.addLegalOp<vector::BroadcastOp>();
49 // To start with, we're mainly interested in eliminating TransferRead ops
50 // that can be converted to load + broadcast
51 target.addDynamicallyLegalOp<vector::TransferReadOp>(
52 [](vector::TransferReadOp op) { return false; });
53 RewritePatternSet patterns(&getContext());
54 vector::populateVectorTransferLoweringPatterns(patterns);
55 vector::populateVectorMaskMaterializationPatterns(patterns, true);
56
57 if (failed(applyPartialConversion(f, target, std::move(patterns))))
58 signalPassFailure();
59 }
60};
61
62std::unique_ptr<OperationPass<func::FuncOp>> AIE::createAIEVectorOptPass() {
63 return std::make_unique<AIEVectorOptPass>();
64}
Include the generated interface declarations.
std::unique_ptr< mlir::OperationPass< mlir::func::FuncOp > > createAIEVectorOptPass()
void runOnOperation() override
void getDependentDialects(DialectRegistry &registry) const override