In my Google Summer of Code, 2021 with LFortran under the umbrella of NumFOCUS, I worked on adding semantic and LLVM backend support for arrays and allocatables as per Fortran standards. Specifically, the project resulted in addition of support for array declaration, operations on arrays (slicing, unary and binary operations), allocatable arrays, automatic deallocation, passing arrays to subroutines and functions. At the LLVM level, structures have been used as descriptors to store the necessary information related to an array such as the pointer to the data, offset and dimensions’ lower and upper bounds. Operations on arrays are converted to
do loops while storing the intermediate results in compiler generated variables. Memory for allocatable arrays is reserved in heap using
malloc and freed using
free in C runtime library. Automatic deallocation is achieved by freeing memory of those allocatable arrays in a particular scope which haven’t been manually deallocated by the user. We pass pointers to array descriptors (for arrays on heap) and pointers to data (for arrays on stack) in functions and subroutines. In this talk, I would be covering each of these topics in detail with some examples of internal representations (ASR, LLVM) generated by LFortran.