From dc875a042e14430a538d9133a2396af71abda105 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Tue, 17 Jun 2008 13:28:50 -0500 Subject: [PATCH] wrap polyhedron in an additional structure for being able to represent unions --- include/cloog/ppl_backend.h | 24 ++++++++-------- source/ppl/clast.c | 2 +- source/ppl/domain.c | 69 +++++++++++++-------------------------------- 3 files changed, 32 insertions(+), 63 deletions(-) diff --git a/include/cloog/ppl_backend.h b/include/cloog/ppl_backend.h index 118f89c..56e0f01 100644 --- a/include/cloog/ppl_backend.h +++ b/include/cloog/ppl_backend.h @@ -26,20 +26,20 @@ cloog_finalize (void) ppl_finalize (); } -/** - * CloogDomain structure: - * this structure contains a polyhedron in the PolyLib shape and the number of - * active references to this structure. Because CLooG uses many copies of - * domains there is no need to actually copy these domains but just to return - * a pointer to them and to increment the number of active references. Each time - * a CloogDomain will be freed, we will decrement the active reference counter - * and actually free it if its value is zero. - */ +typedef struct ppl_polyhedra_union { + Polyhedron *_polyhedron; +} ppl_polyhedra_union; + typedef struct cloogdomain { - Polyhedron *_polyhedron ; /**< A convex polyhedral domain. */ - int _references ; /**< Number of references to this structure. */ - struct cloogdomain *_next; /**< Next polyhedra in the union of convex polyhedra. */ + struct ppl_polyhedra_union *_polyhedron; + int _references; } CloogDomain; extern void debug_cloog_domain (CloogDomain *); + +static inline Polyhedron * +cloog_domain_polyhedron (CloogDomain * domain) +{ + return domain->_polyhedron->_polyhedron; +} diff --git a/source/ppl/clast.c b/source/ppl/clast.c index be85aa5..703dc58 100644 --- a/source/ppl/clast.c +++ b/source/ppl/clast.c @@ -1382,7 +1382,7 @@ cloog_simplify_domain_matrix_with_equalities (CloogDomain *domain, int level, /* FIXME: the access to ->_polyhedron is a hack to avoid exporting the CloogMatrix in a .h file: the whole clast.c file should be rewritten specifically to Polylib and PPL. */ - temp = Polyhedron2Constraints(domain->_polyhedron); + temp = Polyhedron2Constraints(cloog_domain_polyhedron (domain)); cloog_matrix_normalize (temp, level); res = cloog_matrix_simplify (temp, equal, level, nb_parameters); cloog_matrix_free(temp); diff --git a/source/ppl/domain.c b/source/ppl/domain.c index add4d9f..ead8d76 100644 --- a/source/ppl/domain.c +++ b/source/ppl/domain.c @@ -169,7 +169,7 @@ cloog_value_leak_down () static inline Polyhedron * cloog_domain_polyhedron_set (CloogDomain * d, Polyhedron * p) { - return d->_polyhedron = p; + return d->_polyhedron->_polyhedron = p; } static inline void @@ -178,15 +178,8 @@ cloog_domain_set_references (CloogDomain * d, int i) d->_references = i; } -/** - * cloog_domain_malloc function: - * This function allocates the memory space for a CloogDomain structure and - * sets its fields with default values. Then it returns a pointer to the - * allocated space. - * - November 21th 2005: first version. - */ static CloogDomain * -cloog_domain_malloc () +cloog_domain_alloc (Polyhedron * polyhedron) { CloogDomain *domain; @@ -197,39 +190,13 @@ cloog_domain_malloc () exit (1); } - /* We set the various fields with default values. */ - cloog_domain_polyhedron_set (domain, NULL); + domain->_polyhedron = (ppl_polyhedra_union *) malloc (sizeof (ppl_polyhedra_union)); + domain->_polyhedron->_polyhedron = polyhedron; cloog_domain_set_references (domain, 1); return domain; } - -/** - * cloog_domain_alloc function: - * This function allocates the memory space for a CloogDomain structure and - * sets its fields with those given as input. Then it returns a pointer to the - * allocated space. - * - April 19th 2005: first version. - * - November 21th 2005: cloog_domain_malloc use. - */ -static CloogDomain * -cloog_domain_alloc (Polyhedron * polyhedron) -{ - CloogDomain *domain; - - if (polyhedron == NULL) - return NULL; - else - { - domain = cloog_domain_malloc (); - cloog_domain_polyhedron_set (domain, polyhedron); - - return domain; - } -} - - /** * cloog_domain_matrix2domain function: * Given a matrix of constraints (matrix), this function constructs and returns @@ -243,13 +210,6 @@ cloog_domain_matrix2domain (CloogMatrix * matrix) return (cloog_domain_alloc (Constraints2Polyhedron (matrix, MAX_RAYS))); } - -static inline Polyhedron * -cloog_domain_polyhedron (CloogDomain * domain) -{ - return domain->_polyhedron; -} - /** * cloog_domain_domain2matrix function: * Given a polyhedron (in domain), this function returns its corresponding @@ -422,15 +382,18 @@ cloog_domain_print (FILE * foo, CloogDomain * domain) void cloog_domain_free (CloogDomain * domain) { - if (domain != NULL) + if (domain) { cloog_domain_set_references (domain, cloog_domain_references (domain) - 1); if (cloog_domain_references (domain) == 0) { - if (cloog_domain_polyhedron (domain) != NULL) - Domain_Free (cloog_domain_polyhedron (domain)); + if (cloog_domain_polyhedron (domain)) + { + Domain_Free (cloog_domain_polyhedron (domain)); + cloog_domain_polyhedron_set (domain, NULL); + } free (domain); } @@ -555,7 +518,10 @@ cloog_polyhedron_dim (Polyhedron * p) int cloog_domain_isconvex (CloogDomain * domain) { - return !cloog_domain_polyhedron_next (domain); + if (cloog_domain_polyhedron (domain)) + return !cloog_domain_polyhedron_next (domain); + + return 1; } unsigned @@ -701,7 +667,7 @@ cloog_domain_intersection (CloogDomain * dom1, CloogDomain * dom2) Polyhedron *p1, *p2; ppl_Polyhedron_t ppl1, ppl2; - res = cloog_domain_malloc (); + res = cloog_domain_empty (cloog_domain_dim (dom1)); for (p1 = cloog_domain_polyhedron (dom1); p1; p1 = cloog_polyhedron_next (p1)) { @@ -1843,8 +1809,11 @@ cloog_domain_cut_first (CloogDomain * domain) { CloogDomain *rest; - if ((domain != NULL) && (cloog_domain_polyhedron (domain) != NULL)) + if (domain && cloog_domain_polyhedron (domain)) { + if (!cloog_domain_polyhedron_next (domain)) + return NULL; + rest = cloog_domain_alloc (cloog_domain_polyhedron_next (domain)); cloog_domain_polyhedron_set_next (domain, NULL); } -- 2.11.4.GIT