This patch aims to implement the option of allocating new arrays created by polly on heap instead of stack.
To enable this option, a key named 'allocation' must be written in the imported json file with the value 'heap'.
We need such a feature because in a next iteration, we will implement a mechanism of maximal static expansion which will need a way to allocate arrays on heap. Indeed, the expansion is very costly in terms of memory and doing the allocation on stack is not worth considering.
The malloc and the free are added respectively at polly.start and polly.exiting such that there is no use-after-free (for instance in case of Scop in a loop) and such that all memory cells allocated with a malloc are free'd when we don't need them anymore.
We also add :
- In the class ScopArrayInfo, we add a boolean as member called IsOnHeap which represents the fact that the array in allocated on heap or not.
- A new branch in the method allocateNewArrays in the ISLNodeBuilder for the case of heap allocation. allocateNewArrays now takes a BBPair containing polly.start and polly.exiting. allocateNewArrays takes this two blocs and add the malloc and free calls respectively to polly.start and polly.exiting.
- As IntPtrTy for the malloc call, we use the DalaLayout one.
To do that, we have modified :
- CreateScopArrayInfo and getOrCreateScopArrayInfo such that it return a non-const SAI, in order to be able to call setIsOnHeap in the JSONImporter.
- executeScopConditionnaly such that it return both start block and end block of the scop, because we need this two blocs to be able to add the malloc and the free calls at the right position.