MLIR-AIE 1.4.5.dev
AIESubstituteShimDMAAllocations.cpp
Go to the documentation of this file.
1//===- AIESubstituteShimDMAAllocations.cpp -----------------------*- C++
2//-*-===//
3//
4// Copyright (C) 2024 Advanced Micro Devices, Inc.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <algorithm>
10#include <iterator>
11
15
16#include "mlir/IR/PatternMatch.h"
17#include "mlir/IR/SymbolTable.h"
18#include "mlir/Pass/Pass.h"
19
20namespace xilinx::AIEX {
21#define GEN_PASS_DEF_AIESUBSTITUTESHIMDMAALLOCATIONS
22#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
23} // namespace xilinx::AIEX
24
25using namespace mlir;
26using namespace xilinx;
27using namespace xilinx::AIEX;
28
29namespace {
30
31struct AIESubstituteShimDMAAllocationsPass
32 : xilinx::AIEX::impl::AIESubstituteShimDMAAllocationsBase<
33 AIESubstituteShimDMAAllocationsPass> {
34
35 void runOnOperation() override {
36 AIE::DeviceOp device = getOperation();
37 mlir::SymbolTable symbolTable(device);
38
39 SmallVector<DMAConfigureTaskForOp> tasks;
40 device.walk([&](DMAConfigureTaskForOp op) { tasks.push_back(op); });
41
42 IRRewriter rewriter(&getContext());
43 for (DMAConfigureTaskForOp op : tasks) {
44 AIE::ShimDMAAllocationOp alloc_op =
45 symbolTable.lookup<AIE::ShimDMAAllocationOp>(
46 op.getAlloc().getRootReference());
47 if (!alloc_op) {
48 op.emitOpError("no shim DMA allocation found for symbol");
49 return signalPassFailure();
50 }
51
52 AIE::TileOp tile = alloc_op.getTileOp();
53 if (!tile) {
54 op.emitOpError("shim DMA allocation must reference a valid TileOp");
55 return signalPassFailure();
56 }
57
58 rewriter.setInsertionPoint(op);
59 DMAConfigureTaskOp new_op = DMAConfigureTaskOp::create(
60 rewriter, op.getLoc(), rewriter.getIndexType(), tile.getResult(),
61 alloc_op.getChannelDirAttr(),
62 rewriter.getI32IntegerAttr((int32_t)alloc_op.getChannelIndex()),
63 rewriter.getBoolAttr(op.getIssueToken()),
64 rewriter.getI32IntegerAttr(op.getRepeatCount()),
65 /*repeat_count_val=*/op.getRepeatCountVal(),
66 alloc_op.getPacket().value_or(nullptr));
67 rewriter.replaceAllUsesWith(op.getResult(), new_op.getResult());
68 rewriter.inlineRegionBefore(op.getBody(), new_op.getBody(),
69 new_op.getBody().begin());
70 rewriter.eraseOp(op);
71 }
72 }
73};
74
75} // namespace
76
77std::unique_ptr<OperationPass<AIE::DeviceOp>>
79 return std::make_unique<AIESubstituteShimDMAAllocationsPass>();
80}
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIESubstituteShimDMAAllocationsPass()