X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flpp%2Fsp_matrix.c;h=41453169db830b13263664ba53362d42b4da8850;hb=2cfb4be35e6255d7cd59824e9b7a5eea39705227;hp=1059c0afa406d68606d1baa32c7dc99ca05b9a50;hpb=4cc881755b5280cd5a3649ecb8d7c8fe197a7fc9;p=libfirm diff --git a/ir/lpp/sp_matrix.c b/ir/lpp/sp_matrix.c index 1059c0afa..41453169d 100644 --- a/ir/lpp/sp_matrix.c +++ b/ir/lpp/sp_matrix.c @@ -1,22 +1,33 @@ +/* + * 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. * Complexity is O(1) then. * Random access or right-to-left and bottom-to-top is O(m*n). */ - -#ifdef _WIN32 -#include -#endif -#ifdef HAVE_ALLOCA_H -#include -#endif +#include "config.h" #include #include @@ -25,7 +36,7 @@ #include "sp_matrix.h" -#include "irtools.h" +#include "util.h" #include "bitset.h" #include "xmalloc.h" @@ -602,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)) { @@ -617,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; @@ -634,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); @@ -651,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 @@ -676,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; @@ -698,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) @@ -746,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);