MLIR-AIE 1.4.6.dev
AIEPacketIdSpace.cpp
Go to the documentation of this file.
1//===- AIEPacketIdSpace.cpp -------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2026 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
9
10using namespace xilinx;
11using namespace xilinx::AIE;
12
13PacketIdSpace::PacketIdSpace(DeviceOp device, bool reserveControllerIds)
14 : max(static_cast<int>(device.getTargetModel().getMaxPacketId())) {
15 if (reserveControllerIds ||
16 AIEDialect::ReserveControllerPacketIdsAttrHelper(device.getContext())
17 .isAttrPresent(device)) {
18 for (auto [tile, id] :
19 device.getTargetModel().getTileToControllerIdMap(true))
20 taken.insert(id);
21 for (auto tile : device.getOps<TileOp>())
22 if (auto id = tile->getAttrOfType<PacketInfoAttr>("controller_id");
23 id && id.isAssigned())
24 taken.insert(id.assignedId());
25 }
26 device.walk([&](PacketFlowOp flow) { taken.insert(flow.IDInt()); });
27 // An id a rule already matches would reach that rule's master too, at any
28 // slave port the rule's rules sit on; an imported overlay's rules match
29 // whole cubes of ids.
30 device.walk([&](PacketRuleOp rule) {
31 for (int id = 0; id <= max; ++id)
32 if ((id & rule.maskInt()) == rule.valueInt())
33 taken.insert(id);
34 });
35 device.walk([&](TracePacketOp packet) {
36 if (std::optional<int32_t> id = packet.getId()) {
37 taken.insert(*id);
38 }
39 });
40 auto pinned = [&](PacketInfoAttr header) {
41 if (header && header.isAssigned()) {
42 taken.insert(header.assignedId());
43 }
44 };
45 for (auto route : device.getOps<RouteOp>()) {
46 pinned(route.getPacketAttr());
47 }
48 for (auto fifo : device.getOps<ObjectFifoCreateOp>()) {
49 pinned(fifo.packetHeader());
50 }
51}
52
53std::optional<int> PacketIdSpace::takeLowestFrom(int from) {
54 for (int id = from; id <= max; id++) {
55 if (taken.insert(id).second) {
56 return id;
57 }
58 }
59 return std::nullopt;
60}
std::optional< int > takeLowestFrom(int from=0)
Takes and returns the lowest free id at or above from, or nothing when the field is exhausted.
PacketIdSpace(DeviceOp device, bool reserveControllerIds=false)
Controller ids are taken when the device carries aie.reserve_controller_packet_ids or reserveControll...
const AIETargetModel & getTargetModel(mlir::Operation *op)