Пример #1
0
/* Extract a common guard from the grafts in "list" that can be hoisted
 * out of the current level.  If no such guard can be found, then return
 * a universal set.
 *
 * If all the grafts in the list have the same guard and if this guard
 * is independent of the current level, then it can be hoisted out.
 * If there is only one graft in the list and if its guard
 * depends on the current level, then we eliminate this level and
 * return the result.
 *
 * Otherwise, we return the unshifted simple hull of the guards.
 * In order to be able to hoist as many constraints as possible,
 * but at the same time avoid hoisting constraints that did not
 * appear in the guards in the first place, we intersect the guards
 * with all the information that is available (i.e., the domain
 * from the build and the enforced constraints of the graft) and
 * compute the unshifted hull of the result using only constraints
 * from the original guards.
 * In particular, intersecting the guards with other known information
 * allows us to hoist guards that are only explicit is some of
 * the grafts and implicit in the others.
 *
 * The special case for equal guards is needed in case those guards
 * are non-convex.  Taking the simple hull would remove information
 * and would not allow for these guards to be hoisted completely.
 */
__isl_give isl_set *isl_ast_graft_list_extract_hoistable_guard(
	__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
{
	int i, n;
	int equal;
	isl_ctx *ctx;
	isl_set *guard;
	isl_set_list *set_list;
	isl_basic_set *hull;

	if (!list || !build)
		return NULL;

	n = isl_ast_graft_list_n_ast_graft(list);
	if (n == 0)
		return isl_set_universe(isl_ast_build_get_space(build, 1));

	equal = equal_independent_guards(list, build);
	if (equal < 0)
		return NULL;

	if (equal || n == 1) {
		isl_ast_graft *graft_0;

		graft_0 = isl_ast_graft_list_get_ast_graft(list, 0);
		if (!graft_0)
			return NULL;
		guard = isl_set_copy(graft_0->guard);
		if (!equal)
			guard = hoist_guard(guard, build);
		isl_ast_graft_free(graft_0);
		return guard;
	}

	ctx = isl_ast_build_get_ctx(build);
	set_list = isl_set_list_alloc(ctx, n);
	guard = isl_set_empty(isl_ast_build_get_space(build, 1));
	for (i = 0; i < n; ++i) {
		isl_ast_graft *graft;
		isl_basic_set *enforced;
		isl_set *guard_i;

		graft = isl_ast_graft_list_get_ast_graft(list, i);
		enforced = isl_ast_graft_get_enforced(graft);
		guard_i = isl_set_copy(graft->guard);
		isl_ast_graft_free(graft);
		set_list = isl_set_list_add(set_list, isl_set_copy(guard_i));
		guard_i = isl_set_intersect(guard_i,
					    isl_set_from_basic_set(enforced));
		guard_i = isl_set_intersect(guard_i,
					    isl_ast_build_get_domain(build));
		guard = isl_set_union(guard, guard_i);
	}
	hull = isl_set_unshifted_simple_hull_from_set_list(guard, set_list);
	guard = isl_set_from_basic_set(hull);
	return hoist_guard(guard, build);
}
Пример #2
0
/* Extract a common guard from the grafts in "list" that can be hoisted
 * out of the current level.  If no such guard can be found, then return
 * a universal set.
 *
 * If all the grafts in the list have the same guard and if this guard
 * is independent of the current level, then it can be hoisted out.
 * Otherwise, we return the unshifted simple hull of the guards.
 *
 * The special case for equal guards is needed in case those guards
 * are non-convex.  Taking the simple hull would remove information
 * and would not allow for these guards to be hoisted completely.
 */
static __isl_give isl_set *extract_hoistable_guard(
	__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build)
{
	int i, n;
	int depth;
	isl_ast_graft *graft_0;
	int equal;
	isl_set *guard;

	if (!list || !build)
		return NULL;

	n = isl_ast_graft_list_n_ast_graft(list);
	if (n == 0)
		return isl_set_universe(isl_ast_build_get_space(build, 1));

	equal = equal_independent_guards(list, build);
	if (equal < 0)
		return NULL;

	graft_0 = isl_ast_graft_list_get_ast_graft(list, 0);
	if (!graft_0)
		return NULL;
	guard = isl_set_copy(graft_0->guard);
	isl_ast_graft_free(graft_0);
	if (equal)
		return guard;

	depth = isl_ast_build_get_depth(build);
	if (depth < isl_set_dim(guard, isl_dim_set)) {
		guard = isl_set_remove_divs_involving_dims(guard,
						isl_dim_set, depth, 1);
		guard = isl_set_eliminate(guard, isl_dim_set, depth, 1);
		guard = isl_set_compute_divs(guard);
	}

	for (i = 1; i < n; ++i) {
		isl_ast_graft *graft;
		isl_basic_set *hull;
		int is_universe;

		is_universe = isl_set_plain_is_universe(guard);
		if (is_universe < 0)
			guard = isl_set_free(guard);
		if (is_universe)
			break;

		graft = isl_ast_graft_list_get_ast_graft(list, i);
		if (!graft) {
			guard = isl_set_free(guard);
			break;
		}
		guard = isl_set_union(guard, isl_set_copy(graft->guard));
		hull = isl_set_unshifted_simple_hull(guard);
		guard = isl_set_from_basic_set(hull);
		isl_ast_graft_free(graft);
	}

	return guard;
}
Пример #3
0
__isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1,
	__isl_take isl_point *pnt2)
{
	isl_basic_set *bset;
	bset = isl_basic_set_box_from_points(pnt1, pnt2);
	return isl_set_from_basic_set(bset);
}
Пример #4
0
static int qpolynomial_bound_on_domain_range(__isl_take isl_basic_set *bset,
	__isl_take isl_qpolynomial *poly, struct range_data *data)
{
	unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
	unsigned nvar = isl_basic_set_dim(bset, isl_dim_set);
	isl_set *set = NULL;

	if (!bset)
		goto error;

	if (nvar == 0)
		return add_guarded_poly(bset, poly, data);

	set = isl_set_from_basic_set(bset);
	set = isl_set_split_dims(set, isl_dim_param, 0, nparam);
	set = isl_set_split_dims(set, isl_dim_set, 0, nvar);

	data->poly = poly;

	data->test_monotonicity = 1;
	if (isl_set_foreach_basic_set(set, &basic_guarded_poly_bound, data) < 0)
		goto error;

	isl_set_free(set);
	isl_qpolynomial_free(poly);

	return 0;
error:
	isl_set_free(set);
	isl_qpolynomial_free(poly);
	return -1;
}
Пример #5
0
/* Insert an if node around a copy of "data->node" testing the condition
 * encoded in guard "bset" and add the result to data->list.
 */
