13#include "mlir/Pass/Pass.h"
20#define GEN_PASS_DEF_AIEASSIGNPACKETIDS
21#include "aie/Dialect/AIE/Transforms/AIEPasses.h.inc"
26struct AIEAssignPacketIdsPass
27 :
public xilinx::AIE::impl::AIEAssignPacketIdsBase<AIEAssignPacketIdsPass> {
30 void runOnOperation()
override {
31 DeviceOp device = getOperation();
32 PacketIdSpace space(device);
36 for (
auto route : device.getOps<RouteOp>()) {
37 std::optional<PacketInfoAttr> packet = route.getPacket();
38 if (packet && packet->isAssigned() &&
39 packet->assignedId() > space.
maxId()) {
40 route.emitOpError(
"pkt_id ")
41 << packet->assignedId() <<
" is out of range (max " << space.
maxId()
43 return signalPassFailure();
51 SmallVector<RouteOp> unpinned;
52 for (
auto route : device.getOps<RouteOp>()) {
53 std::optional<PacketInfoAttr> packet = route.getPacket();
54 if ((packet || clPacketSwObjectFifos) &&
55 !(packet && packet->isAssigned()))
56 unpinned.push_back(route);
58 if (unpinned.size() > 1) {
60 llvm::stable_sort(unpinned, [&](RouteOp a, RouteOp b) {
61 return rank.lookup(a) < rank.lookup(b);
69 DenseMap<StringRef, DMAStartOp> dmaStartByEndpoint;
70 device.walk([&](DMAStartOp start) {
71 if (FlatSymbolRefAttr name = start.getEndpoint())
72 dmaStartByEndpoint.try_emplace(name.getValue(), start);
75 for (
auto route : unpinned) {
76 std::optional<PacketInfoAttr> packet = route.getPacket();
77 for (StringRef source : route.getSourceNames()) {
78 auto it = dmaStartByEndpoint.find(source);
79 if (it == dmaStartByEndpoint.end())
81 it->second.emitOpError(
"names @")
83 <<
", the source of a packet-switched route without a pinned "
84 "pkt_id; pin pkt_id on each route it sources and state that "
85 "header in each of the program's BDs";
86 return signalPassFailure();
90 route.emitOpError(
"max number of packet IDs reached");
91 return signalPassFailure();
93 uint16_t type = packet ? packet->getPktType() : 0;
94 route.setPacketAttr(PacketInfoAttr::get(device.getContext(), type, *
id));
101std::unique_ptr<OperationPass<DeviceOp>>
103 return std::make_unique<AIEAssignPacketIdsPass>();
106std::unique_ptr<OperationPass<DeviceOp>>
108 AIEAssignPacketIdsOptions options;
109 options.clPacketSwObjectFifos = packetSwitched;
110 return std::make_unique<AIEAssignPacketIdsPass>(options);
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.
int maxId() const
The largest id the target's header field holds.
std::unique_ptr< mlir::OperationPass< DeviceOp > > createAIEAssignPacketIdsPass()
llvm::DenseMap< mlir::Operation *, unsigned > rank() const
Rank the nodes by their features and then, a round at a time until no class splits,...
static StructuralGraph of(DeviceOp device)
The ops directly in device but its runtime sequences, each with the ops nested in it,...