Size of mlir::Type

Hi all,

Is there a way to get the size of the Type?

For example, I have a StructType which contains some types with their offsets. I want to compare the offset value with the size of the type. I think in LLVM this can be done via DataLayout. Is there a similar thing in MLIR?

In general, no. There may even be types for with the size does not make sense, or may depend on the lowering decisions that will be taken later. For example, we have different possible conversions from memref to LLVM, if we pass it as function argument. We need some high-level equivalent of datalayout in MLIR.

i* and f* are supposed to have as many bits as *, index has some bitwidth that can be parameterized when lowering to LLVM. If you are interested in sizes at the LLVM level, you can use the DataLayout object associated with the llvm::Module stored inside LLVMDialect. This will likely change soon though.

1 Like

+1. Asking for a mlir::Type's size in general might not make sense. It is more reasonable for lower-level dialects that more closely model hardwares. In SPIR-V, we have grown some ad-hoc utility functions to compute the size of some types for conversion and serialization. They should be consolidated into one place that is accessible to various components, like putting on the SPIR-V type hierarchy. Iā€™d image a MLIR DataLayout to be in the form of some interface where type can participate so that if we have them on the type hierarchy they can be naturally implemented.