summaryrefslogtreecommitdiffhomepage
path: root/ir/kaps
diff options
context:
space:
mode:
authorSebastian Buchwald <Sebastian.Buchwald@kit.edu>2013-04-23 14:21:08 +0200
committerSebastian Buchwald <Sebastian.Buchwald@kit.edu>2013-04-23 14:39:51 +0200
commit3f9c84bc1e6f4b0f207c73b6d812f727c0c8e3d7 (patch)
treeb14685b02ca951f1e42264da9ccd91e8305e34af /ir/kaps
parentd50a29a5254587d4a63d33f0106a4b3d03996a30 (diff)
Made kaps robust against self loops.
Diffstat (limited to 'ir/kaps')
-rw-r--r--ir/kaps/kaps.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/ir/kaps/kaps.c b/ir/kaps/kaps.c
index 8061a55..9018fe3 100644
--- a/ir/kaps/kaps.c
+++ b/ir/kaps/kaps.c
@@ -102,6 +102,24 @@ void add_node_costs(pbqp_t *pbqp, unsigned node_index, vector_t *costs)
void add_edge_costs(pbqp_t *pbqp, unsigned src_index, unsigned tgt_index,
pbqp_matrix_t *costs)
{
+ /* Add self loops to the node's costs. */
+ if (src_index == tgt_index) {
+ assert(costs->rows == costs->cols);
+
+ unsigned length = costs->rows;
+ vector_t *diagonal = vector_alloc(pbqp, length);
+
+ for (unsigned i = length; i-- != 0;) {
+ num value = costs->entries[i * length + i];
+
+ vector_set(diagonal, i, value);
+ }
+
+ add_node_costs(pbqp, src_index, diagonal);
+
+ return;
+ }
+
pbqp_edge_t *edge = get_edge(pbqp, src_index, tgt_index);
if (tgt_index < src_index) {