MLIR-AIE 1.4.5.dev
AIEXDialect.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_AIEX_DIALECT_H
10#define MLIR_AIEX_DIALECT_H
11
13
14#include "mlir/IR/BuiltinAttributes.h"
15
16// Include dialect declarations such as parseAttributes, parseType
17#include "aie/Dialect/AIEX/IR/AIEXDialect.h.inc"
19#include "mlir/IR/Operation.h"
20
21#include "aie/Dialect/AIEX/IR/AIEXInterfaces.h.inc"
22
23#define GET_ATTRDEF_CLASSES
24#include "aie/Dialect/AIEX/IR/AIEXAttrDefs.h.inc"
25
26// include TableGen generated Op definitions
27#define GET_OP_CLASSES
28#include "aie/Dialect/AIEX/IR/AIEX.h.inc"
29
30#define GET_TYPEDEF_CLASSES
31#include "aie/Dialect/AIEX/IR/AIEXTypes.h.inc"
32
33#include "llvm/ADT/StringRef.h"
34
35#include <optional>
36
37namespace xilinx {
38namespace AIEX {
39
40void getHardwareStridesWraps(const AIE::AIETargetModel &targetModel,
41 mlir::Operation *op,
42 mlir::BaseMemRefType referencedBufType,
43 llvm::SmallVector<int64_t, 4> inputSizes,
44 llvm::SmallVector<int64_t, 4> inputStrides,
45 llvm::SmallVector<int64_t, 4> &sizes,
46 llvm::SmallVector<int64_t, 4> &strides);
47mlir::LogicalResult
48verifyStridesWraps(mlir::Operation *forOp,
49 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
50 mlir::BaseMemRefType referencedBufType, int tileCol,
51 int tileRow, llvm::SmallVector<int64_t, 4> inputSizes,
52 llvm::SmallVector<int64_t, 4> inputStrides,
53 llvm::SmallVector<int64_t, 4> hardwareSizes,
54 llvm::SmallVector<int64_t, 4> hardwareStrides,
55 bool skipTransformationChecks = false);
56bool isLinearTransfer(llvm::ArrayRef<int64_t> sizes,
57 llvm::ArrayRef<int64_t> strides);
58
59// Returns true when sizes/strides (innermost-first, same convention as
60// NpuDmaMemcpyNdOp) describe a contiguous row-major scan:
61// strides[0] == 1
62// for i in 1..2: if sizes[i] > 1 then strides[i] == product of sizes[0..i-1]
63// The repeat dimension (index 3) is excluded.
64// Size-1 dimensions are allowed to carry any stride value because that stride
65// is never applied during the transfer (the loop runs only once).
66// This is the vector-form counterpart of AIE::isContiguousBDTransfer.
67bool isContiguousTransfer(llvm::ArrayRef<int64_t> sizes,
68 llvm::ArrayRef<int64_t> strides);
69
70// Whether the DMA lowerings encode the BD in linear mode (no ND wrap limits):
71// a linear transfer, or a contiguous one on a shim NOC tile. Innermost first.
72bool isLinearModeTransfer(const AIE::AIETargetModel &targetModel, int col,
73 int row, llvm::ArrayRef<int64_t> sizes,
74 llvm::ArrayRef<int64_t> strides);
75
76// Folds an SSA value to a compile-time uint32_t if it is a constant integer,
77// otherwise returns nullopt. Used by ops whose operands carry
78// compile-time-known values in the static lowering path.
79std::optional<uint32_t> getConstantIntOperand(mlir::Value v);
80std::optional<uint64_t> getConstantInt64Operand(mlir::Value v);
81
82// Materializes a 32-bit integer constant. The inverse of getConstantIntOperand:
83// used when lowering passes feed a compile-time-known value into an npu op
84// whose operand is an SSA i32. The bit pattern (including high-bit values such
85// as 0x80000000) is preserved.
86mlir::Value createConstantI32(mlir::OpBuilder &builder, mlir::Location loc,
87 uint32_t value);
88
89// Materializes an address_patch `arg_plus` offset as the narrowest constant
90// that holds it: i32 while the value fits, i64 beyond that. aie-rt carries the
91// field as u64, so truncating a wider offset mis-addresses the buffer.
92mlir::Value createConstantArgPlus(mlir::OpBuilder &builder, mlir::Location loc,
93 uint64_t value);
94
95// The first `aie.dma_start` or `aie.dma` in one of `device`'s shim DMAs, which
96// starts a channel teardown cannot stop, or null.
97mlir::Operation *findShimDmaStart(AIE::DeviceOp device);
98
99} // namespace AIEX
100} // namespace xilinx
101
102#endif
mlir::Operation * findShimDmaStart(AIE::DeviceOp device)
bool isContiguousTransfer(llvm::ArrayRef< int64_t > sizes, llvm::ArrayRef< int64_t > strides)
mlir::LogicalResult verifyStridesWraps(mlir::Operation *forOp, llvm::function_ref< mlir::InFlightDiagnostic()> emitError, mlir::BaseMemRefType referencedBufType, int tileCol, int tileRow, llvm::SmallVector< int64_t, 4 > inputSizes, llvm::SmallVector< int64_t, 4 > inputStrides, llvm::SmallVector< int64_t, 4 > hardwareSizes, llvm::SmallVector< int64_t, 4 > hardwareStrides, bool skipTransformationChecks=false)
std::optional< uint64_t > getConstantInt64Operand(mlir::Value v)
std::optional< uint32_t > getConstantIntOperand(mlir::Value v)
mlir::Value createConstantArgPlus(mlir::OpBuilder &builder, mlir::Location loc, uint64_t value)
void getHardwareStridesWraps(const AIE::AIETargetModel &targetModel, mlir::Operation *op, mlir::BaseMemRefType referencedBufType, llvm::SmallVector< int64_t, 4 > inputSizes, llvm::SmallVector< int64_t, 4 > inputStrides, llvm::SmallVector< int64_t, 4 > &sizes, llvm::SmallVector< int64_t, 4 > &strides)
bool isLinearModeTransfer(const AIE::AIETargetModel &targetModel, int col, int row, llvm::ArrayRef< int64_t > sizes, llvm::ArrayRef< int64_t > strides)
bool isLinearTransfer(llvm::ArrayRef< int64_t > sizes, llvm::ArrayRef< int64_t > strides)
mlir::Value createConstantI32(mlir::OpBuilder &builder, mlir::Location loc, uint32_t value)