From 93a4120f652039cc8b6133dd0deba3b2bf5b7d2e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 16 Jul 2016 18:04:59 +0200 Subject: [PATCH] isl_tab: keep track of location of inserted integer division in undo stack When an integer division is added to the basic map representation of an isl_tab, it is currently always added at the end. However, this will be changed in an upcoming commit. That is, integer divisions may also get added at other positions. Store the position of the added integer division in the undo stack and take this position into account when dropping the integer division on undo. Signed-off-by: Sven Verdoolaege --- isl_tab.c | 20 +++++++++++++------- isl_tab_pip.c | 7 ++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/isl_tab.c b/isl_tab.c index e041ef61..4d0a414a 100644 --- a/isl_tab.c +++ b/isl_tab.c @@ -2327,7 +2327,7 @@ int isl_tab_add_div(struct isl_tab *tab, __isl_keep isl_vec *div, if (k < 0) return -1; isl_seq_cpy(tab->bmap->div[k], div->el, div->size); - if (isl_tab_push(tab, isl_tab_undo_bmap_div) < 0) + if (isl_tab_push_var(tab, isl_tab_undo_bmap_div, &tab->var[r]) < 0) return -1; if (add_div_constraints(tab, k, add_ineq, user) < 0) @@ -3409,14 +3409,20 @@ static int perform_undo_var(struct isl_tab *tab, struct isl_tab_undo *undo) } /* Undo the addition of an integer division to the basic map representation - * of "tab". + * of "tab" in position "pos". */ -static isl_stat drop_bmap_div(struct isl_tab *tab) +static isl_stat drop_bmap_div(struct isl_tab *tab, int pos) { - if (isl_basic_map_free_div(tab->bmap, 1) < 0) + int off; + + off = tab->n_var - isl_basic_map_dim(tab->bmap, isl_dim_div); + if (isl_basic_map_drop_div(tab->bmap, pos - off) < 0) return isl_stat_error; - if (tab->samples) - tab->samples->n_col--; + if (tab->samples) { + tab->samples = isl_mat_drop_cols(tab->samples, 1 + pos, 1); + if (!tab->samples) + return isl_stat_error; + } return isl_stat_ok; } @@ -3522,7 +3528,7 @@ static int perform_undo(struct isl_tab *tab, struct isl_tab_undo *undo) case isl_tab_undo_bmap_ineq: return isl_basic_map_free_inequality(tab->bmap, 1); case isl_tab_undo_bmap_div: - return drop_bmap_div(tab); + return drop_bmap_div(tab, undo->u.var_index); case isl_tab_undo_saved_basis: if (restore_basis(tab, undo->u.col_var) < 0) return -1; diff --git a/isl_tab_pip.c b/isl_tab_pip.c index 94e51a80..57f0b67e 100644 --- a/isl_tab_pip.c +++ b/isl_tab_pip.c @@ -3210,13 +3210,13 @@ static isl_bool context_gbr_add_div(struct isl_context *context, { struct isl_context_gbr *cgbr = (struct isl_context_gbr *)context; if (cgbr->cone) { - int k; + int k, r; if (isl_tab_extend_cons(cgbr->cone, 3) < 0) return isl_bool_error; if (isl_tab_extend_vars(cgbr->cone, 1) < 0) return isl_bool_error; - if (isl_tab_allocate_var(cgbr->cone) <0) + if ((r = isl_tab_allocate_var(cgbr->cone)) <0) return isl_bool_error; cgbr->cone->bmap = isl_basic_map_extend_space(cgbr->cone->bmap, @@ -3225,7 +3225,8 @@ static isl_bool context_gbr_add_div(struct isl_context *context, if (k < 0) return isl_bool_error; isl_seq_cpy(cgbr->cone->bmap->div[k], div->el, div->size); - if (isl_tab_push(cgbr->cone, isl_tab_undo_bmap_div) < 0) + if (isl_tab_push_var(cgbr->cone, isl_tab_undo_bmap_div, + &cgbr->cone->var[r]) < 0) return isl_bool_error; } return context_tab_add_div(cgbr->tab, div, -- 2.11.4.GIT