Put the parallel context alloca into the function entry block.
We use lifetime markers to limit the actual life range (similar to clang).
Differential Revision: http://reviews.llvm.org/D5582
llvm-svn: 219005
diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp
index 10595f9..c0994b3 100644
--- a/polly/lib/CodeGen/LoopGenerators.cpp
+++ b/polly/lib/CodeGen/LoopGenerators.cpp
@@ -168,6 +168,11 @@
Builder.CreateCall(SubFn, SubFnParam);
createCallJoinThreads();
+ // Mark the end of the lifetime for the parameter struct.
+ Type *Ty = Struct->getType();
+ ConstantInt *SizeOf = Builder.getInt64(DL.getTypeAllocSize(Ty));
+ Builder.CreateLifetimeEnd(Struct, SizeOf);
+
return IV;
}
@@ -273,9 +278,17 @@
for (Value *V : Values)
Members.push_back(V->getType());
+ // We do not want to allocate the alloca inside any loop, thus we allocate it
+ // in the entry block of the function and use annotations to denote the actual
+ // live span (similar to clang).
+ BasicBlock &EntryBB = Builder.GetInsertBlock()->getParent()->getEntryBlock();
+ Instruction *IP = EntryBB.getFirstInsertionPt();
StructType *Ty = StructType::get(Builder.getContext(), Members);
- Value *Struct =
- new AllocaInst(Ty, 0, "polly.par.userContext", Builder.GetInsertPoint());
+ Value *Struct = new AllocaInst(Ty, 0, "polly.par.userContext", IP);
+
+ // Mark the start of the lifetime for the parameter struct.
+ ConstantInt *SizeOf = Builder.getInt64(DL.getTypeAllocSize(Ty));
+ Builder.CreateLifetimeStart(Struct, SizeOf);
for (unsigned i = 0; i < Values.size(); i++) {
Value *Address = Builder.CreateStructGEP(Struct, i);