19#include "mlir/Pass/Pass.h"
20#include "mlir/Transforms/DialectConversion.h"
21#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22#include "llvm/ADT/TypeSwitch.h"
25#define GEN_PASS_DEF_AIESUBSTITUTESHIMDMAALLOCATIONS
26#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
35struct DMAConfigureTaskForOpPattern
36 :
public mlir::OpRewritePattern<DMAConfigureTaskForOp> {
38 using OpRewritePattern::OpRewritePattern;
40 LogicalResult matchAndRewrite(DMAConfigureTaskForOp op,
41 PatternRewriter &rewriter)
const override {
42 AIE::DeviceOp device = op->getParentOfType<AIE::DeviceOp>();
44 AIE::ShimDMAAllocationOp alloc_op = AIE::ShimDMAAllocationOp::getForSymbol(
45 device, op.getAlloc().getRootReference());
47 return op.emitOpError(
"no shim DMA allocation found for symbol");
50 AIE::TileOp tile = alloc_op.getTileOp();
52 return op.emitOpError(
53 "shim DMA allocation must reference a valid TileOp");
56 DMAConfigureTaskOp new_op = DMAConfigureTaskOp::create(
57 rewriter, op.getLoc(), rewriter.getIndexType(), tile.getResult(),
58 alloc_op.getChannelDir(), (int32_t)alloc_op.getChannelIndex(),
59 op.getIssueToken(), op.getRepeatCount(),
60 alloc_op.getPacket().value_or(
nullptr));
61 rewriter.replaceAllUsesWith(op.getResult(), new_op.getResult());
62 rewriter.inlineRegionBefore(op.getBody(), new_op.getBody(),
63 new_op.getBody().begin());
69struct AIESubstituteShimDMAAllocationsPass
70 : xilinx::AIEX::impl::AIESubstituteShimDMAAllocationsBase<
71 AIESubstituteShimDMAAllocationsPass> {
73 void runOnOperation()
override {
74 AIE::DeviceOp device = getOperation();
78 RewritePatternSet patterns(&getContext());
79 patterns.insert<DMAConfigureTaskForOpPattern>(&getContext());
81 (void)applyPatternsGreedily(device, std::move(patterns));
87std::unique_ptr<OperationPass<AIE::DeviceOp>>
89 return std::make_unique<AIESubstituteShimDMAAllocationsPass>();
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIESubstituteShimDMAAllocationsPass()