Constrain mhlo.const to static shaped tensors.

Constants of unknown shape cannot be materialized. In most cases, one likely wants to use a scalar constant and rely on broadcasting instead.

PiperOrigin-RevId: 324252475
This commit is contained in:
Stephan Herhut 2020-07-31 11:50:22 -07:00 committed by TensorFlow MLIR Team
parent 734b9b25fd
commit 9cbe5f2285
2 changed files with 18 additions and 2 deletions

View File

@ -52,7 +52,7 @@ def HLO_ConstOp : HLO_Op<"constant",
); );
let results = (outs let results = (outs
HLO_Tensor:$output HLO_StaticShapeTensor:$output
); );
let builders = [OpBuilder< let builders = [OpBuilder<

View File

@ -939,7 +939,23 @@ func @constants() -> () {
func @constant_invalid() -> () { func @constant_invalid() -> () {
// expected-error@+1 {{op failed to verify that all of {value, output} have same type}} // expected-error@+1 {{op failed to verify that all of {value, output} have same type}}
%0 = "mhlo.constant"() {value = dense<0> : tensor<i32>} : () -> (tensor<*xi32>) %0 = "mhlo.constant"() {value = dense<0> : tensor<i32>} : () -> (tensor<3xi32>)
return
}
// -----
func @constant_invalid() -> () {
// expected-error@+1 {{op result #0 must be statically shaped tensor}}
%0 = "mhlo.constant"() {value = dense<1> : tensor<i32>} : () -> tensor<?xi32>
return
}
// -----
func @constant_invalid() -> () {
// expected-error@+1 {{elements literal type must have static shape}}
%0 = "mhlo.constant"() {value = dense<1> : tensor<?xi32>} : () -> tensor<?xi32>
return return
} }