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// 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
19
20#include "mlir/Pass/Pass.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/SmallVector.h"
23
24#include <set>
25
26namespace xilinx::AIEX {
27#define GEN_PASS_DEF_AIERESERVERUNTIMEBDIDS
28#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
29} // namespace xilinx::AIEX
30
31using namespace mlir;
32using namespace xilinx;
33using namespace xilinx::AIE;
34using namespace xilinx::AIEX;
35
36namespace {
37
38struct AIEReserveRuntimeBDIDsPass
39 : xilinx::AIEX::impl::AIEReserveRuntimeBDIDsBase<
40 AIEReserveRuntimeBDIDsPass> {
41
42 void runOnOperation() override {
43 DeviceOp device = getOperation();
44
45 llvm::DenseMap<TileOp, std::set<int32_t>> reserved;
46 forEachRuntimePinnedBdId(device, [&](Operation *, Operation *tile,
47 std::optional<int>, int32_t id) {
48 if (auto placed = dyn_cast<TileOp>(tile))
49 reserved[placed].insert(id);
50 });
51
52 for (auto &[tile, ids] : reserved) {
53 SmallVector<int32_t> sorted(ids.begin(), ids.end());
54 tile->setAttr("aiex.reserved_bd_ids",
55 DenseI32ArrayAttr::get(&getContext(), sorted));
56 }
57 }
58};
59
60} // namespace
61
62std::unique_ptr<mlir::OperationPass<AIE::DeviceOp>>
64 return std::make_unique<AIEReserveRuntimeBDIDsPass>();
65}
void forEachRuntimePinnedBdId(AIE::DeviceOp device, llvm::function_ref< void(Operation *op, Operation *tile, std::optional< int > channel, int32_t id)> pinned)
Definition AIEUtils.cpp:599
std::unique_ptr< mlir::OperationPass< AIE::DeviceOp > > createAIEReserveRuntimeBDIDsPass()