20 MLIRContext *ctx, ArrayRef<int64_t> shape, SmallVector<Attribute> &dimensionSizes
23 dimensionSizes = llvm::map_to_vector(shape, [&builder](int64_t v) -> Attribute {
24 return builder.getIndexAttr(v);
26 assert(dimensionSizes.size() == shape.size());
31 EmitErrorFn emitError, MLIRContext *ctx, ArrayRef<Attribute> dimensionSizes,
32 SmallVector<int64_t> &shape
34 assert(shape.empty());
40 auto errFunc = emitError ? llvm::unique_function<InFlightDiagnostic()>(emitError)
41 : mlir::detail::getDefaultDiagnosticEmitFn(ctx);
48 for (Attribute a : dimensionSizes) {
49 if (
auto p = llvm::dyn_cast_if_present<IntegerAttr>(a)) {
51 }
else if (llvm::isa_and_present<SymbolRefAttr, AffineMapAttr>(a)) {
53 shape.push_back(ShapedType::kDynamic);
56 llvm::report_fatal_error(
"computeShapeFromDims() is out of sync with ArrayDimensionTypes");
60 assert(shape.size() == dimensionSizes.size());
65 AsmParser &parser, SmallVector<int64_t> &shape, SmallVector<Attribute> dimensionSizes
69 auto emitError = [&parser] {
return parser.emitError(parser.getCurrentLocation()); };
77 EmitErrorFn emitError, Type elementType, ArrayRef<Attribute> dimensionSizes,
78 ArrayRef<int64_t> shape
96inline ArrayType createArrayOfSizeOne(Type elemType) {
return ArrayType::get(elemType, {1}); }
100bool ArrayType::collectIndices(llvm::function_ref<
void(ArrayAttr)> inserter)
const {
101 if (!hasStaticShape()) {
104 MLIRContext *ctx = getContext();
106 for (int64_t e = getNumElements(), i = 0; i < e; ++i) {
107 auto delinearized = idxGen.delinearize(i, ctx);
108 assert(delinearized.has_value());
109 inserter(ArrayAttr::get(ctx, delinearized.value()));
115 SmallVector<ArrayAttr> ret;
116 bool success = collectIndices([&ret](ArrayAttr v) { ret.push_back(v); });
117 return success ? std::make_optional(ret) : std::nullopt;
122 DenseMap<Attribute, Type> ret;
124 bool success = collectIndices([&](ArrayAttr v) { ret[v] = destructAs; });
125 return success ? std::make_optional(ret) : std::nullopt;
130 if (!hasStaticShape()) {
134 ArrayAttr indexAttr = llvm::dyn_cast<ArrayAttr>(index);
146ParseResult
parseAttrVec(AsmParser &parser, SmallVector<Attribute> &value) {
147 SmallVector<Attribute> attrs;
148 auto parseElement = [&]() -> ParseResult {
149 auto qResult = parser.parseOptionalQuestion();
150 if (succeeded(qResult)) {
151 auto &builder = parser.getBuilder();
152 value.push_back(builder.getIntegerAttr(builder.getIndexType(), ShapedType::kDynamic));
156 if (succeeded(attrParseResult)) {
159 return ParseResult(attrParseResult);
161 if (failed(parser.parseCommaSeparatedList(AsmParser::Delimiter::None, parseElement))) {
162 return parser.emitError(parser.getCurrentLocation(),
"failed to parse array dimensions");
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.
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)
::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
::llvm::ArrayRef<::mlir::Attribute > getDimensionSizes() const
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)
LogicalResult computeShapeFromDims(EmitErrorFn emitError, MLIRContext *ctx, ArrayRef< Attribute > dimensionSizes, SmallVector< int64_t > &shape)
ParseResult parseDerivedShape(AsmParser &parser, SmallVector< int64_t > &shape, SmallVector< Attribute > dimensionSizes)
llvm::function_ref< mlir::InFlightDiagnostic()> EmitErrorFn
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)
LogicalResult verifyArrayType(EmitErrorFn emitError, Type elementType, ArrayRef< Attribute > dimensionSizes)
Attribute forceIntAttrType(Attribute attr)
int64_t fromAPInt(llvm::APInt i)
LogicalResult verifyArrayDimSizes(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes)