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::isDynamic(dim1) && !ShapedType::isDynamic(dim2) &&
78 auto sType1 = llvm::dyn_cast<ShapedType>(type1);
79 auto sType2 = llvm::dyn_cast<ShapedType>(type2);
83 return success(!sType2);
87 if (!sType1.hasRank() || !sType2.hasRank())
96 if (types1.size() != types2.size())
98 for (
auto it : llvm::zip_first(types1, types2))
107 auto staticDim = std::accumulate(
108 dims.begin(), dims.end(), 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>(
122 types, [](
auto type) {
return llvm::dyn_cast<ShapedType>(type); });
125 if (llvm::none_of(shapedTypes, [](
auto t) {
return t; }))
127 if (!llvm::all_of(shapedTypes, [](
auto t) {
return t; }))
131 bool hasScalableVecTypes =
false;
132 bool hasNonScalableVecTypes =
false;
133 for (
Type t : types) {
134 auto vType = llvm::dyn_cast<VectorType>(t);
135 if (vType && vType.isScalable())
136 hasScalableVecTypes =
true;
138 hasNonScalableVecTypes =
true;
139 if (hasScalableVecTypes && hasNonScalableVecTypes)
144 auto shapes = llvm::filter_to_vector<8>(
145 shapedTypes, [](
auto shapedType) {
return shapedType.hasRank(); });
150 auto firstRank = shapes.front().getRank();
151 if (llvm::any_of(shapes,
152 [&](
auto shape) {
return firstRank != shape.getRank(); }))
155 for (
unsigned i = 0; i < firstRank; ++i) {
157 auto dims = llvm::map_to_vector<8>(
158 llvm::make_filter_range(
159 shapes, [&](
auto shape) {
return shape.getRank() >= i; }),
160 [&](
auto shape) {
return shape.getDimSize(i); });
169 return llvm::cast<ShapedType>(value.
getType()).getElementType();
173 return llvm::cast<ShapedType>(value.
getType()).getElementType();
179 assert(indices.size() == newTypes.size() &&
180 "mismatch between indice and type count");
184 auto fromIt = oldTypes.begin();
185 for (
auto it : llvm::zip(indices, newTypes)) {
186 const auto toIt = oldTypes.begin() + std::get<0>(it);
187 storage.append(fromIt, toIt);
188 storage.push_back(std::get<1>(it));
191 storage.append(fromIt, oldTypes.end());
200 for (
unsigned i = 0, e = types.size(); i < e; ++i)
202 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.