add isl_map_from_pw_aff
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 24 Jun 2011 12:56:49 +0000 (14:56 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 25 Jun 2011 20:22:21 +0000 (22:22 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/aff.h
isl_aff.c

index 4063f47..1727771 100644 (file)
@@ -1029,11 +1029,13 @@ C<isl_dim_set> and C<isl_dim_div> for sets and
 of C<isl_dim_cst>, C<isl_dim_param>,
 C<isl_dim_in>, C<isl_dim_out> and C<isl_dim_div> for relations.
 
-A basic relation can also be constructed from an affine expression
+A (basic) relation can also be constructed from a (piecewise) affine expression
 or a list of affine expressions (See L<"Piecewise Quasi Affine Expressions">).
 
        __isl_give isl_basic_map *isl_basic_map_from_aff(
                __isl_take isl_aff *aff);
+       __isl_give isl_map *isl_map_from_pw_aff(
+               __isl_take isl_pw_aff *pwaff);
        __isl_give isl_basic_map *isl_basic_map_from_aff_list(
                __isl_take isl_dim *domain_dim,
                __isl_take isl_aff_list *list);
index 65abb1a..9de587e 100644 (file)
@@ -91,6 +91,8 @@ __isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
 __isl_give isl_pw_aff *isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff);
 void *isl_pw_aff_free(__isl_take isl_pw_aff *pwaff);
 
+__isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff);
+
 __isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
        __isl_keep isl_pw_aff *pwaff);
 void isl_pw_aff_dump(__isl_keep isl_pw_aff *pwaff);
index 055c46c..74c4b14 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -858,3 +858,36 @@ error:
        isl_pw_aff_free(pwaff2);
        return NULL;
 }
+
+/* Construct a map with as domain the domain of pwaff and
+ * one-dimensional range corresponding to the affine expressions.
+ */
+__isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff)
+{
+       int i;
+       isl_dim *dim;
+       isl_map *map;
+
+       if (!pwaff)
+               return NULL;
+
+       dim = isl_pw_aff_get_dim(pwaff);
+       dim = isl_dim_from_domain(dim);
+       dim = isl_dim_add(dim, isl_dim_out, 1);
+       map = isl_map_empty(dim);
+
+       for (i = 0; i < pwaff->n; ++i) {
+               isl_basic_map *bmap;
+               isl_map *map_i;
+
+               bmap = isl_basic_map_from_aff(isl_aff_copy(pwaff->p[i].aff));
+               map_i = isl_map_from_basic_map(bmap);
+               map_i = isl_map_intersect_domain(map_i,
+                                               isl_set_copy(pwaff->p[i].set));
+               map = isl_map_union_disjoint(map, map_i);
+       }
+
+       isl_pw_aff_free(pwaff);
+
+       return map;
+}