From 197465bb20307c3df2781e89a03afab431d17364 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 14 Oct 2014 12:53:43 +0200 Subject: [PATCH] add isl_basic_map_shift_div We will need this to shift some integer divisions in one basic map to align them with integer divisions in another basic map during coalescing. Signed-off-by: Sven Verdoolaege --- isl_map_private.h | 3 +++ isl_map_simplify.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/isl_map_private.h b/isl_map_private.h index adbd8a2d..a424ef99 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -407,6 +407,9 @@ int isl_basic_map_output_defining_equality(__isl_keep isl_basic_map *bmap, __isl_give isl_basic_map *isl_basic_map_reduce_coefficients( __isl_take isl_basic_map *bmap); +__isl_give isl_basic_map *isl_basic_map_shift_div( + __isl_take isl_basic_map *bmap, int div, isl_int shift); + __isl_give isl_basic_map_list *isl_map_get_basic_map_list( __isl_keep isl_map *map); diff --git a/isl_map_simplify.c b/isl_map_simplify.c index 6d6c798c..fdde7308 100644 --- a/isl_map_simplify.c +++ b/isl_map_simplify.c @@ -3470,3 +3470,51 @@ error: isl_vec_free(v); return isl_basic_map_free(bmap); } + +/* Shift the integer division at position "div" of "bmap" by "shift". + * + * That is, if the integer division has the form + * + * floor(f(x)/d) + * + * then replace it by + * + * floor((f(x) + shift * d)/d) - shift + */ +__isl_give isl_basic_map *isl_basic_map_shift_div( + __isl_take isl_basic_map *bmap, int div, isl_int shift) +{ + int i; + unsigned total; + + if (!bmap) + return NULL; + + total = isl_basic_map_dim(bmap, isl_dim_all); + total -= isl_basic_map_dim(bmap, isl_dim_div); + + isl_int_addmul(bmap->div[div][1], shift, bmap->div[div][0]); + + for (i = 0; i < bmap->n_eq; ++i) { + if (isl_int_is_zero(bmap->eq[i][1 + total + div])) + continue; + isl_int_submul(bmap->eq[i][0], + shift, bmap->eq[i][1 + total + div]); + } + for (i = 0; i < bmap->n_ineq; ++i) { + if (isl_int_is_zero(bmap->ineq[i][1 + total + div])) + continue; + isl_int_submul(bmap->ineq[i][0], + shift, bmap->ineq[i][1 + total + div]); + } + for (i = 0; i < bmap->n_div; ++i) { + if (isl_int_is_zero(bmap->div[i][0])) + continue; + if (isl_int_is_zero(bmap->div[i][1 + 1 + total + div])) + continue; + isl_int_submul(bmap->div[i][1], + shift, bmap->div[i][1 + 1 + total + div]); + } + + return bmap; +} -- 2.11.4.GIT