19#include "mlir/Pass/Pass.h"
20#include "mlir/Transforms/DialectConversion.h"
21#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22#include "llvm/ADT/TypeSwitch.h"
30struct DMAConfigureTaskForOpPattern
31 :
public mlir::OpRewritePattern<DMAConfigureTaskForOp> {
33 using OpRewritePattern::OpRewritePattern;
35 LogicalResult matchAndRewrite(DMAConfigureTaskForOp op,
36 PatternRewriter &rewriter)
const override {
37 AIE::DeviceOp device = op->getParentOfType<AIE::DeviceOp>();
39 AIE::ShimDMAAllocationOp alloc_op =
40 AIE::ShimDMAAllocationOp::getForSymbol(device, op.getAlloc());
42 return op.emitOpError(
"no shim DMA allocation found for symbol");
45 const int col = alloc_op.getCol();
46 AIE::TileOp tile = AIE::TileOp::getOrCreate(rewriter, device, col, 0);
47 DMAConfigureTaskOp new_op = rewriter.create<DMAConfigureTaskOp>(
48 op.getLoc(), rewriter.getIndexType(), tile.getResult(),
49 alloc_op.getChannelDir(), (int32_t)alloc_op.getChannelIndex(),
50 op.getIssueToken(), op.getRepeatCount());
51 rewriter.replaceAllUsesWith(op.getResult(), new_op.getResult());
52 rewriter.inlineRegionBefore(op.getBody(), new_op.getBody(),
53 new_op.getBody().begin());
59struct AIESubstituteShimDMAAllocationsPass
60 : AIESubstituteShimDMAAllocationsBase<AIESubstituteShimDMAAllocationsPass> {
62 void runOnOperation()
override {
63 AIE::DeviceOp device = getOperation();
67 RewritePatternSet patterns(&getContext());
68 patterns.insert<DMAConfigureTaskForOpPattern>(&getContext());
70 (void)applyPatternsGreedily(device, std::move(patterns));
76std::unique_ptr<OperationPass<AIE::DeviceOp>>
78 return std::make_unique<AIESubstituteShimDMAAllocationsPass>();
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIESubstituteShimDMAAllocationsPass()