diff options
author | Sven Verdoolaege <skimo@kotnet.org> | 2011-08-09 22:37:52 +0200 |
---|---|---|
committer | Sven Verdoolaege <skimo@kotnet.org> | 2011-09-03 12:04:54 +0200 |
commit | d61a6a3d40eeb95ae9576299d08b8616ac2f13a3 (patch) | |
tree | 8367b89d61b6980f651ecb42f36caca7389e35fe | |
parent | 13124d38c6874e4b76d8384ac1a19eed7e806bcd (diff) | |
download | isl-d61a6a3d40eeb95ae9576299d08b8616ac2f13a3.tar.gz isl-d61a6a3d40eeb95ae9576299d08b8616ac2f13a3.tar.bz2 isl-d61a6a3d40eeb95ae9576299d08b8616ac2f13a3.zip |
add isl_map_flat_domain_product
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
-rw-r--r-- | doc/user.pod | 13 | ||||
-rw-r--r-- | include/isl/map.h | 9 | ||||
-rw-r--r-- | include/isl/space.h | 2 | ||||
-rw-r--r-- | isl_map.c | 127 | ||||
-rw-r--r-- | isl_space.c | 41 | ||||
-rw-r--r-- | isl_space_private.h | 1 |
6 files changed, 193 insertions, 0 deletions
diff --git a/doc/user.pod b/doc/user.pod index 3d9a0078..45e6a980 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1942,10 +1942,14 @@ then the name of the space is also removed. __isl_take isl_basic_set *bset); __isl_give isl_set *isl_set_flatten( __isl_take isl_set *set); + __isl_give isl_basic_map *isl_basic_map_flatten_domain( + __isl_take isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_flatten_range( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_flatten_range( __isl_take isl_map *map); + __isl_give isl_map *isl_map_flatten_domain( + __isl_take isl_map *map); __isl_give isl_basic_map *isl_basic_map_flatten( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_flatten( @@ -2151,9 +2155,15 @@ the same (number of) parameters. __isl_give isl_union_set *isl_union_set_product( __isl_take isl_union_set *uset1, __isl_take isl_union_set *uset2); + __isl_give isl_basic_map *isl_basic_map_domain_product( + __isl_take isl_basic_map *bmap1, + __isl_take isl_basic_map *bmap2); __isl_give isl_basic_map *isl_basic_map_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); + __isl_give isl_map *isl_map_domain_product( + __isl_take isl_map *map1, + __isl_take isl_map *map2); __isl_give isl_map *isl_map_range_product( __isl_take isl_map *map1, __isl_take isl_map *map2); @@ -2182,6 +2192,9 @@ instead. __isl_give isl_basic_map *isl_basic_map_flat_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); + __isl_give isl_map *isl_map_flat_domain_product( + __isl_take isl_map *map1, + __isl_take isl_map *map2); __isl_give isl_map *isl_map_flat_range_product( __isl_take isl_map *map1, __isl_take isl_map *map2); diff --git a/include/isl/map.h b/include/isl/map.h index 179427f7..84db68ac 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -301,8 +301,12 @@ __isl_give isl_map *isl_map_apply_range( __isl_take isl_map *map2); __isl_give isl_map *isl_map_product(__isl_take isl_map *map1, __isl_take isl_map *map2); +__isl_give isl_basic_map *isl_basic_map_domain_product( + __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); __isl_give isl_basic_map *isl_basic_map_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); +__isl_give isl_map *isl_map_domain_product(__isl_take isl_map *map1, + __isl_take isl_map *map2); __isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2); __isl_give isl_basic_map *isl_basic_map_flat_product( @@ -311,6 +315,8 @@ __isl_give isl_map *isl_map_flat_product(__isl_take isl_map *map1, __isl_take isl_map *map2); __isl_give isl_basic_map *isl_basic_map_flat_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); +__isl_give isl_map *isl_map_flat_domain_product(__isl_take isl_map *map1, + __isl_take isl_map *map2); __isl_give isl_map *isl_map_flat_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2); __isl_give isl_map *isl_map_intersect(__isl_take isl_map *map1, @@ -376,8 +382,11 @@ __isl_give isl_basic_map *isl_basic_set_unwrap(__isl_take isl_basic_set *bset); __isl_give isl_map *isl_set_unwrap(__isl_take isl_set *set); __isl_give isl_basic_map *isl_basic_map_flatten(__isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_flatten(__isl_take isl_map *map); +__isl_give isl_basic_map *isl_basic_map_flatten_domain( + __isl_take isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_flatten_range( __isl_take isl_basic_map *bmap); +__isl_give isl_map *isl_map_flatten_domain(__isl_take isl_map *map); __isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map); __isl_give isl_basic_set *isl_basic_set_flatten(__isl_take isl_basic_set *bset); __isl_give isl_set *isl_set_flatten(__isl_take isl_set *set); diff --git a/include/isl/space.h b/include/isl/space.h index 8a859ae7..92ee6b19 100644 --- a/include/isl/space.h +++ b/include/isl/space.h @@ -80,6 +80,8 @@ __isl_give isl_space *isl_space_join(__isl_take isl_space *left, __isl_take isl_space *right); __isl_give isl_space *isl_space_product(__isl_take isl_space *left, __isl_take isl_space *right); +__isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left, + __isl_take isl_space *right); __isl_give isl_space *isl_space_range_product(__isl_take isl_space *left, __isl_take isl_space *right); __isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *dim); @@ -7763,6 +7763,51 @@ __isl_give isl_basic_set *isl_basic_set_flat_product( return isl_basic_map_flat_range_product(bset1, bset2); } +__isl_give isl_basic_map *isl_basic_map_domain_product( + __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) +{ + isl_space *space_result = NULL; + isl_basic_map *bmap; + unsigned in1, in2, out, nparam, total, pos; + struct isl_dim_map *dim_map1, *dim_map2; + + if (!bmap1 || !bmap2) + goto error; + + space_result = isl_space_domain_product(isl_space_copy(bmap1->dim), + isl_space_copy(bmap2->dim)); + + in1 = isl_basic_map_dim(bmap1, isl_dim_in); + in2 = isl_basic_map_dim(bmap2, isl_dim_in); + out = isl_basic_map_dim(bmap1, isl_dim_out); + nparam = isl_basic_map_dim(bmap1, isl_dim_param); + + total = nparam + in1 + in2 + out + bmap1->n_div + bmap2->n_div; + dim_map1 = isl_dim_map_alloc(bmap1->ctx, total); + dim_map2 = isl_dim_map_alloc(bmap1->ctx, total); + isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0); + isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0); + isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam); + isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos += in1); + isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += in2); + isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos); + isl_dim_map_div(dim_map1, bmap1, pos += out); + isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div); + + bmap = isl_basic_map_alloc_space(space_result, + bmap1->n_div + bmap2->n_div, + bmap1->n_eq + bmap2->n_eq, + bmap1->n_ineq + bmap2->n_ineq); + bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1); + bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2); + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); +error: + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); + return NULL; +} + __isl_give isl_basic_map *isl_basic_map_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { @@ -7904,6 +7949,15 @@ __isl_give isl_set *isl_set_flat_product(__isl_take isl_set *set1, return isl_map_flat_range_product(set1, set2); } +/* Given two maps A -> B and C -> D, construct a map [A -> C] -> (B * D) + */ +static __isl_give isl_map *map_domain_product_aligned(__isl_take isl_map *map1, + __isl_take isl_map *map2) +{ + return map_product(map1, map2, &isl_space_domain_product, + &isl_basic_map_domain_product); +} + /* Given two maps A -> B and C -> D, construct a map (A * C) -> [B -> D] */ static __isl_give isl_map *map_range_product_aligned(__isl_take isl_map *map1, @@ -7913,6 +7967,13 @@ static __isl_give isl_map *map_range_product_aligned(__isl_take isl_map *map1, &isl_basic_map_range_product); } +__isl_give isl_map *isl_map_domain_product(__isl_take isl_map *map1, + __isl_take isl_map *map2) +{ + return isl_map_align_params_map_map_and(map1, map2, + &map_domain_product_aligned); +} + __isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2) { @@ -7920,6 +7981,18 @@ __isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1, &map_range_product_aligned); } +/* Given two maps A -> B and C -> D, construct a map (A, C) -> (B * D) + */ +__isl_give isl_map *isl_map_flat_domain_product(__isl_take isl_map *map1, + __isl_take isl_map *map2) +{ + isl_map *prod; + + prod = isl_map_domain_product(map1, map2); + prod = isl_map_flatten_domain(prod); + return prod; +} + /* Given two maps A -> B and C -> D, construct a map (A * C) -> (B, D) */ __isl_give isl_map *isl_map_flat_range_product(__isl_take isl_map *map1, @@ -8810,6 +8883,31 @@ __isl_give isl_basic_set *isl_basic_set_flatten(__isl_take isl_basic_set *bset) return (isl_basic_set *)isl_basic_map_flatten((isl_basic_map *)bset); } +__isl_give isl_basic_map *isl_basic_map_flatten_domain( + __isl_take isl_basic_map *bmap) +{ + if (!bmap) + return NULL; + + if (!bmap->dim->nested[0]) + return bmap; + + bmap = isl_basic_map_cow(bmap); + if (!bmap) + return NULL; + + bmap->dim = isl_space_flatten_domain(bmap->dim); + if (!bmap->dim) + goto error; + + bmap = isl_basic_map_finalize(bmap); + + return bmap; +error: + isl_basic_map_free(bmap); + return NULL; +} + __isl_give isl_basic_map *isl_basic_map_flatten_range( __isl_take isl_basic_map *bmap) { @@ -8882,6 +8980,35 @@ __isl_give isl_map *isl_set_flatten_map(__isl_take isl_set *set) return map; } +__isl_give isl_map *isl_map_flatten_domain(__isl_take isl_map *map) +{ + int i; + + if (!map) + return NULL; + + if (!map->dim->nested[0]) + return map; + + map = isl_map_cow(map); + if (!map) + return NULL; + + for (i = 0; i < map->n; ++i) { + map->p[i] = isl_basic_map_flatten_domain(map->p[i]); + if (!map->p[i]) + goto error; + } + map->dim = isl_space_flatten_domain(map->dim); + if (!map->dim) + goto error; + + return map; +error: + isl_map_free(map); + return NULL; +} + __isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map) { int i; diff --git a/isl_space.c b/isl_space.c index b6e6b5a1..6a9e9d74 100644 --- a/isl_space.c +++ b/isl_space.c @@ -869,6 +869,37 @@ error: return NULL; } +/* Given two spaces { A -> C } and { B -> C }, construct the space + * { [A -> B] -> C } + */ +__isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left, + __isl_take isl_space *right) +{ + isl_space *ran, *dom1, *dom2, *nest; + + if (!left || !right) + goto error; + + if (!match(left, isl_dim_param, right, isl_dim_param)) + isl_die(left->ctx, isl_error_invalid, + "parameters need to match", goto error); + if (!isl_space_tuple_match(left, isl_dim_out, right, isl_dim_out)) + isl_die(left->ctx, isl_error_invalid, + "ranges need to match", goto error); + + ran = isl_space_range(isl_space_copy(left)); + + dom1 = isl_space_domain(left); + dom2 = isl_space_domain(right); + nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2)); + + return isl_space_join(isl_space_reverse(nest), ran); +error: + isl_space_free(left); + isl_space_free(right); + return NULL; +} + __isl_give isl_space *isl_space_range_product(__isl_take isl_space *left, __isl_take isl_space *right) { @@ -1316,6 +1347,16 @@ __isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim) return dim; } +__isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim) +{ + if (!dim) + return NULL; + if (!dim->nested[0]) + return dim; + + return isl_space_reset(dim, isl_dim_in); +} + __isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim) { if (!dim) diff --git a/isl_space_private.h b/isl_space_private.h index 12324405..74480d61 100644 --- a/isl_space_private.h +++ b/isl_space_private.h @@ -36,6 +36,7 @@ int isl_space_has_named_params(__isl_keep isl_space *dim); __isl_give isl_space *isl_space_reset(__isl_take isl_space *dim, enum isl_dim_type type); __isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim); __isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim); __isl_give isl_space *isl_space_replace(__isl_take isl_space *dst, |