MLIR-AIE 1.4.6.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/DenseSet.h"
15#include "llvm/ADT/STLFunctionalExtras.h"
16#include "llvm/ADT/SmallVector.h"
17
18#include <optional>
19#include <tuple>
20
21namespace xilinx::AIE {
22
23/// Shim endpoint lifetimes, including calls to self-contained runtime
24/// sequences. MM2S transfers conservatively remain live until their sequence
25/// returns.
27public:
28 /// A shim end a runtime sequence transfers through.
29 struct End {
30 mlir::StringAttr fifo;
31 /// An MM2S end, sending into the array.
32 bool sends;
33 };
34
35 /// `endOf` maps a symbol a runtime sequence transfers through to the
36 /// objectFIFO end it belongs to, or nothing when it belongs to none.
38 DeviceOp device,
39 llvm::function_ref<std::optional<End>(mlir::StringAttr)> endOf);
40
42 mlir::ModuleOp module,
43 llvm::function_ref<std::optional<End>(DeviceOp, mlir::StringAttr)> endOf);
44
45 /// Whether both ends permit sharing, explicitly or by MM2S lifetime analysis.
46 bool apart(mlir::StringAttr a, mlir::StringAttr b) const;
47
48 bool isUsed(mlir::StringAttr end) const;
49
50 /// Splits `ends` into groups whose members are pairwise apart, each group
51 /// taking one channel: first fit, ordered by the ends' spans in flight.
52 /// Returns indices into `ends`.
53 llvm::SmallVector<llvm::SmallVector<unsigned>>
54 groups(llvm::ArrayRef<mlir::StringAttr> ends) const;
55
56private:
57 void analyze(
58 mlir::Operation *root,
59 llvm::function_ref<std::optional<End>(DeviceOp, mlir::StringAttr)> endOf);
60
61 llvm::DenseMap<mlir::StringAttr,
62 llvm::SmallVector<std::tuple<unsigned, int64_t, int64_t>>>
63 lifetimes;
64 llvm::DenseSet<mlir::StringAttr> used;
65 llvm::DenseMap<mlir::StringAttr, llvm::SmallVector<mlir::StringAttr>>
66 permissions;
67 llvm::DenseSet<std::pair<mlir::StringAttr, mlir::StringAttr>> overlaps;
68 bool unknown = false;
69};
70
71} // namespace xilinx::AIE
72
73#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 isUsed(mlir::StringAttr end) const
bool apart(mlir::StringAttr a, mlir::StringAttr b) const
Whether both ends permit sharing, explicitly or by MM2S lifetime analysis.
ShimTransferSpans(mlir::ModuleOp module, llvm::function_ref< std::optional< End >(DeviceOp, mlir::StringAttr)> endOf)
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.