MLIR-AIE 1.4.6.dev
AIEReserveRuntimeBDIDs.cpp
Go to the documentation of this file.
1//===- AIEReserveRuntimeBDIDs.cpp -------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2026 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7//
8// Records compile-time-pinned runtime-sequence BD ids on each aie.tile so the
9// static BD assignment avoids them: aiex.reserved_bd_ids for ids held in every
10// pool of the tile, aiex.reserved_channel_bd_ids for one channel's pool only.
11//
12//===----------------------------------------------------------------------===//
13
19
20#include "mlir/Pass/Pass.h"
21#include "llvm/ADT/MapVector.h"
22#include "llvm/ADT/SmallVector.h"
23
24namespace xilinx::AIEX {
25#define GEN_PASS_DEF_AIERESERVERUNTIMEBDIDS
26#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
27} // namespace xilinx::AIEX
28
29using namespace mlir;
30using namespace xilinx;
31using namespace xilinx::AIE;
32using namespace xilinx::AIEX;
33
34namespace {
35
36struct AIEReserveRuntimeBDIDsPass
37 : xilinx::AIEX::impl::AIEReserveRuntimeBDIDsBase<
38 AIEReserveRuntimeBDIDsPass> {
39
40 void runOnOperation() override {
41 DeviceOp device = getOperation();
42
43 const AIETargetModel &targetModel = device.getTargetModel();
44 llvm::MapVector<TileOp, SmallVector<ReservedBdId>> reserved;
46 device, [&](Operation *, Operation *tile, std::optional<int> channel,
47 std::optional<DMAChannelDir> dir, int32_t id) {
48 auto placed = dyn_cast<TileOp>(tile);
49 if (!placed)
50 return;
51 // Reserve tile-wide unless that takes the id from other pools.
52 ReservedBdId r{std::nullopt, id};
53 BdIdGenerator gen(placed.getCol(), placed.getRow(), targetModel);
54 if (channel && dir && id >= 0 &&
55 !gen.holdsTileWide(*channel, *dir, static_cast<uint32_t>(id)))
56 r.channel = std::make_pair(*channel, *dir);
57 reserved[placed].push_back(r);
58 });
59
60 for (auto &[tile, ids] : reserved)
61 setReservedBdIds(tile, ids);
62 }
63};
64
65} // namespace
66
67std::unique_ptr<mlir::OperationPass<AIE::DeviceOp>>
69 return std::make_unique<AIEReserveRuntimeBDIDsPass>();
70}
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIEReserveRuntimeBDIDsPass()
void forEachRuntimePinnedBdId(AIE::DeviceOp device, llvm::function_ref< void(Operation *op, Operation *tile, std::optional< int > channel, std::optional< AIE::DMAChannelDir > dir, int32_t id)> pinned)
Definition AIEUtils.cpp:599
void setReservedBdIds(TileOp tile, llvm::ArrayRef< ReservedBdId > ids)
bool holdsTileWide(int channelIndex, DMAChannelDir dir, uint32_t bdId) const
std::optional< std::pair< int, DMAChannelDir > > channel