change isl_basic_map_foreach_lexmin prototype
[platform/upstream/isl.git] / isl_tab.c
index e45ee88..5151ab6 100644 (file)
--- a/isl_tab.c
+++ b/isl_tab.c
@@ -7,10 +7,12 @@
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
  */
 
+#include <isl_ctx_private.h>
 #include <isl_mat_private.h>
 #include "isl_map_private.h"
 #include "isl_tab.h"
 #include <isl/seq.h>
+#include <isl_config.h>
 
 /*
  * The implementation of tableaus in this file was inspired by Section 8
@@ -171,13 +173,24 @@ struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new)
        return NULL;
 }
 
+static void free_undo_record(struct isl_tab_undo *undo)
+{
+       switch (undo->type) {
+       case isl_tab_undo_saved_basis:
+               free(undo->u.col_var);
+               break;
+       default:;
+       }
+       free(undo);
+}
+
 static void free_undo(struct isl_tab *tab)
 {
        struct isl_tab_undo *undo, *next;
 
        for (undo = tab->top; undo && undo != &tab->bottom; undo = next) {
                next = undo->next;
-               free(undo);
+               free_undo_record(undo);
        }
        tab->top = undo;
 }
@@ -1083,6 +1096,11 @@ int isl_tab_pivot(struct isl_tab *tab, int row, int col)
        struct isl_tab_var *var;
        unsigned off = 2 + tab->M;
 
+       if (tab->mat->ctx->abort) {
+               isl_ctx_set_error(tab->mat->ctx, isl_error_abort);
+               return -1;
+       }
+
        isl_int_swap(mat->row[row][0], mat->row[row][off + col]);
        sgn = isl_int_sgn(mat->row[row][0]);
        if (sgn < 0) {
@@ -1170,6 +1188,11 @@ static int to_row(struct isl_tab *tab, struct isl_tab_var *var, int sign)
        return isl_tab_pivot(tab, r, var->index);
 }
 
+/* Check whether all variables that are marked as non-negative
+ * also have a non-negative sample value.  This function is not
+ * called from the current code but is useful during debugging.
+ */
+static void check_table(struct isl_tab *tab) __attribute__ ((unused));
 static void check_table(struct isl_tab *tab)
 {
        int i;
@@ -2565,7 +2588,6 @@ int isl_tab_select_facet(struct isl_tab *tab, int con)
 
 static int may_be_equality(struct isl_tab *tab, int row)
 {
-       unsigned off = 2 + tab->M;
        return tab->rational ? isl_int_is_zero(tab->mat->row[row][1])
                             : isl_int_lt(tab->mat->row[row][1],
                                            tab->mat->row[row][0]);
@@ -2911,7 +2933,7 @@ static int perform_undo_var(struct isl_tab *tab, struct isl_tab_undo *undo) WARN
 static int perform_undo_var(struct isl_tab *tab, struct isl_tab_undo *undo)
 {
        struct isl_tab_var *var = var_from_index(tab, undo->u.var_index);
-       switch(undo->type) {
+       switch (undo->type) {
        case isl_tab_undo_nonneg:
                var->is_nonneg = 0;
                break;
@@ -2949,6 +2971,10 @@ static int perform_undo_var(struct isl_tab *tab, struct isl_tab_undo *undo)
                break;
        case isl_tab_undo_relax:
                return unrelax(tab, var);
+       default:
+               isl_die(tab->mat->ctx, isl_error_internal,
+                       "perform_undo_var called on invalid undo record",
+                       return -1);
        }
 
        return 0;
@@ -3004,11 +3030,9 @@ static int restore_basis(struct isl_tab *tab, int *col_var)
        }
 
        free(extra);
-       free(col_var);
        return 0;
 error:
        free(extra);
-       free(col_var);
        return -1;
 }
 
@@ -3097,7 +3121,7 @@ int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap)
                        tab->in_undo = 0;
                        return -1;
                }
-               free(undo);
+               free_undo_record(undo);
        }
        tab->in_undo = 0;
        tab->top = undo;
@@ -3235,7 +3259,8 @@ __isl_keep isl_basic_set *isl_tab_peek_bset(struct isl_tab *tab)
        return (isl_basic_set *)tab->bmap;
 }
 
-void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent)
+static void isl_tab_print_internal(__isl_keep struct isl_tab *tab,
+       FILE *out, int indent)
 {
        unsigned r, c;
        int i;
@@ -3304,9 +3329,14 @@ void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent)
        tab->mat->n_row = tab->n_row;
        c = tab->mat->n_col;
        tab->mat->n_col = 2 + tab->M + tab->n_col;
-       isl_mat_dump(tab->mat, out, indent);
+       isl_mat_print_internal(tab->mat, out, indent);
        tab->mat->n_row = r;
        tab->mat->n_col = c;
        if (tab->bmap)
                isl_basic_map_print_internal(tab->bmap, out, indent);
 }
+
+void isl_tab_dump(__isl_keep struct isl_tab *tab)
+{
+       isl_tab_print_internal(tab, stderr, 0);
+}