MLIR-AIE
AIEPlaceTiles.cpp
Go to the documentation of this file.
1//===- AIEPlaceTiles.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 2026 Advanced Micro Devices, Inc.
8//
9//===----------------------------------------------------------------------===//
10
14
15#include "mlir/IR/PatternMatch.h"
16#include "mlir/Transforms/DialectConversion.h"
17
18namespace xilinx::AIE {
19#define GEN_PASS_DEF_AIEPLACETILES
20#include "aie/Dialect/AIE/Transforms/AIEPasses.h.inc"
21} // namespace xilinx::AIE
22
23#define DEBUG_TYPE "aie-place-tiles"
24
25using namespace mlir;
26using namespace xilinx;
27using namespace xilinx::AIE;
28
29namespace {
30
31struct ConvertLogicalTileToTile : OpConversionPattern<LogicalTileOp> {
32 ConvertLogicalTileToTile(MLIRContext *context, DeviceOp &d, Placer &p,
33 PatternBenefit benefit = 1)
34 : OpConversionPattern(context, benefit), device(d), placer(p) {}
35
36 LogicalResult
37 matchAndRewrite(LogicalTileOp logicalTile, OpAdaptor adaptor,
38 ConversionPatternRewriter &rewriter) const override {
39 auto placement = placer.getPlacement(logicalTile);
40 if (!placement)
41 return logicalTile.emitError("no placement found for logical tile");
42
43 // Handle merging multiple logical tiles to same physical tile
44 TileOp tileOp =
45 TileOp::getOrCreate(rewriter, device, placement->col, placement->row);
46
47 if (auto scheme = logicalTile.getAllocationScheme())
48 tileOp.setAllocationScheme(scheme);
49
50 rewriter.replaceOp(logicalTile, tileOp.getResult());
51 return success();
52 }
53
54private:
55 DeviceOp device;
56 Placer &placer;
57};
58
59struct AIEPlaceTilesPass
60 : xilinx::AIE::impl::AIEPlaceTilesBase<AIEPlaceTilesPass> {
61 void runOnOperation() override {
62 DeviceOp device = getOperation();
63
64 // Create placer
65 std::shared_ptr<Placer> placer;
66 switch (clPlacerType) {
67 case PlacerType::SequentialPlacer: {
68 std::optional<int> coresPerCol = std::nullopt;
69 if (clCoresPerCol >= 0)
70 coresPerCol = clCoresPerCol;
71 placer = std::make_shared<SequentialPlacer>(coresPerCol);
72 break;
73 }
74 }
75
76 placer->initialize(device.getTargetModel());
77 if (failed(placer->place(device)))
78 return signalPassFailure();
79
80 ConversionTarget target(getContext());
81 target.addLegalOp<TileOp>();
82 target.addIllegalOp<LogicalTileOp>();
83 target.addLegalDialect<AIEDialect>();
84
85 RewritePatternSet patterns(&getContext());
86 patterns.add<ConvertLogicalTileToTile>(device.getContext(), device,
87 *placer);
88
89 if (failed(applyPartialConversion(device, target, std::move(patterns))))
90 return signalPassFailure();
91 }
92};
93
94} // namespace
95
96std::unique_ptr<OperationPass<DeviceOp>> AIE::createAIEPlaceTilesPass() {
97 return std::make_unique<AIEPlaceTilesPass>();
98}
Include the generated interface declarations.
std::unique_ptr< mlir::OperationPass< DeviceOp > > createAIEPlaceTilesPass()