Blame isl-0.16.1/isl_union_eval.c

Packit fb9d21
/*
Packit fb9d21
 * Copyright 2010      INRIA Saclay
Packit fb9d21
 *
Packit fb9d21
 * Use of this software is governed by the MIT license
Packit fb9d21
 *
Packit fb9d21
 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
Packit fb9d21
 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
Packit fb9d21
 * 91893 Orsay, France
Packit fb9d21
 */
Packit fb9d21
Packit fb9d21
#include <isl_union_macro.h>
Packit fb9d21
Packit fb9d21
/* Is the domain space of "entry" equal to "space"?
Packit fb9d21
 */
Packit fb9d21
static int FN(UNION,has_domain_space)(const void *entry, const void *val)
Packit fb9d21
{
Packit fb9d21
	PART *part = (PART *)entry;
Packit fb9d21
	isl_space *space = (isl_space *) val;
Packit fb9d21
Packit fb9d21
	if (isl_space_is_params(space))
Packit fb9d21
		return isl_space_is_set(part->dim);
Packit fb9d21
Packit fb9d21
	return isl_space_tuple_is_equal(part->dim, isl_dim_in,
Packit fb9d21
					space, isl_dim_set);
Packit fb9d21
}
Packit fb9d21
Packit fb9d21
__isl_give isl_val *FN(UNION,eval)(__isl_take UNION *u,
Packit fb9d21
	__isl_take isl_point *pnt)
Packit fb9d21
{
Packit fb9d21
	uint32_t hash;
Packit fb9d21
	struct isl_hash_table_entry *entry;
Packit fb9d21
	isl_space *space;
Packit fb9d21
	isl_val *v;
Packit fb9d21
Packit fb9d21
	if (!u || !pnt)
Packit fb9d21
		goto error;
Packit fb9d21
Packit fb9d21
	space = isl_space_copy(pnt->dim);
Packit fb9d21
	if (!space)
Packit fb9d21
		goto error;
Packit fb9d21
	hash = isl_space_get_hash(space);
Packit fb9d21
	entry = isl_hash_table_find(u->space->ctx, &u->table,
Packit fb9d21
				    hash, &FN(UNION,has_domain_space),
Packit fb9d21
				    space, 0);
Packit fb9d21
	isl_space_free(space);
Packit fb9d21
	if (!entry) {
Packit fb9d21
		v = isl_val_zero(isl_point_get_ctx(pnt));
Packit fb9d21
		isl_point_free(pnt);
Packit fb9d21
	} else {
Packit fb9d21
		v = FN(PART,eval)(FN(PART,copy)(entry->data), pnt);
Packit fb9d21
	}
Packit fb9d21
	FN(UNION,free)(u);
Packit fb9d21
	return v;
Packit fb9d21
error:
Packit fb9d21
	FN(UNION,free)(u);
Packit fb9d21
	isl_point_free(pnt);
Packit fb9d21
	return NULL;
Packit fb9d21
}