[mlir][IR] Improve `clone` function return type of shaped types
authorMatthias Springer <me@m-sp.org>
Thu, 25 May 2023 07:22:19 +0000 (09:22 +0200)
committerMatthias Springer <me@m-sp.org>
Thu, 25 May 2023 07:27:33 +0000 (09:27 +0200)
commitc0261eb02bb092d8842d3c57297e23f31d75cb96
treebcb3b3f8185c27226f30150bb5f37362783053b0
parent92723d5a32acefc98a618ebfa47da22002b8e911
[mlir][IR] Improve `clone` function return type of shaped types

There are `clone` overloads that take a shape as a parameter. These overloads are guaranteed to return a ranked shaped type.

`TensorType::clone`/`BaseMemRefType::clone` used to always return a `TensorType`/`BaseMemRefType`. The variants that take a shape parameter now return a `RankedTensorType`/`MemRefType`. Better static type information can make extra casts at the call site obsolete.

E.g.:
```
{TensorType/RankedTensorType} t;
t.clone({1, 2})  // now returns RankedTensorType instead of TensorType
```

Also improve documentation for `clone`.

Differential Revision: https://reviews.llvm.org/D150865
mlir/include/mlir/IR/BuiltinTypeInterfaces.td
mlir/include/mlir/IR/BuiltinTypes.h
mlir/include/mlir/IR/BuiltinTypes.td
mlir/lib/IR/BuiltinTypes.cpp