16#include <mlir/IR/BuiltinTypeInterfaces.h>
23 MLIRContext *ctx, ArrayRef<int64_t> shape, SmallVector<Attribute> &dimensionSizes
26 dimensionSizes = llvm::map_to_vector(shape, [&builder](int64_t v) -> Attribute {
27 return builder.getIndexAttr(v);
29 assert(dimensionSizes.size() == shape.size());
34 EmitErrorFn emitError, ArrayRef<Attribute> dimensionSizes, SmallVector<int64_t> &shape
36 assert(shape.empty());
44 for (Attribute a : dimensionSizes) {
45 if (
auto p = llvm::dyn_cast_if_present<IntegerAttr>(a)) {
47 }
else if (llvm::isa_and_present<SymbolRefAttr, AffineMapAttr>(a)) {
49 shape.push_back(ShapedType::kDynamic);
52 llvm::report_fatal_error(
"computeShapeFromDims() is out of sync with ArrayDimensionTypes");
56 assert(shape.size() == dimensionSizes.size());
61 AsmParser &parser, SmallVector<int64_t> &shape,
62 SmallVector<Attribute> dimensionSizes
66 auto emitError = [&parser] {
76 function_ref<InFlightDiagnostic()> emitError, Type elementType,
77 ArrayRef<Attribute> dimensionSizes, ArrayRef<int64_t>
99bool ArrayType::collectIndices(llvm::function_ref<
void(ArrayAttr)> inserter)
const {
100 if (!hasStaticShape()) {
103 MLIRContext *ctx = getContext();
105 for (int64_t e = getNumElements(), i = 0; i < e; ++i) {
106 auto delinearized = idxGen.delinearize(i, ctx);
107 assert(delinearized.has_value());
108 inserter(ArrayAttr::get(ctx, delinearized.value()));
114 SmallVector<ArrayAttr> ret;
115 bool success = collectIndices([&ret](ArrayAttr v) { ret.push_back(v); });
116 return success ? std::make_optional(ret) : std::nullopt;
121 DenseMap<Attribute, Type> ret;
123 bool success = collectIndices([&](ArrayAttr v) { ret[v] = destructAs; });
124 return success ? std::make_optional(ret) : std::nullopt;
129 if (!hasStaticShape()) {
133 ArrayAttr indexAttr = llvm::dyn_cast<ArrayAttr>(index);
145ParseResult
parseAttrVec(AsmParser &parser, SmallVector<Attribute> &value) {
146 SmallVector<Attribute> attrs;
147 auto parseElement = [&parser, &value]() -> ParseResult {
148 auto qResult = parser.parseOptionalQuestion();
149 if (succeeded(qResult)) {
150 auto &builder = parser.getBuilder();
151 value.push_back(builder.getIntegerAttr(builder.getIndexType(), ShapedType::kDynamic));
155 if (succeeded(attrParseResult)) {
156 auto emitError = [&parser] {
159 FailureOr<Attribute> forced =
forceIntAttrType(*attrParseResult, emitError);
160 if (failed(forced)) {
163 value.push_back(*forced);
165 return ParseResult(attrParseResult);
167 if (failed(parser.parseCommaSeparatedList(AsmParser::Delimiter::None, parseElement))) {
168 return parser.emitError(parser.getCurrentLocation(),
"failed to parse array dimensions");
Wrapper around InFlightDiagnostic that can either be a regular InFlightDiagnostic or a special versio...
static ArrayIndexGen from(ArrayType)
Construct new ArrayIndexGen. Will assert if hasStaticShape() is false.
::llvm::ArrayRef< int64_t > getShape() const
ArrayType cloneWith(std::optional<::llvm::ArrayRef< int64_t > > shape, ::mlir::Type elementType) const
Clone this type with the given shape and element type.
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
std::optional<::llvm::SmallVector<::mlir::ArrayAttr > > getSubelementIndices() const
Return a list of all valid indices for this ArrayType.
::mlir::Type getElementType() const
::std::optional<::llvm::DenseMap<::mlir::Attribute, ::mlir::Type > > getSubelementIndexMap() const
Required by DestructurableTypeInterface / SROA pass.
::mlir::Type getTypeAtIndex(::mlir::Attribute index) const
Required by DestructurableTypeInterface / SROA pass.
static ArrayType get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
::llvm::ArrayRef<::mlir::Attribute > getDimensionSizes() const
LogicalResult computeShapeFromDims(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes, SmallVector< int64_t > &shape)
ParseResult parseAttrVec(AsmParser &parser, SmallVector< Attribute > &value)
void printDerivedShape(AsmPrinter &, ArrayRef< int64_t >, ArrayRef< Attribute >)
LogicalResult computeDimsFromShape(MLIRContext *ctx, ArrayRef< int64_t > shape, SmallVector< Attribute > &dimensionSizes)
void printAttrVec(AsmPrinter &printer, ArrayRef< Attribute > value)
ParseResult parseDerivedShape(AsmParser &parser, SmallVector< int64_t > &shape, SmallVector< Attribute > dimensionSizes)
FailureOr< Attribute > forceIntAttrType(Attribute attr, EmitErrorFn emitError)
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)
LogicalResult verifyArrayType(EmitErrorFn emitError, Type elementType, ArrayRef< Attribute > dimensionSizes)
llvm::function_ref< InFlightDiagnosticWrapper()> EmitErrorFn
Callback to produce an error diagnostic.
OwningEmitErrorFn wrapNonNullableInFlightDiagnostic(llvm::function_ref< mlir::InFlightDiagnostic()> emitError)
int64_t fromAPInt(const llvm::APInt &i)
LogicalResult verifyArrayDimSizes(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes)