8#ifndef AIE_DIALECT_AIE_TRANSFORMS_AIESHIMSHARING_H
9#define AIE_DIALECT_AIE_TRANSFORMS_AIESHIMSHARING_H
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15#include "llvm/ADT/STLFunctionalExtras.h"
16#include "llvm/ADT/SmallSet.h"
17#include "llvm/ADT/SmallVector.h"
31 llvm::DenseMap<mlir::Operation *, llvm::SmallSet<int, 2>>
circuits;
33 llvm::DenseMap<std::pair<mlir::Operation *, int>,
34 llvm::SmallVector<mlir::StringAttr>>
37 llvm::DenseMap<std::pair<mlir::Operation *, int>,
unsigned>
packetFlows;
68 using Gates = llvm::DenseMap<mlir::StringAttr, llvm::SmallVector<Gate>>;
72 static mlir::StringAttr
keyOf(RouteEndpointOp endpoint);
77 static std::optional<End>
endOf(DeviceOp device, mlir::StringAttr symbol);
91 llvm::function_ref<std::optional<End>(mlir::StringAttr)>
endOf,
92 std::optional<Gates> gates = std::nullopt,
bool plannedOverlay =
false);
95 mlir::ModuleOp module,
96 llvm::function_ref<std::optional<End>(DeviceOp, mlir::StringAttr)>
endOf,
97 std::optional<Gates> gates = std::nullopt);
105 llvm::function_ref<mlir::StringAttr(RouteEndpointOp)>
keyOf);
109 bool apart(mlir::StringAttr a, mlir::StringAttr b)
const;
111 bool isUsed(mlir::StringAttr end)
const;
114 mlir::StringAttr
overlayEnd(
int column)
const;
120 std::optional<int64_t>
bytes(
unsigned seq, mlir::StringAttr end)
const {
121 auto it = spans[seq].find(end);
122 return it == spans[seq].end() ? std::nullopt : it->second.bytes;
126 bool names(
unsigned seq, mlir::StringAttr end)
const {
127 return spans[seq].contains(end);
133 llvm::SmallVector<llvm::SmallVector<unsigned>>
134 groups(llvm::ArrayRef<mlir::StringAttr> ends)
const;
141 llvm::SmallVector<mlir::StringAttr>
listed;
152 llvm::SmallVector<llvm::SmallVector<unsigned>>
groups;
159 Plan plan(llvm::ArrayRef<mlir::StringAttr> ends,
160 llvm::ArrayRef<mlir::StringAttr>
names,
161 llvm::ArrayRef<SharedChannel> shared)
const;
166 int64_t first = std::numeric_limits<int64_t>::max();
168 int64_t lastIssue = -1;
169 int64_t lastDone = -1;
171 int64_t lastAwaited = -1;
174 std::optional<int64_t>
bytes = 0;
178 mlir::Operation *root,
179 llvm::function_ref<std::optional<End>(DeviceOp, mlir::StringAttr)>
endOf);
181 mlir::Operation *root,
182 llvm::function_ref<std::optional<End>(DeviceOp, mlir::StringAttr)>
endOf);
185 bool gated(mlir::StringAttr a, mlir::StringAttr b)
const;
188 llvm::SmallVector<const Gate *> usableGates(mlir::StringAttr end)
const;
191 bool before(
const llvm::DenseMap<mlir::StringAttr, Span> &byFifo,
192 const Span &x,
const Span &y,
const Gate *gate)
const;
195 bool contained(mlir::StringAttr end,
const Gate &gate)
const;
197 llvm::DenseMap<mlir::StringAttr,
198 llvm::SmallVector<std::tuple<unsigned, int64_t, int64_t>>>
200 llvm::DenseSet<mlir::StringAttr> used;
201 llvm::DenseMap<mlir::StringAttr, llvm::SmallVector<mlir::StringAttr>>
204 llvm::DenseSet<mlir::StringAttr> receivers;
205 llvm::DenseSet<std::pair<mlir::StringAttr, mlir::StringAttr>> overlaps;
206 bool unknown =
false;
207 llvm::SmallVector<llvm::DenseMap<mlir::StringAttr, Span>> spans;
208 std::optional<Gates> gates;
209 mlir::MLIRContext *context =
nullptr;
211 mutable llvm::DenseMap<mlir::StringAttr, llvm::SmallVector<const Gate *>>
214 mutable llvm::DenseMap<mlir::StringAttr, bool> namedCache;
216 int overlayColumns = 0;
std::optional< int64_t > bytes(unsigned seq, mlir::StringAttr end) const
The bytes runtime sequence seq moves through end, nullopt when not static or when end is not one of i...
ShimTransferSpans(mlir::ModuleOp module, llvm::function_ref< std::optional< End >(DeviceOp, mlir::StringAttr)> endOf, std::optional< Gates > gates=std::nullopt)
llvm::DenseMap< mlir::StringAttr, llvm::SmallVector< Gate > > Gates
Plan plan(llvm::ArrayRef< mlir::StringAttr > ends, llvm::ArrayRef< mlir::StringAttr > names, llvm::ArrayRef< SharedChannel > shared) const
Plans ends (keyed as apart() takes keys); names[i] is how shared's lists name ends[i].
bool isUsed(mlir::StringAttr end) const
bool names(unsigned seq, mlir::StringAttr end) const
Whether runtime sequence seq transfers through end at all, static or not; bytes alone cannot tell a d...
unsigned sequences() const
The number of runtime sequences bytes indexes into.
bool apart(mlir::StringAttr a, mlir::StringAttr b) const
Whether both ends permit sharing: explicitly, by MM2S lifetime analysis, or, for a receiving end,...
static std::optional< End > endOf(DeviceOp device, mlir::StringAttr symbol)
The end a runtime sequence of device transfers through when it names symbol: a shim DMA route end,...
static mlir::StringAttr keyOf(RouteEndpointOp endpoint)
How ends and gates name a shim route end: by its objectFIFO, else by its own symbol.
mlir::StringAttr overlayEnd(int column) const
The planned control overlay channel's end on column column's shim tile.
llvm::SmallVector< llvm::SmallVector< unsigned > > groups(llvm::ArrayRef< mlir::StringAttr > ends) const
Splits ends into groups whose members are pairwise apart, each group taking one channel: first fit,...
ShimTransferSpans(DeviceOp device, llvm::function_ref< std::optional< End >(mlir::StringAttr)> endOf, std::optional< Gates > gates=std::nullopt, bool plannedOverlay=false)
endOf maps a symbol a runtime sequence transfers through to the objectFIFO end it belongs to,...
static Gates provenGates(DeviceOp device, llvm::function_ref< mlir::StringAttr(RouteEndpointOp)> keyOf)
Each receiving end's gates, keyed by keyOf: the shim inputs whose consumption its progress proves,...
ShimMM2SUses shimMM2SUses(DeviceOp device, bool packetSwitched)
The shim MM2S channels device's overlay weighs, for aie-generate-column-control-overlay.
llvm::DenseMap< std::pair< mlir::Operation *, int >, unsigned > packetFlows
Packet flows per (tile, channel).
llvm::DenseMap< mlir::Operation *, llvm::SmallSet< int, 2 > > circuits
Channels a circuit-switched route end, flow, allocation or shim mux holds, per shim tile op.
llvm::DenseMap< std::pair< mlir::Operation *, int >, llvm::SmallVector< mlir::StringAttr > > packetEnds
Packet-switched route ends, by name, per (tile, channel).
A shim end a runtime sequence transfers through.
bool sends
An MM2S end, sending into the array.
Gate(mlir::StringAttr input, ConsumedByAttr proof)
How one shim tile's unpinned ends in one direction share channels, as objectFIFO allocation shares th...
llvm::SmallVector< llvm::SmallVector< unsigned > > groups
The other ends, in groups taking one channel each.
llvm::SmallVector< std::optional< unsigned > > sharedChannel
Per end, the index of the shared channel it takes, if any.
SharedChannel(llvm::SmallVector< mlir::StringAttr > listed, bool pinned)
bool pinned
Whether a route end pins the channel, which then takes no other end.
llvm::SmallVector< mlir::StringAttr > listed