In this patch, we try to support load/store/alloca for scalable structures. We have posted a RFC for the proposal in the mailing list. https://groups.google.com/g/llvm-dev/c/6ZK2eS4-8t0/m/PG6H1NNDBAAJ
In RISC-V vector intrinsics, we have defined types containing multiple scalable vectors. Due to the flexible configuration of vector types with LMUL, the struct is a good fit to represent these types containing multiple scalable vectors. We permit users to define auto variables using these types. That is why we need to support load, store, and alloca for the scalable structure.
To support load, store and alloca for the scalable structure, we have to achieve the following two points.
- In StructLayout, we use uint64_t for the StructSize. Currently, we have TypeSize to represent the size of data. We should modify the StructLayout using the TypeSize for data size regardless to support scalable struct or not.
- In order to handle load and store scalable struct correctly, we need to modify ComputeValueVTs() to return the correct information. The returned Offsets should be represented as TypeSize. In order to collect the correct information, we need to represent the StructSize in StructLayout using TypeSize. (refer to the first point.)
We have some limitation for the scalable structure.
- Due to the TypeSize could only represent either scalable size or fixed size, we could not mix the fixed objects and scalable objects in a struct. We only support struct with all scalable objects.
- We only need load/store/alloca scalable struct. We have no need to support GEP for scalable struct. It could alleviate the effort to expand the capabilities of IR.
The is special code in DataLayout::getStructLayout that allocates the size of StructLayout to account for the needed size of MemberOffsets. That code does not appear to be updated in this patch.
I'm not sure we want to use SmallVector here. The minimum size is increasing the size of every StructLayout object. SmallVector contains the number of elements which is redundant with the NumElements in the StructLayout itself. SmallVector also contains an additional field for the capacity of the allocated memory.
Can we go back to the variable sized array and update DataLayout::getStructLayout to use TypeSize instead of uint64_t to calculate the needed space?