MLIR-AIE 1.4.5.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// A tile's buffer-descriptor ids are one shared pool, but the static tile
9// program and the runtime sequence get their ids from two separate passes that
10// do not see each other. This prepass records those compile-time-pinned runtime
11// ids per tile as an aiex.reserved_bd_ids attribute on each aie.tile.
12//
13//===----------------------------------------------------------------------===//
14
18
19#include "mlir/Pass/Pass.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/SmallVector.h"
22
23#include <set>
24
25namespace xilinx::AIEX {
26#define GEN_PASS_DEF_AIERESERVERUNTIMEBDIDS
27#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
28} // namespace xilinx::AIEX
29
30using namespace mlir;
31using namespace xilinx;
32using namespace xilinx::AIE;
33using namespace xilinx::AIEX;
34
35namespace {
36
37struct AIEReserveRuntimeBDIDsPass
38 : xilinx::AIEX::impl::AIEReserveRuntimeBDIDsBase<
39 AIEReserveRuntimeBDIDsPass> {
40
41 void runOnOperation() override {
42 DeviceOp device = getOperation();
43
44 llvm::DenseMap<TileOp, std::set<int32_t>> reserved;
45 device.walk([&](DMAConfigureTaskOp cfg) {
46 TileOp tile = cfg.tryGetTileOp();
47 if (!tile)
48 return;
49 cfg.walk([&](DMABDOp bd) {
50 if (bd.getBdId().has_value())
51 reserved[tile].insert(bd.getBdId().value());
52 });
53 });
54
55 for (auto &[tile, ids] : reserved) {
56 SmallVector<int32_t> sorted(ids.begin(), ids.end());
57 tile->setAttr("aiex.reserved_bd_ids",
58 DenseI32ArrayAttr::get(&getContext(), sorted));
59 }
60 }
61};
62
63} // namespace
64
65std::unique_ptr<mlir::OperationPass<AIE::DeviceOp>>
67 return std::make_unique<AIEReserveRuntimeBDIDsPass>();
68}
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIEReserveRuntimeBDIDsPass()