17#include <mlir/IR/DialectImplementation.h>
19#include <llvm/ADT/TypeSwitch.h>
24#define GET_TYPEDEF_CLASSES
31 explicit ArrayValueCopyDialectInterface(mlir::Dialect *owner)
32 : ValueCopyDialectInterface(owner) {}
34 bool canMaterializeValueCopy(mlir::Type type)
const final {
35 auto arrayType = llvm::dyn_cast<llzk::array::ArrayType>(type);
36 return arrayType && (llvm::isa<mlir::NoneType>(arrayType.getElementType()) ||
37 (arrayType.hasStaticShape() &&
41 std::string getValueCopyFailureReason(mlir::Type type)
const final {
42 auto arrayType = llvm::dyn_cast<llzk::array::ArrayType>(type);
44 return ValueCopyDialectInterface::getValueCopyFailureReason(type);
46 if (!arrayType.hasStaticShape()) {
47 return "dynamic or symbolic payload arrays cannot be copied independently; "
48 "flatten or resolve array shapes first";
50 return "array element copy is unsupported: " +
54 mlir::FailureOr<mlir::Value> materializeValueCopy(
55 mlir::OpBuilder &builder, mlir::Location loc, mlir::Value
source
57 auto arrayType = llvm::dyn_cast<llzk::array::ArrayType>(
source.getType());
58 if (!arrayType || !canMaterializeValueCopy(arrayType)) {
59 return mlir::failure();
65 if (llvm::isa<mlir::NoneType>(arrayType.getElementType())) {
70 std::optional<mlir::SmallVector<mlir::ArrayAttr>> indices = arrayType.getSubelementIndices();
71 assert(indices.has_value() &&
"static arrays must provide concrete element indices");
72 for (mlir::ArrayAttr index : *indices) {
75 if (mlir::failed(copied)) {
76 return mlir::failure();
79 builder, loc, destination.getResult(), index, *copied
82 return destination.getResult();
92auto llzk::array::ArrayDialect::initialize() ->
void {
100 #define GET_TYPEDEF_LIST
104 addInterfaces<LLZKDialectBytecodeInterface<ArrayDialect>, ArrayValueCopyDialectInterface>();
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Dialect hook for materializing independent storage for mutable value types.
static void genWrite(::mlir::OpBuilder &bldr, ::mlir::Location loc, ::mlir::Value arrayRef, ::mlir::ValueRange indices, ::mlir::Value value)
Create an array.write or array.insert for one concrete element or subarray.
::mlir::Value genRead(::mlir::OpBuilder &bldr, ::mlir::Location loc, ::mlir::Value arrayRef, ::mlir::ValueRange indices)
Create an array.read or array.extract for one concrete element or subarray.
static CreateArrayOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::llzk::array::ArrayType result, ::mlir::ValueRange elements={})
std::string getValueCopyFailureReason(Type type)
FailureOr< Value > materializeValueCopy(OpBuilder &builder, Location loc, Value source)
bool canMaterializeValueCopy(Type type)