summaryrefslogtreecommitdiffstats
path: root/polly/lib/CodeGen/CodeGeneration.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2017-06-28 13:02:43 +0000
committerMichael Kruse <llvm@meinersbur.de>2017-06-28 13:02:43 +0000
commitb738ffa845493d8af0d08acaa7c8b2b91dd295b2 (patch)
tree7c85429afaab29206e92f701599eaac3d08f3fb5 /polly/lib/CodeGen/CodeGeneration.cpp
parent72d25399379c7195d8a3d2f9f497ac68252483e9 (diff)
downloadbcm5719-llvm-b738ffa845493d8af0d08acaa7c8b2b91dd295b2.tar.gz
bcm5719-llvm-b738ffa845493d8af0d08acaa7c8b2b91dd295b2.zip
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 llvm-svn: 306540
Diffstat (limited to 'polly/lib/CodeGen/CodeGeneration.cpp')
-rw-r--r--polly/lib/CodeGen/CodeGeneration.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index fc2bcf056fb..0e80058f1a1 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -187,7 +187,7 @@ static bool CodeGen(Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT,
// All arrays must have their base pointers known before
// ScopAnnotator::buildAliasScopes.
- NodeBuilder.allocateNewArrays();
+ NodeBuilder.allocateNewArrays(StartExitBlocks);
Annotator.buildAliasScopes(S);
if (PerfMonitoring) {
@@ -232,7 +232,14 @@ static bool CodeGen(Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT,
Value *RTC = NodeBuilder.createRTC(AI.getRunCondition());
Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC);
- Builder.SetInsertPoint(&StartBlock->front());
+
+ // Explicitly set the insert point to the end of the block to avoid that a
+ // split at the builder's current
+ // insert position would move the malloc calls to the wrong BasicBlock.
+ // Ideally we would just split the block during allocation of the new
+ // arrays, but this would break the assumption that there are no blocks
+ // between polly.start and polly.exiting (at this point).
+ Builder.SetInsertPoint(StartBlock->getTerminator());
NodeBuilder.create(AstRoot);
NodeBuilder.finalize();
OpenPOWER on IntegriCloud