From 1356ac75d1e99d6f26d198a691f727b23e811c09 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 3 Oct 2014 19:12:05 +0000 Subject: 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 --- polly/lib/CodeGen/LoopGenerators.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'polly/lib/CodeGen/LoopGenerators.cpp') diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index 10595f90341..c0994b3d643 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -168,6 +168,11 @@ Value *ParallelLoopGenerator::createParallelLoop( 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 @@ ParallelLoopGenerator::storeValuesIntoStruct(SetVector &Values) { 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); -- cgit v1.2.3