Split RN into 2 phases.
[libfirm] / matrix.c
index b47ba8d..cd3bfba 100644 (file)
--- a/matrix.c
+++ b/matrix.c
@@ -1,7 +1,36 @@
+/*
+ * Copyright (C) 1995-2008 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.
+ */
+
+/**
+ * @file
+ * @brief   PBQP matrix.
+ * @date    02.10.2008
+ * @author  Sebastian Buchwald
+ * @version $Id$
+ */
+#include "config.h"
+
 #include <assert.h>
 #include <string.h>
 
 #include "pbqp_t.h"
+#include "vector.h"
 #include "matrix.h"
 
 pbqp_matrix *pbqp_matrix_alloc(pbqp *pbqp, unsigned rows, unsigned cols)
@@ -148,6 +177,34 @@ num pbqp_matrix_get_col_min(pbqp_matrix *matrix, unsigned col_index, vector *fla
        return min;
 }
 
+unsigned pbqp_matrix_get_col_min_index(pbqp_matrix *matrix, unsigned col_index, vector *flags)
+{
+       unsigned row_index;
+       unsigned min_index = 0;
+       num      min       = INF_COSTS;
+
+       assert(matrix);
+       assert(flags);
+       assert(matrix->rows == flags->len);
+
+       unsigned col_len = matrix->cols;
+       unsigned row_len = matrix->rows;
+
+       for (row_index = 0; row_index < row_len; ++row_index) {
+               /* Ignore virtual deleted columns. */
+               if (flags->entries[row_index].data == INF_COSTS) continue;
+
+               num elem = matrix->entries[row_index * col_len + col_index];
+
+               if (elem < min) {
+                       min = elem;
+                       min_index = row_index;
+               }
+       }
+
+       return min_index;
+}
+
 void pbqp_matrix_sub_col_value(pbqp_matrix *matrix, unsigned col_index,
                vector *flags, num value)
 {
@@ -200,6 +257,33 @@ num pbqp_matrix_get_row_min(pbqp_matrix *matrix, unsigned row_index, vector *fla
        return min;
 }
 
+unsigned pbqp_matrix_get_row_min_index(pbqp_matrix *matrix, unsigned row_index, vector *flags)
+{
+       unsigned col_index;
+       unsigned min_index = 0;
+       num      min       = INF_COSTS;
+
+       assert(matrix);
+       assert(flags);
+       assert(matrix->cols == flags->len);
+
+       unsigned len = flags->len;
+
+       for (col_index = 0; col_index < len; ++col_index) {
+               /* Ignore virtual deleted columns. */
+               if (flags->entries[col_index].data == INF_COSTS) continue;
+
+               num elem = matrix->entries[row_index * len + col_index];
+
+               if (elem < min) {
+                       min = elem;
+                       min_index = col_index;
+               }
+       }
+
+       return min_index;
+}
+
 void pbqp_matrix_sub_row_value(pbqp_matrix *matrix, unsigned row_index,
                vector *flags, num value)
 {