[GPGPU] Move getExtend to C++ [NFC]

llvm-svn: 311123
This commit is contained in:
Tobias Grosser 2017-08-17 21:20:28 +00:00
parent 8e58ad5182
commit d2e57981fd
1 changed files with 35 additions and 54 deletions

View File

@ -2760,77 +2760,58 @@ public:
/// @param Array The array to derive the extent for.
///
/// @returns An isl_set describing the extent of the array.
__isl_give isl_set *getExtent(ScopArrayInfo *Array) {
isl::set getExtent(ScopArrayInfo *Array) {
unsigned NumDims = Array->getNumberOfDimensions();
isl_union_map *Accesses = S->getAccesses().release();
Accesses =
isl_union_map_intersect_domain(Accesses, S->getDomains().release());
Accesses = isl_union_map_detect_equalities(Accesses);
isl_union_set *AccessUSet = isl_union_map_range(Accesses);
AccessUSet = isl_union_set_coalesce(AccessUSet);
AccessUSet = isl_union_set_detect_equalities(AccessUSet);
AccessUSet = isl_union_set_coalesce(AccessUSet);
isl::union_map Accesses = S->getAccesses();
Accesses = Accesses.intersect_domain(S->getDomains());
Accesses = Accesses.detect_equalities();
isl::union_set AccessUSet = Accesses.range();
AccessUSet = AccessUSet.coalesce();
AccessUSet = AccessUSet.detect_equalities();
AccessUSet = AccessUSet.coalesce();
if (isl_union_set_is_empty(AccessUSet)) {
isl_union_set_free(AccessUSet);
return isl_set_empty(Array->getSpace().release());
}
if (AccessUSet.is_empty())
return isl::set::empty(Array->getSpace());
if (Array->getNumberOfDimensions() == 0) {
isl_union_set_free(AccessUSet);
return isl_set_universe(Array->getSpace().release());
}
if (Array->getNumberOfDimensions() == 0)
return isl::set::universe(Array->getSpace());
isl_set *AccessSet =
isl_union_set_extract_set(AccessUSet, Array->getSpace().release());
isl::set AccessSet = AccessUSet.extract_set(Array->getSpace());
isl_union_set_free(AccessUSet);
isl_local_space *LS =
isl_local_space_from_space(Array->getSpace().release());
isl::local_space LS = isl::local_space(Array->getSpace());
isl_pw_aff *Val =
isl_pw_aff_from_aff(isl_aff_var_on_domain(LS, isl_dim_set, 0));
isl::pw_aff Val = isl::aff::var_on_domain(LS, isl::dim::set, 0);
isl::pw_aff OuterMin = AccessSet.dim_min(0);
isl::pw_aff OuterMax = AccessSet.dim_max(0);
OuterMin = OuterMin.add_dims(isl::dim::in, Val.dim(isl::dim::in));
OuterMax = OuterMax.add_dims(isl::dim::in, Val.dim(isl::dim::in));
OuterMin = OuterMin.set_tuple_id(isl::dim::in, Array->getBasePtrId());
OuterMax = OuterMax.set_tuple_id(isl::dim::in, Array->getBasePtrId());
isl_pw_aff *OuterMin = isl_set_dim_min(isl_set_copy(AccessSet), 0);
isl_pw_aff *OuterMax = isl_set_dim_max(AccessSet, 0);
OuterMin = isl_pw_aff_add_dims(OuterMin, isl_dim_in,
isl_pw_aff_dim(Val, isl_dim_in));
OuterMax = isl_pw_aff_add_dims(OuterMax, isl_dim_in,
isl_pw_aff_dim(Val, isl_dim_in));
OuterMin = isl_pw_aff_set_tuple_id(OuterMin, isl_dim_in,
Array->getBasePtrId().release());
OuterMax = isl_pw_aff_set_tuple_id(OuterMax, isl_dim_in,
Array->getBasePtrId().release());
isl::set Extent = isl::set::universe(Array->getSpace());
isl_set *Extent = isl_set_universe(Array->getSpace().release());
Extent = isl_set_intersect(
Extent, isl_pw_aff_le_set(OuterMin, isl_pw_aff_copy(Val)));
Extent = isl_set_intersect(Extent, isl_pw_aff_ge_set(OuterMax, Val));
Extent = Extent.intersect(OuterMin.le_set(Val));
Extent = Extent.intersect(OuterMax.ge_set(Val));
for (unsigned i = 1; i < NumDims; ++i)
Extent = isl_set_lower_bound_si(Extent, isl_dim_set, i, 0);
Extent = Extent.lower_bound_si(isl::dim::set, i, 0);
for (unsigned i = 0; i < NumDims; ++i) {
isl_pw_aff *PwAff =
const_cast<isl_pw_aff *>(Array->getDimensionSizePw(i).release());
isl::pw_aff PwAff = Array->getDimensionSizePw(i);
// isl_pw_aff can be NULL for zero dimension. Only in the case of a
// Fortran array will we have a legitimate dimension.
if (!PwAff) {
if (PwAff.is_null()) {
assert(i == 0 && "invalid dimension isl_pw_aff for nonzero dimension");
continue;
}
isl_pw_aff *Val = isl_pw_aff_from_aff(isl_aff_var_on_domain(
isl_local_space_from_space(Array->getSpace().release()), isl_dim_set,
i));
PwAff = isl_pw_aff_add_dims(PwAff, isl_dim_in,
isl_pw_aff_dim(Val, isl_dim_in));
PwAff = isl_pw_aff_set_tuple_id(PwAff, isl_dim_in,
isl_pw_aff_get_tuple_id(Val, isl_dim_in));
auto *Set = isl_pw_aff_gt_set(PwAff, Val);
Extent = isl_set_intersect(Set, Extent);
isl::pw_aff Val = isl::aff::var_on_domain(
isl::local_space(Array->getSpace()), isl::dim::set, i);
PwAff = PwAff.add_dims(isl::dim::in, Val.dim(isl::dim::in));
PwAff = PwAff.set_tuple_id(isl::dim::in, Val.get_tuple_id(isl::dim::in));
isl::set Set = PwAff.gt_set(Val);
Extent = Set.intersect(Extent);
}
return Extent;
@ -2931,7 +2912,7 @@ public:
PPCGArray.name = strdup(Array->getName().c_str());
PPCGArray.extent = nullptr;
PPCGArray.n_index = Array->getNumberOfDimensions();
PPCGArray.extent = getExtent(Array);
PPCGArray.extent = getExtent(Array).release();
PPCGArray.n_ref = 0;
PPCGArray.refs = nullptr;
PPCGArray.accessed = true;
@ -3008,7 +2989,7 @@ public:
// 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();
return !getExtent(SAI).is_empty();
});
SmallVector<ScopArrayInfo *, 4> ValidSAIs(ValidSAIsRange.begin(),
ValidSAIsRange.end());