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
22#define DEBUG_TYPE "aie-vector-opt"
23
24using namespace mlir;
25using namespace xilinx;
26using namespace xilinx::AIE;
27
28struct AIEVectorOptPass : AIEVectorOptBase<AIEVectorOptPass> {
29 void getDependentDialects(DialectRegistry &registry) const override {
30 registry.insert<func::FuncDialect>();
31 registry.insert<memref::MemRefDialect>();
32 }
33 void runOnOperation() override {
34 func::FuncOp f = getOperation();
35
36 // Initial store->load forwarding
37 IRRewriter rewriter(&getContext());
38 vector::transferOpflowOpt(rewriter, f);
39
40 ConversionTarget target(getContext());
41 target.addLegalDialect<memref::MemRefDialect>();
42 target.addLegalOp<vector::BroadcastOp>();
43 // To start with, we're mainly interested in eliminating TransferRead ops
44 // that can be converted to load + broadcast
45 target.addDynamicallyLegalOp<vector::TransferReadOp>(
46 [](vector::TransferReadOp op) { return false; });
47 RewritePatternSet patterns(&getContext());
48 vector::populateVectorTransferLoweringPatterns(patterns);
49 vector::populateVectorMaskMaterializationPatterns(patterns, true);
50
51 if (failed(applyPartialConversion(f, target, std::move(patterns))))
52 signalPassFailure();
53 }
54};
55
56std::unique_ptr<OperationPass<func::FuncOp>> AIE::createAIEVectorOptPass() {
57 return std::make_unique<AIEVectorOptPass>();
58}
Include the generated interface declarations.
std::unique_ptr< mlir::OperationPass< mlir::func::FuncOp > > createAIEVectorOptPass()
void runOnOperation() override
void getDependentDialects(DialectRegistry &registry) const override