From b06ff4574e22bf997aa741bc09fc143c265b1816 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Tue, 9 Aug 2016 15:35:06 +0000 Subject: [GPGPU] Support PHI nodes used in GPU kernel Ensure the right scalar allocations are used as the host location of data transfers. For the device code, we clear the allocation cache before device code generation to be able to generate new device-specific allocation and we need to make sure to add back the old host allocations as soon as the device code generation is finished. llvm-svn: 278126 --- polly/lib/CodeGen/PPCGCodeGeneration.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'polly/lib/CodeGen/PPCGCodeGeneration.cpp') diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index 32858fc213d..2ca25ab1238 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -722,14 +722,14 @@ void GPUNodeBuilder::createDataTransfer(__isl_take isl_ast_node *TransferStmt, auto ScopArray = (ScopArrayInfo *)(Array->user); Value *Size = getArraySize(Array); - Value *HostPtr = ScopArray->getBasePtr(); - Value *DevPtr = DeviceAllocations[ScopArray]; - if (gpu_array_is_scalar(Array)) { - HostPtr = Builder.CreateAlloca(ScopArray->getElementType()); - Builder.CreateStore(ScopArray->getBasePtr(), HostPtr); - } + Value *HostPtr; + + if (gpu_array_is_scalar(Array)) + HostPtr = BlockGen.getOrCreateAlloca(ScopArray); + else + HostPtr = ScopArray->getBasePtr(); HostPtr = Builder.CreatePointerCast(HostPtr, Builder.getInt8PtrTy()); @@ -1074,6 +1074,10 @@ void GPUNodeBuilder::createKernel(__isl_take isl_ast_node *KernelStmt) { Instruction &HostInsertPoint = *Builder.GetInsertPoint(); IslExprBuilder::IDToValueTy HostIDs = IDToValue; ValueMapT HostValueMap = ValueMap; + BlockGenerator::ScalarAllocaMapTy HostScalarMap = ScalarMap; + BlockGenerator::ScalarAllocaMapTy HostPHIOpMap = PHIOpMap; + ScalarMap.clear(); + PHIOpMap.clear(); SetVector Loops; @@ -1102,9 +1106,9 @@ void GPUNodeBuilder::createKernel(__isl_take isl_ast_node *KernelStmt) { Builder.SetInsertPoint(&HostInsertPoint); IDToValue = HostIDs; - ValueMap = HostValueMap; - ScalarMap.clear(); - PHIOpMap.clear(); + ValueMap = std::move(HostValueMap); + ScalarMap = std::move(HostScalarMap); + PHIOpMap = std::move(HostPHIOpMap); EscapeMap.clear(); IDToSAI.clear(); Annotator.resetAlternativeAliasBases(); @@ -1283,7 +1287,7 @@ void GPUNodeBuilder::prepareKernelArguments(ppcg_kernel *Kernel, Function *FN) { continue; } - Value *Alloca = BlockGen.getOrCreateScalarAlloca(SAI->getBasePtr()); + Value *Alloca = BlockGen.getOrCreateAlloca(SAI); Value *ArgPtr = &*Arg; Type *TypePtr = SAI->getElementType()->getPointerTo(); Value *TypedArgPtr = Builder.CreatePointerCast(ArgPtr, TypePtr); -- cgit v1.2.3