/* Mark the space as being that of a parameter domain, by setting * both tuples to isl_id_none. */ static __isl_give isl_space *mark_as_params(isl_space *space) { if (!space) return NULL; space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none); space = isl_space_set_tuple_id(space, isl_dim_out, &isl_id_none); return space; }
/* Construct a contraction from "prefix" and "domain" for a new group * in "grouping". * * The values of the prefix schedule "prefix" are used as instances * of the new group. The identifier of the group is constructed * in such a way that it does not conflict with those of earlier * groups nor with statements in the domain of the original * schedule constraints. * The isl_multi_union_pw_aff "prefix" then simply needs to be * converted to an isl_union_pw_multi_aff. However, this is not * possible if "prefix" is zero-dimensional, so in this case, * a contraction is constructed from "domain" instead. */ static isl_union_pw_multi_aff *group_contraction_from_prefix_and_domain( struct ppcg_grouping *grouping, __isl_keep isl_multi_union_pw_aff *prefix, __isl_keep isl_union_set *domain) { isl_id *id; isl_space *space; int dim; space = isl_multi_union_pw_aff_get_space(prefix); if (!space) return NULL; dim = isl_space_dim(space, isl_dim_set); id = construct_group_id(grouping, space); if (dim == 0) { isl_multi_val *mv; space = isl_multi_union_pw_aff_get_space(prefix); space = isl_space_set_tuple_id(space, isl_dim_set, id); mv = isl_multi_val_zero(space); domain = isl_union_set_copy(domain); return isl_union_pw_multi_aff_multi_val_on_domain(domain, mv); } prefix = isl_multi_union_pw_aff_copy(prefix); prefix = isl_multi_union_pw_aff_set_tuple_id(prefix, isl_dim_out, id); return isl_union_pw_multi_aff_from_multi_union_pw_aff(prefix); }
/* Mark the space as being that of a set, by setting the domain tuple * to isl_id_none. */ static __isl_give isl_space *mark_as_set(__isl_take isl_space *space) { space = isl_space_cow(space); if (!space) return NULL; space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none); return space; }
/* Construct a unique identifier for a group in "grouping". * * The name is of the form G_n, with n the first value starting at * grouping->group_id that does not result in an identifier * that is already in use in the domain of the original schedule * constraints. */ static isl_id *construct_group_id(struct ppcg_grouping *grouping, __isl_take isl_space *space) { isl_ctx *ctx; isl_id *id; isl_bool empty; isl_union_set *domain; if (!space) return NULL; ctx = isl_space_get_ctx(space); domain = isl_schedule_constraints_get_domain(grouping->sc); do { char buffer[20]; isl_id *id; isl_set *set; snprintf(buffer, sizeof(buffer), "G_%d", grouping->group_id); grouping->group_id++; id = isl_id_alloc(ctx, buffer, NULL); space = isl_space_set_tuple_id(space, isl_dim_set, id); set = isl_union_set_extract_set(domain, isl_space_copy(space)); empty = isl_set_plain_is_empty(set); isl_set_free(set); } while (empty >= 0 && !empty); if (empty < 0) space = isl_space_free(space); id = isl_space_get_tuple_id(space, isl_dim_set); isl_space_free(space); isl_union_set_free(domain); return id; }
/// @brief Create a new scattering for PollyStmt. /// /// @param m The matrix describing the new scattering. /// @param PollyStmt The statement to create the scattering for. /// /// @return An isl_map describing the scattering. isl_map *scatteringForStmt(scoplib_matrix_p m, ScopStmt *PollyStmt, int scatteringDims) { unsigned NbParam = PollyStmt->getNumParams(); unsigned NbIterators = PollyStmt->getNumIterators(); unsigned NbScattering; if (scatteringDims == -1) NbScattering = m->NbColumns - 2 - NbParam - NbIterators; else NbScattering = scatteringDims; isl_ctx *ctx = PollyStmt->getParent()->getIslCtx(); isl_space *Space = isl_dim_alloc(ctx, NbParam, NbIterators, NbScattering); isl_space *ParamSpace = PollyStmt->getParent()->getParamSpace(); // We need to copy the isl_ids for the parameter dimensions to the new // map. Without doing this the current map would have different // ids then the new one, even though both are named identically. for (unsigned i = 0; i < isl_space_dim(Space, isl_dim_param); i++) { isl_id *id = isl_space_get_dim_id(ParamSpace, isl_dim_param, i); Space = isl_space_set_dim_id(Space, isl_dim_param, i, id); } isl_space_free(ParamSpace); Space = isl_space_set_tuple_name(Space, isl_dim_out, "scattering"); Space = isl_space_set_tuple_id(Space, isl_dim_in, PollyStmt->getDomainId()); if (scatteringDims == -1) return mapFromMatrix(m, Space); return mapFromMatrix(m, Space, scatteringDims); }