MLIR-AIE 1.4.5.dev
AIEShimSharing.h
Go to the documentation of this file.
1//===- AIEShimSharing.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_AIESHIMSHARING_H
9#define AIE_DIALECT_AIE_TRANSFORMS_AIESHIMSHARING_H
10
12
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/STLFunctionalExtras.h"
15#include "llvm/ADT/SmallVector.h"
16
17#include <optional>
18
19namespace xilinx::AIE {
20
21/// When the runtime sequences have each shim end's transfers in flight, so
22/// that ends never in flight together can take turns on one shim channel.
23/// Different runtime sequences never overlap (a dispatch finishes its
24/// transfers before the next starts). Within one, a receiving end's transfers
25/// must all be awaited or freed before the other's first, and a loop spans
26/// its body; a sending end stays in flight to the end of its sequence, as a
27/// shim MM2S task reports itself complete before its words leave the shim.
28/// Ends are known by their objectFIFO's name, before or after split.
29/// The placer and objectFIFO allocation both decide by this, so they agree.
31public:
32 /// A shim end a runtime sequence transfers through.
33 struct End {
34 mlir::StringAttr fifo;
35 /// An MM2S end, sending into the array.
36 bool sends;
37 };
38
39 /// `endOf` maps a symbol a runtime sequence transfers through to the
40 /// objectFIFO end it belongs to, or nothing when it belongs to none.
42 DeviceOp device,
43 llvm::function_ref<std::optional<End>(mlir::StringAttr)> endOf);
44
45 /// Whether the ends of `a` and `b` are never in flight together.
46 bool apart(mlir::StringAttr a, mlir::StringAttr b) const;
47
48 /// Splits `ends` into groups whose members are pairwise apart, each group
49 /// taking one channel: first fit, in name order. Returns indices into `ends`.
50 llvm::SmallVector<llvm::SmallVector<unsigned>>
51 groups(llvm::ArrayRef<mlir::StringAttr> ends) const;
52
53private:
54 struct Span {
55 int64_t first = std::numeric_limits<int64_t>::max();
56 int64_t last = -1;
57 int64_t lastIssue = -1;
58 int64_t lastDone = -1;
59 bool sends = false;
60 };
61 llvm::SmallVector<llvm::DenseMap<mlir::StringAttr, Span>> spans;
62};
63
64} // namespace xilinx::AIE
65
66#endif // AIE_DIALECT_AIE_TRANSFORMS_AIESHIMSHARING_H
ShimTransferSpans(DeviceOp device, llvm::function_ref< std::optional< End >(mlir::StringAttr)> endOf)
endOf maps a symbol a runtime sequence transfers through to the objectFIFO end it belongs to,...
bool apart(mlir::StringAttr a, mlir::StringAttr b) const
Whether the ends of a and b are never in flight together.
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,...
A shim end a runtime sequence transfers through.
bool sends
An MM2S end, sending into the array.