예제 #1
0
파일: util.c 프로젝트: Meinersbur/ppcg
/* Compute the size of a bounding box around the origin and "set",
 * where "set" is assumed to contain only non-negative elements.
 * In particular, compute the maximal value of "set" in each direction
 * and add one.
 */
__isl_give isl_multi_pw_aff *ppcg_size_from_extent(__isl_take isl_set *set)
{
	int i, n;
	isl_multi_pw_aff *mpa;

	n = isl_set_dim(set, isl_dim_set);
	mpa = isl_multi_pw_aff_zero(isl_set_get_space(set));
	for (i = 0; i < n; ++i) {
		isl_space *space;
		isl_aff *one;
		isl_pw_aff *bound;

		if (!isl_set_dim_has_upper_bound(set, isl_dim_set, i)) {
			const char *name;
			name = isl_set_get_tuple_name(set);
			if (!name)
				name = "";
			fprintf(stderr, "unable to determine extent of '%s' "
				"in dimension %d\n", name, i);
			set = isl_set_free(set);
		}
		bound = isl_set_dim_max(isl_set_copy(set), i);

		space = isl_pw_aff_get_domain_space(bound);
		one = isl_aff_zero_on_domain(isl_local_space_from_space(space));
		one = isl_aff_add_constant_si(one, 1);
		bound = isl_pw_aff_add(bound, isl_pw_aff_from_aff(one));
		mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, bound);
	}
	isl_set_free(set);

	return mpa;
}
예제 #2
0
파일: aff.c 프로젝트: realincubus/pet
/* Return the result of applying the comparison operator "type"
 * to "pa1" and "pa2".
 *
 * In particular, construct an isl_pw_aff that is equal to 1
 * on the subset of the shared domain of "pa1" and "pa2" where
 * the comparison holds and 0 on the other part of the shared domain.
 *
 * If "pa1" or "pa2" involve any NaN, then return NaN.
 */
__isl_give isl_pw_aff *pet_comparison(enum pet_op_type type,
	__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
{
	isl_set *dom;
	isl_set *cond;
	isl_pw_aff *res;

	if (!pa1 || !pa2)
		goto error;
	if (isl_pw_aff_involves_nan(pa1) || isl_pw_aff_involves_nan(pa2)) {
		isl_space *space = isl_pw_aff_get_domain_space(pa1);
		isl_local_space *ls = isl_local_space_from_space(space);
		isl_pw_aff_free(pa1);
		isl_pw_aff_free(pa2);
		return isl_pw_aff_nan_on_domain(ls);
	}

	dom = isl_pw_aff_domain(isl_pw_aff_copy(pa1));
	dom = isl_set_intersect(dom, isl_pw_aff_domain(isl_pw_aff_copy(pa2)));

	switch (type) {
	case pet_op_lt:
		cond = isl_pw_aff_lt_set(pa1, pa2);
		break;
	case pet_op_le:
		cond = isl_pw_aff_le_set(pa1, pa2);
		break;
	case pet_op_gt:
		cond = isl_pw_aff_gt_set(pa1, pa2);
		break;
	case pet_op_ge:
		cond = isl_pw_aff_ge_set(pa1, pa2);
		break;
	case pet_op_eq:
		cond = isl_pw_aff_eq_set(pa1, pa2);
		break;
	case pet_op_ne:
		cond = isl_pw_aff_ne_set(pa1, pa2);
		break;
	default:
		isl_die(isl_pw_aff_get_ctx(pa1), isl_error_internal,
			"not a comparison operator", cond = NULL);
		isl_pw_aff_free(pa1);
		isl_pw_aff_free(pa2);
	}

	cond = isl_set_coalesce(cond);
	res = indicator_function(cond, dom);

	return res;
error:
	isl_pw_aff_free(pa1);
	isl_pw_aff_free(pa2);
	return NULL;
}
예제 #3
0
파일: aff.c 프로젝트: realincubus/pet
/* Return "!!pa", i.e., a function that is equal to 1 when "pa"
 * is non-zero and equal to 0 when "pa" is equal to zero,
 * on the domain of "pa".
 *
 * If "pa" involves any NaN, then return NaN.
 */
__isl_give isl_pw_aff *pet_to_bool(__isl_take isl_pw_aff *pa)
{
	isl_set *cond, *dom;

	if (!pa)
		return NULL;
	if (isl_pw_aff_involves_nan(pa)) {
		isl_space *space = isl_pw_aff_get_domain_space(pa);
		isl_local_space *ls = isl_local_space_from_space(space);
		isl_pw_aff_free(pa);
		return isl_pw_aff_nan_on_domain(ls);
	}

	dom = isl_pw_aff_domain(isl_pw_aff_copy(pa));
	cond = isl_pw_aff_non_zero_set(pa);
	pa = indicator_function(cond, dom);

	return pa;
}