let description = [{
Adds two sizes or indices. If either operand is an error it will be
propagated to the result. The operands can be of type `size` or `index`. If
- at least one of the operands can hold an error, i.e. if it is of type `size`,
- the result must be of type `size`. If error propagation is not possible
- because both operands are of type `index` then the result may be of type
- `size` or `index`.
+ at least one of the operands can hold an error, i.e. if it is of type
+ `size`, the result must be of type `size`. If error propagation is not
+ possible because both operands are of type `index` then the result may be
+ of type `size` or `index`.
}];
let arguments = (ins Shape_SizeOrIndexType:$lhs, Shape_SizeOrIndexType:$rhs);
let builders = [OpBuilder<(ins "::mlir::Type":$result,
"::mlir::Value":$lhs, "::mlir::Value":$rhs,
"/*optional*/ ::mlir::StringAttr":$error), [{
- build($_builder, $_state, result, ::llvm::makeArrayRef({lhs, rhs}), error);
+ build($_builder, $_state, result, ::llvm::makeArrayRef({lhs, rhs}),
+ error);
}]>
];
If at least one of the operands can hold an error, i.e. if it is of type
`size`, the result must be of type `size`. If error propagation is not
possible because both operands are of type `index` then the result may be
- of type `size` or `index`. If both operands and result are of type `index`,
- their runtime values could be negative. The result is rounded toward
- negative infinity, i.e. floor(lhs / rhs), such that
+ of type `size` or `index`. If both operands and result are of type
+ `index`, their runtime values could be negative. The result is rounded
+ toward negative infinity, i.e. floor(lhs / rhs), such that
div(lhs, rhs) * rhs + mod(lhs, rhs) = lhs
let summary = "Returns whether the input shapes or extent tensors are equal";
let description = [{
Takes one or more shape or extent tensor operands and determines whether
- they are equal. When extent tensors are compared to shapes they are regarded
- as their equivalent non-error shapes. Error shapes can be tested for
- equality like any other shape value, meaning that the error value is equal
- to itself.
+ they are equal. When extent tensors are compared to shapes they are
+ regarded as their equivalent non-error shapes. Error shapes can be tested
+ for equality like any other shape value, meaning that the error value is
+ equal to itself.
}];
let arguments = (ins Variadic<Shape_ShapeOrExtentTensorType>:$shapes);
def Shape_IsBroadcastableOp : Shape_Op<"is_broadcastable", [Commutative]> {
let summary = "Determines if 2+ shapes can be successfully broadcasted";
let description = [{
- Given multiple input shapes or extent tensors, return a predicate specifying
- if they are broadcastable. This broadcastable follows the same logic as what
- shape.broadcast documents.
+ Given multiple input shapes or extent tensors, return a predicate
+ specifying if they are broadcastable. This broadcastable follows the same
+ logic as what shape.broadcast documents.
Concretely, shape.is_broadcastable returning true implies that
shape.broadcast will not give an error, and shape.cstr_broadcastable will
let arguments = (ins AnyShaped:$value,
Shape_SizeOrIndexType:$index);
let results = (outs Shape_SizeOrIndexType:$extent);
- let assemblyFormat = "$value `,` $index attr-dict `:` type($value) `,` type($index) `->` "
- "type($extent)";
+ let assemblyFormat = "$value `,` $index attr-dict `:` type($value) `,`"
+ "type($index) `->` type($extent)";
let builders = [
// Builder that allows passing a constant dimension as a simple integer.
/// Get the `index` value as integer if it is constant.
std::optional<int64_t> getConstantIndex();
- /// Returns when two result types are compatible for this op; method used by
- /// InferTypeOpInterface
+ /// Returns when two result types are compatible for this op; method used
+ /// by InferTypeOpInterface
static bool isCompatibleReturnTypes(TypeRange l, TypeRange r);
}];
let arguments = (ins Shape_ShapeOrExtentTensorType:$shape,
Shape_SizeOrIndexType:$dim);
let results = (outs Shape_SizeOrIndexType:$extent);
- let assemblyFormat = "$shape `,` $dim attr-dict `:` type($shape) `,` type($dim) `->` "
- "type($extent)";
+ let assemblyFormat = "$shape `,` $dim attr-dict `:` type($shape) `,` "
+ "type($dim) `->` type($extent)";
let builders = [
// Builder that allows passing a constant dimension as a simple integer.
let extraClassDeclaration = [{
/// Get the `dim` value as integer if it is constant.
std::optional<int64_t> getConstantDim();
- /// Returns when two result types are compatible for this op; method used by
- /// InferTypeOpInterface
+ /// Returns when two result types are compatible for this op; method used
+ /// by InferTypeOpInterface
static bool isCompatibleReturnTypes(TypeRange l, TypeRange r);
}];
let description = [{
Multiplies two sizes or indices. If either operand is an error it will be
propagated to the result. The operands can be of type `size` or `index`. If
- at least one of the operands can hold an error, i.e. if it is of type `size`,
- the result must be of type `size`. If error propagation is not possible
- because both operands are of type `index` then the result may be of type
- `size` or `index`.
+ at least one of the operands can hold an error, i.e. if it is of type
+ `size`, the result must be of type `size`. If error propagation is not
+ possible because both operands are of type `index` then the result may be
+ of type `size` or `index`.
}];
let arguments = (ins Shape_SizeOrIndexType:$lhs, Shape_SizeOrIndexType:$rhs);
[Pure, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
let summary = "Returns the number of elements for a given shape";
let description = [{
- Returns the number of elements for a given shape which is the product of its
- extents. If the argument is of type `shape` then the result will be of type
- `size` and potential errors will be propagated. Otherwise, if the argument
- is and extent tensor `tensor<?xindex>` then the result will be of type
- `index`.
+ Returns the number of elements for a given shape which is the product of
+ its extents. If the argument is of type `shape` then the result will be of
+ type `size` and potential errors will be propagated. Otherwise, if the
+ argument is and extent tensor `tensor<?xindex>` then the result will be of
+ type `index`.
}];
let arguments = (ins Shape_ShapeOrExtentTensorType:$shape);
number of elements can be computed as follows:
```mlir
- func.func @reduce(%shape : !shape.shape, %init : !shape.size) -> !shape.size {
+ func.func @reduce(%shape : !shape.shape, %init : !shape.size) ->
+ !shape.size {
%num_elements = shape.reduce(%shape, %init) -> !shape.size {
^bb0(%index: index, %dim: !shape.size, %acc: !shape.size):
%updated_acc = "shape.mul"(%acc, %dim) :
let summary = "Returns value as a shape";
let description = [{
- The operations takes a ValueShape and returns a Shape corresponding to the value.
- If the input value cannot be shape (e.g., not a 1D tensor of integral value
- representing sizes) then this propagages the error shape. E.g.,
+ The operations takes a ValueShape and returns a Shape corresponding to the
+ value. If the input value cannot be shape (e.g., not a 1D tensor of
+ integral value representing sizes) then this propagages the error shape.
+ E.g.,
```mlir
// The following
This operation is the complement of `shape_of` wrt ValueShape values.
}];
- let arguments = (ins AnyTypeOf<[1DTensorOf<[AnyInteger, Index]>, Shape_ValueShapeType]>:$arg);
+ let arguments = (ins AnyTypeOf<[1DTensorOf<[AnyInteger, Index]>,
+ Shape_ValueShapeType]>:$arg);
let results = (outs Shape_ShapeOrExtentTensorType:$result);
let assemblyFormat = "$arg attr-dict `:` type($arg) `->` type($result)";
def Shape_SplitAtOp : Shape_Op<"split_at", [Pure]> {
let summary = "Splits a shape at a given index";
let description = [{
- Splits a shape at a given dimension `index`, returning two shapes.
- If `index` is negative, it is treated as indexing from the back of the
- shape. This negative-handling behavior is important when handling unranked
- shapes, where the positive index is not necessarily knowable due to a
- dynamic number of leading dimensions. If the result is in extent tensor form
- out of bounds indices result in undefined behavior.
+ Splits a shape at a given dimension `index`, returning two shapes. If
+ `index` is negative, it is treated as indexing from the back of the shape.
+ This negative-handling behavior is important when handling unranked shapes,
+ where the positive index is not necessarily knowable due to a dynamic
+ number of leading dimensions. If the result is in extent tensor form out of
+ bounds indices result in undefined behavior.
Examples:
- split_at([4,5,6], index=0) -> [], [4,5,6]
concat([], [4,5,6]) -> [4,5,6]
}];
- let arguments = (ins Shape_ShapeOrExtentTensorType:$lhs, Shape_ShapeOrExtentTensorType:$rhs);
+ let arguments = (ins Shape_ShapeOrExtentTensorType:$lhs,
+ Shape_ShapeOrExtentTensorType:$rhs);
let results = (outs Shape_ShapeOrExtentTensorType:$result);
let assemblyFormat = [{
// the AssumingOp.
//
// This does no checks on the inputs to the AssumingOp.
- static void inlineRegionIntoParent(AssumingOp &op, PatternRewriter &rewriter);
+ static void inlineRegionIntoParent(AssumingOp &op,
+ PatternRewriter &rewriter);
}];
let builders = [
}];
let arguments = (ins SymbolNameAttr:$sym_name,
- OptionalAttr<StrAttr>:$sym_visibility);
- let arguments = (ins DictionaryAttr:$mapping);
+ OptionalAttr<StrAttr>:$sym_visibility,
+ DictionaryAttr:$mapping);
let regions = (region AnyRegion:$body);
let extraClassDeclaration = [{
/// Returns the region on the current operation that is callable. This may
/// return null in the case of an external callable object, e.g. an external
/// function.
- ::mlir::Region *getCallableRegion() { return isExternal() ? nullptr : &getBody(); }
+ ::mlir::Region *getCallableRegion() {
+ return isExternal() ? nullptr : &getBody();
+ }
/// Returns the results types that the callable region produces when
/// executed.
- ArrayRef<Type> getCallableResults() { return getFunctionType().getResults(); }
+ ArrayRef<Type> getCallableResults() {
+ return getFunctionType().getResults();
+ }
//===------------------------------------------------------------------===//
// FunctionOpInterface Methods
[Pure, HasParent<"FuncOp">, ReturnLike, Terminator]> {
let summary = "Shape function return operation";
let description = [{
- The `shape.return` operation represents a return operation within a function.
- The operation takes variable number of operands and produces no results.
+ The `shape.return` operation represents a return operation within a
+ function. The operation takes variable number of operands and produces no
+ results.
}];
let arguments = (ins Variadic<AnyType>:$operands);