Week 5 - Allocatable Arrays
So, this week was focussed on adding support for allocatable arrays. I had a meeting with Ondrej earlier this week for discussing various approaches for this feature. One method is to just allocate memory for allocatables on stack. This is actually done by one of the Fortran compilers. The problem with this approach is that we can run out of stack space (which is limited for every program/process) if the requested amount of memory is too large. Hence, allocating memory for allocatable arrays on heap seems a better and I think a more natural option. So, the question in front of us was how to do that? One way is to use CreateMalloc
API provided by LLVM. Another idea is to use malloc
provided by C (we use C-runtime as well). We picked the second idea because we believe it will provide better control and an easy way out. Though the game is not over yet. Another question to be answered is what to send to C API and what to get back? A pointer? However, we cannot write in advance various types that can be passed to allocate
(derived types are infinite). So, other option is to pass void
pointer. However, LLVM doesn’t allow that. A solution to this problem is to pass size and receive a long
(64 bit integer) and convert to pointer of desired type inside LLVM (using CreateIntToPtr
API). There is one more solution in my mind. I am thinking to recieve char*
instead of long
from C and then convert that char*
to desired type (bitcast
maybe). I intend to try out once statements like, allocate(a(n:2*n))
start working. As of now, passing lower bound doesn’t work with allocate
. Everything else is supported.
Ondrej also provided reviews on my array slicing MR. I have addressed them and it is ready for reviews/merging.
MR - !976
MR - !943.