MLIR-AIE 1.4.6.dev
AIEDialect.h
Go to the documentation of this file.
1//===- AIEDialect.h ---------------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2019-2022 Xilinx, Inc.
4// Copyright (C) 2022-2026 Advanced Micro Devices, Inc.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_AIE_DIALECT_H
10#define MLIR_AIE_DIALECT_H
11
12#include "AIEEnums.h"
14
16
17#include "mlir/Dialect/DLTI/Traits.h"
18#include "mlir/Dialect/Func/IR/FuncOps.h"
19#include "mlir/Dialect/MemRef/IR/MemRef.h"
20#include "mlir/IR/BuiltinAttributes.h"
21#include "mlir/IR/OpDefinition.h"
22#include "mlir/IR/OpImplementation.h"
23#include "mlir/IR/SymbolTable.h"
24#include "mlir/Interfaces/DataLayoutInterfaces.h"
25
26#include "llvm/ADT/ArrayRef.h"
27#include "llvm/ADT/STLExtras.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/StringSwitch.h"
30
31namespace xilinx::AIE {
32
33// Check that the given DMA-like op (e.g. MemOp, ShimDMAOp)
34// has valid BDs.
35template <typename ConcreteType>
36struct HasValidBDs : mlir::OpTrait::TraitBase<ConcreteType, HasValidBDs> {
37 static mlir::LogicalResult verifyTrait(mlir::Operation *op);
38};
39
40// Check that the given DMA-like op (e.g. MemOp, ShimDMAOp)
41// has valid channels.
42template <typename ConcreteType>
44 : mlir::OpTrait::TraitBase<ConcreteType, HasValidBDs> {
45 static mlir::LogicalResult verifyTrait(mlir::Operation *op);
46};
47
48template <typename ConcreteType>
50 : mlir::OpTrait::TraitBase<ConcreteType, SkipAccessibilityCheckTrait> {};
51
52// Supplies `Symbol`'s visibility accessors for ops that keep visibility in a
53// plain `sym_visibility` attribute rather than in a tablegen-declared argument
54// (which is what upstream's `SymbolVisibility` trait requires).
55template <typename ConcreteType>
57 : mlir::OpTrait::TraitBase<ConcreteType, AttrBasedSymbolVisibility> {
58 static constexpr llvm::StringRef getVisibilityAttrName() {
59 return "sym_visibility";
60 }
61
62 // `mlir::detail::verifySymbol` only checks the inherent attribute, so it
63 // never sees ours.
64 static mlir::LogicalResult verifyTrait(mlir::Operation *op) {
65 mlir::Attribute vis = op->getAttr(getVisibilityAttrName());
66 if (!vis)
67 return mlir::success();
68 auto visStrAttr = llvm::dyn_cast<mlir::StringAttr>(vis);
69 if (!visStrAttr)
70 return op->emitOpError()
71 << "requires visibility attribute '" << getVisibilityAttrName()
72 << "' to be a string attribute, but got " << vis;
73 if (!llvm::is_contained(
74 llvm::ArrayRef<llvm::StringRef>{"public", "private", "nested"},
75 visStrAttr.getValue()))
76 return op->emitOpError()
77 << "visibility expected to be one of [\"public\", \"private\", "
78 "\"nested\"], but got "
79 << visStrAttr;
80 return mlir::success();
81 }
82
83 mlir::SymbolTable::Visibility getVisibility() {
84 mlir::StringAttr vis =
85 this->getOperation()->template getAttrOfType<mlir::StringAttr>(
87 if (!vis)
88 return mlir::SymbolTable::Visibility::Public;
89 return llvm::StringSwitch<mlir::SymbolTable::Visibility>(vis.getValue())
90 .Case("private", mlir::SymbolTable::Visibility::Private)
91 .Case("nested", mlir::SymbolTable::Visibility::Nested)
92 .Default(mlir::SymbolTable::Visibility::Public);
93 }
94
95 void setVisibility(mlir::SymbolTable::Visibility vis) {
96 mlir::Operation *op = this->getOperation();
97 if (vis == mlir::SymbolTable::Visibility::Public) {
98 op->removeAttr(getVisibilityAttrName());
99 return;
100 }
101 assert((vis == mlir::SymbolTable::Visibility::Private ||
102 vis == mlir::SymbolTable::Visibility::Nested) &&
103 "unknown symbol visibility kind");
104 llvm::StringRef visName =
105 vis == mlir::SymbolTable::Visibility::Private ? "private" : "nested";
106 op->setAttr(getVisibilityAttrName(),
107 mlir::StringAttr::get(op->getContext(), visName));
108 }
109};
110
111// Marker trait for operations that can be flow endpoints (e.g., TileOp, CoreOp,
112// MemOp)
113template <typename ConcreteType>
114struct IsFlowEndPoint : mlir::OpTrait::TraitBase<ConcreteType, IsFlowEndPoint> {
115};
116
117class TileOp;
118class RouteEndpointOp;
119
121 uint32_t burstLength);
123 uint32_t burstLength);
124
125// Looks up a name, falling back to a scan for the `sym_name` attribute.
126// `aie.buffer`, `aie.external_buffer`, `aie.lock` and `aie.dma` are referred to
127// by name but define an SSA value, so they cannot be `Symbol` ops and
128// `mlir::SymbolTable` does not find them.
129mlir::Operation *lookupNamedOpIn(mlir::Operation *symbolTableOp,
130 mlir::StringAttr name);
131mlir::Operation *lookupNamedOpIn(mlir::Operation *symbolTableOp,
132 llvm::StringRef name);
133// Looks in the symbol table nearest to (or at) `from`.
134mlir::Operation *lookupNamedOp(mlir::Operation *from, mlir::StringAttr name);
135mlir::Operation *lookupNamedOp(mlir::Operation *from, llvm::StringRef name);
136
137template <typename OpTy, typename NameT>
138OpTy lookupNamedOpIn(mlir::Operation *symbolTableOp, NameT name) {
139 return llvm::dyn_cast_if_present<OpTy>(lookupNamedOpIn(symbolTableOp, name));
140}
141
142template <typename OpTy, typename NameT>
143OpTy lookupNamedOp(mlir::Operation *from, NameT name) {
144 return llvm::dyn_cast_if_present<OpTy>(lookupNamedOp(from, name));
145}
146
147// `lookupNamedOpIn` indexed once, for resolving many names in a symbol table
148// whose named ops do not change meanwhile.
150public:
151 explicit NamedOpTable(mlir::Operation *symbolTableOp);
152
153 mlir::Operation *lookup(mlir::StringAttr name) const {
154 return ops.lookup(name);
155 }
156 template <typename OpTy>
157 OpTy lookup(mlir::StringAttr name) const {
158 return llvm::dyn_cast_if_present<OpTy>(lookup(name));
159 }
160
161 // "<prefix><n>" for the first n from `counter` up that no op in the table
162 // has. `counter` moves past n, so names drawn from one counter differ
163 // although the table does not record them.
164 std::string uniqueName(llvm::StringRef prefix, unsigned &counter) const;
165
166private:
167 mlir::MLIRContext *context;
168 llvm::DenseMap<mlir::StringAttr, mlir::Operation *> ops;
169};
170
171// The NamedOpTables of several symbol tables, each indexed on first use, as
172// mlir::SymbolTableCollection is for symbols.
174public:
175 NamedOpTable &getTable(mlir::Operation *symbolTableOp) {
176 return tables.try_emplace(symbolTableOp, symbolTableOp).first->second;
177 }
178 template <typename OpTy>
179 OpTy lookupIn(mlir::Operation *symbolTableOp, mlir::StringAttr name) {
180 return getTable(symbolTableOp).lookup<OpTy>(name);
181 }
182
183private:
184 llvm::DenseMap<mlir::Operation *, NamedOpTable> tables;
185};
186
187mlir::LogicalResult
188verifyOffsetSizeAndStrideOp(mlir::OffsetSizeAndStrideOpInterface op);
189
190// custom<TypedDynamicIndexList>($values, $integers, type($values)): the
191// upstream custom<DynamicIndexList> with an optional type on each SSA entry,
192// `%v` for i64 and `%v : type` otherwise.
194 mlir::OpAsmParser &parser,
195 llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &values,
196 mlir::DenseI64ArrayAttr &integers,
197 llvm::SmallVectorImpl<mlir::Type> &types);
198void printTypedDynamicIndexList(mlir::OpAsmPrinter &printer,
199 mlir::Operation *op, mlir::OperandRange values,
200 llvm::ArrayRef<int64_t> integers,
201 mlir::TypeRange types);
202
203} // namespace xilinx::AIE
204
205namespace xilinx::AIE {
206mlir::LogicalResult
207myVerifyOffsetSizeAndStrideOp(mlir::OffsetSizeAndStrideOpInterface op);
208template <typename ConcreteOp>
211 static ::mlir::LogicalResult verifyTrait(::mlir::Operation *op) {
213 ::mlir::cast<::mlir::OffsetSizeAndStrideOpInterface>(op));
214 }
215};
216
218 : ::mlir::OffsetSizeAndStrideOpInterface {
219 template <typename ConcreteOp>
220 struct Trait : public MyOffsetSizeAndStrideOpInterfaceTrait<ConcreteOp> {};
221};
222} // namespace xilinx::AIE
223
224// Include dialect declarations such as parseAttributes, parseType
225#include "aie/Dialect/AIE/IR/AIEDialect.h.inc"
226
227namespace xilinx::AIE {
228
230
231} // namespace xilinx::AIE
232
233////////////////////////////////////////////////////////////////////////////////
234/////////////////////// Custom Types for the Dialect ///////////////////////////
235////////////////////////////////////////////////////////////////////////////////
236
237#define GET_TYPEDEF_CLASSES
238#include "aie/Dialect/AIE/IR/AIETypes.h.inc"
239
240////////////////////////////////////////////////////////////////////////////////
241// Custom Attributes ///////////////////////////////////////////////////////////
242////////////////////////////////////////////////////////////////////////////////
243
244#define GET_ATTRDEF_CLASSES
245#include "aie/Dialect/AIE/IR/AIEAttrs.h.inc"
246
247// Interfaces come after the attributes and types their methods traffic in.
248#include "aie/Dialect/AIE/IR/AIEInterfaces.h.inc"
249
250////////////////////////////////////////////////////////////////////////////////
251//////////////////// Custom Operations for the Dialect /////////////////////////
252////////////////////////////////////////////////////////////////////////////////
253
254namespace xilinx::AIE {
255
256WireBundle getConnectingBundle(WireBundle dir);
257
258#define GENERATE_TO_STRING(TYPE_WITH_INSERTION_OP) \
259 friend std::string to_string(const TYPE_WITH_INSERTION_OP &s) { \
260 std::ostringstream ss; \
261 ss << s; \
262 return ss.str(); \
263 }
264
265using Port = struct Port {
266 WireBundle bundle;
267 int channel;
268
269 bool operator==(const Port &rhs) const {
270 return std::tie(bundle, channel) == std::tie(rhs.bundle, rhs.channel);
271 }
272
273 bool operator!=(const Port &rhs) const { return !(*this == rhs); }
274
275 bool operator<(const Port &rhs) const {
276 return std::tie(bundle, channel) < std::tie(rhs.bundle, rhs.channel);
277 }
278
279 friend std::ostream &operator<<(std::ostream &os, const Port &port) {
280 os << "(";
281 os << stringifyWireBundle(port.bundle).str();
282 os << ": " << std::to_string(port.channel) << ")";
283 return os;
284 }
285
287
288 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
289 const Port &port) {
290 os << to_string(port);
291 return os;
292 }
293};
294
295/// The switchbox input driven by an output's physical wire, with the channel
296/// preserved. Endpoint bundles have no wire and return nullopt. This describes
297/// geometry, not device bounds or port availability, which callers validate.
298std::optional<std::pair<TileID, Port>> getLinkedInput(TileID tile, Port output);
299
300/// getLinkedInput, restricted to tiles on the device.
301std::optional<std::pair<TileID, Port>>
302getConnectingWireEndpoint(const AIETargetModel &targetModel, TileID tile,
303 Port port);
304
305using Connect = struct Connect {
306 Port src;
307 Port dst;
308
309 bool operator==(const Connect &rhs) const {
310 return std::tie(src, dst) == std::tie(rhs.src, rhs.dst);
311 }
312
313 bool operator!=(const Connect &rhs) const { return !(*this == rhs); }
314
315 bool operator<(const Connect &rhs) const {
316 return std::tie(src, dst) < std::tie(rhs.src, rhs.dst);
317 }
318};
319
320using DMAChannel = struct DMAChannel {
321 DMAChannelDir direction;
322 int channel;
323
324 bool operator==(const DMAChannel &rhs) const {
325 return std::tie(direction, channel) == std::tie(rhs.direction, rhs.channel);
326 }
327};
328
329const AIETargetModel &getTargetModel(mlir::Operation *op);
330const AIETargetModel &getTargetModel(AIEDevice device);
331
332/// Which of `a`'s and `b`'s memory modules both tiles can address.
334
335mlir::ParseResult
336parseObjectFifoProducerTile(mlir::OpAsmParser &parser,
337 mlir::OpAsmParser::UnresolvedOperand &operand,
338 BDDimLayoutArrayAttr &dimensions);
339
340void printObjectFifoProducerTile(mlir::OpAsmPrinter &printer,
341 mlir::Operation *op, mlir::Value operand,
342 BDDimLayoutArrayAttr dimensions);
343
344mlir::ParseResult parseDMAStartChannel(mlir::OpAsmParser &parser,
345 mlir::Attribute &channel);
346
347void printDMAStartChannel(mlir::OpAsmPrinter &printer, mlir::Operation *op,
348 mlir::Attribute channel);
349
350mlir::ParseResult
351parseObjectFifoAcquireObjects(mlir::OpAsmParser &parser,
352 ObjectFifoPortAttr &port,
353 llvm::SmallVectorImpl<mlir::Type> &objects);
354
355void printObjectFifoAcquireObjects(mlir::OpAsmPrinter &printer,
356 mlir::Operation *op, ObjectFifoPortAttr port,
357 mlir::TypeRange objects);
358
359mlir::ParseResult parseObjectFifoReleaseCount(mlir::OpAsmParser &parser,
360 ObjectFifoPortAttr &port,
361 mlir::IntegerAttr &size);
362
363void printObjectFifoReleaseCount(mlir::OpAsmPrinter &printer,
364 mlir::Operation *op, ObjectFifoPortAttr port,
365 mlir::IntegerAttr size);
366
368 mlir::OpAsmParser &parser,
369 llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &tiles,
370 BDDimLayoutArrayArrayAttr &dimensions);
371
372void printObjectFifoConsumerTiles(mlir::OpAsmPrinter &printer,
373 mlir::Operation *op, mlir::OperandRange tiles,
374 BDDimLayoutArrayArrayAttr dimsPerTileAttr);
375
376mlir::ParseResult
377parseFlowVias(mlir::OpAsmParser &parser,
378 llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &vias,
379 mlir::DenseI32ArrayAttr &ingressBundles,
380 mlir::DenseI32ArrayAttr &ingressChannels,
381 mlir::DenseI32ArrayAttr &egressBundles,
382 mlir::DenseI32ArrayAttr &egressChannels);
383
384void printFlowVias(mlir::OpAsmPrinter &printer, mlir::Operation *op,
385 mlir::OperandRange vias,
386 mlir::DenseI32ArrayAttr ingressBundles,
387 mlir::DenseI32ArrayAttr ingressChannels,
388 mlir::DenseI32ArrayAttr egressBundles,
389 mlir::DenseI32ArrayAttr egressChannels);
390
391int32_t getBufferBaseAddress(mlir::Operation *bufOp);
392
393// The banks a memref's address space names (5-8 one bank each, 9-14 a pair),
394// or none.
395llvm::SmallVector<int, 2> banksFromMemorySpace(mlir::Type type);
396
397// Trace Event Value Parsing/Printing (handles both string and typed enums)
398mlir::ParseResult parseTraceEvent(mlir::AsmParser &parser,
399 mlir::Attribute &result);
400void printTraceEventEnum(mlir::AsmPrinter &printer, mlir::Attribute attr);
401
402} // namespace xilinx::AIE
403
404namespace xilinx::AIE {
405
406// A draining walk over a whole stream of objects rather than one of them:
407// output `j` walks `inner` from object `advance * j - top` on, reading `span`
408// consecutive objects through the inner dimension `rowDim` steps by one
409// object (none when `span` is 1); the `top` objects before the first and
410// `bottom` past the last of `objects` read as zeros.
412 int64_t objectSize;
413 int64_t outputs;
414 int64_t advance;
415 int64_t span;
416 int64_t top;
417 int64_t bottom;
418 int64_t objects;
419 int64_t rowDim;
420 llvm::SmallVector<BDDimLayoutAttr> inner;
421
422 // Elements each output moves.
423 int64_t transfer() const;
424};
425
426// Where a tile sits, if known: a placed tile's coordinates, or a placer's
427// current position for a logical one.
428using TilePositions = llvm::function_ref<std::optional<TileID>(mlir::Value)>;
429
430// A link participant other than the pool's owner whose aie.objectfifo.allocate
431// may share the link's pool: its tiles, and the objects of its end off the
432// link's tile.
434 mlir::Value producer;
435 mlir::Value consumer;
436 mlir::Value delegate;
437 int64_t depth;
438};
439
440// What sizes a link's pool wherever tiles sit (ObjectFifoLinkOp::getPoolPlan):
441// the depth without sharers, and each participant that may share it.
443 mlir::Value linkTile;
444 int64_t depth;
445 llvm::SmallVector<LinkPoolSharer> sharers;
446 // The pool's depth where `positions` puts the tiles: a sharer counts where
447 // ObjectFifoCreateOp::allocatedHome finds it a home on the link's tile.
448 int64_t depthAt(const AIETargetModel &target, TilePositions positions) const;
449};
450
451// The DMA end aie-objectfifo-split gives a fifo on one tile, known before
452// placement.
454 // BD ids the end takes, as ObjectFifoDmaEndpointOp::getNumBDs counts them.
455 int64_t bds;
456 // The pool this end walks.
457 mlir::Operation *pool;
458 // Tells a fifo's own consumer pools on the same tile apart.
459 int id;
460 // The pool's depth. Walked whole, a pool's ends take one BD id each.
461 int64_t depth;
462 // Whether one BD per side can walk the pool whole.
464 // Bytes in each of the pool's objects.
465 int64_t objectBytes;
466 // Objects the split lays contiguously in one buffer; zero if none do.
468 // The DMA channel the end pins, if any.
469 std::optional<int> channel;
470};
471
472// Why a fifo's objects cannot be its link's pool's objects
473// (ObjectFifoCreateOp::linkPoolMisfit).
474enum class LinkPoolMisfit {
476 // The pool's owner has another object type.
478 // The fifo has initial objects, but the pool starts with its owner's.
480 // A merge's inputs take turns filling the pool through one DMA end.
482 // A dispatch's outputs take turns draining the pool through one DMA end.
484 // The fifo is one link's output and another's input.
486};
487
488// One output of a StreamWindow: the first object it reads, counting the `top`
489// zero objects, and the lock units it takes before and gives back after.
491 int64_t first;
492 int64_t acquire;
493 int64_t release;
494};
495
496} // namespace xilinx::AIE
497
498// include TableGen generated Op definitions
499#define GET_OP_CLASSES
500#include "aie/Dialect/AIE/IR/AIEOps.h.inc"
501
502namespace xilinx::AIE {
503
504// Whether a core on `tile` acquires or releases `fifo` through `port`, so
505// the split gives that end a core endpoint.
506bool hasCoreAccess(DeviceOp device, mlir::Value tile, ObjectFifoCreateOp fifo,
507 ObjectFifoPort port);
508
509// The endpoints `end`'s `turns` names, each once, in order of first turn;
510// none when it takes no turns.
511llvm::SmallVector<ObjectFifoDmaEndpointOp>
512turnEndpoints(ObjectFifoDmaEndpointOp end);
513
514// Passes a chain of turns is unrolled for, given each end's turns a pass and
515// descriptors: until every end is back at its first descriptor. An end on a
516// contiguous pool, given 0 descriptors, takes as many as its turns need.
517int64_t turnPasses(llvm::ArrayRef<std::pair<int64_t, int64_t>> ends);
518
519// Whether packets leave `master` of `tile` with their header: not into a DMA,
520// nor down the shim's South to one, unless `keep` says.
521bool keepsPktHeader(TileID tile, Port master, std::optional<bool> keep);
522
523// Whether a route asking for `header`, null for no preference, carries
524// packet headers: aie-assign-packet-ids gives one to every route asking for
525// none when `packetSwDefault` (its packet-sw-objFifos) is set.
526inline bool isPacketSwitched(PacketInfoAttr header, bool packetSwDefault) {
527 return header || packetSwDefault;
528}
529
530// Whether `bundle` links a switchbox to a neighbouring one.
531inline bool isDirectional(WireBundle bundle) {
532 return bundle == WireBundle::North || bundle == WireBundle::South ||
533 bundle == WireBundle::East || bundle == WireBundle::West;
534}
535
536void collectTiles(DeviceOp &device,
537 llvm::DenseMap<TileID, mlir::Operation *> &tiles);
538
540 DeviceOp &device,
541 llvm::DenseMap<mlir::Operation *, llvm::SmallVector<BufferOp, 4>> &buffers);
542
543// Returns true when a BDDimLayoutAttr array (outermost-first) describes a
544// contiguous row-major scan: innermost stride == 1 and each outer stride
545// equals the product of all inner sizes. Used by DMABDOp verification and
546// canonicalization to allow natural ND forms on shim tiles that will be
547// linearized by the compiler.
548bool isContiguousBDTransfer(llvm::ArrayRef<BDDimLayoutAttr> dims);
549
550// The elements a BD streaming `dims` with `pads` sends, each dimension widened
551// by its padding; `fallback` unless it has both.
552int64_t paddedSize(llvm::ArrayRef<BDDimLayoutAttr> dims,
553 llvm::ArrayRef<BDPadLayoutAttr> pads, int64_t fallback);
554
555// Bytes one value of `type` takes under `layout`.
556int64_t getMemRefSizeInBytes(mlir::MemRefType type,
557 const mlir::DataLayout &layout);
558
559// The dimensions aie-normalize-dma-bd-dims leaves a constant BD with, given its
560// dimensions (outermost first) and its length in elements: none when it
561// becomes one linear transfer, else its size-1 dimensions dropped. nullopt
562// when it stays as written: no size-1 dimension, or a length that is not the
563// dimensions' product (a leading repeat outside the length).
564std::optional<llvm::SmallVector<BDDimLayoutAttr>>
565normalizedBDDims(llvm::ArrayRef<BDDimLayoutAttr> dims, int64_t len);
566
567// The byte size of `lengthUnit` elements of `buffer`, checked to be a multiple
568// of 16 bytes whose word count fits a 32-bit BD length.
569mlir::FailureOr<int64_t> getLengthUnitBytes(mlir::Operation *op,
570 int64_t lengthUnit,
571 mlir::BaseMemRefType buffer);
572
573// Validate a BD's runtime length (`length_parameter`, see aie.dma_bd) against
574// its static pattern, shared by aie.dma_bd and aiex.npu.dma_memcpy_nd.
575// `lenElems` is the static length of one iteration, in elements. `contiguous`
576// says the BD is lowered in linear mode; otherwise the added length continues
577// the third dimension as placed by placeRuntimeLengthDimension, so
578// `innerSizes` (the three innermost sizes, innermost-first) must give it a
579// size above one and a row that divides the length unit.
580mlir::LogicalResult verifyLengthParameter(mlir::Operation *op,
581 std::optional<int64_t> lengthUnit,
582 mlir::BaseMemRefType buffer,
583 std::optional<int64_t> lenElems,
584 bool contiguous,
585 llvm::ArrayRef<int64_t> innerSizes);
586
587// The added length of a runtime-length BD steps the third dimension. When that
588// dimension has size one, its stride is not encoded, so a pattern stepping
589// rows in its second dimension is lowered with them in the third instead and
590// the second left at size one. `sizes` and `strides` are innermost-first and
591// hold at least three dimensions.
592void placeRuntimeLengthDimension(llvm::MutableArrayRef<int64_t> sizes,
593 llvm::MutableArrayRef<int64_t> strides);
594
595// Validate the tile a runtime-length BD is lowered on: an AIE2/AIE2P shim NOC
596// tile whose BD buffer length is a whole 32-bit register, which the firmware
597// update adds to.
598mlir::LogicalResult verifyLengthParameterTile(mlir::Operation *op,
599 const AIETargetModel &targetModel,
600 int col, int row);
601
602// Validate the sender-side out_of_order_id field on a single BD. Callable from
603// the AIEX dialect, whose runtime-sequence task BDs skip DMABDOp::verify.
604mlir::LogicalResult
605verifyDMABDOutOfOrderId(DMABDOp bd, bool packetEnabledByContext = false);
606
607// Validate a BD's iteration attribute against its tile type's iteration and
608// step fields. Callable from the AIEX dialect, like verifyDMABDOutOfOrderId.
609mlir::LogicalResult verifyDMABDIteration(DMABDOp bd, AIETileType tileType);
610
611// Below allocation a packet header is only useful once its id is assigned.
612// `what` names the attribute in the diagnostic. Callable from the AIEX
613// dialect, whose runtime ops carry the same header.
614mlir::LogicalResult verifyAssignedPacket(mlir::Operation *op,
615 PacketInfoAttr packet,
616 llvm::StringRef what = "packet");
617
618// `channel` names one of `tile`'s DMA channels in `dir`. Callable from the
619// AIEX dialect.
620mlir::LogicalResult verifyDMAChannelIndex(mlir::Operation *op, TileLike tile,
621 DMAChannelDir dir, int64_t channel);
622
623// As verifyDMAChannelIndex, and the tile has a DMA: a shim PL tile has none.
624mlir::LogicalResult verifyDMAChannel(mlir::Operation *op, TileLike tile,
625 DMAChannelDir dir, int64_t channel);
626// As above, for the tile at (`col`, `row`).
627mlir::LogicalResult verifyDMAChannel(mlir::Operation *op,
628 const AIETargetModel &targetModel, int col,
629 int row, DMAChannelDir dir,
630 int64_t channel);
631// Check the tile has the ControlMM2S/TraceS2MM channel; data directions pass.
632mlir::LogicalResult
634 const AIETargetModel &targetModel, int col,
635 int row, DMAChannelDir dir, int64_t channel);
636// As above; an unplaced tile passes.
637mlir::LogicalResult verifyControlOrTraceDMAChannel(mlir::Operation *op,
638 TileLike tile,
639 DMAChannelDir dir,
640 int64_t channel);
641
642// Validate an out-of-order S2MM channel and its receive BDs.
643mlir::LogicalResult
644verifyOutOfOrderChannel(mlir::Operation *op, DMAChannelDir dir, bool outOfOrder,
645 llvm::ArrayRef<DMABDOp> bds,
646 bool packetEnabledByContext = false);
647
648// Validate the use_locks of one BD block and return them. A BD has one acquire
649// field and one release field; by convention the block uses either no lock or
650// both, except that an out-of-order BD may release alone. Either result is
651// null when the block has no such lock.
652mlir::LogicalResult verifyBdLockPair(mlir::Block &block, bool outOfOrder,
653 UseLockOp &acquire, UseLockOp &release);
654
655// The stream window `dims` (outermost first) and `pads` (`(top, bottom)` on
656// the outermost dimension only) describe over objects of `objectSize`
657// elements. The outermost dimension steps whole objects between outputs; at
658// most one inner dimension steps whole objects, by one; the others stay
659// within an object. Fills `window` on success.
660mlir::LogicalResult
661inferStreamWindow(llvm::ArrayRef<BDDimLayoutAttr> dims,
662 llvm::ArrayRef<BDPadLayoutAttr> pads, int64_t objectSize,
663 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
664 StreamWindow &window);
665
666// Each output's step: it takes the objects up to the newest it reads and gives
667// back those no later output reads, the last one all that are left.
668llvm::SmallVector<StreamWindowStep> streamWindowSteps(const StreamWindow &w);
669
670// BD ids already assigned within a tile's static DMA program (the
671// aie.dma_bd chain(s) inside one DmaBody-implementing op: aie.mem,
672// aie.memtile_dma, aie.shim_dma).
673llvm::SmallVector<uint32_t> getAssignedBdIds(DmaBody program);
674
675// Fails, with an error on each, if a dma_start in `device` still names a route
676// endpoint in place of a channel index. For passes and translations that need
677// the index, which aie-objectfifo-allocate assigns.
678mlir::LogicalResult verifyDMAChannelsResolved(DeviceOp device);
679
680} // namespace xilinx::AIE
681
682namespace llvm {
683// Functions hash just like pointers.
684template <>
685struct DenseMapInfo<xilinx::AIE::ObjectFifoAcquireOp> {
686 static unsigned getHashValue(xilinx::AIE::ObjectFifoAcquireOp val) {
687 return hash_value(val.getAsOpaquePointer());
688 }
689
690 static bool isEqual(xilinx::AIE::ObjectFifoAcquireOp lhs,
691 xilinx::AIE::ObjectFifoAcquireOp rhs) {
692 return lhs == rhs;
693 }
694};
695} // namespace llvm
696
697namespace llvm {
698// Functions hash just like pointers.
699template <>
700struct DenseMapInfo<xilinx::AIE::ObjectFifoCreateOp> {
701 static unsigned getHashValue(xilinx::AIE::ObjectFifoCreateOp val) {
702 return hash_value(val.getAsOpaquePointer());
703 }
704
705 static bool isEqual(xilinx::AIE::ObjectFifoCreateOp lhs,
706 xilinx::AIE::ObjectFifoCreateOp rhs) {
707 return lhs == rhs;
708 }
709};
710
711template <>
712struct DenseMapInfo<xilinx::AIE::DMAChannel> {
713 using FirstInfo = DenseMapInfo<xilinx::AIE::DMAChannelDir>;
714 using SecondInfo = DenseMapInfo<int>;
715
716 static unsigned getHashValue(const xilinx::AIE::DMAChannel &d) {
717 return detail::combineHashValue(FirstInfo::getHashValue(d.direction),
718 SecondInfo::getHashValue(d.channel));
719 }
720
721 static bool isEqual(const xilinx::AIE::DMAChannel &lhs,
722 const xilinx::AIE::DMAChannel &rhs) {
723 return lhs == rhs;
724 }
725};
726
727template <>
728struct DenseMapInfo<xilinx::AIE::Port> {
729 using FirstInfo = DenseMapInfo<xilinx::AIE::WireBundle>;
730 using SecondInfo = DenseMapInfo<int>;
731
732 static unsigned getHashValue(const xilinx::AIE::Port &d) {
733 return detail::combineHashValue(FirstInfo::getHashValue(d.bundle),
734 SecondInfo::getHashValue(d.channel));
735 }
736
737 static bool isEqual(const xilinx::AIE::Port &lhs,
738 const xilinx::AIE::Port &rhs) {
739 return lhs == rhs;
740 }
741};
742
743} // namespace llvm
744
745template <>
746struct std::less<xilinx::AIE::Port> {
748 const xilinx::AIE::Port &b) const {
749 return a.bundle == b.bundle ? a.channel < b.channel : a.bundle < b.bundle;
750 }
751};
752
753template <>
754struct std::hash<xilinx::AIE::Port> {
755 std::size_t operator()(const xilinx::AIE::Port &p) const noexcept {
756 std::size_t h1 = std::hash<xilinx::AIE::WireBundle>{}(p.bundle);
757 std::size_t h2 = std::hash<int>{}(p.channel);
758 return h1 ^ h2 << 1;
759 }
760};
761
762#endif
#define GENERATE_TO_STRING(TYPE_WITH_INSERTION_OP)
Definition AIEDialect.h:258
SharedMemory
Which of two tiles' memory modules both of them can address.
OpTy lookupIn(mlir::Operation *symbolTableOp, mlir::StringAttr name)
Definition AIEDialect.h:179
NamedOpTable & getTable(mlir::Operation *symbolTableOp)
Definition AIEDialect.h:175
NamedOpTable(mlir::Operation *symbolTableOp)
std::string uniqueName(llvm::StringRef prefix, unsigned &counter) const
OpTy lookup(mlir::StringAttr name) const
Definition AIEDialect.h:157
mlir::Operation * lookup(mlir::StringAttr name) const
Definition AIEDialect.h:153
mlir::LogicalResult verifyDMAChannel(mlir::Operation *op, TileLike tile, DMAChannelDir dir, int64_t channel)
bool isContiguousBDTransfer(llvm::ArrayRef< BDDimLayoutAttr > dims)
mlir::ParseResult parseFlowVias(mlir::OpAsmParser &parser, llvm::SmallVectorImpl< mlir::OpAsmParser::UnresolvedOperand > &vias, mlir::DenseI32ArrayAttr &ingressBundles, mlir::DenseI32ArrayAttr &ingressChannels, mlir::DenseI32ArrayAttr &egressBundles, mlir::DenseI32ArrayAttr &egressChannels)
void printObjectFifoProducerTile(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::Value operand, BDDimLayoutArrayAttr dimensions)
void printTypedDynamicIndexList(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange values, llvm::ArrayRef< int64_t > integers, mlir::TypeRange types)
llvm::SmallVector< ObjectFifoDmaEndpointOp > turnEndpoints(ObjectFifoDmaEndpointOp end)
llvm::function_ref< std::optional< TileID >(mlir::Value)> TilePositions
Definition AIEDialect.h:428
std::optional< llvm::SmallVector< BDDimLayoutAttr > > normalizedBDDims(llvm::ArrayRef< BDDimLayoutAttr > dims, int64_t len)
bool hasCoreAccess(DeviceOp device, mlir::Value tile, ObjectFifoCreateOp fifo, ObjectFifoPort port)
mlir::LogicalResult verifyLengthParameterTile(mlir::Operation *op, const AIETargetModel &targetModel, int col, int row)
uint32_t getShimBurstLengthBytes(const AIE::AIETargetModel &tm, uint32_t burstLength)
void collectTiles(DeviceOp &device, llvm::DenseMap< TileID, mlir::Operation * > &tiles)
int64_t getMemRefSizeInBytes(mlir::MemRefType type, const mlir::DataLayout &layout)
llvm::SmallVector< int, 2 > banksFromMemorySpace(mlir::Type type)
void collectBuffers(DeviceOp &device, llvm::DenseMap< mlir::Operation *, llvm::SmallVector< BufferOp, 4 > > &buffers)
bool isPacketSwitched(PacketInfoAttr header, bool packetSwDefault)
Definition AIEDialect.h:526
mlir::ParseResult parseTraceEvent(mlir::AsmParser &parser, mlir::Attribute &result)
mlir::LogicalResult verifyOffsetSizeAndStrideOp(mlir::OffsetSizeAndStrideOpInterface op)
void registerAIETranslations()
void printObjectFifoAcquireObjects(mlir::OpAsmPrinter &printer, mlir::Operation *op, ObjectFifoPortAttr port, mlir::TypeRange objects)
mlir::LogicalResult verifyBdLockPair(mlir::Block &block, bool outOfOrder, UseLockOp &acquire, UseLockOp &release)
mlir::LogicalResult verifyAssignedPacket(mlir::Operation *op, PacketInfoAttr packet, llvm::StringRef what="packet")
mlir::ParseResult parseTypedDynamicIndexList(mlir::OpAsmParser &parser, llvm::SmallVectorImpl< mlir::OpAsmParser::UnresolvedOperand > &values, mlir::DenseI64ArrayAttr &integers, llvm::SmallVectorImpl< mlir::Type > &types)
void printObjectFifoConsumerTiles(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange tiles, BDDimLayoutArrayArrayAttr dimsPerTileAttr)
mlir::Operation * lookupNamedOpIn(mlir::Operation *symbolTableOp, mlir::StringAttr name)
uint32_t getShimBurstLengthEncoding(const AIE::AIETargetModel &tm, uint32_t burstLength)
mlir::LogicalResult verifyDMABDOutOfOrderId(DMABDOp bd, bool packetEnabledByContext=false)
mlir::ParseResult parseObjectFifoAcquireObjects(mlir::OpAsmParser &parser, ObjectFifoPortAttr &port, llvm::SmallVectorImpl< mlir::Type > &objects)
mlir::LogicalResult verifyOutOfOrderChannel(mlir::Operation *op, DMAChannelDir dir, bool outOfOrder, llvm::ArrayRef< DMABDOp > bds, bool packetEnabledByContext=false)
struct Connect { Port src; Port dst; bool operator==(const Connect &rhs) const { return std::tie(src, dst)==std::tie(rhs.src, rhs.dst); } bool operator!=(const Connect &rhs) const { return !(*this==rhs);} bool operator<(const Connect &rhs) const { return std::tie(src, dst)< std::tie(rhs.src, rhs.dst); } } Connect
Definition AIEDialect.h:305
void printDMAStartChannel(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::Attribute channel)
mlir::LogicalResult verifyLengthParameter(mlir::Operation *op, std::optional< int64_t > lengthUnit, mlir::BaseMemRefType buffer, std::optional< int64_t > lenElems, bool contiguous, llvm::ArrayRef< int64_t > innerSizes)
mlir::LogicalResult verifyDMAChannelIndex(mlir::Operation *op, TileLike tile, DMAChannelDir dir, int64_t channel)
struct TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")"; return os; } friend std::string to_string(const TileID &s) { std::ostringstream ss; ss<< s; return ss.str(); } friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const TileID &s) { os<< to_string(s); return os; } inline bool operator<(const TileID &rhs) const { return std::tie(col, row)< std::tie(rhs.col, rhs.row); } bool operator==(const TileID &rhs) const { return std::tie(col, row)==std::tie(rhs.col, rhs.row); } bool operator!=(const TileID &rhs) const { return !(*this==rhs);} int col, row;} TileID
int32_t getBufferBaseAddress(mlir::Operation *bufOp)
bool isDirectional(WireBundle bundle)
Definition AIEDialect.h:531
mlir::ParseResult parseDMAStartChannel(mlir::OpAsmParser &parser, mlir::Attribute &channel)
std::optional< std::pair< TileID, Port > > getLinkedInput(TileID tile, Port output)
The switchbox input driven by an output's physical wire, with the channel preserved.
llvm::SmallVector< uint32_t > getAssignedBdIds(DmaBody program)
llvm::SmallVector< StreamWindowStep > streamWindowSteps(const StreamWindow &w)
int64_t turnPasses(llvm::ArrayRef< std::pair< int64_t, int64_t > > ends)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const SwitchSettings &ss)
const AIETargetModel & getTargetModel(mlir::Operation *op)
bool keepsPktHeader(TileID tile, Port master, std::optional< bool > keep)
struct DMAChannel { DMAChannelDir direction; int channel; bool operator==(const DMAChannel &rhs) const { return std::tie(direction, channel)==std::tie(rhs.direction, rhs.channel); } } DMAChannel
Definition AIEDialect.h:320
mlir::LogicalResult verifyDMAChannelsResolved(DeviceOp device)
mlir::Operation * lookupNamedOp(mlir::Operation *from, mlir::StringAttr name)
mlir::ParseResult parseObjectFifoProducerTile(mlir::OpAsmParser &parser, mlir::OpAsmParser::UnresolvedOperand &operand, BDDimLayoutArrayAttr &dimensions)
void printTraceEventEnum(mlir::AsmPrinter &printer, mlir::Attribute attr)
void placeRuntimeLengthDimension(llvm::MutableArrayRef< int64_t > sizes, llvm::MutableArrayRef< int64_t > strides)
mlir::LogicalResult myVerifyOffsetSizeAndStrideOp(mlir::OffsetSizeAndStrideOpInterface op)
mlir::LogicalResult inferStreamWindow(llvm::ArrayRef< BDDimLayoutAttr > dims, llvm::ArrayRef< BDPadLayoutAttr > pads, int64_t objectSize, llvm::function_ref< mlir::InFlightDiagnostic()> emitError, StreamWindow &window)
mlir::LogicalResult verifyDMABDIteration(DMABDOp bd, AIETileType tileType)
void printFlowVias(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange vias, mlir::DenseI32ArrayAttr ingressBundles, mlir::DenseI32ArrayAttr ingressChannels, mlir::DenseI32ArrayAttr egressBundles, mlir::DenseI32ArrayAttr egressChannels)
struct Port { WireBundle bundle; int channel; bool operator==(const Port &rhs) const { return std::tie(bundle, channel)==std::tie(rhs.bundle, rhs.channel); } bool operator!=(const Port &rhs) const { return !(*this==rhs);} bool operator<(const Port &rhs) const { return std::tie(bundle, channel)< std::tie(rhs.bundle, rhs.channel); } friend std::ostream &operator<<(std::ostream &os, const Port &port) { os<< "("; os<< stringifyWireBundle(port.bundle).str(); os<< ": "<< std::to_string(port.channel)<< ")"; return os; } friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Port &port) { os<< to_string(port); return os; } } Port
Definition AIEDialect.h:265
mlir::ParseResult parseObjectFifoReleaseCount(mlir::OpAsmParser &parser, ObjectFifoPortAttr &port, mlir::IntegerAttr &size)
AIETargetModel::SharedMemory sharedMemory(TileOp a, TileOp b)
Which of a's and b's memory modules both tiles can address.
std::optional< std::pair< TileID, Port > > getConnectingWireEndpoint(const AIETargetModel &targetModel, TileID tile, Port port)
getLinkedInput, restricted to tiles on the device.
mlir::LogicalResult verifyControlOrTraceDMAChannel(mlir::Operation *op, const AIETargetModel &targetModel, int col, int row, DMAChannelDir dir, int64_t channel)
mlir::FailureOr< int64_t > getLengthUnitBytes(mlir::Operation *op, int64_t lengthUnit, mlir::BaseMemRefType buffer)
int64_t paddedSize(llvm::ArrayRef< BDDimLayoutAttr > dims, llvm::ArrayRef< BDPadLayoutAttr > pads, int64_t fallback)
mlir::ParseResult parseObjectFifoConsumerTiles(mlir::OpAsmParser &parser, llvm::SmallVectorImpl< mlir::OpAsmParser::UnresolvedOperand > &tiles, BDDimLayoutArrayArrayAttr &dimensions)
void printObjectFifoReleaseCount(mlir::OpAsmPrinter &printer, mlir::Operation *op, ObjectFifoPortAttr port, mlir::IntegerAttr size)
WireBundle getConnectingBundle(WireBundle dir)
static bool isEqual(const xilinx::AIE::DMAChannel &lhs, const xilinx::AIE::DMAChannel &rhs)
Definition AIEDialect.h:721
DenseMapInfo< xilinx::AIE::DMAChannelDir > FirstInfo
Definition AIEDialect.h:713
static unsigned getHashValue(const xilinx::AIE::DMAChannel &d)
Definition AIEDialect.h:716
static bool isEqual(xilinx::AIE::ObjectFifoAcquireOp lhs, xilinx::AIE::ObjectFifoAcquireOp rhs)
Definition AIEDialect.h:690
static unsigned getHashValue(xilinx::AIE::ObjectFifoAcquireOp val)
Definition AIEDialect.h:686
static bool isEqual(xilinx::AIE::ObjectFifoCreateOp lhs, xilinx::AIE::ObjectFifoCreateOp rhs)
Definition AIEDialect.h:705
static unsigned getHashValue(xilinx::AIE::ObjectFifoCreateOp val)
Definition AIEDialect.h:701
static unsigned getHashValue(const xilinx::AIE::Port &d)
Definition AIEDialect.h:732
DenseMapInfo< xilinx::AIE::WireBundle > FirstInfo
Definition AIEDialect.h:729
static bool isEqual(const xilinx::AIE::Port &lhs, const xilinx::AIE::Port &rhs)
Definition AIEDialect.h:737
std::size_t operator()(const xilinx::AIE::Port &p) const noexcept
Definition AIEDialect.h:755
bool operator()(const xilinx::AIE::Port &a, const xilinx::AIE::Port &b) const
Definition AIEDialect.h:747
mlir::SymbolTable::Visibility getVisibility()
Definition AIEDialect.h:83
void setVisibility(mlir::SymbolTable::Visibility vis)
Definition AIEDialect.h:95
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
Definition AIEDialect.h:64
static constexpr llvm::StringRef getVisibilityAttrName()
Definition AIEDialect.h:58
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
int64_t depthAt(const AIETargetModel &target, TilePositions positions) const
llvm::SmallVector< LinkPoolSharer > sharers
Definition AIEDialect.h:445
::mlir::LogicalResult verifyTrait(::mlir::Operation *op)
Definition AIEDialect.h:211
std::optional< int > channel
Definition AIEDialect.h:469
mlir::Operation * pool
Definition AIEDialect.h:457
llvm::SmallVector< BDDimLayoutAttr > inner
Definition AIEDialect.h:420