MLIR-AIE 1.4.6.dev
AIEChannelTurns.h
Go to the documentation of this file.
1//===- AIEChannelTurns.h ----------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2026 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef AIE_DIALECT_AIE_TRANSFORMS_AIECHANNELTURNS_H
9#define AIE_DIALECT_AIE_TRANSFORMS_AIECHANNELTURNS_H
10
12
13#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/SmallVector.h"
15
16#include <string>
17
18namespace xilinx::AIE {
19
20/// The order one core moves objects through several pools, read off its
21/// program, so that one DMA channel can serve those pools in turn. The core's
22/// period is the innermost loop holding every acquire and release on the
23/// pools, with the loops of static trip count inside it unrolled and the
24/// branches on their counters folded; where a branch depends on that loop's
25/// own counter, the next loop out. Its order through them must not depend on
26/// data.
27class CoreTurns {
28public:
29 /// Reads the order off the program of the core working through `ends`, all
30 /// draining (the channel fills their pools) or all filling (the channel
31 /// drains them). Fails, saying why in `reason`, when the order is not
32 /// static.
33 mlir::LogicalResult read(llvm::ArrayRef<ObjectFifoCoreEndpointOp> ends,
34 std::string &reason);
35 /// The same, before split: `names` are objectFIFOs `core` acquires from
36 /// (`coreDrains`) or into.
37 mlir::LogicalResult read(CoreOp core, llvm::ArrayRef<mlir::StringAttr> names,
38 bool coreDrains, std::string &reason);
39
40 /// Indices into `ends`, one per object the channel moves in a period of the
41 /// core's steady state.
42 llvm::ArrayRef<unsigned> turns() const { return order; }
43
44 /// The loop `read` took as the core's period, once it found one.
45 mlir::Operation *periodLoop() const { return loop; }
46
47 /// Whether `read` found a steady state in which the period moves none of
48 /// the objects: the core keeps what it holds and never takes or hands over
49 /// another. `read` fails then, since there are no turns to take.
50 bool movesNone() const { return idle; }
51
52 /// The first acquire the period runs, with its branches folded; null when
53 /// it runs none.
54 mlir::Operation *periodAcquire() const;
55
56 /// Whether a channel moving objects in `turns()` order forever, through
57 /// pools of `depths`, never has itself and the core both waiting. Settles
58 /// `turns()` on the shortest such order cut from the period's.
59 bool keepsUp(llvm::ArrayRef<int64_t> depths);
60
61private:
62 bool keepsUp(llvm::ArrayRef<unsigned> order,
63 llvm::ArrayRef<int64_t> depths) const;
64 mlir::LogicalResult wholeRunKeepsTurns(
65 CoreOp core,
66 llvm::ArrayRef<std::pair<ObjectFifoReleaseOp, unsigned>> releases,
67 std::string &reason) const;
68
69 struct Event {
70 unsigned end;
71 int64_t count;
72 bool acquire;
73 mlir::Operation *op;
74 };
75
76 llvm::SmallVector<Event> period;
77 llvm::SmallVector<unsigned> order;
78 mlir::Operation *loop = nullptr;
79 size_t ends = 0;
80 bool coreDrains = true;
81 bool idle = false;
82};
83
84} // namespace xilinx::AIE
85
86#endif // AIE_DIALECT_AIE_TRANSFORMS_AIECHANNELTURNS_H
The order one core moves objects through several pools, read off its program, so that one DMA channel...
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 ...
bool keepsUp(llvm::ArrayRef< int64_t > depths)
Whether a channel moving objects in turns() order forever, through pools of depths,...
mlir::LogicalResult read(CoreOp core, llvm::ArrayRef< mlir::StringAttr > names, bool coreDrains, std::string &reason)
The same, before split: names are objectFIFOs core acquires from (coreDrains) or into.
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.