isl_tab_detect_redundant: return status instead of isl_tab *
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 28 Nov 2009 19:16:03 +0000 (20:16 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 7 Dec 2009 15:56:29 +0000 (16:56 +0100)
isl_coalesce.c
isl_convex_hull.c
isl_map_simplify.c
isl_tab.c
isl_tab.h

index 0716916..33399d9 100644 (file)
@@ -184,8 +184,7 @@ static int fuse(struct isl_map *map, int i, int j, struct isl_tab **tabs,
                ISL_F_SET(fused, ISL_BASIC_MAP_RATIONAL);
 
        fused_tab = isl_tab_from_basic_map(fused);
-       fused_tab = isl_tab_detect_redundant(fused_tab);
-       if (!fused_tab)
+       if (isl_tab_detect_redundant(fused_tab) < 0)
                goto error;
 
        isl_basic_map_free(map->p[i]);
@@ -196,6 +195,7 @@ static int fuse(struct isl_map *map, int i, int j, struct isl_tab **tabs,
 
        return 1;
 error:
+       isl_tab_free(fused_tab);
        isl_basic_map_free(fused);
        return -1;
 }
@@ -582,7 +582,8 @@ struct isl_map *isl_map_coalesce(struct isl_map *map)
                if (!ISL_F_ISSET(map->p[i], ISL_BASIC_MAP_NO_IMPLICIT))
                        tabs[i] = isl_tab_detect_implicit_equalities(tabs[i]);
                if (!ISL_F_ISSET(map->p[i], ISL_BASIC_MAP_NO_REDUNDANT))
-                       tabs[i] = isl_tab_detect_redundant(tabs[i]);
+                       if (isl_tab_detect_redundant(tabs[i]) < 0)
+                               goto error;
        }
        for (i = map->n - 1; i >= 0; --i)
                if (tabs[i]->empty)
index d50b054..c6f2806 100644 (file)
@@ -95,12 +95,17 @@ struct isl_basic_map *isl_basic_map_convex_hull(struct isl_basic_map *bmap)
 
        tab = isl_tab_from_basic_map(bmap);
        tab = isl_tab_detect_implicit_equalities(tab);
-       tab = isl_tab_detect_redundant(tab);
+       if (isl_tab_detect_redundant(tab) < 0)
+               goto error;
        bmap = isl_basic_map_update_from_tab(bmap, tab);
        isl_tab_free(tab);
        ISL_F_SET(bmap, ISL_BASIC_MAP_NO_IMPLICIT);
        ISL_F_SET(bmap, ISL_BASIC_MAP_NO_REDUNDANT);
        return bmap;
+error:
+       isl_tab_free(tab);
+       isl_basic_map_free(bmap);
+       return NULL;
 }
 
 struct isl_basic_set *isl_basic_set_convex_hull(struct isl_basic_set *bset)
index e17dffb..41fee62 100644 (file)
@@ -1586,9 +1586,10 @@ static struct isl_basic_set *uset_gist(struct isl_basic_set *bset,
                        goto error;
        bset = isl_basic_set_add_constraints(combined, bset, 0);
        tab = isl_tab_detect_implicit_equalities(tab);
-       tab = isl_tab_detect_redundant(tab);
-       if (!tab)
+       if (isl_tab_detect_redundant(tab) < 0) {
+               isl_tab_free(tab);
                goto error2;
+       }
        for (i = 0; i < context_ineq; ++i) {
                tab->con[i].is_zero = 0;
                tab->con[i].is_redundant = 1;
index 2583e09..23493e8 100644 (file)
--- a/isl_tab.c
+++ b/isl_tab.c
@@ -2421,17 +2421,17 @@ static int con_is_redundant(struct isl_tab *tab, struct isl_tab_var *var)
  * If not, we mark the row as being redundant (assuming it hasn't
  * been detected as being obviously redundant in the mean time).
  */
-struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab)
+int isl_tab_detect_redundant(struct isl_tab *tab)
 {
        int i;
        unsigned n_marked;
 
        if (!tab)
-               return NULL;
+               return -1;
        if (tab->empty)
-               return tab;
+               return 0;
        if (tab->n_redundant == tab->n_row)
-               return tab;
+               return 0;
 
        n_marked = 0;
        for (i = tab->n_redundant; i < tab->n_row; ++i) {
@@ -2468,10 +2468,10 @@ struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab)
                n_marked--;
                red = con_is_redundant(tab, var);
                if (red < 0)
-                       goto error;
+                       return -1;
                if (red && !var->is_redundant)
                        if (isl_tab_mark_redundant(tab, var->index) < 0)
-                               goto error;
+                               return -1;
                for (i = tab->n_dead; i < tab->n_col; ++i) {
                        var = var_from_col(tab, i);
                        if (!var->marked)
@@ -2483,10 +2483,7 @@ struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab)
                }
        }
 
-       return tab;
-error:
-       isl_tab_free(tab);
-       return NULL;
+       return 0;
 }
 
 int isl_tab_is_equality(struct isl_tab *tab, int con)
index 920dea7..bf9ef88 100644 (file)
--- a/isl_tab.h
+++ b/isl_tab.h
@@ -173,7 +173,7 @@ struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
        struct isl_tab *tab);
 struct isl_tab *isl_tab_detect_implicit_equalities(struct isl_tab *tab) WARN_UNUSED;
-struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab) WARN_UNUSED;
+int isl_tab_detect_redundant(struct isl_tab *tab) WARN_UNUSED;
 #define ISL_TAB_SAVE_DUAL      (1 << 0)
 enum isl_lp_result isl_tab_min(struct isl_tab *tab,
        isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,