Heap allocation for new arrays.
commit5a313b76acf885c9c722c49f635f178d2f6802eb
authorMichael Kruse <llvm@meinersbur.de>
Wed, 28 Jun 2017 13:02:43 +0000 (28 13:02 +0000)
committerMichael Kruse <llvm@meinersbur.de>
Wed, 28 Jun 2017 13:02:43 +0000 (28 13:02 +0000)
tree41a57fd1c14d0365fe137128305765fb8a20f57b
parent621fbe4fe7e8a0cf7ab04fcb6370bd0095104253
Heap allocation for new arrays.

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 blocks and add the malloc and free calls respectively to
  polly.start and polly.exiting.
- As IntPtrTy for the malloc call, we use the DataLayout one.

To do that, we have modified :

- createScopArrayInfo and getOrCreateScopArrayInfo such that it returns
  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.

Differential Revision: https://reviews.llvm.org/D33688

git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@306540 91177308-0d34-0410-b5e6-96231b3b80d8
include/polly/CodeGen/IslNodeBuilder.h
include/polly/ScopInfo.h
lib/Analysis/ScopInfo.cpp
lib/CodeGen/CodeGeneration.cpp
lib/CodeGen/IslNodeBuilder.cpp
lib/Exchange/JSONExporter.cpp
test/Isl/CodeGen/MemAccess/create_arrays_heap.ll [new file with mode: 0644]
test/Isl/CodeGen/MemAccess/create_arrays_heap___%for.cond1.preheader---%for.end18.jscop [new file with mode: 0644]
test/Isl/CodeGen/MemAccess/create_arrays_heap___%for.cond1.preheader---%for.end18.jscop.transformed [new file with mode: 0644]