18#include "llvm/ADT/SmallVectorExtras.h"
24 if (
auto st = llvm::dyn_cast<ShapedType>(type))
25 return st.getElementType();
34 if (
auto typedAttr = llvm::dyn_cast<TypedAttr>(attr))
41 t.getFlattenedTypes(fTypes);
49 if (
auto opaque = llvm::dyn_cast<mlir::OpaqueType>(type))
50 return opaque.getDialectNamespace() == dialect &&
51 opaque.getTypeData() == typeData;
60 if (shape1.size() != shape2.size())
62 for (
auto dims : llvm::zip(shape1, shape2)) {
63 int64_t dim1 = std::get<0>(dims);
64 int64_t dim2 = std::get<1>(dims);
65 if (ShapedType::isStatic(dim1) && ShapedType::isStatic(dim2) &&
78 auto sType1 = llvm::dyn_cast<ShapedType>(type1);
79 auto sType2 = llvm::dyn_cast<ShapedType>(type2);
87 if (!sType1.hasRank() || !sType2.hasRank())
96 if (types1.size() != types2.size())
98 for (
auto it : llvm::zip_first(types1, types2))
108 llvm::accumulate(dims, dims.front(), [](
auto fold,
auto dim) {
109 return ShapedType::isDynamic(dim) ? fold : dim;
111 return success(llvm::all_of(dims, [&](
auto dim) {
112 return ShapedType::isDynamic(dim) || dim == staticDim;
121 auto shapedTypes = llvm::map_to_vector<8>(types, llvm::DynCastTo<ShapedType>);
124 if (llvm::none_of(shapedTypes, [](
auto t) {
return t; }))
126 if (!llvm::all_of(shapedTypes, [](
auto t) {
return t; }))
130 bool hasScalableVecTypes =
false;
131 bool hasNonScalableVecTypes =
false;
132 for (
Type t : types) {
133 auto vType = llvm::dyn_cast<VectorType>(t);
134 if (vType && vType.isScalable())
135 hasScalableVecTypes =
true;
137 hasNonScalableVecTypes =
true;
138 if (hasScalableVecTypes && hasNonScalableVecTypes)
143 auto shapes = llvm::filter_to_vector<8>(
144 shapedTypes, [](
auto shapedType) {
return shapedType.hasRank(); });
149 auto firstRank = shapes.front().getRank();
150 if (llvm::any_of(shapes,
151 [&](
auto shape) {
return firstRank !=
shape.getRank(); }))
154 for (
unsigned i = 0; i < firstRank; ++i) {
156 auto dims = llvm::map_to_vector<8>(
157 llvm::make_filter_range(
158 shapes, [&](
auto shape) {
return shape.getRank() >= i; }),
159 [&](
auto shape) {
return shape.getDimSize(i); });
168 return llvm::cast<ShapedType>(value.
getType()).getElementType();
172 return llvm::cast<ShapedType>(value.
getType()).getElementType();
178 assert(
indices.size() == newTypes.size() &&
179 "mismatch between indice and type count");
183 auto fromIt = oldTypes.begin();
184 for (
auto it : llvm::zip(
indices, newTypes)) {
185 const auto toIt = oldTypes.begin() + std::get<0>(it);
186 storage.append(fromIt, toIt);
187 storage.push_back(std::get<1>(it));
190 storage.append(fromIt, oldTypes.end());
199 for (
unsigned i = 0, e = types.size(); i < e; ++i)
201 storage.emplace_back(types[i]);
Attributes are known-constant values of operations.
Type mapElement(Value value) const
Map the element to the iterator result type.
Type mapElement(Value value) const
Map the element to the iterator result type.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Include the generated interface declarations.
LogicalResult verifyCompatibleShapes(TypeRange types1, TypeRange types2)
Returns success if the given two arrays have the same number of elements and each pair wise entries h...
SmallVector< Type, 10 > getFlattenedTypes(TupleType t)
Get the types within a nested Tuple.
bool isOpaqueTypeWithName(Type type, StringRef dialect, StringRef typeData)
Return true if the specified type is an opaque type with the specified dialect and typeData.
TypeRange filterTypesOut(TypeRange types, const BitVector &indices, SmallVectorImpl< Type > &storage)
Filters out any elements referenced by indices.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
LogicalResult verifyCompatibleDims(ArrayRef< int64_t > dims)
Dimensions are compatible if all non-dynamic dims are equal.
LogicalResult verifyCompatibleShape(ArrayRef< int64_t > shape1, ArrayRef< int64_t > shape2)
Returns success if the given two shapes are compatible.
TypeRange insertTypesInto(TypeRange oldTypes, ArrayRef< unsigned > indices, TypeRange newTypes, SmallVectorImpl< Type > &storage)
Insert a set of newTypes into oldTypes at the given indices.