forked from OSchip/llvm-project
[MLIR][Shape] Allow `num_elements` to operate on extent tensors
Re-landing with dependent change landed and error condition relaxed. Beyond the change to error condition exactly https://reviews.llvm.org/D84445.
This commit is contained in:
parent
5142448a5e
commit
07f227c0eb
|
@ -333,19 +333,19 @@ def Shape_NumElementsOp : Shape_Op<"num_elements", [NoSideEffect]> {
|
||||||
let summary = "Returns the number of elements for a given shape";
|
let summary = "Returns the number of elements for a given shape";
|
||||||
let description = [{
|
let description = [{
|
||||||
Returns the number of elements for a given shape which is the product of its
|
Returns the number of elements for a given shape which is the product of its
|
||||||
dimensions.
|
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
|
||||||
```mlir
|
is and extent tensor `tensor<?xindex>` then the result will be of type
|
||||||
%product = shape.mul %lhs, %rhs
|
`index`.
|
||||||
```
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins Shape_ShapeType:$shape);
|
let arguments = (ins Shape_ShapeOrExtentTensorType:$shape);
|
||||||
let results = (outs Shape_SizeType:$result);
|
let results = (outs Shape_SizeOrIndexType:$result);
|
||||||
|
|
||||||
let assemblyFormat = "$shape attr-dict";
|
let assemblyFormat = "$shape `:` type($shape) `->` type($result) attr-dict";
|
||||||
|
|
||||||
let hasFolder = 1;
|
let hasFolder = 1;
|
||||||
|
let verifier = [{ return ::verifySizeOrIndexOp(*this); }];
|
||||||
}
|
}
|
||||||
|
|
||||||
def Shape_ReduceOp : Shape_Op<"reduce",
|
def Shape_ReduceOp : Shape_Op<"reduce",
|
||||||
|
|
|
@ -217,7 +217,7 @@ func @num_elements() -> !shape.size {
|
||||||
// CHECK-NOT: shape.const_shape
|
// CHECK-NOT: shape.const_shape
|
||||||
%shape = shape.const_shape [4, 5, 6] : !shape.shape
|
%shape = shape.const_shape [4, 5, 6] : !shape.shape
|
||||||
// CHECK-NOT: shape.num_elements
|
// CHECK-NOT: shape.num_elements
|
||||||
%num_elements = shape.num_elements %shape
|
%num_elements = shape.num_elements %shape : !shape.shape -> !shape.size
|
||||||
// CHECK: %[[NUM:.*]] = shape.const_size 120
|
// CHECK: %[[NUM:.*]] = shape.const_size 120
|
||||||
// CHECK-NEXT: return %[[NUM]] : !shape.size
|
// CHECK-NEXT: return %[[NUM]] : !shape.size
|
||||||
return %num_elements : !shape.size
|
return %num_elements : !shape.size
|
||||||
|
@ -229,7 +229,7 @@ func @num_elements() -> !shape.size {
|
||||||
// CHECK-LABEL: func @nonfoldable_num_elements
|
// CHECK-LABEL: func @nonfoldable_num_elements
|
||||||
func @nonfoldable_num_elements(%shape : !shape.shape) -> !shape.size {
|
func @nonfoldable_num_elements(%shape : !shape.shape) -> !shape.size {
|
||||||
// CHECK-NOT: shape.const_{{.*}}
|
// CHECK-NOT: shape.const_{{.*}}
|
||||||
%num_elements = shape.num_elements %shape
|
%num_elements = shape.num_elements %shape : !shape.shape -> !shape.size
|
||||||
return %num_elements : !shape.size
|
return %num_elements : !shape.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,3 +120,11 @@ func @mul_error_possible(%lhs : !shape.size, %rhs : index) -> index {
|
||||||
return %result : index
|
return %result : index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----
|
||||||
|
|
||||||
|
func @num_elements_error_possible(%arg : !shape.shape) -> index {
|
||||||
|
// expected-error@+1 {{if at least one of the operands can hold error values then the result must be of type `size` to propagate them}}
|
||||||
|
%result = shape.num_elements %arg : !shape.shape -> index
|
||||||
|
return %result : index
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,3 +195,14 @@ func @any() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func @num_elements_extent_tensor(%arg : tensor<?xindex>) -> index {
|
||||||
|
%result = shape.num_elements %arg : tensor<?xindex> -> index
|
||||||
|
return %result : index
|
||||||
|
}
|
||||||
|
|
||||||
|
func @num_elements_shape(%arg : !shape.shape) -> !shape.size {
|
||||||
|
%result = shape.num_elements %arg : !shape.shape -> !shape.size
|
||||||
|
return %result : !shape.size
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// RUN: mlir-opt -shape-to-shape-lowering -split-input-file %s | FileCheck %s
|
// RUN: mlir-opt -shape-to-shape-lowering -split-input-file %s | FileCheck %s
|
||||||
|
|
||||||
// CHECK-LABEL: func @num_elements_to_reduce(
|
// CHECK-LABEL: func @num_elements_to_reduce
|
||||||
// CHECK-SAME: [[ARG:%.*]]: !shape.shape) -> !shape.size {
|
// CHECK-SAME: ([[ARG:%.*]]: !shape.shape) -> !shape.size
|
||||||
func @num_elements_to_reduce(%shape : !shape.shape) -> !shape.size {
|
func @num_elements_to_reduce(%shape : !shape.shape) -> !shape.size {
|
||||||
%num_elements = shape.num_elements %shape
|
%num_elements = shape.num_elements %shape : !shape.shape -> !shape.size
|
||||||
return %num_elements : !shape.size
|
return %num_elements : !shape.size
|
||||||
}
|
}
|
||||||
// CHECK: [[C1:%.*]] = shape.const_size 1
|
// CHECK: [[C1:%.*]] = shape.const_size 1
|
||||||
|
|
Loading…
Reference in New Issue