!foldl(!head(strings), !tail(strings), prev, cur, prev # sep # cur));
}
-// Concatenates a list of integers into a string separated with comma.
-class Stringify<list<int> integers> :
- StrJoin<!foreach(i, integers, !cast<string>(i))>;
+// Concatenates a list of integers into a string with a separator (default ", ")
+class StrJoinInt<list<int> integers, string sep = ", "> :
+ StrJoin<!foreach(i, integers, !cast<string>(i)), sep>;
//===----------------------------------------------------------------------===//
// Predicate definitions
class Type<Pred condition, string descr = ""> :
TypeConstraint<condition, descr>;
+// Allows providing an alternative name and description to an existing type def.
+class TypeAlias<Type t, string description = t.description> :
+ Type<t.predicate, description>;
+
// A variadic type constraint. It expands to zero or more of the base type. This
// class is used for supporting variadic operands/results. An op can declare no
// more than one variadic operand/result, and that operand/result must be the
BuildableType<"getIntegerType(" # width # ")"> {
int bitwidth = width;
}
+
+class IntOfWidths<list<int> widths> :
+ AnyTypeOf<!foreach(w, widths, I<w>),
+ StrJoinInt<widths, "/">.result # "-bit integer">;
+
def I1 : I<1>;
def I8 : I<8>;
def I16 : I<16>;
int bitwidth = width;
}
+class FloatOfWidths<list<int> widths> :
+ AnyTypeOf<!foreach(w, widths, F<w>),
+ StrJoinInt<widths, "/">.result # "-bit float">;
+
def F16 : F<16>;
def F32 : F<32>;
def F64 : F<64>;
code getElementTypeCall = elementTypeCall;
}
-class ShapedContainerType<Type etype, Pred containerPred, string descr> :
- ContainerType<etype, containerPred,
+class ShapedContainerType<list<Type> allowedTypes, Pred containerPred, string descr> :
+ ContainerType<AnyTypeOf<allowedTypes>, containerPred,
"$_self.cast<ShapedType>().getElementType()", descr>;
// Vector types.
-class VectorOf<list<Type> allowedTypes, string elementDescription = ""> :
- ShapedContainerType<AnyTypeOf<allowedTypes, elementDescription>,
- IsVectorTypePred, "vector">;
+class VectorOf<list<Type> allowedTypes> :
+ ShapedContainerType<allowedTypes, IsVectorTypePred, "vector">;
def AnyVector : VectorOf<[AnyType]>;
// Tensor types.
// Any tensor type whose element type is from the given `allowedTypes` list
-class TensorOf<list<Type> allowedTypes, string elementDescription = ""> :
- ShapedContainerType<AnyTypeOf<allowedTypes, elementDescription>,
- IsTensorTypePred, "tensor">;
+class TensorOf<list<Type> allowedTypes> :
+ ShapedContainerType<allowedTypes, IsTensorTypePred, "tensor">;
def AnyTensor : TensorOf<[AnyType]>;
// TODO(b/132735995) Use ShapedContainerType when MemRef subclasses ShapedType.
// Memrefs are blocks of data with fixed type and rank.
-class MemRefOf<list<Type> allowedTypes, string elementDescription = ""> :
- ContainerType<AnyTypeOf<allowedTypes, elementDescription>, IsMemRefTypePred,
+class MemRefOf<list<Type> allowedTypes> :
+ ContainerType<AnyTypeOf<allowedTypes>, IsMemRefTypePred,
"$_self.cast<MemRefType>().getElementType()", "memref">;
def AnyMemRef : MemRefOf<[AnyType]>;
CPred<"llvm::is_splat(mlir::functional::map("
"[this](unsigned i) { return this->getOperand(i)->getType()"
".cast<ShapedType>().getElementType(); }, "
- "llvm::ArrayRef<unsigned>({" # Stringify<indices>.result # "})))">;
+ "llvm::ArrayRef<unsigned>({" # StrJoinInt<indices>.result # "})))">;
//===----------------------------------------------------------------------===//
// Pattern definitions