For unranked code generation for cwise ops we need an operation that can take
UnrankedMemRefType and flatten it into a 1D vector, i.e.
memref<?xelement_type>. After the unary operation is computed, the vector has to be reshaped back to it’s original shape. So what we need is a reshape operation that supports unranked memrefs.
The operation will take
shape memref as a second argument. Having variadic
IndexType size arguments is not possible since we don’t know how many are there in the dynamically-ranked case. Having
TensorType to pass the shape is also not optimal, because we would have to care about allocating it.
Here are some example applications of the op:
a. Both source and destination types are ranked memref types.
```mlir // Reshape statically-shaped memref. %dst = reshape_memref_cast %src(%shape) : (memref<4x1xf32>, memref<1xindex>) to memref<4xf32> ``` b. Source type is ranked, destination type is unranked. ```mlir // Reshape dynamically-shaped 1D memref. %dst = reshape_memref_cast %src(%shape) : (memref<?xf32>, memref<?xindex>) to memref<*xf32> ``` c. Source type is unranked, destination type is ranked. ```mlir // Flatten unranked memref. %dst = reshape_memref_cast %src(%shape) : (memref<*xf32>, memref<1xindex>) to memref<?xf32> ```