static int insert_if(__isl_take isl_basic_set *bset, void *user)
{
	struct isl_insert_if_data *data = user;
	isl_ast_node *node;
	isl_set *set;

	set = isl_set_from_basic_set(bset);
	node = isl_ast_node_copy(data->node);
	node = ast_node_insert_if(node, set, data->build);
	data->list = isl_ast_node_list_add(data->list, node);

	return 0;
}
Пример #6
0
/* Compute the union of all the constraints in domain.  */
isl_union_set *nfm_union_domain_union_domains(isl_ctx *ctx,
		struct nfm_union_domain *union_domain)
{
	isl_union_set *union_set;

	assert(union_domain);
	assert(union_domain->domain);

	IF_DEBUG(fprintf(stdout, " Starting the union function.\n"));

	nfm_union_domain *head = union_domain;
	union_set = isl_union_set_empty(nfm_domain_get_space(ctx, union_domain->domain));

	IF_DEBUG(fprintf(stdout, " Initial value for the union set is:"));
	IF_DEBUG(isl_union_set_dump(union_set));

	while (head != NULL)
	{
		nfm_domain *domain = head->domain;
		isl_bset_list *bset_list = nfm_domain_intersect_constraints(ctx, domain);
		IF_DEBUG(fprintf(stdout, " The constraints at this iteration,"
					 " represented as a set, are:"));
		IF_DEBUG(isl_bset_list_dump(bset_list));

	  	while (bset_list != NULL)
		{
			union_set = isl_union_set_union(union_set,
					isl_union_set_from_set(
						isl_set_from_basic_set(
							bset_list->bset)));
			bset_list = bset_list->next;
		}

		IF_DEBUG(fprintf(stdout, " Results of the union:"));
		IF_DEBUG(isl_union_set_dump(union_set));
		head  = head->next;
	}

	IF_DEBUG(fprintf(stdout, " End of the union function.\n"));

	return union_set;
}
Пример #7
0
/* Helper function to add a guarded polynomial to either pwf_tight or pwf,
 * depending on whether the result has been determined to be tight.
 */
static isl_stat add_guarded_poly(__isl_take isl_basic_set *bset,
	__isl_take isl_qpolynomial *poly, struct range_data *data)
{
	enum isl_fold type = data->sign < 0 ? isl_fold_min : isl_fold_max;
	isl_set *set;
	isl_qpolynomial_fold *fold;
	isl_pw_qpolynomial_fold *pwf;

	bset = isl_basic_set_params(bset);
	poly = isl_qpolynomial_project_domain_on_params(poly);

	fold = isl_qpolynomial_fold_alloc(type, poly);
	set = isl_set_from_basic_set(bset);
	pwf = isl_pw_qpolynomial_fold_alloc(type, set, fold);
	if (data->tight)
		data->pwf_tight = isl_pw_qpolynomial_fold_fold(
						data->pwf_tight, pwf);
	else
		data->pwf = isl_pw_qpolynomial_fold_fold(data->pwf, pwf);

	return isl_stat_ok;
}
Пример #8
0
__isl_give isl_set *isl_set_from_point(__isl_take isl_point *pnt)
{
	isl_basic_set *bset;
	bset = isl_basic_set_from_point(pnt);
	return isl_set_from_basic_set(bset);
}