1//===-- OpInterfaces.td ------------------------------------*- tablegen -*-===//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
8//===----------------------------------------------------------------------===//
10#ifndef LLZK_ARRAY_OP_INTERFACES
11#define LLZK_ARRAY_OP_INTERFACES
13include "llzk/Dialect/Array/IR/Types.td"
15include "mlir/IR/Interfaces.td"
16include "mlir/Interfaces/SideEffectInterfaces.td"
17include "mlir/Interfaces/MemorySlotInterfaces.td"
19def ArrayRefOpInterface : OpInterface<"ArrayRefOpInterface"> {
21 Common interface for operations that reference an array value.
23 let cppNamespace = "::llzk::array";
26 // Requires implementors to have a '$arr_ref' argument.
27 InterfaceMethod<[{Gets the SSA Value for the referenced array.}],
28 "::mlir::TypedValue<::llzk::array::ArrayType>",
31 [{Gets the mutable operand slot holding the SSA Value for the referenced array.}],
32 "::mlir::OpOperand &", "getArrRefMutable", (ins)>,
35 let extraClassDeclaration = [{
36 /// Gets the type of the referenced array.
37 inline ::llzk::array::ArrayType getArrRefType() { return getArrRef().getType(); }
41def ArrayAccessOpInterface
42 : OpInterface<"ArrayAccessOpInterface", [ArrayRefOpInterface]> {
44 Common interface for operations that read or write from an array.
46 let cppNamespace = "::llzk::array";
49 // Requires implementors to have a '$indices' argument.
51 [{Gets the operand range containing the index for each dimension.}],
52 "::mlir::Operation::operand_range", "getIndices", (ins)>,
54 [{Gets the mutable operand range containing the index for each dimension.}],
55 "::mlir::MutableOperandRange", "getIndicesMutable", (ins)>,
57 [{Return `true` if the op is a read, `false` if it's a write.}],
58 "bool", "isRead", (ins)>,
61 let extraClassDeclaration = [{
62 /// Compute the dimensions of the read/write value. Removing the number
63 /// of indices provided from the front dimensions of the base array type
64 /// gives the dimensions/shape of that value.
65 inline ::mlir::ArrayRef<::mlir::Attribute> getValueOperandDims() {
66 return getArrRefType().getDimensionSizes().drop_front(getIndices().size());
69 /// Returns the multi-dimensional indices of the array access as an Attribute
70 /// array or a null pointer if a valid index cannot be computed for any dimension.
71 ::mlir::ArrayAttr indexOperandsToAttributeArray();
73 /// Required by companion interface DestructurableAccessorOpInterface / SROA pass
74 bool canRewire(const ::mlir::DestructurableMemorySlot &slot,
75 ::llvm::SmallPtrSetImpl<::mlir::Attribute> &usedIndices,
76 ::mlir::SmallVectorImpl<::mlir::MemorySlot> &mustBeSafelyUsed);
78 /// Required by companion interface DestructurableAccessorOpInterface / SROA pass
79 ::mlir::DeletionKind rewire(const ::mlir::DestructurableMemorySlot &slot,
80 ::llvm::DenseMap<::mlir::Attribute, ::mlir::MemorySlot> &subslots,
81 ::mlir::RewriterBase &rewriter);
85#endif // LLZK_ARRAY_OP_INTERFACES