Extended perm insertion by setting the colors of the outs.
[libfirm] / ir / be / sp_matrix.c
index 1a3f495..d62e216 100644 (file)
@@ -1,17 +1,25 @@
 /**
+ * Author:      Daniel Grund
+ * Date:               07.04.2005
+ * Copyright:   (c) Universitaet Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+
  * Sparse matrix storage with linked lists for rows and cols.
- * I did not need floats, so this is all integer.
- * @author Daniel Grund
- * @date 07.04.2005
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <alloca.h>
 #include <assert.h>
 #include "sp_matrix.h"
 #include "list.h"
@@ -72,7 +80,7 @@ static INLINE int _m_new_size(int old_size, int min) {
 
 /**
  * Allocates space for @p count entries in the rows array and
- * intitializes all entries from @p start to the end.
+ * inititializes all entries from @p start to the end.
  */
 static INLINE void _m_alloc_row(sp_matrix_t *m, int start, int count) {
        int p;
@@ -88,7 +96,7 @@ static INLINE void _m_alloc_row(sp_matrix_t *m, int start, int count) {
 
 /**
  * Allocates space for @p count entries in the cols array and
- * intitializes all entries from @p start to the end.
+ * inititializes all entries from @p start to the end.
  */
 static INLINE void _m_alloc_col(sp_matrix_t *m, int start, int count) {
        int p;
@@ -163,7 +171,7 @@ void del_matrix(sp_matrix_t *m) {
        free(m);
 }
 
-void matrix_set(sp_matrix_t *m, int row, int col, int val) {
+void matrix_set(sp_matrix_t *m, int row, int col, matrix_type val) {
        matrix_elem_t *me = NULL;
        entry_t *entr;
        struct list_head *leftof, *above;
@@ -221,7 +229,7 @@ void matrix_set(sp_matrix_t *m, int row, int col, int val) {
        m->entries++;
 }
 
-int matrix_get(const sp_matrix_t *m, int row, int col) {
+matrix_type matrix_get(const sp_matrix_t *m, int row, int col) {
        struct list_head *dummy;
        matrix_elem_t *me;
 
@@ -332,8 +340,10 @@ void matrix_optimize(sp_matrix_t *m) {
 
        /* kill all double-entries (Mij and Mji are set) */
        matrix_foreach(m, e) {
+    int t_val;
+
                assert(e->row != e->col && "Root has itself as arg. Ok. But the arg (=root) will alwazs have the same color as root");
-               int t_val = matrix_get(m, e->col, e->row);
+               t_val = matrix_get(m, e->col, e->row);
                if (t_val) {
                        matrix_set(m, e->col, e->row, 0);
                        matrix_set(m, e->row, e->col, e->val + t_val);
@@ -384,7 +394,7 @@ void matrix_dump(sp_matrix_t *m, FILE *out, int factor) {
                matrix_foreach_in_row(m, i, e) {
                        for (o=last_idx+1; o<e->col; ++o)
                                fprintf(out, "0");
-                       fprintf(out, "%d", factor*e->val);
+                       fprintf(out, "%f", factor*e->val);
                        last_idx = e->col;
                }
                for (o=last_idx+1; o<=m->maxcol; ++o)