diff options
| author | Tobias Grosser <tobias@grosser.es> | 2016-08-04 06:55:59 +0000 |
|---|---|---|
| committer | Tobias Grosser <tobias@grosser.es> | 2016-08-04 06:55:59 +0000 |
| commit | 00bb5a99f58c9b64d10aa3f204e44d2d3b000b16 (patch) | |
| tree | 0cbe0700a0fc2e9d00a5e0bf74f639e6269e3149 /polly/lib/CodeGen | |
| parent | 3216f8546c96a6613253901e79b056aede79f04e (diff) | |
| download | bcm5719-llvm-00bb5a99f58c9b64d10aa3f204e44d2d3b000b16.tar.gz bcm5719-llvm-00bb5a99f58c9b64d10aa3f204e44d2d3b000b16.zip | |
GPGPU: Handle scalar array references
Pass the content of scalar array references to the alloca on the kernel side
and do not pass them additional as normal LLVM scalar value.
llvm-svn: 277699
Diffstat (limited to 'polly/lib/CodeGen')
| -rw-r--r-- | polly/lib/CodeGen/IslNodeBuilder.cpp | 16 | ||||
| -rw-r--r-- | polly/lib/CodeGen/PPCGCodeGeneration.cpp | 35 |
2 files changed, 38 insertions, 13 deletions
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp index 989f9270390..e46304fe2e6 100644 --- a/polly/lib/CodeGen/IslNodeBuilder.cpp +++ b/polly/lib/CodeGen/IslNodeBuilder.cpp @@ -193,17 +193,8 @@ static int findReferencesInBlock(struct SubtreeReferences &References, return 0; } -/// Extract the out-of-scop values and SCEVs referenced from a ScopStmt. -/// -/// This includes the SCEVUnknowns referenced by the SCEVs used in the -/// statement and the base pointers of the memory accesses. For scalar -/// statements we force the generation of alloca memory locations and list -/// these locations in the set of out-of-scop values as well. -/// -/// @param Stmt The statement for which to extract the information. -/// @param UserPtr A void pointer that can be casted to a SubtreeReferences -/// structure. -isl_stat addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr) { +isl_stat addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr, + bool CreateScalarRefs) { auto &References = *static_cast<struct SubtreeReferences *>(UserPtr); if (Stmt->isBlockStmt()) @@ -226,7 +217,8 @@ isl_stat addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr) { continue; } - References.Values.insert(References.BlockGen.getOrCreateAlloca(*Access)); + if (CreateScalarRefs) + References.Values.insert(References.BlockGen.getOrCreateAlloca(*Access)); } return isl_stat_ok; diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index 388ee8fdf05..46deae38a8a 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -242,6 +242,12 @@ private: /// @param Array The array for which to compute a size. Value *getArraySize(gpu_array_info *Array); + /// Prepare the kernel arguments for kernel code generation + /// + /// @param Kernel The kernel to generate code for. + /// @param FN The function created for the kernel. + void prepareKernelArguments(ppcg_kernel *Kernel, Function *FN); + /// Create kernel function. /// /// Create a kernel function located in a newly created module that can serve @@ -775,7 +781,7 @@ isl_bool collectReferencesInGPUStmt(__isl_keep isl_ast_node *Node, void *User) { auto Stmt = (ScopStmt *)KernelStmt->u.d.stmt->stmt; isl_id_free(Id); - addReferencesFromStmt(Stmt, User); + addReferencesFromStmt(Stmt, User, false /* CreateScalarRefs */); return isl_bool_true; } @@ -1167,6 +1173,32 @@ void GPUNodeBuilder::insertKernelIntrinsics(ppcg_kernel *Kernel) { } } +void GPUNodeBuilder::prepareKernelArguments(ppcg_kernel *Kernel, Function *FN) { + auto Arg = FN->arg_begin(); + for (long i = 0; i < Kernel->n_array; i++) { + if (!ppcg_kernel_requires_array_argument(Kernel, i)) + continue; + + isl_id *Id = isl_space_get_tuple_id(Prog->array[i].space, isl_dim_set); + const ScopArrayInfo *SAI = ScopArrayInfo::getFromId(isl_id_copy(Id)); + isl_id_free(Id); + + if (SAI->getNumberOfDimensions() > 0) { + Arg++; + continue; + } + + Value *Alloca = BlockGen.getOrCreateScalarAlloca(SAI->getBasePtr()); + Value *ArgPtr = &*Arg; + Type *TypePtr = SAI->getElementType()->getPointerTo(); + Value *TypedArgPtr = Builder.CreatePointerCast(ArgPtr, TypePtr); + Value *Val = Builder.CreateLoad(TypedArgPtr); + Builder.CreateStore(Val, Alloca); + + Arg++; + } +} + void GPUNodeBuilder::createKernelFunction(ppcg_kernel *Kernel, SetVector<Value *> &SubtreeValues) { @@ -1189,6 +1221,7 @@ void GPUNodeBuilder::createKernelFunction(ppcg_kernel *Kernel, ScopDetection::markFunctionAsInvalid(FN); + prepareKernelArguments(Kernel, FN); insertKernelIntrinsics(Kernel); } |

