ia32: Remove (empty) emitters from nodes, which should never be emitted.
[libfirm] / ir / lpp / sp_matrix.c
index 7a598a1..4145316 100644 (file)
@@ -1,9 +1,26 @@
+/*
+ * Copyright (C) 2005-2011 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
 /**
- * Author:      Daniel Grund, Christian Wuerdig
- * Date:        07.04.2005
- * Copyright:   (c) Universitaet Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
- * CVS-Id:      $Id: sp_matrix.c 24123 2008-11-28 15:08:27Z mallon $
+ * @file
+ * @brief   Sparse matrix storage with linked lists for rows and cols.
+ * @author  Daniel Grund
  *
  * Sparse matrix storage with linked lists for rows and cols.
  * Matrix is optimized for left-to-right and top-to-bottom access.
@@ -19,7 +36,7 @@
 
 #include "sp_matrix.h"
 
-#include "irtools.h"
+#include "util.h"
 #include "bitset.h"
 #include "xmalloc.h"
 
@@ -596,7 +613,6 @@ static int cmp_count(const void *e1, const void *e2)
 
 static inline void matrix_fill_row(sp_matrix_t *m, int row, bitset_t *fullrow)
 {
-       const matrix_elem_t *e;
        bitset_set(fullrow, row);
        matrix_foreach_in_col(m, row, e) {
                if (! bitset_is_set(fullrow, e->row)) {
@@ -611,7 +627,6 @@ void matrix_optimize(sp_matrix_t *m)
 {
        int i, size, redo;
        int *c;
-       const matrix_elem_t *e;
        bitset_t *fullrow;
 
        size = MAX(m->maxcol, m->maxrow)+1;
@@ -628,7 +643,7 @@ void matrix_optimize(sp_matrix_t *m)
                }
        }
 
-       c       = alloca(size * sizeof(*c));
+       c       = ALLOCAN(int, size);
        redo    = 1;
        fullrow = bitset_alloca(size);
 
@@ -645,7 +660,8 @@ void matrix_optimize(sp_matrix_t *m)
                        if (c[i] == 1 && ! bitset_is_set(fullrow, i)) {
                                redo = 1;
                                /* if the other row isn't empty move the e in there, else fill e's row */
-                               if (e = matrix_row_first(m, i), e) {
+                               matrix_elem_t const *const e = matrix_row_first(m, i);
+                               if (e) {
                                        if (c[e->col] > 0)
                                                matrix_fill_row(m, e->col, fullrow);
                                        else
@@ -670,7 +686,6 @@ void matrix_optimize(sp_matrix_t *m)
 void matrix_dump(sp_matrix_t *m, FILE *out, int factor)
 {
        int i, o, last_idx;
-       const matrix_elem_t *e;
 
        for (i = 0; i <= m->maxrow; ++i) {
                last_idx = -1;
@@ -692,7 +707,6 @@ void matrix_dump(sp_matrix_t *m, FILE *out, int factor)
 void matrix_self_test(int d)
 {
        int i, o;
-       const matrix_elem_t *e;
        sp_matrix_t *m = new_matrix(10, 10);
 
        for (i = 0; i < d; ++i)
@@ -740,9 +754,10 @@ void matrix_self_test(int d)
        matrix_set(m, 3,5,4);
        matrix_set(m, 4,4,5);
        matrix_set(m, 5,5,6);
-       for (i=1, e = matrix_first(m); e; ++i, e=matrix_next(m))
-               assert(e->val == i);
-       assert(i == 7);
+       i = 0;
+       matrix_foreach(m, e)
+               assert(e->val == ++i);
+       assert(i == 6);
        matrix_set(m, 1,1,0);
        assert(5 == matrix_get_entries(m));
        del_matrix(m);