From 43f178bbc9c75aea3df73632ae5fb4ca59a96c99 Mon Sep 17 00:00:00 2001 From: Siddharth Bhat Date: Tue, 25 Jul 2017 12:35:36 +0000 Subject: [PPCGCodeGeneration] Skip arrays with empty extent. Invariant load hoisted scalars, and arrays whose size we can statically compute to be 0 do not need to be allocated as arrays. Invariant load hoisted scalars are sent to the kernel directly as parameters. Earlier, we used to allocate `0` bytes of memory for these because our computation of size from `PPCGCodeGeneration::getArraySize` would result in `0`. Now, since we don't invariant loads as arrays in PPCGCodeGeneration, this problem does not occur anymore. Differential Revision: https://reviews.llvm.org/D35795 llvm-svn: 308971 --- polly/lib/CodeGen/PPCGCodeGeneration.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'polly/lib/CodeGen') diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index c35ff50986a..75c060aa7f3 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -2714,9 +2714,10 @@ public: /// Create the arrays for @p PPCGProg. /// /// @param PPCGProg The program to compute the arrays for. - void createArrays(gpu_prog *PPCGProg) { + void createArrays(gpu_prog *PPCGProg, + const SmallVector &ValidSAIs) { int i = 0; - for (auto &Array : S->arrays()) { + for (auto &Array : ValidSAIs) { std::string TypeName; raw_string_ostream OS(TypeName); @@ -2800,11 +2801,25 @@ public: isl_union_map_empty(isl_set_get_space(PPCGScop->context)); PPCGProg->n_stmts = std::distance(S->begin(), S->end()); PPCGProg->stmts = getStatements(); - PPCGProg->n_array = std::distance(S->array_begin(), S->array_end()); + + // Only consider arrays that have a non-empty extent. + // Otherwise, this will cause us to consider the following kinds of + // empty arrays: + // 1. Invariant loads that are represented by SAI objects. + // 2. Arrays with statically known zero size. + auto ValidSAIsRange = + make_filter_range(S->arrays(), [this](ScopArrayInfo *SAI) -> bool { + return !isl::manage(getExtent(SAI)).is_empty(); + }); + SmallVector ValidSAIs(ValidSAIsRange.begin(), + ValidSAIsRange.end()); + + PPCGProg->n_array = + ValidSAIs.size(); // std::distance(S->array_begin(), S->array_end()); PPCGProg->array = isl_calloc_array(S->getIslCtx(), struct gpu_array_info, PPCGProg->n_array); - createArrays(PPCGProg); + createArrays(PPCGProg, ValidSAIs); PPCGProg->may_persist = compute_may_persist(PPCGProg); return PPCGProg; -- cgit v1.2.3