MLIR-AIE 1.4.6.dev
AIEObjectFifoVerify.cpp
Go to the documentation of this file.
1//===- AIEObjectFifoVerify.cpp ----------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2026 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
15
16#include "mlir/Dialect/Arith/IR/Arith.h"
17#include "mlir/Dialect/MemRef/IR/MemRef.h"
18#include "mlir/Dialect/SCF/IR/SCF.h"
19#include "mlir/Dialect/Utils/StaticValueUtils.h"
20#include "mlir/IR/Matchers.h"
21#include "mlir/Interfaces/DataLayoutInterfaces.h"
22#include "mlir/Pass/Pass.h"
23#include "llvm/ADT/MapVector.h"
24#include "llvm/ADT/SetVector.h"
25#include "llvm/ADT/TypeSwitch.h"
26#include "llvm/Support/CheckedArithmetic.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/MathExtras.h"
29
30#include <algorithm>
31#include <functional>
32#include <memory>
33#include <numeric>
34#include <optional>
35
36using namespace mlir;
37using namespace xilinx;
38using namespace xilinx::AIE;
39
40#define DEBUG_TYPE "aie-objectfifo-verify"
41
42namespace xilinx::AIE {
43#define GEN_PASS_DEF_AIEOBJECTFIFOVERIFY
44#include "aie/Dialect/AIE/Transforms/AIEPasses.h.inc"
45} // namespace xilinx::AIE
46
47namespace {
48
49struct SegmentActors {
50 SmallVector<Operation *> fillers;
51 SmallVector<Operation *> drainers;
52};
53
54/// A DMA endpoint with an iteration count moves this many objects through its
55/// pool, then stops.
56struct TransferBudget {
57 ObjectFifoDmaEndpointOp endpoint;
58 int32_t iterations;
59 int64_t objects;
60};
61
62static std::optional<int64_t> getStaticTripCount(scf::ForOp forOp) {
63 if (forOp.getSingleLowerBound() && forOp.getSingleUpperBound() &&
64 forOp.getSingleStep()) {
65 if (std::optional<llvm::APInt> tc = forOp.getStaticTripCount()) {
66 return tc->getSExtValue();
67 }
68 }
69 return std::nullopt;
70}
71
72/// Whether `op` is a loop that runs forever: an `scf.while` on a constant true
73/// condition. An `scf.for` runs its trip count, however large.
74static bool runsForever(Operation *op) {
75 auto whileOp = dyn_cast<scf::WhileOp>(op);
76 return whileOp && isForeverLoop(whileOp);
77}
78
79/// Objects of the fifo `name` still held after `block` runs, entered holding
80/// `held`: an acquire holds at least its count, a release gives its count
81/// back. Unknown when an access sits under anything but a static loop, or a
82/// loop's count has not settled after two passes.
83static std::optional<int64_t> heldAfter(Block &block, StringRef name,
84 int64_t held) {
85 for (Operation &op : block) {
86 if (auto acquire = dyn_cast<ObjectFifoAcquireOp>(op)) {
87 if (acquire.getObjFifoName() == name)
88 held = std::max<int64_t>(held, acquire.acqNumber());
89 continue;
90 }
91 if (auto release = dyn_cast<ObjectFifoReleaseOp>(op)) {
92 if (release.getObjFifoName() == name)
93 held -= release.relNumber();
94 if (held < 0)
95 return std::nullopt;
96 continue;
97 }
98 bool touches = op.getNumRegions() != 0 &&
99 op.walk([&](Operation *inner) {
100 auto acquire = dyn_cast<ObjectFifoAcquireOp>(inner);
101 auto release = dyn_cast<ObjectFifoReleaseOp>(inner);
102 if ((acquire && acquire.getObjFifoName() == name) ||
103 (release && release.getObjFifoName() == name))
104 return WalkResult::interrupt();
105 return WalkResult::advance();
106 }).wasInterrupted();
107 if (!touches)
108 continue;
109 auto forOp = dyn_cast<scf::ForOp>(op);
110 std::optional<int64_t> trip =
111 forOp ? getStaticTripCount(forOp) : std::nullopt;
112 if (!trip)
113 return std::nullopt;
114 if (*trip == 0)
115 continue;
116 std::optional<int64_t> once = heldAfter(*forOp.getBody(), name, held);
117 if (!once)
118 return std::nullopt;
119 if (*trip > 1 && heldAfter(*forOp.getBody(), name, *once) != once)
120 return std::nullopt;
121 held = *once;
122 }
123 return held;
124}
125
126/// The trip count of `forOp`: static, or an upper bound the host writes as
127/// one constant for every dispatch. That is a word of an `aie.buffer` of
128/// 32-bit words the cores only load, which every runtime sequence of the
129/// device writes with the same constant (`aiex.npu.rtp_write`), directly in
130/// its body, before it sets a lock (`aiex.set_lock`) the core waits on ahead
131/// of the load. The lock starts at 0 and each release gives back no more
132/// than the acquire just before it took, so every load follows a write.
133static std::optional<int64_t> tripCount(scf::ForOp forOp, DeviceOp device) {
134 if (std::optional<int64_t> trip = getStaticTripCount(forOp))
135 return trip;
136 std::optional<int64_t> lower = getConstantIntValue(forOp.getLowerBound());
137 std::optional<int64_t> step = getConstantIntValue(forOp.getStep());
138 Value bound = forOp.getUpperBound();
139 if (auto cast = bound.getDefiningOp<arith::IndexCastOp>())
140 bound = cast.getIn();
141 auto load = bound.getDefiningOp<memref::LoadOp>();
142 if (!lower || !step || *step <= 0 || !load || load.getIndices().size() != 1)
143 return std::nullopt;
144 std::optional<int64_t> index = getConstantIntValue(load.getIndices().front());
145 auto buffer = load.getMemRef().getDefiningOp<BufferOp>();
146 // An RTP write's index counts 32-bit words, so only in a buffer of them is
147 // that the element the load reads.
148 auto type = buffer ? dyn_cast<MemRefType>(buffer.getType()) : MemRefType();
149 if (!index || !type || !type.getElementType().isInteger(32) ||
150 !type.getLayout().isIdentity() || !buffer.getSymName() ||
151 buffer.getInitialValue() ||
152 llvm::any_of(buffer->getUsers(),
153 [](Operation *user) { return !isa<memref::LoadOp>(user); }))
154 return std::nullopt;
155
156 UseLockOp wait;
157 for (Operation *prev = load->getPrevNode(); prev && !wait;
158 prev = prev->getPrevNode())
159 if (auto use = dyn_cast<UseLockOp>(prev); use && !use.release())
160 wait = use;
161 std::optional<int64_t> waitsFor =
162 wait ? getConstantIntValue(wait.getValue()) : std::nullopt;
163 LockOp lock = wait ? wait.getLock().getDefiningOp<LockOp>() : LockOp();
164 if (!lock || !wait.acquireGE() || !waitsFor || *waitsFor < 1 ||
165 !wait.getAcqEn() ||
166 wait.getBlocking().value_or(LockBlocking::Blocking) !=
167 LockBlocking::Blocking ||
168 lock.getInit().value_or(0) != 0)
169 return std::nullopt;
170 for (Operation *user : lock->getUsers()) {
171 if (isa<AIEX::SetLockOp>(user))
172 continue;
173 auto use = dyn_cast<UseLockOp>(user);
174 if (!use)
175 return std::nullopt;
176 if (!use.release())
177 continue;
178 std::optional<int64_t> given = getConstantIntValue(use.getValue());
179 UseLockOp before;
180 for (Operation *prev = use->getPrevNode(); prev && !before;
181 prev = prev->getPrevNode())
182 if (auto other = dyn_cast<UseLockOp>(prev);
183 other && other.getLock() == use.getLock())
184 before = other;
185 std::optional<int64_t> taken = before && !before.release()
186 ? getConstantIntValue(before.getValue())
187 : std::nullopt;
188 if (!given || !taken || *given > *taken)
189 return std::nullopt;
190 }
191
192 TileOp tile = buffer.getTileOp();
193 const AIETargetModel &tm = device.getTargetModel();
194 auto reachesTile = [&](FlatSymbolRefAttr named, std::optional<int32_t> col,
195 std::optional<int32_t> row,
196 std::optional<int64_t> address) {
197 if (named)
198 return named.getValue() == *buffer.getSymName();
199 if (!col || !row) {
200 if (!address)
201 return true;
202 col = tm.getColumnFromAddress(static_cast<uint32_t>(*address));
203 row = tm.getRowFromAddress(static_cast<uint32_t>(*address));
204 }
205 return *col == tile.getCol() && *row == tile.getRow();
206 };
207
208 std::optional<int64_t> value;
209 for (auto sequence : device.getOps<RuntimeSequenceOp>()) {
210 bool written = false;
211 WalkResult walk = sequence.walk([&](Operation *op) {
212 bool rawWrite =
213 llvm::TypeSwitch<Operation *, bool>(op)
214 .Case<AIEX::NpuWrite32Op, AIEX::NpuMaskWrite32Op>([&](auto w) {
215 return reachesTile(w.getBufferAttr(), w.getColumn(), w.getRow(),
216 getConstantIntValue(w.getAddress()));
217 })
218 .Case([&](AIEX::NpuBlockWriteOp w) {
219 return reachesTile(w.getBufferAttr(), w.getColumn(), w.getRow(),
220 w.getAddress());
221 })
222 .Case([&](AIEX::NpuPushQueueOp push) {
223 return reachesTile({}, push.getColumn(), push.getRow(), {});
224 })
225 .Default(false);
226 if (rawWrite)
227 return WalkResult::interrupt();
228 if (auto write = dyn_cast<AIEX::NpuWriteRTPOp>(op)) {
229 if (write.getBuffer() != *buffer.getSymName() ||
230 write.getIndex() != *index)
231 return WalkResult::advance();
232 // A write under a branch or a loop may never run.
233 std::optional<int64_t> word = getConstantIntValue(write.getValue());
234 if (write->getParentOp() != sequence || !word ||
235 (value && *value != *word))
236 return WalkResult::interrupt();
237 value = word;
238 written = true;
239 return WalkResult::advance();
240 }
241 auto set = dyn_cast<AIEX::SetLockOp>(op);
242 if (set && set.getLock() == lock.getResult() && !written)
243 return WalkResult::interrupt();
244 return WalkResult::advance();
245 });
246 if (walk.wasInterrupted())
247 return std::nullopt;
248 }
249 if (!value)
250 return std::nullopt;
251 return *value > *lower ? (*value - *lower + *step - 1) / *step : 0;
252}
253
254/// The ratio (in, out) such that a core, once it has released r objects of
255/// `out`, has taken at least r * in / out objects of `in`, at every point.
256///
257/// Each region of the core is summarized by two sets of (taken, released)
258/// pairs: for a ratio k, the smallest taken - k * released over `end` bounds
259/// that value where the region ends, and over `low` at every point inside it,
260/// on every path. A branch may take either arm and a loop whose trip count
261/// `tripCount` cannot tell may run any number of times, so the ratio holds
262/// whatever decides them. Unknown when a branch's arms, or the passes of a
263/// loop whose count is unknown, leave different objects held, or when `in` or
264/// `out` is used under any other region.
265class TakeRatio {
266public:
267 TakeRatio(DeviceOp device, StringRef in, StringRef out)
268 : device(device), in(in), out(out) {}
269
270 std::optional<std::pair<int64_t, int64_t>> of(CoreOp core) {
271 core.walk([&](Operation *op) {
272 if (fifoOf(op) != in && fifoOf(op) != out)
273 return;
274 for (Operation *parent = op->getParentOp(); parent != core;
275 parent = parent->getParentOp())
276 onUsePath.insert(parent);
277 used = true;
278 });
279 Region &body = core.getBody();
280 if (!used || !body.hasOneBlock())
281 return std::nullopt;
282 Held held;
283 std::optional<Effect> effect = analyze(body.front(), held);
284 if (!effect)
285 return std::nullopt;
286 std::optional<Pair> least;
287 for (const Pair &pair : llvm::concat<const Pair>(effect->low, bounds))
288 if (pair.released > 0 && (!least || pair.taken * least->released <
289 least->taken * pair.released))
290 least = pair;
291 if (!least || least->taken == 0)
292 return std::nullopt;
293 int64_t common = std::gcd(least->taken, least->released);
294 return std::make_pair(least->taken / common, least->released / common);
295 }
296
297private:
298 struct Pair {
299 int64_t taken, released;
300 };
301 struct Effect {
302 SmallVector<Pair> end = {{0, 0}}, low = {{0, 0}};
303 };
304 struct Held {
305 int64_t in = 0, out = 0;
306 bool operator==(const Held &other) const {
307 return in == other.in && out == other.out;
308 }
309 };
310 static constexpr size_t maxPairs = 64;
311 static constexpr int64_t maxPeeledPasses = 4096;
312
313 static StringRef fifoOf(Operation *op) {
314 if (auto acquire = dyn_cast<ObjectFifoAcquireOp>(op))
315 return acquire.getObjFifoName();
316 if (auto release = dyn_cast<ObjectFifoReleaseOp>(op))
317 return release.getObjFifoName();
318 return {};
319 }
320
321 // Keeps the pairs no other bounds from below: one with no more taken and no
322 // fewer released gives a smaller taken - k * released for every k >= 0.
323 std::optional<SmallVector<Pair>> prune(ArrayRef<Pair> pairs) {
324 SmallVector<Pair> kept;
325 for (auto [index, pair] : llvm::enumerate(pairs)) {
326 bool dominated = false;
327 for (auto [other, by] : llvm::enumerate(pairs))
328 dominated |= other != index && by.taken <= pair.taken &&
329 by.released >= pair.released &&
330 (by.taken != pair.taken || by.released != pair.released ||
331 other < index);
332 if (!dominated)
333 kept.push_back(pair);
334 }
335 if (kept.size() > maxPairs)
336 return std::nullopt;
337 return kept;
338 }
339
340 std::optional<SmallVector<Pair>> sum(ArrayRef<Pair> a, ArrayRef<Pair> b) {
341 SmallVector<Pair> sums;
342 for (const Pair &x : a)
343 for (const Pair &y : b) {
344 Pair both;
345 if (llvm::AddOverflow(x.taken, y.taken, both.taken) ||
346 llvm::AddOverflow(x.released, y.released, both.released))
347 return std::nullopt;
348 sums.push_back(both);
349 }
350 return prune(sums);
351 }
352
353 std::optional<SmallVector<Pair>> scale(ArrayRef<Pair> pairs, int64_t n) {
354 SmallVector<Pair> scaled;
355 for (const Pair &pair : pairs) {
356 Pair times;
357 if (llvm::MulOverflow(pair.taken, n, times.taken) ||
358 llvm::MulOverflow(pair.released, n, times.released))
359 return std::nullopt;
360 scaled.push_back(times);
361 }
362 return scaled;
363 }
364
365 std::optional<Effect> then(const Effect &first, const Effect &second) {
366 std::optional<SmallVector<Pair>> end = sum(first.end, second.end);
367 std::optional<SmallVector<Pair>> late = sum(first.end, second.low);
368 if (!end || !late)
369 return std::nullopt;
370 std::optional<SmallVector<Pair>> low =
371 prune(llvm::to_vector(llvm::concat<const Pair>(first.low, *late)));
372 if (!low)
373 return std::nullopt;
374 return Effect{*end, *low};
375 }
376
377 std::optional<Effect> either(const Effect &a, const Effect &b) {
378 std::optional<SmallVector<Pair>> end =
379 prune(llvm::to_vector(llvm::concat<const Pair>(a.end, b.end)));
380 std::optional<SmallVector<Pair>> low =
381 prune(llvm::to_vector(llvm::concat<const Pair>(a.low, b.low)));
382 if (!end || !low)
383 return std::nullopt;
384 return Effect{*end, *low};
385 }
386
387 // `n` >= 1 passes of `pass`, each starting with the objects it ends with
388 // held: the value at a point of pass j is j times a pass's end plus a point
389 // of one pass, smallest at j = 0 or j = n - 1.
390 std::optional<Effect> repeat(const Effect &pass, int64_t n) {
391 std::optional<SmallVector<Pair>> end = scale(pass.end, n);
392 std::optional<SmallVector<Pair>> before = scale(pass.end, n - 1);
393 std::optional<SmallVector<Pair>> late =
394 before ? sum(*before, pass.low) : std::nullopt;
395 if (!end || !late)
396 return std::nullopt;
397 std::optional<SmallVector<Pair>> low =
398 prune(llvm::to_vector(llvm::concat<const Pair>(pass.low, *late)));
399 std::optional<SmallVector<Pair>> ends = prune(*end);
400 if (!low || !ends)
401 return std::nullopt;
402 return Effect{*ends, *low};
403 }
404
405 // Any number of passes: the ratio must keep each pass's end at or above
406 // its start, recorded in `bounds`; then a point of pass j is no lower than
407 // a point of one pass, and the end no lower than the start.
408 Effect anyRepeat(const Effect &pass) {
409 llvm::append_range(bounds, pass.end);
410 Effect any;
411 llvm::append_range(any.low, pass.low);
412 return any;
413 }
414
415 std::optional<Effect> analyze(Block &block, Held &held) {
416 Effect effect;
417 for (Operation &op : block) {
418 std::optional<Effect> step = analyzeOp(op, held);
419 if (!step)
420 return std::nullopt;
421 std::optional<Effect> next = then(effect, *step);
422 if (!next)
423 return std::nullopt;
424 effect = *next;
425 }
426 return effect;
427 }
428
429 std::optional<Effect> analyzeOp(Operation &op, Held &held) {
430 StringRef fifo = fifoOf(&op);
431 if (fifo == in || fifo == out) {
432 int64_t &count = fifo == in ? held.in : held.out;
433 Effect effect;
434 if (auto acquire = dyn_cast<ObjectFifoAcquireOp>(op)) {
435 int64_t wanted = acquire.acqNumber();
436 if (fifo == in)
437 effect.end = {{std::max<int64_t>(0, wanted - count), 0}};
438 count = std::max(count, wanted);
439 return effect;
440 }
441 int64_t released = cast<ObjectFifoReleaseOp>(op).relNumber();
442 if (released > count)
443 return std::nullopt;
444 count -= released;
445 if (fifo == out) {
446 effect.end = {{0, released}};
447 effect.low.push_back({0, released});
448 }
449 return effect;
450 }
451 if (!onUsePath.contains(&op))
452 return Effect();
453 if (auto forOp = dyn_cast<scf::ForOp>(op)) {
454 std::optional<int64_t> trip = tripCount(forOp, device);
455 Held entry = held;
456 if (!trip) {
457 std::optional<Effect> pass = analyze(*forOp.getBody(), held);
458 if (!pass || !(held == entry))
459 return std::nullopt;
460 return anyRepeat(*pass);
461 }
462 Effect total;
463 for (int64_t done = 0; done < *trip; ++done) {
464 Held before = held;
465 std::optional<Effect> pass = analyze(*forOp.getBody(), held);
466 std::optional<Effect> rest = pass;
467 // Any number of passes covers this many, where counting overflows.
468 if (pass && held == before) {
469 rest = repeat(*pass, *trip - done);
470 if (!rest)
471 rest = anyRepeat(*pass);
472 }
473 std::optional<Effect> next = rest ? then(total, *rest) : std::nullopt;
474 if (!next || (!(held == before) && done >= maxPeeledPasses))
475 return std::nullopt;
476 total = *next;
477 if (held == before)
478 break;
479 }
480 return total;
481 }
482 if (auto ifOp = dyn_cast<scf::IfOp>(op)) {
483 Held otherwise = held;
484 std::optional<Effect> taken = analyze(ifOp.getThenRegion().front(), held);
485 std::optional<Effect> skipped =
486 ifOp.getElseRegion().empty()
487 ? Effect()
488 : analyze(ifOp.getElseRegion().front(), otherwise);
489 if (!taken || !skipped || !(held == otherwise))
490 return std::nullopt;
491 return either(*taken, *skipped);
492 }
493 if (auto whileOp = dyn_cast<scf::WhileOp>(op)) {
494 Held entry = held;
495 std::optional<Effect> check = analyze(*whileOp.getBeforeBody(), held);
496 Held afterCheck = held;
497 std::optional<Effect> body =
498 check ? analyze(*whileOp.getAfterBody(), held) : std::nullopt;
499 if (!body || !(held == entry))
500 return std::nullopt;
501 held = afterCheck;
502 std::optional<Effect> pass = then(*body, *check);
503 return pass ? then(*check, anyRepeat(*pass)) : std::nullopt;
504 }
505 return std::nullopt;
506 }
507
508 DeviceOp device;
509 StringRef in, out;
510 llvm::SmallPtrSet<Operation *, 16> onUsePath;
511 bool used = false;
512 // Pass ends of loops that may run any number of times.
513 SmallVector<Pair> bounds;
514};
515
516struct AIEObjectFifoVerifyPass
517 : public xilinx::AIE::impl::AIEObjectFifoVerifyBase<
518 AIEObjectFifoVerifyPass> {
519
520 /// Which pools get locks. Without locks nothing waits on a release, and
521 /// nothing a core holds stays taken.
522 std::shared_ptr<PoolLocks> poolLocks;
523
524 /// Every segment needs an actor at each end, so that what one writes another
525 /// reads. A segment may go unfilled when the pool's objects start full, and
526 /// may name no endpoint at an end its `manualFill` or `manualDrain` hands to
527 /// a DMA program the author writes.
528 LogicalResult verifyActors(ObjectFifoPoolOp pool,
529 ArrayRef<SegmentActors> actors) {
530 bool external = llvm::any_of(pool.getBufferOps(), [](BufferLike buffer) {
531 return isa<ExternalBufferOp>(buffer.getOperation());
532 });
533 std::vector<ObjectFifoSegmentOp> segmentOps = pool.getSegmentOps();
534 for (auto [index, segment] : llvm::enumerate(actors)) {
535 ObjectFifoSegmentOp segmentOp = segmentOps[index];
536 bool manualFill = segmentOp.getManualFill();
537 bool manualDrain = segmentOp.getManualDrain();
538 if (segment.fillers.size() > 1 ||
539 (manualFill && !segment.fillers.empty())) {
540 return pool.emitOpError("segment ")
541 << index << " is filled by more than one endpoint";
542 }
543 if (segment.drainers.size() > 1 ||
544 (manualDrain && !segment.drainers.empty())) {
545 return pool.emitOpError("segment ")
546 << index << " is drained by more than one endpoint";
547 }
548 // The host works an external pool's buffers, so it stands in for the end
549 // this device does not program.
550 bool hostDrains = external && !segment.fillers.empty();
551 bool hostFills = external && !segment.drainers.empty();
552 if (segment.drainers.empty() && !hostDrains && !manualDrain) {
553 return pool.emitOpError("segment ") << index << " has no drainer";
554 }
555 if (segment.fillers.empty() && !pool.getInitValues() && !hostFills &&
556 !manualFill) {
557 return pool.emitOpError("segment ") << index << " has no filler";
558 }
559 }
560 return success();
561 }
562
563 /// An endpoint that is not connected carries data nowhere.
564 LogicalResult verifyFlows(DeviceOp device,
565 SymbolTableCollection &symbolTables) {
566 DenseMap<StringRef, int> appearances;
567 for (auto flow : device.getOps<RouteOp>()) {
568 for (StringRef source : flow.getSourceNames()) {
569 appearances[source]++;
570 }
571 for (StringRef dest : flow.getDestinationNames()) {
572 appearances[dest]++;
573 }
574 }
575
576 for (auto endpoint : device.getOps<RouteEndpoint>()) {
577 int count =
578 appearances.lookup(cast<SymbolOpInterface>(*endpoint).getName());
579 if (count == 0) {
580 return endpoint->emitOpError("is not connected by any flow");
581 }
582 if (auto dma = dyn_cast<ObjectFifoDmaEndpointOp>(*endpoint);
583 dma && dma.getDispatch()) {
584 if (failed(verifyDispatch(device, dma, symbolTables)))
585 return failure();
586 continue;
587 }
588 // An aie.route_endpoint's own verifier says which flows may share it.
589 if (count > 1 && !isa<RouteEndpointOp>(endpoint.getOperation())) {
590 return endpoint->emitOpError(
591 "drives one channel, so at most one flow may name it, but "
592 "it is named ")
593 << count << " times";
594 }
595 }
596 return success();
597 }
598
599 /// A dispatching endpoint is the one source of one packet-switched route per
600 /// destination it takes turns between, and of nothing else. A second route to
601 /// the same destination is refused there, by the count every endpoint gets.
602 LogicalResult verifyDispatch(DeviceOp device,
603 ObjectFifoDmaEndpointOp endpoint,
604 SymbolTableCollection &symbolTables) {
605 StringRef name = endpoint.getSymName();
606 llvm::SmallSetVector<StringRef, 4> turns;
607 for (StringRef dest :
608 endpoint.getDispatchAttr().getAsValueRange<FlatSymbolRefAttr>())
609 turns.insert(dest);
610 llvm::SmallDenseSet<StringRef, 4> reached;
611 for (auto flow : device.getOps<RouteOp>()) {
612 if (flow.namesAsDestination(name))
613 return flow.emitOpError("names dispatching endpoint @")
614 << name << " as a destination";
615 if (!flow.namesAsSource(name))
616 continue;
617 if (flow.getSources().size() != 1 || flow.getDestinations().size() != 1)
618 return flow.emitOpError("leaves dispatching endpoint @")
619 << name
620 << " for one destination, so it has one source and "
621 "one destination";
622 if (!flow.getPacket())
623 return flow.emitOpError("leaves dispatching endpoint @")
624 << name << " and needs a packet header to tell its turns apart";
625 StringRef dest = *flow.getDestinationNames().begin();
626 if (!turns.contains(dest))
627 return flow.emitOpError("reaches @")
628 << dest << ", which dispatching endpoint @" << name
629 << " never takes a turn for";
630 reached.insert(dest);
631 }
632 for (StringRef dest : turns)
633 if (!reached.contains(dest))
634 return endpoint.emitOpError("dispatches to @")
635 << dest << ", but no route from it reaches there";
636
637 // Every turn moves the same chain through the dispatching endpoint, one
638 // object per turn, so each turn's destination must move as many elements
639 // as the dispatching endpoint itself does.
640 int64_t elements = transferElements(endpoint);
641 for (StringRef dest : turns) {
642 auto destEndpoint = symbolTables.lookupSymbolIn<ObjectFifoDmaEndpointOp>(
643 device, StringAttr::get(device.getContext(), dest));
644 if (!destEndpoint)
645 continue;
646 int64_t destElements = transferElements(destEndpoint);
647 if (destElements != elements)
648 return endpoint.emitOpError("dispatches, so every turn moves ")
649 << elements << " elements, but @" << dest << " moves "
650 << destElements;
651 }
652 return success();
653 }
654
655 /// The elements one pass of an endpoint's chain moves: each selected segment
656 /// once, through its transform where it has one.
657 static int64_t transferElements(ObjectFifoDmaEndpointOp endpoint) {
658 int64_t elements = 0;
659 std::optional<ArrayRef<BDDimLayoutArrayAttr>> dimensions =
660 endpoint.getDimensions();
661 for (auto [index, segment] :
662 llvm::enumerate(endpoint.getSelectedSegments())) {
663 BDDimLayoutArrayAttr dims;
664 if (dimensions && index < dimensions->size()) {
665 dims = (*dimensions)[index];
666 }
667 if (dims && !dims.empty()) {
668 int64_t product = 1;
669 for (BDDimLayoutAttr dim : dims) {
670 product *= dim.getSize();
671 }
672 elements += product;
673 } else {
674 elements += segment.getSize();
675 }
676 }
677 return elements;
678 }
679
680 /// A fan-in's destination fills its next object with whatever packet
681 /// arrives, and a packet is one pass of its sender's chain, so every end has
682 /// to move the same number of elements or two senders share an object. A
683 /// route endpoint's transfers are the runtime's and are not checked here.
684 LogicalResult verifyFanIn(DeviceOp device,
685 SymbolTableCollection &symbolTables) {
686 for (auto flow : device.getOps<RouteOp>()) {
687 if (!flow.isFanIn()) {
688 continue;
689 }
690 std::optional<std::pair<StringRef, int64_t>> first;
691 auto check = [&](StringRef name) -> LogicalResult {
692 auto endpoint = symbolTables.lookupSymbolIn<ObjectFifoDmaEndpointOp>(
693 device, StringAttr::get(device.getContext(), name));
694 if (!endpoint) {
695 return success();
696 }
697 int64_t elements = transferElements(endpoint);
698 if (!first) {
699 first = {name, elements};
700 return success();
701 }
702 if (elements != first->second) {
703 return flow.emitOpError("fans in, so every end moves one object of "
704 "the same size, but @")
705 << first->first << " moves " << first->second
706 << " elements and @" << name << " moves " << elements;
707 }
708 return success();
709 };
710 for (StringRef name : flow.getSourceNames()) {
711 if (failed(check(name))) {
712 return failure();
713 }
714 }
715 for (StringRef name : flow.getDestinationNames()) {
716 if (failed(check(name))) {
717 return failure();
718 }
719 }
720 }
721 return success();
722 }
723
724 /// A loop body that releases more than it acquires underflows the held count
725 /// as it repeats, whatever the trip count. Accesses split across nesting
726 /// levels are excluded: balancing them needs the inner trip counts. This runs
727 /// before lowering because afterwards the imbalance survives only as
728 /// loop-carried lock values, which no scan can decide.
729 LogicalResult verifyOverRelease(DeviceOp device) {
730 for (auto coreOp : device.getOps<CoreOp>()) {
731 WalkResult result = coreOp.walk([&](Operation *loop) {
732 if (!isObjectFifoLoop(loop)) {
733 return WalkResult::advance();
734 }
735 auto directlyIn = [&](Operation *op) {
736 return getObjectFifoLoopParent(op) == loop;
737 };
738 DenseMap<StringRef, int64_t> acquired;
739 DenseMap<StringRef, int64_t> released;
740 DenseMap<StringRef, Operation *> blame;
741 DenseSet<StringRef> spansNestedLoop;
742
743 loop->walk([&](ObjectFifoAcquireOp a) {
744 StringRef key = a.getObjFifoName();
745 if (!directlyIn(a)) {
746 spansNestedLoop.insert(key);
747 } else {
748 acquired[key] += a.acqNumber();
749 blame.try_emplace(key, a);
750 }
751 });
752 loop->walk([&](ObjectFifoReleaseOp r) {
753 StringRef key = r.getObjFifoName();
754 if (!directlyIn(r)) {
755 spansNestedLoop.insert(key);
756 } else {
757 released[key] += r.relNumber();
758 blame.try_emplace(key, r);
759 }
760 });
761
762 for (auto &[key, count] : released) {
763 if (spansNestedLoop.contains(key) || count <= acquired.lookup(key)) {
764 continue;
765 }
766 blame.lookup(key)->emitOpError(
767 "cannot release more elements than are already acquired");
768 return WalkResult::interrupt();
769 }
770 return WalkResult::advance();
771 });
772 if (result.wasInterrupted()) {
773 return failure();
774 }
775 }
776 return success();
777 }
778
779 /// A DMA endpoint with an iteration count stops after `iterCount * depth`
780 /// objects, so a core that must release more through the same pool waits
781 /// forever for the rest, or leaves objects it filled unsent. Only
782 /// releases static loop bounds force are counted, so what is reported is
783 /// certain; a conditional release, or one in an `scf.while` such as a loop
784 /// that runs forever, is left out, since such a core stalling once the data
785 /// stops is how those designs end. An `scf.for` counts its trip count,
786 /// however large. When all of a core's releases are counted, the DMA endpoint
787 /// is bounded too: it cannot drain more than the core hands over, nor fill
788 /// more than the pool's depth plus what the core releases.
789 LogicalResult verifyTransferBudgets(DeviceOp device) {
790 DenseMap<Operation *, TransferBudget> budgets;
791 for (auto endpoint : device.getOps<ObjectFifoDmaEndpointOp>()) {
792 std::optional<int32_t> iterations = endpoint.getIterCount();
793 ObjectFifoPoolOp pool = endpoint.getPoolOp();
794 if (!iterations || !pool) {
795 continue;
796 }
797 budgets[pool] = {endpoint, *iterations,
798 int64_t{*iterations} * pool.getDepth()};
799 }
800 if (budgets.empty()) {
801 return success();
802 }
803
804 DenseMap<StringRef, int64_t> released;
805 DenseMap<StringRef, ObjectFifoReleaseOp> blame;
806 DenseSet<StringRef> uncounted;
807 device.walk([&](ObjectFifoReleaseOp release) {
808 StringRef key = release.getObjFifoName();
809 std::optional<int64_t> runs = AIEX::staticExecutions(release);
810 if (!runs) {
811 uncounted.insert(key);
812 return;
813 }
814 released[key] += *runs * release.relNumber();
815 blame.try_emplace(key, release);
816 });
817 DenseSet<StringRef> acquired;
818 device.walk([&](ObjectFifoAcquireOp acquire) {
819 acquired.insert(acquire.getObjFifoName());
820 });
821
822 for (auto endpoint : device.getOps<ObjectFifoCoreEndpointOp>()) {
823 // A segment-selecting endpoint sees a share of the pool, not the whole.
824 auto budget = budgets.find(endpoint.getPoolOp());
825 if (budget == budgets.end() || endpoint.getSegments()) {
826 continue;
827 }
828 StringRef name = endpoint.getSymName();
829 int64_t count = released.lookup(name);
830 ObjectFifoDmaEndpointOp dma = budget->second.endpoint;
831 ObjectFifoPoolOp pool = endpoint.getPoolOp();
832 int64_t depth = pool.getDepth();
833 if (count > budget->second.objects) {
834 InFlightDiagnostic diag =
835 blame.lookup(name).emitOpError("releases ")
836 << count << " objects through @" << name
837 << " over the run, but the pool's DMA endpoint stops after "
838 << budget->second.objects << " (iterCount "
839 << budget->second.iterations << " x depth " << depth << ")";
840 // A producer finishes while the pool still has free objects to fill.
841 if (!endpoint.drains() && count <= budget->second.objects + depth)
842 diag << ", leaving " << count - budget->second.objects
843 << " in the pool unsent";
844 else
845 diag << ", so the core would wait forever for the rest";
846 diag.attachNote(dma.getLoc()) << "the DMA endpoint is here";
847 return failure();
848 }
849
850 if (!acquired.contains(name) || uncounted.contains(name) ||
851 dma.getSegments() || pool.getInitValues() ||
852 dma.drains() == endpoint.drains() || !poolLocks->needsLocks(pool)) {
853 continue;
854 }
855 int64_t reachable = endpoint.drains() ? count + depth : count;
856 if (budget->second.objects <= reachable) {
857 continue;
858 }
859 InFlightDiagnostic diag =
860 dma.emitOpError(dma.drains() ? "drains " : "fills ")
861 << budget->second.objects << " objects (iterCount "
862 << budget->second.iterations << " x depth " << depth
863 << ") before it stops, but the core releases exactly " << count
864 << " through @" << name;
865 if (endpoint.drains())
866 diag << ", leaving room for only " << reachable;
867 diag << ", so the DMA endpoint would wait forever for the rest";
868 diag.attachNote(endpoint.getLoc()) << "the core endpoint is here";
869 return failure();
870 }
871 return success();
872 }
873
874 /// A core that reaches its end still holding objects never gives their locks
875 /// back, and locks keep their counts until a PDI load, so the next run of
876 /// the configuration finds those objects taken. Only cores certain to end
877 /// are checked: one block, and no `scf.while`. A fifo an
878 /// `aiex.dma_channel_reset_for` re-arms in every runtime sequence that moves
879 /// data through it gets its locks back each launch.
880 LogicalResult verifyHeldAtEnd(DeviceOp device,
881 SymbolTableCollection &symbolTables) {
882 // The sequences that fill or drain a fifo by name must each re-arm it;
883 // where none names it (a link fills it), every sequence must. Every
884 // fifo needs this at most once across however many cores hold it.
885 llvm::DenseMap<StringRef, SmallVector<RuntimeSequenceOp>> launchesByFifo;
886 std::optional<SmallVector<RuntimeSequenceOp>> allLaunches;
887 auto launchesOf = [&](std::optional<StringRef> fifo)
888 -> const SmallVector<RuntimeSequenceOp> & {
889 if (!fifo) {
890 if (!allLaunches)
891 allLaunches.emplace(
892 llvm::to_vector(device.getOps<RuntimeSequenceOp>()));
893 return *allLaunches;
894 }
895 auto [it, inserted] = launchesByFifo.try_emplace(*fifo);
896 if (inserted) {
897 for (auto seq : device.getOps<RuntimeSequenceOp>())
898 if (AIEX::namesFifo(seq, *fifo, symbolTables))
899 it->second.push_back(seq);
900 if (it->second.empty())
901 llvm::append_range(it->second, device.getOps<RuntimeSequenceOp>());
902 }
903 return it->second;
904 };
905 for (auto core : device.getOps<CoreOp>()) {
906 Region &body = core.getBody();
907 if (!body.hasOneBlock())
908 continue;
909 bool mayNotEnd =
910 core.walk([](scf::WhileOp) { return WalkResult::interrupt(); })
911 .wasInterrupted();
912 if (mayNotEnd)
913 continue;
914 llvm::MapVector<StringRef, ObjectFifoAcquireOp> firstAcquire;
915 core.walk([&](ObjectFifoAcquireOp acquire) {
916 firstAcquire.insert({acquire.getObjFifoName(), acquire});
917 });
918 for (auto &[name, acquire] : firstAcquire) {
919 std::optional<int64_t> held = heldAfter(body.front(), name, 0);
920 if (!held || *held == 0)
921 continue;
922 auto endpoint =
923 symbolTables.lookupNearestSymbolFrom<ObjectFifoCoreEndpointOp>(
924 device, acquire.getObjFifoNameAttr());
925 ObjectFifoPoolOp pool = endpoint ? endpoint.getPoolOp() : nullptr;
926 std::optional<StringRef> fifo =
927 pool ? pool.getFifoName() : std::nullopt;
928 auto rearms =
929 fifo ? poolLocks->rearms().find(*fifo) : poolLocks->rearms().end();
930 bool rearmedEveryLaunch =
931 rearms != poolLocks->rearms().end() &&
932 llvm::all_of(launchesOf(fifo), [&](RuntimeSequenceOp seq) {
933 return llvm::any_of(rearms->second, [&](auto reset) {
934 return reset->getParentOp() == seq;
935 });
936 });
937 if (pool && (!poolLocks->needsLocks(pool) || rearmedEveryLaunch))
938 continue;
939 InFlightDiagnostic diag =
940 core.emitOpError("ends with ")
941 << *held << " acquired from @" << name
942 << " never released, so their locks stay taken into the next run "
943 "of this configuration";
944 diag.attachNote(acquire.getLoc()) << "acquired here";
945 return failure();
946 }
947 }
948 return success();
949 }
950
951 /// A core whose loop repeats forever, and whose every repetition acquires
952 /// objects of a pool but releases none, keeps the same objects for good. The
953 /// end opposite it then stops once the pool is full, if it does not stop by
954 /// itself first: checked where that end is a DMA endpoint without an
955 /// iteration count, or a core that moves objects each time its own loop
956 /// repeats forever. A core holding an object acquired before its loop, for
957 /// the whole configuration, is left alone, as is a loop the core may never
958 /// reach.
959 LogicalResult verifyAdvances(DeviceOp device) {
960 // Whether `loop` runs, and repeats forever: it or a loop around it runs
961 // forever, and nothing on the way from the core may skip it.
962 auto repeatsForever = [](Operation *loop) {
963 bool forever = false;
964 for (Operation *op = loop; !isa<CoreOp>(op); op = op->getParentOp()) {
965 Block *block = op->getBlock();
966 if (block != &op->getParentRegion()->front() ||
967 llvm::any_of(
968 llvm::make_range(block->begin(), op->getIterator()),
969 [&](Operation &before) { return runsForever(&before); }))
970 return false;
971 auto forOp = dyn_cast<scf::ForOp>(op);
972 auto whileOp = dyn_cast<scf::WhileOp>(op);
973 std::optional<int64_t> trip =
974 forOp ? getStaticTripCount(forOp) : std::nullopt;
975 if ((forOp && (!trip || *trip == 0)) ||
976 (whileOp && !isForeverLoop(whileOp)))
977 return false;
978 forever |= runsForever(op);
979 Operation *parent = op->getParentOp();
980 if (auto ifOp = dyn_cast<scf::IfOp>(parent)) {
981 bool inThen = op->getParentRegion() == &ifOp.getThenRegion();
982 if (!matchPattern(ifOp.getCondition(), inThen ? m_One() : m_Zero()))
983 return false;
984 } else if (auto parentWhile = dyn_cast<scf::WhileOp>(parent)) {
985 if (op->getParentRegion() != &parentWhile.getAfter())
986 return false;
987 } else if (!isa<scf::ForOp, CoreOp>(parent)) {
988 return false;
989 }
990 }
991 return forever;
992 };
993
994 for (auto endpoint : device.getOps<ObjectFifoCoreEndpointOp>()) {
995 ObjectFifoPoolOp pool = endpoint.getPoolOp();
996 if (!pool || pool.getInitValues() || endpoint.getSegments() ||
997 !poolLocks->needsLocks(pool))
998 continue;
999 Operation *keepsMoving = nullptr;
1000 for (auto dma : device.getOps<ObjectFifoDmaEndpointOp>())
1001 if (dma.getPoolOp() == pool && dma.drains() != endpoint.drains() &&
1002 !dma.getIterCount() && !dma.getSegments())
1003 keepsMoving = dma;
1004 for (auto other : device.getOps<ObjectFifoCoreEndpointOp>()) {
1005 if (keepsMoving || other.getPoolOp() != pool ||
1006 other.drains() == endpoint.drains() || other.getSegments())
1007 continue;
1008 CoreTurns otherTurns;
1009 std::string otherReason;
1010 if (succeeded(otherTurns.read({other}, otherReason)) &&
1011 repeatsForever(otherTurns.periodLoop()))
1012 keepsMoving = other;
1013 }
1014 if (!keepsMoving)
1015 continue;
1016
1017 CoreTurns turns;
1018 std::string reason;
1019 if (succeeded(turns.read({endpoint}, reason)) || !turns.movesNone() ||
1020 !repeatsForever(turns.periodLoop()))
1021 continue;
1022 auto acquire =
1023 dyn_cast_or_null<ObjectFifoAcquireOp>(turns.periodAcquire());
1024 if (!acquire)
1025 continue;
1026 InFlightDiagnostic diag =
1027 acquire.emitOpError("takes from @")
1028 << endpoint.getSymName()
1029 << " each time its loop repeats, but the loop releases none of "
1030 "them, so ";
1031 if (endpoint.drains())
1032 diag << "the core keeps the same objects forever and the end "
1033 "filling the pool stops once it is full";
1034 else
1035 diag << "nothing the core writes there is ever sent";
1036 diag.attachNote(keepsMoving->getLoc()) << "the other end is here";
1037 return failure();
1038 }
1039 return success();
1040 }
1041
1042 /// Bytes one run of `sequence` moves through the shim endpoint `name`, when
1043 /// every use of it is a DMA task whose starts, repeats and lengths are
1044 /// static.
1045 static std::optional<int64_t> hostBytes(RuntimeSequenceOp sequence,
1046 StringAttr name) {
1047 std::optional<SymbolTable::UseRange> uses =
1048 SymbolTable::getSymbolUses(name, &sequence.getBody());
1049 if (!uses)
1050 return std::nullopt;
1051 std::optional<int64_t> bytes = 0;
1052 for (const SymbolTable::SymbolUse &use : *uses) {
1053 auto task = dyn_cast<AIEX::DMAConfigureTaskForOp>(use.getUser());
1054 std::optional<int64_t> runs =
1055 task ? AIEX::staticExecutions(task) : std::nullopt;
1056 std::optional<int64_t> streamed =
1057 runs ? task.getStaticBytesStreamed() : std::nullopt;
1058 if (!streamed)
1059 return std::nullopt;
1060 std::optional<int64_t> moved = llvm::checkedMul(*runs, *streamed);
1061 bytes = moved ? llvm::checkedAdd(*bytes, *moved) : std::nullopt;
1062 if (!bytes)
1063 return std::nullopt;
1064 }
1065 return bytes;
1066 }
1067
1068 /// Bytes one object of `endpoint` carries over its channel, its elements
1069 /// sized as a buffer descriptor's length counts them.
1070 static int64_t objectBytes(ObjectFifoDmaEndpointOp endpoint) {
1071 auto type = cast<MemRefType>(endpoint.getPoolOp().getElemType());
1072 return transferElements(endpoint) *
1073 static_cast<int64_t>(DataLayout::closest(endpoint).getTypeSize(
1074 type.getElementType()));
1075 }
1076
1077 /// Objects the DMA endpoint `endpoint` moves in one run of `sequence`, traced
1078 /// to the shim directly or through one pool with one DMA endpoint toward the
1079 /// shim.
1080 std::optional<int64_t> hostObjects(DeviceOp device,
1081 RuntimeSequenceOp sequence,
1082 ObjectFifoDmaEndpointOp endpoint,
1083 bool throughPool) {
1084 if (endpoint.getIterCount() || endpoint.getDispatch())
1085 return std::nullopt;
1086 StringRef name = endpoint.getSymName();
1087 SmallVector<StringRef> peers;
1088 for (auto route : device.getOps<RouteOp>()) {
1089 if (endpoint.drains() ? route.namesAsSource(name)
1090 : route.namesAsDestination(name)) {
1091 auto names = endpoint.drains() ? route.getDestinationNames()
1092 : route.getSourceNames();
1093 peers.append(names.begin(), names.end());
1094 }
1095 }
1096 if (peers.size() != 1)
1097 return std::nullopt;
1098 Operation *peer = SymbolTable::lookupNearestSymbolFrom(
1099 device, StringAttr::get(device.getContext(), peers.front()));
1100 // A draining endpoint sends each object `getRepeat` times.
1101 int64_t sent = objectBytes(endpoint) * endpoint.getRepeat();
1102 int64_t perObject = endpoint.drains() ? sent : objectBytes(endpoint);
1103
1104 int64_t bytes;
1105 if (auto shim = dyn_cast_or_null<RouteEndpointOp>(peer)) {
1106 std::optional<int64_t> host = hostBytes(sequence, shim.getSymNameAttr());
1107 if (!host)
1108 return std::nullopt;
1109 bytes = *host;
1110 } else if (auto other = dyn_cast_or_null<ObjectFifoDmaEndpointOp>(peer);
1111 other && throughPool && other.drains() != endpoint.drains()) {
1112 ObjectFifoDmaEndpointOp toward;
1113 for (auto candidate : device.getOps<ObjectFifoDmaEndpointOp>()) {
1114 if (candidate == other || candidate.getPoolOp() != other.getPoolOp() ||
1115 candidate.drains() == other.drains())
1116 continue;
1117 if (toward)
1118 return std::nullopt;
1119 toward = candidate;
1120 }
1121 if (!toward)
1122 return std::nullopt;
1123 std::optional<int64_t> objects =
1124 hostObjects(device, sequence, toward, false);
1125 if (!objects)
1126 return std::nullopt;
1127 bytes =
1128 *objects * (other.drains() ? objectBytes(other) * other.getRepeat()
1129 : objectBytes(other));
1130 } else {
1131 return std::nullopt;
1132 }
1133 if (perObject == 0 || bytes % perObject)
1134 return std::nullopt;
1135 return bytes / perObject;
1136 }
1137
1138 /// A Worker whose forever loop waits once for each dispatch's parameters
1139 /// runs one pass of that loop per dispatch, so the objects one pass moves
1140 /// through a fifo must be the objects one run of the runtime sequence moves
1141 /// through it, or the core drifts out of step with the dispatches. A pass
1142 /// runs the fifo's period, an inner loop where that is the innermost loop
1143 /// around its accesses, as often as the static loops between them repeat.
1144 /// Checked when one runtime sequence syncs the parameters, so every
1145 /// dispatch runs it, and its transfers on the fifo are static. A sync sets
1146 /// the core's lock rather than adding to it, so where a run syncs twice the
1147 /// core may take only one, and nothing is checked.
1148 LogicalResult verifyDispatchVolumes(DeviceOp device) {
1149 RuntimeSequenceOp sequence;
1150 for (auto candidate : device.getOps<RuntimeSequenceOp>()) {
1151 auto ops = candidate.getBody()
1152 .getOps<AIEX::SyncScratchpadParametersFromHostOp>();
1153 int64_t count = std::distance(ops.begin(), ops.end());
1154 // With a core waiting, --aie-lower-scratchpad-parameters syncs once in a
1155 // sequence that has no sync of its own, unless the sequence opts out.
1156 if (count == 0) {
1157 BoolAttr preamble = candidate.getEmitParameterSyncPreambleAttr();
1158 count = !preamble || preamble.getValue();
1159 }
1160 if (count == 0)
1161 continue;
1162 if (sequence || count > 1)
1163 return success();
1164 sequence = candidate;
1165 }
1166 if (!sequence)
1167 return success();
1168
1169 for (auto endpoint : device.getOps<ObjectFifoCoreEndpointOp>()) {
1170 ObjectFifoPoolOp pool = endpoint.getPoolOp();
1171 if (!pool || pool.getInitValues() || endpoint.getSegments() ||
1172 !poolLocks->needsLocks(pool))
1173 continue;
1174 ObjectFifoDmaEndpointOp dma;
1175 bool single = true;
1176 for (auto candidate : device.getOps<ObjectFifoDmaEndpointOp>()) {
1177 if (candidate.getPoolOp() != pool ||
1178 candidate.drains() == endpoint.drains())
1179 continue;
1180 single = !dma;
1181 dma = candidate;
1182 }
1183 if (!dma || !single || dma.getSegments())
1184 continue;
1185
1186 CoreTurns turns;
1187 std::string reason;
1188 if (failed(turns.read({endpoint}, reason)))
1189 continue;
1190 Operation *loop = turns.periodLoop();
1191 std::optional<int64_t> periods = 1;
1192 for (; periods && !isa<CoreOp>(loop) && !runsForever(loop);
1193 loop = loop->getParentOp()) {
1194 auto forOp = dyn_cast<scf::ForOp>(loop);
1195 std::optional<int64_t> trip =
1196 forOp ? getStaticTripCount(forOp) : std::nullopt;
1197 periods = trip && loop->getBlock() == &loop->getParentRegion()->front()
1198 ? llvm::checkedMul(*periods, *trip)
1199 : std::nullopt;
1200 }
1201 if (!periods || isa<CoreOp>(loop))
1202 continue;
1203 // Two waits a pass serve two dispatches, and a wait under a branch or an
1204 // inner loop may serve none or several.
1205 auto whileLoop = dyn_cast<scf::WhileOp>(loop);
1206 Block *body = whileLoop ? whileLoop.getAfterBody()
1207 : cast<scf::ForOp>(loop).getBody();
1208 int64_t waits = 0;
1209 loop->walk([&](AIEX::WaitScratchpadParametersOp) { waits++; });
1210 if (waits != 1 ||
1211 body->getOps<AIEX::WaitScratchpadParametersOp>().empty())
1212 continue;
1213 std::optional<int64_t> perDispatch = llvm::checkedMul(
1214 *periods, static_cast<int64_t>(turns.turns().size()));
1215 if (!perDispatch)
1216 continue;
1217 std::optional<int64_t> objects = hostObjects(device, sequence, dma, true);
1218 LLVM_DEBUG(llvm::dbgs()
1219 << "dispatch volume of @" << endpoint.getSymName()
1220 << ": the core moves " << *perDispatch << ", @"
1221 << sequence.getSymName() << " moves "
1222 << (objects ? std::to_string(*objects) : "an unknown count")
1223 << "\n");
1224 if (!objects || *objects == *perDispatch)
1225 continue;
1226
1227 ObjectFifoAcquireOp acquire;
1228 loop->walk([&](ObjectFifoAcquireOp op) {
1229 if (!acquire && op.getObjFifoName() == endpoint.getSymName())
1230 acquire = op;
1231 });
1232 if (!acquire)
1233 continue;
1234 InFlightDiagnostic diag =
1235 acquire.emitOpError()
1236 << (endpoint.drains() ? "takes " : "hands over ") << *perDispatch
1237 << " objects through @" << endpoint.getSymName()
1238 << " for each dispatch, one pass of a loop that waits for each "
1239 "dispatch's parameters, but each run of runtime sequence @"
1240 << sequence.getSymName() << " moves " << *objects
1241 << ", so the core drifts out of step with the dispatches";
1242 diag.attachNote(sequence.getLoc()) << "the runtime sequence is here";
1243 return failure();
1244 }
1245 return success();
1246 }
1247
1248 using PoolActors = DenseMap<Operation *, SmallVector<SegmentActors>>;
1249
1250 /// A place the bytes some endpoint sends reach: once `far` has taken some
1251 /// of them, the endpoint has sent at least `inBytes` for every `outBytes`
1252 /// taken. With a nonzero `lagObject`, they pass a later segment of a join
1253 /// on the way, whose drainer takes `lagObject` bytes an object and has taken
1254 /// at least `lagIn` for every `lagOut` `far` took: that holds in whole
1255 /// objects of the join only (see recordConsumption's granule).
1256 struct Reach {
1257 Operation *far;
1258 int64_t inBytes, outBytes;
1259 int64_t lagObject = 0, lagIn = 0, lagOut = 0;
1260 };
1261
1262 static int64_t segmentBytes(ObjectFifoPoolOp pool,
1263 ArrayRef<ObjectFifoSegmentOp> segments) {
1264 int64_t elements = 0;
1265 for (ObjectFifoSegmentOp segment : segments)
1266 elements += segment.getSize();
1267 auto type = cast<MemRefType>(pool.getElemType());
1268 return elements *
1269 static_cast<int64_t>(
1270 DataLayout::closest(pool).getTypeSize(type.getElementType()));
1271 }
1272
1273 /// Whether `dma` moves each object's bytes once, neither padding, repeating
1274 /// nor dispatching them.
1275 static bool passesOn(ObjectFifoDmaEndpointOp dma) {
1276 return !dma.getPadDimensions() && !dma.getDispatch() &&
1277 dma.getRepeat() == 1;
1278 }
1279
1280 /// Where the bytes the endpoint `from` sends end up, scaled by `scale`: a
1281 /// shim's route endpoint, or a core endpoint draining a pool on the way.
1282 /// Every destination of a route is reached. A pool is entered through a
1283 /// fill that alone fills its segments and left through each drainer of the
1284 /// same segments, of the fill's last segment alone (a split), or of all
1285 /// segments when the fill fills the first (a join): segments release once
1286 /// written, so only those drainers' progress bounds the whole of the fill's.
1287 /// Bytes pass only through DMAs that neither pad, repeat nor dispatch them,
1288 /// counted as each DMA's transform moves them, and only to a destination no
1289 /// other route merges into, with no packet header kept in its bytes.
1290 void carries(DeviceOp device, StringAttr from, const PoolActors &actors,
1291 Reach scale, llvm::SmallPtrSetImpl<Operation *> &onPath,
1292 SmallVectorImpl<Reach> &reaches) {
1293 RouteOp route;
1294 for (auto candidate : device.getOps<RouteOp>()) {
1295 if (!candidate.namesAsSource(from.getValue()))
1296 continue;
1297 if (route)
1298 return;
1299 route = candidate;
1300 }
1301 if (!route || route.getSources().size() != 1 || route.getKeepPktHeader())
1302 return;
1303 for (StringRef name : route.getDestinationNames()) {
1304 if (llvm::any_of(device.getOps<RouteOp>(), [&](RouteOp other) {
1305 return other != route && other.namesAsDestination(name);
1306 }))
1307 continue;
1308 Operation *dest = SymbolTable::lookupNearestSymbolFrom(
1309 device, StringAttr::get(device.getContext(), name));
1310 if (auto shim = dyn_cast_or_null<RouteEndpointOp>(dest)) {
1311 Reach at = scale;
1312 at.far = shim;
1313 if (shim.getBundle() == WireBundle::DMA &&
1314 shim.getTileLike().isShimTile())
1315 reaches.push_back(at);
1316 continue;
1317 }
1318 auto fill = dyn_cast_or_null<ObjectFifoDmaEndpointOp>(dest);
1319 if (!fill || fill.drains() || !passesOn(fill))
1320 continue;
1321 ObjectFifoPoolOp pool = fill.getPoolOp();
1322 if (!pool || pool.getInitValues() || pool.getContiguous() ||
1323 !poolLocks->needsLocks(pool) || onPath.contains(pool))
1324 continue;
1325 auto it = actors.find(pool);
1326 if (it == actors.end())
1327 continue;
1328 std::vector<ObjectFifoSegmentOp> all = pool.getSegmentOps();
1329 std::vector<ObjectFifoSegmentOp> filled = fill.getSelectedSegments();
1330 auto indexOf = [&](ObjectFifoSegmentOp segment) {
1331 return llvm::find(all, segment) - all.begin();
1332 };
1333 if (filled.empty() || llvm::any_of(filled, [&](auto segment) {
1334 return it->second[indexOf(segment)].fillers.size() != 1;
1335 }))
1336 continue;
1337 llvm::SetVector<Operation *> drainers;
1338 for (const SegmentActors &segment : it->second)
1339 drainers.insert(segment.drainers.begin(), segment.drainers.end());
1340 onPath.insert(pool);
1341 for (Operation *drainer : drainers) {
1342 auto core = dyn_cast<ObjectFifoCoreEndpointOp>(drainer);
1343 auto dma = dyn_cast<ObjectFifoDmaEndpointOp>(drainer);
1344 if (dma && !passesOn(dma))
1345 continue;
1346 std::vector<ObjectFifoSegmentOp> drained =
1347 core ? core.getSelectedSegments() : dma.getSelectedSegments();
1348 if (drained.empty())
1349 continue;
1350 bool split = drained.size() == 1 && drained.front() == filled.back();
1351 bool join = filled.size() == 1 && filled.front() == drained.front();
1352 // A later segment of a join is taken only after those ahead of it in
1353 // each object (a join's drainer reads its segments in order, any
1354 // transform staying within each), so its progress shows in whole
1355 // objects alone; one such segment per path.
1356 bool laterJoin = dma && filled.size() == 1 && !join &&
1357 llvm::is_contained(drained, filled.front());
1358 if ((drained != filled && !split && !join && !laterJoin) ||
1359 (laterJoin && scale.lagObject))
1360 continue;
1361 int64_t in = objectBytes(fill);
1362 int64_t out = core ? segmentBytes(pool, drained) : objectBytes(dma);
1363 Reach next = scale;
1364 next.far = drainer;
1365 if (in <= 0 || out <= 0 ||
1366 llvm::MulOverflow(scale.inBytes, in, next.inBytes) ||
1367 llvm::MulOverflow(scale.outBytes, out, next.outBytes) ||
1368 (scale.lagObject &&
1369 (llvm::MulOverflow(scale.lagIn, in, next.lagIn) ||
1370 llvm::MulOverflow(scale.lagOut, out, next.lagOut))))
1371 continue;
1372 int64_t common = std::gcd(next.inBytes, next.outBytes);
1373 next.inBytes /= common;
1374 next.outBytes /= common;
1375 if (laterJoin)
1376 next = {next.far, next.inBytes, next.outBytes, out, 1, 1};
1377 if (next.lagObject) {
1378 int64_t lagCommon = std::gcd(next.lagIn, next.lagOut);
1379 next.lagIn /= lagCommon;
1380 next.lagOut /= lagCommon;
1381 }
1382 if (core)
1383 reaches.push_back(next);
1384 else
1385 carries(device, dma.getSymNameAttr(), actors, next, onPath, reaches);
1386 }
1387 onPath.erase(pool);
1388 }
1389 }
1390
1391 /// Records on each shim input the shim outputs whose progress proves it
1392 /// consumed (#aie.consumed_by). Its bytes reach such an output; or they
1393 /// reach a core that, on every path through its program (TakeRatio), takes
1394 /// its share of them before each release into a fifo whose bytes reach the
1395 /// output, or another such core. A shim input sends a byte before anything
1396 /// downstream can take it, and the host receives a byte only after the
1397 /// cores released it, so once the output has received R bytes the input's
1398 /// first R * in / out have been sent; with a granule (see carries), R
1399 /// rounded down to a multiple of it.
1400 void recordConsumption(DeviceOp device, const PoolActors &actors) {
1401 MLIRContext *ctx = device.getContext();
1402 struct Share {
1403 int64_t in, out, granule;
1404 };
1405 // Proofs are listed by their outputs' structural rank, found once and
1406 // only for an input with several.
1407 std::optional<DenseMap<Operation *, unsigned>> rank;
1408 for (auto input : device.getOps<RouteEndpointOp>()) {
1409 if (input.getBundle() != WireBundle::DMA ||
1410 !input.getTileLike().isShimTile())
1411 continue;
1412 // Per output, one proof: one without a granule where there is one, else
1413 // the most bytes for every `out` received, then the smallest granule.
1414 llvm::MapVector<Operation *, Share> proofs;
1415 auto prove = [&](RouteEndpointOp output, const Reach &reach) {
1416 Share share{reach.inBytes, reach.outBytes, 0};
1417 if (reach.lagObject) {
1418 // The smallest R with R * lagIn a multiple of lagOut * lagObject.
1419 int64_t whole;
1420 if (llvm::MulOverflow(reach.lagOut, reach.lagObject, whole))
1421 return;
1422 share.granule = whole / std::gcd(whole, reach.lagIn);
1423 }
1424 auto [it, inserted] = proofs.try_emplace(output, share);
1425 const Share &old = it->second;
1426 int64_t lhs, rhs;
1427 if (inserted || llvm::MulOverflow(share.in, old.out, lhs) ||
1428 llvm::MulOverflow(old.in, share.out, rhs))
1429 return;
1430 if ((old.granule && !share.granule) ||
1431 (!old.granule == !share.granule &&
1432 (lhs > rhs || (lhs == rhs && share.granule < old.granule))))
1433 it->second = share;
1434 };
1435 SmallVector<Reach> reaches;
1436 llvm::SmallPtrSet<Operation *, 8> onPath;
1437 carries(device, input.getSymNameAttr(), actors, {nullptr, 1, 1}, onPath,
1438 reaches);
1439 // A core passes the input on through each fifo it fills, perhaps to
1440 // another core, and so on, a few hops deep.
1441 constexpr int maxCoreHops = 4;
1442 SmallVector<std::pair<Reach, int>> work;
1443 for (const Reach &reach : reaches)
1444 work.push_back({reach, 0});
1445 while (!work.empty()) {
1446 auto [reach, hops] = work.pop_back_val();
1447 if (auto output = dyn_cast<RouteEndpointOp>(reach.far)) {
1448 prove(output, reach);
1449 continue;
1450 }
1451 if (hops == maxCoreHops)
1452 continue;
1453 auto consumer = cast<ObjectFifoCoreEndpointOp>(reach.far);
1454 CoreOp core;
1455 for (Operation *user : consumer.getTile().getUsers())
1456 if (auto candidate = dyn_cast<CoreOp>(user))
1457 core = candidate;
1458 if (!core)
1459 continue;
1460 int64_t takenBytes =
1461 segmentBytes(consumer.getPoolOp(), consumer.getSelectedSegments());
1462 for (auto producer : device.getOps<ObjectFifoCoreEndpointOp>()) {
1463 ObjectFifoPoolOp pool = producer.getPoolOp();
1464 if (producer.drains() || producer.getSegments() ||
1465 producer.getTile() != consumer.getTile() || !pool ||
1466 pool.getInitValues() || !poolLocks->needsLocks(pool))
1467 continue;
1468 auto it = actors.find(pool);
1469 if (it == actors.end() || it->second.size() != 1 ||
1470 it->second.front().fillers.size() != 1 ||
1471 it->second.front().drainers.size() != 1)
1472 continue;
1473 Operation *drainer = it->second.front().drainers.front();
1474 std::optional<std::pair<int64_t, int64_t>> ratio =
1475 TakeRatio(device, consumer.getSymName(), producer.getSymName())
1476 .of(core);
1477 if (!ratio)
1478 continue;
1479 // Once the next place has taken X bytes, the drainer sent X *
1480 // next.inBytes / next.outBytes, the core released at least that
1481 // much of the producer and so took `taken` bytes of the consumer
1482 // for every `released`, of which the input sent reach's share.
1483 // `released` counts what the drainer moves of each object.
1484 auto dma = dyn_cast<ObjectFifoDmaEndpointOp>(drainer);
1485 int64_t taken, released;
1486 if ((dma && !passesOn(dma)) ||
1487 llvm::MulOverflow(ratio->first, takenBytes, taken) ||
1488 llvm::MulOverflow(
1489 ratio->second,
1490 dma ? objectBytes(dma)
1491 : segmentBytes(pool, producer.getSelectedSegments()),
1492 released) ||
1493 released <= 0)
1494 continue;
1495 // A core sharing the pool's memory takes what this one released.
1496 SmallVector<Reach> nexts;
1497 if (!dma) {
1498 nexts.push_back({drainer, 1, 1, 0, 0, 0});
1499 } else {
1500 llvm::SmallPtrSet<Operation *, 8> outPath;
1501 carries(device, dma.getSymNameAttr(), actors, {nullptr, 1, 1},
1502 outPath, nexts);
1503 }
1504 for (const Reach &next : nexts) {
1505 if (reach.lagObject && next.lagObject)
1506 continue;
1507 Reach composed = next;
1508 if (llvm::MulOverflow(next.inBytes, taken, composed.inBytes) ||
1509 llvm::MulOverflow(composed.inBytes, reach.inBytes,
1510 composed.inBytes) ||
1511 llvm::MulOverflow(next.outBytes, released, composed.outBytes) ||
1512 llvm::MulOverflow(composed.outBytes, reach.outBytes,
1513 composed.outBytes))
1514 continue;
1515 int64_t common = std::gcd(composed.inBytes, composed.outBytes);
1516 composed.inBytes /= common;
1517 composed.outBytes /= common;
1518 // A join before the core: its drainer took at least what the
1519 // core took, scaled on to the next place as the input's share is.
1520 if (reach.lagObject) {
1521 composed.lagObject = reach.lagObject;
1522 if (llvm::MulOverflow(reach.lagIn, taken, composed.lagIn) ||
1523 llvm::MulOverflow(composed.lagIn, next.inBytes,
1524 composed.lagIn) ||
1525 llvm::MulOverflow(reach.lagOut, released, composed.lagOut) ||
1526 llvm::MulOverflow(composed.lagOut, next.outBytes,
1527 composed.lagOut))
1528 continue;
1529 int64_t lagCommon = std::gcd(composed.lagIn, composed.lagOut);
1530 composed.lagIn /= lagCommon;
1531 composed.lagOut /= lagCommon;
1532 }
1533 work.push_back({composed, hops + 1});
1534 }
1535 }
1536 }
1537 if (proofs.empty()) {
1538 input.removeConsumedByAttr();
1539 continue;
1540 }
1541 auto ordered = proofs.takeVector();
1542 if (ordered.size() > 1) {
1543 if (!rank)
1544 rank = StructuralGraph::of(device).rank();
1545 llvm::stable_sort(ordered, [&](const auto &a, const auto &b) {
1546 return rank->lookup(a.first) < rank->lookup(b.first);
1547 });
1548 }
1549 SmallVector<Attribute> attrs;
1550 for (auto [output, share] : ordered) {
1551 int64_t common = std::gcd(share.in, share.out);
1552 attrs.push_back(ConsumedByAttr::get(
1553 ctx,
1554 FlatSymbolRefAttr::get(
1555 cast<RouteEndpointOp>(output).getSymNameAttr()),
1556 share.in / common, share.out / common, share.granule,
1557 /*device=*/FlatSymbolRefAttr()));
1558 }
1559 input.setConsumedByAttr(ArrayAttr::get(ctx, attrs));
1560 }
1561 }
1562
1563 /// An out-of-order sender names the buffer each object lands in, and one BD
1564 /// carries one such name, so the ends have to hold the same buffers in the
1565 /// same order. Naming a slice of a larger buffer would need the sender split
1566 /// into one descriptor per slice, which nothing does yet.
1567 LogicalResult verifyOutOfOrderPools(DeviceOp device) {
1568 auto lookup = [&](FlatSymbolRefAttr name) {
1569 return dyn_cast_or_null<ObjectFifoDmaEndpointOp>(
1570 SymbolTable::lookupNearestSymbolFrom(device, name.getAttr()));
1571 };
1572 auto objectBytes = [](ObjectFifoPoolOp pool) -> int64_t {
1573 auto type = dyn_cast<MemRefType>(pool.getElemType());
1574 if (!type)
1575 return 0;
1576 return (type.getNumElements() * type.getElementTypeBitWidth() + 7) / 8;
1577 };
1578 for (auto flow : device.getOps<RouteOp>()) {
1579 if (flow.getSources().size() != 1)
1580 continue;
1581 ObjectFifoDmaEndpointOp src =
1582 lookup(cast<FlatSymbolRefAttr>(flow.getSources()[0]));
1583 ObjectFifoDmaEndpointOp firstReceiver;
1584 for (auto destName :
1585 flow.getDestinations().getAsRange<FlatSymbolRefAttr>()) {
1586 ObjectFifoDmaEndpointOp dst = lookup(destName);
1587 if (!dst || !dst.getOutOfOrder())
1588 continue;
1589 if (!firstReceiver)
1590 firstReceiver = dst;
1591 if (firstReceiver.getNumDescriptors() != dst.getNumDescriptors() ||
1592 objectBytes(firstReceiver.getPoolOp()) !=
1593 objectBytes(dst.getPoolOp()))
1594 return flow.emitOpError(
1595 "out-of-order broadcast destinations require matching buffer "
1596 "counts and object sizes");
1597 if (!src || !src.getOutOfOrder())
1598 continue;
1599 ObjectFifoPoolOp from = src.getPoolOp(), to = dst.getPoolOp();
1600 if (!from || !to)
1601 continue;
1602 if (src.getNumDescriptors() != dst.getNumDescriptors() ||
1603 objectBytes(from) != objectBytes(to))
1604 return src.emitOpError("sends out of order from ")
1605 << src.getNumDescriptors() << " buffers of "
1606 << objectBytes(from) << " bytes into "
1607 << dst.getNumDescriptors() << " of " << objectBytes(to)
1608 << "; an out-of-order fifo needs the same buffers at both "
1609 "ends, because one descriptor names one whole buffer";
1610 }
1611 }
1612 return success();
1613 }
1614
1615 void runOnOperation() override {
1616 DeviceOp device = getOperation();
1617 poolLocks = std::make_shared<PoolLocks>(device);
1618
1619 DenseMap<Operation *, SmallVector<SegmentActors>> actorsPerPool;
1620 for (auto pool : device.getOps<ObjectFifoPoolOp>()) {
1621 actorsPerPool[pool].resize(pool.getSegmentOps().size());
1622 }
1623
1624 auto record = [&](auto endpoint) {
1625 ObjectFifoPoolOp pool = endpoint.getPoolOp();
1626 if (!pool) {
1627 return;
1628 }
1629 auto &actors = actorsPerPool[pool];
1630 std::vector<ObjectFifoSegmentOp> all = pool.getSegmentOps();
1631 for (ObjectFifoSegmentOp segment : endpoint.getSelectedSegments()) {
1632 size_t index = llvm::find(all, segment) - all.begin();
1633 (endpoint.drains() ? actors[index].drainers : actors[index].fillers)
1634 .push_back(endpoint);
1635 }
1636 };
1637
1638 for (auto endpoint : device.getOps<ObjectFifoCoreEndpointOp>()) {
1639 record(endpoint);
1640 }
1641 for (auto endpoint : device.getOps<ObjectFifoDmaEndpointOp>()) {
1642 record(endpoint);
1643 }
1644
1645 for (auto pool : device.getOps<ObjectFifoPoolOp>()) {
1646 if (failed(verifyActors(pool, actorsPerPool[pool]))) {
1647 return signalPassFailure();
1648 }
1649 }
1650
1651 SymbolTableCollection symbolTables;
1652 if (failed(verifyFlows(device, symbolTables)) ||
1653 failed(verifyFanIn(device, symbolTables)) ||
1654 failed(verifyOverRelease(device)) ||
1655 failed(verifyTransferBudgets(device)) ||
1656 failed(verifyHeldAtEnd(device, symbolTables)) ||
1657 failed(verifyAdvances(device)) ||
1658 failed(verifyDispatchVolumes(device)) ||
1659 failed(verifyOutOfOrderPools(device))) {
1660 return signalPassFailure();
1661 }
1662 recordConsumption(device, actorsPerPool);
1663 }
1664};
1665
1666} // namespace
1667
1668std::unique_ptr<OperationPass<DeviceOp>>
1670 return std::make_unique<AIEObjectFifoVerifyPass>();
1671}
mlir::LogicalResult read(llvm::ArrayRef< ObjectFifoCoreEndpointOp > ends, std::string &reason)
Reads the order off the program of the core working through ends, all draining (the channel fills the...
bool movesNone() const
Whether read found a steady state in which the period moves none of the objects: the core keeps what ...
mlir::Operation * periodAcquire() const
The first acquire the period runs, with its branches folded; null when it runs none.
llvm::ArrayRef< unsigned > turns() const
Indices into ends, one per object the channel moves in a period of the core's steady state.
mlir::Operation * periodLoop() const
The loop read took as the core's period, once it found one.
bool namesFifo(Operation *op, StringRef fifo, SymbolTableCollection &symbols)
Definition AIEUtils.cpp:386
std::optional< int64_t > staticExecutions(Operation *op)
Definition AIEUtils.cpp:329
std::unique_ptr< mlir::OperationPass< DeviceOp > > createAIEObjectFifoVerifyPass()
bool isForeverLoop(mlir::scf::WhileOp whileOp)
Whether whileOp repeats forever: its condition is a constant true, and its condition region does noth...
mlir::Operation * getObjectFifoLoopParent(mlir::Operation *op)
The innermost loop around op that isObjectFifoLoop accepts, or null.
bool isObjectFifoLoop(mlir::Operation *op)
Whether op is a loop that objectFifo lowering unrolls by the rotation period of the objectFifos acces...
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,...