16#include "mlir/IR/PatternMatch.h"
17#include "mlir/IR/SymbolTable.h"
18#include "mlir/Pass/Pass.h"
21#define GEN_PASS_DEF_AIESUBSTITUTESHIMDMAALLOCATIONS
22#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
31struct AIESubstituteShimDMAAllocationsPass
32 : xilinx::AIEX::impl::AIESubstituteShimDMAAllocationsBase<
33 AIESubstituteShimDMAAllocationsPass> {
35 void runOnOperation()
override {
36 AIE::DeviceOp device = getOperation();
37 mlir::SymbolTable symbolTable(device);
39 SmallVector<DMAConfigureTaskForOp> tasks;
40 device.walk([&](DMAConfigureTaskForOp op) { tasks.push_back(op); });
42 IRRewriter rewriter(&getContext());
43 for (DMAConfigureTaskForOp op : tasks) {
44 AIE::ShimDMAAllocationOp alloc_op =
45 symbolTable.lookup<AIE::ShimDMAAllocationOp>(
46 op.getAlloc().getRootReference());
48 op.emitOpError(
"no shim DMA allocation found for symbol");
49 return signalPassFailure();
52 AIE::TileOp tile = alloc_op.getTileOp();
54 op.emitOpError(
"shim DMA allocation must reference a valid TileOp");
55 return signalPassFailure();
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 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());
77std::unique_ptr<OperationPass<AIE::DeviceOp>>
79 return std::make_unique<AIESubstituteShimDMAAllocationsPass>();
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIESubstituteShimDMAAllocationsPass()