From 9ddd482578caee7d8e39d64abfc2500185bff55e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 25 Sep 2008 10:07:39 +0200 Subject: [PATCH] add isl_set_fast_dim_is_fixed and isl_map_fast_input_is_fixed --- include/isl_map.h | 3 +++ include/isl_set.h | 2 ++ isl_map.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/include/isl_map.h b/include/isl_map.h index 1e656d2..43ca895 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -209,6 +209,9 @@ int isl_map_is_equal(struct isl_map *map1, struct isl_map *map2); void isl_map_dump(struct isl_map *map, FILE *out, int indent); +int isl_map_fast_input_is_fixed(struct isl_map *map, + unsigned in, isl_int *val); + #if defined(__cplusplus) } #endif diff --git a/include/isl_set.h b/include/isl_set.h index 8d5dfaf..3ceef62 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -149,6 +149,8 @@ struct isl_basic_set *isl_set_copy_basic_set(struct isl_set *set); struct isl_set *isl_set_drop_basic_set(struct isl_set *set, struct isl_basic_set *bset); +int isl_set_fast_dim_is_fixed(struct isl_set *set, unsigned dim, isl_int *val); + #if defined(__cplusplus) } #endif diff --git a/isl_map.c b/isl_map.c index 7e2c8da..a981d56 100644 --- a/isl_map.c +++ b/isl_map.c @@ -3696,3 +3696,83 @@ error: isl_basic_map_free(bmap2); return -2; } + +static int isl_basic_map_fast_has_fixed_var(struct isl_basic_map *bmap, + unsigned pos, isl_int *val) +{ + int i; + int d; + unsigned total; + + if (!bmap) + return -1; + total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div; + for (i = 0, d = total-1; i < bmap->n_eq && d+1 > pos; ++i) { + for (; d+1 > pos; --d) + if (!isl_int_is_zero(bmap->eq[i][1+d])) + break; + if (d != pos) + continue; + if (isl_seq_first_non_zero(bmap->eq[i]+1, d) != -1) + return 0; + if (isl_seq_first_non_zero(bmap->eq[i]+1+d+1, total-d-1) != -1) + return 0; + if (!isl_int_is_one(bmap->eq[i][1+d])) + return 0; + if (val) + isl_int_neg(*val, bmap->eq[i][0]); + return 1; + } + return 0; +} + +static int isl_map_fast_has_fixed_var(struct isl_map *map, + unsigned pos, isl_int *val) +{ + int i; + isl_int v; + isl_int tmp; + int fixed; + + if (!map) + return -1; + if (map->n == 0) + return 0; + if (map->n == 1) + return isl_basic_map_fast_has_fixed_var(map->p[0], pos, val); + isl_int_init(v); + isl_int_init(tmp); + fixed = isl_basic_map_fast_has_fixed_var(map->p[0], pos, &v); + for (i = 1; fixed == 1 && i < map->n; ++i) { + fixed = isl_basic_map_fast_has_fixed_var(map->p[i], pos, &tmp); + if (fixed == 1 && isl_int_ne(tmp, v)) + fixed = 0; + } + if (val) + isl_int_set(*val, v); + isl_int_clear(tmp); + isl_int_clear(v); + return fixed; +} + +static int isl_set_fast_has_fixed_var(struct isl_set *set, unsigned pos, + isl_int *val) +{ + return isl_map_fast_has_fixed_var((struct isl_map *)set, pos, val); +} + +/* Check if dimension dim has fixed value and if so and if val is not NULL, + * then return this fixed value in *val. + */ +int isl_set_fast_dim_is_fixed(struct isl_set *set, unsigned dim, isl_int *val) +{ + return isl_set_fast_has_fixed_var(set, set->nparam + dim, val); +} + +/* Check if input variable in has fixed value and if so and if val is not NULL, + * then return this fixed value in *val. + */ +int isl_map_fast_input_is_fixed(struct isl_map *map, unsigned in, isl_int *val) +{ + return isl_map_fast_has_fixed_var(map, map->nparam + in, val); +} -- 2.7.4