All tensor/memref/vector types currently have a shared type interface
ShapedType. This interface provides the following interface methods:
getShape: Asserts that the type is ranked and returns the shape.
There are also a few helper functions around those interface methods such as
getDimSize, etc. Those also assert that the type is ranked.
Add a new
RankedShapedType interface that is a sub-interface of
ShapedType, utilizing interface inheritance (⚙ D140198 [mlir] Add support for interface inheritance).
All previously ranked
ShapedTypes (ranked tensor types, ranked memref types, vector types) implement
RankedShapedType instead of
ShapedType. (They are still considered
ShapedTypes because of the interface inheritance.)
Interface methods and helper functions/members that only make sense for ranked types (e.g.,
kDynamicSize) are moved to
(Dashed lines indicate interface implementation.)
Prototype: ⚙ D148453 [mlir] Add RankedShapedType interface. Most changes are mechanical, but because so many parts of the code base are affected, I decided to send this as an RFC.
Errors that were previously runtime assertion failures (e.g., calling
getShape() on an unranked tensor through
ShapedType) are now compile time errors:
ShapeType no longer have functions such as
ShapedType could be implemented via external models in the tensor/memref/vector dialects. Then, interface methods such as
createRankOp could be added, cleaning up various parts of the code base that currently have a hard-coded switch-case statement when both memref and tensor types are supported.