57 DeviceOp targetOp = getOperation();
60 auto memOps = llvm::to_vector_of<TileElement>(targetOp.getOps<MemOp>());
61 llvm::append_range(memOps, targetOp.getOps<MemTileDMAOp>());
62 llvm::append_range(memOps, targetOp.getOps<ShimDMAOp>());
63 for (TileElement memOp : memOps) {
64 int col = memOp.getTileID().col;
65 int row = memOp.getTileID().row;
68 memOp->walk<WalkOrder::PreOrder>([&](DMABDOp bd) {
69 if (bd.getBdId().has_value())
73 auto dmaOps = memOp.getOperation()->getRegion(0).getOps<DMAOp>();
74 if (!dmaOps.empty()) {
75 for (
auto dmaOp : dmaOps) {
76 auto bdRegions = dmaOp.getBds();
77 for (
auto &bdRegion : bdRegions) {
78 auto &block = bdRegion.getBlocks().front();
79 DMABDOp bd = *block.getOps<DMABDOp>().begin();
80 if (bd.getBdId().has_value()) {
83 "bdId assigned by user but not found during previous walk");
85 std::optional<int32_t> next_id =
86 gen.
nextBdId(dmaOp.getChannelIndex());
89 <<
"Allocator exhausted available BD IDs (maximum "
91 return signalPassFailure();
98 DenseMap<Block *, int> blockChannelMap;
101 for (Block &block : memOp.getOperation()->getRegion(0))
102 for (
auto op : block.getOps<DMAStartOp>()) {
103 int chNum = op.getChannelIndex();
104 blockChannelMap[&block] = chNum;
105 Block *dest = op.getDest();
107 blockChannelMap[dest] = chNum;
108 if (dest->hasNoSuccessors())
110 dest = dest->getSuccessors()[0];
111 if (blockChannelMap.contains(dest))
116 for (Block &block : memOp.getOperation()->getRegion(0)) {
117 if (block.getOps<DMABDOp>().empty())
119 assert(blockChannelMap.count(&block));
120 DMABDOp bd = (*block.getOps<DMABDOp>().begin());
121 if (bd.getBdId().has_value()) {
123 "bdId assigned by user but not found during previous walk");
125 std::optional<int32_t> next_id =
126 gen.
nextBdId(blockChannelMap[&block]);
129 <<
"Allocator exhausted available BD IDs (maximum "
131 return signalPassFailure();
133 bd.setBdId(*next_id);
138 for (TileElement memOp : memOps) {
139 auto dmaOps = memOp.getOperation()->getRegion(0).getOps<DMAOp>();
140 if (!dmaOps.empty()) {
141 for (
auto dmaOp : dmaOps) {
142 auto bdRegions = dmaOp.getBds();
143 for (
auto *bdRegionIt = bdRegions.begin();
144 bdRegionIt != bdRegions.end();) {
145 auto &block = bdRegionIt->getBlocks().front();
146 DMABDOp bd = *block.getOps<DMABDOp>().begin();
147 std::optional<int> nextBdId;
148 if (++bdRegionIt != bdRegions.end())
150 (*bdRegionIt->getBlocks().front().getOps<DMABDOp>().begin())
152 else if (dmaOp.getLoop())
153 nextBdId = (*bdRegions.front()
159 bd.setNextBdId(nextBdId);
163 DenseMap<Block *, int> blockBdIdMap;
164 for (Block &block : memOp.getOperation()->getRegion(0)) {
165 if (block.getOps<DMABDOp>().empty())
167 DMABDOp bd = *block.getOps<DMABDOp>().begin();
168 assert(bd.getBdId().has_value() &&
169 "DMABDOp should have bd_id assigned by now");
170 blockBdIdMap[&block] = bd.getBdId().value();
173 for (Block &block : memOp.getOperation()->getRegion(0)) {
174 if (block.getOps<DMABDOp>().empty())
176 DMABDOp bd = *block.getOps<DMABDOp>().begin();
177 std::optional<int> nextBdId;
178 if (block.getNumSuccessors()) {
179 assert(llvm::range_size(block.getSuccessors()) == 1 &&
180 "should have only one successor block");
181 Block *nextBlock = block.getSuccessor(0);
182 if (!blockBdIdMap.contains(nextBlock))
183 assert(nextBlock->getOperations().size() == 1 &&
184 isa<EndOp>(nextBlock->getOperations().front()) &&
185 "bb that's not in blockMap can only have aie.end");
187 nextBdId = blockBdIdMap[nextBlock];
188 bd.setNextBdId(nextBdId);