Space after if.
[libfirm] / heuristical.c
index 4fb18ce..925b26d 100644 (file)
@@ -17,6 +17,13 @@ static pbqp_node **node_buckets[4];
 static pbqp_node **reduced_bucket = NULL;
 static int         buckets_filled = 0;
 
+static num add(num x, num y)
+{
+       if (x == INF_COSTS || y == INF_COSTS) return INF_COSTS;
+
+       return x + y;
+}
+
 static void init_buckets(void)
 {
        int i;
@@ -96,7 +103,8 @@ static void normalize_towards_source(pbqp *pbqp, pbqp_edge *edge)
 
                if (min != 0) {
                        pbqp_matrix_sub_row_value(mat, src_index, tgt_vec, min);
-                       src_vec->entries[src_index].data += min;
+                       src_vec->entries[src_index].data = add(
+                                       src_vec->entries[src_index].data, min);
 
                        // TODO add to edge_list if inf
                }
@@ -140,7 +148,8 @@ static void normalize_towards_target(pbqp *pbqp, pbqp_edge *edge)
 
                if (min != 0) {
                        pbqp_matrix_sub_col_value(mat, tgt_index, src_vec, min);
-                       tgt_vec->entries[tgt_index].data += min;
+                       tgt_vec->entries[tgt_index].data = add(
+                                       tgt_vec->entries[tgt_index].data, min);
 
                        // TODO add to edge_list if inf
                }
@@ -149,9 +158,12 @@ static void normalize_towards_target(pbqp *pbqp, pbqp_edge *edge)
 
 static void reorder_node(pbqp_node *node)
 {
-       unsigned arity;
-       unsigned old_arity;
-       unsigned old_bucket_len;
+       unsigned    arity;
+       unsigned    old_arity;
+       unsigned    old_bucket_len;
+       unsigned    old_bucket_index;
+       pbqp_node **old_bucket;
+       pbqp_node  *other;
 
        if (!buckets_filled) return;
 
@@ -159,31 +171,34 @@ static void reorder_node(pbqp_node *node)
 
        arity = ARR_LEN(node->edges);
 
-       /* Equal bucket as before */
+       /* Same bucket as before */
        if (arity > 2) return;
 
        /* Assume node lost one incident edge. */
-       old_arity = arity + 1;
+       old_arity        = arity + 1;
+       old_bucket       = node_buckets[old_arity];
+       old_bucket_len   = ARR_LEN(old_bucket);
+       old_bucket_index = node->bucket_index;
 
-       if (ARR_LEN(node_buckets[old_arity]) <= (int)node->bucket_index
-                       || node_buckets[old_arity][node->bucket_index] != node) {
+       if (old_bucket_len <= old_bucket_index ||
+           old_bucket[old_bucket_index] != node) {
                /* Old arity is new arity, so we have nothing to do. */
+               assert(old_bucket_index < ARR_LEN(node_buckets[arity]) &&
+                      node_buckets[arity][old_bucket_index] == node);
                return;
        }
 
-       old_bucket_len = ARR_LEN(node_buckets[old_arity]);
-       assert (node_buckets[old_arity][node->bucket_index] == node);
+       assert(old_bucket[old_bucket_index] == node);
 
        /* Delete node from old bucket... */
-       node_buckets[old_arity][old_bucket_len - 1]->bucket_index
-                       = node->bucket_index;
-       node_buckets[old_arity][node->bucket_index]
-                       = node_buckets[old_arity][old_bucket_len - 1];
-       ARR_SHRINKLEN(node_buckets[old_arity], (int)old_bucket_len - 1);
+       other                        = old_bucket[old_bucket_len - 1];
+       other->bucket_index          = old_bucket_index;
+       old_bucket[old_bucket_index] = other;
+       ARR_SHRINKLEN(node_buckets[old_arity], old_bucket_len - 1);
 
        /* ..and add to new one. */
        node->bucket_index = ARR_LEN(node_buckets[arity]);
-       ARR_APP1(pbqp_node *, node_buckets[arity], node);
+       ARR_APP1(pbqp_node*, node_buckets[arity], node);
 }
 
 static void simplify_edge(pbqp *pbqp, pbqp_edge *edge)
@@ -204,7 +219,7 @@ static void simplify_edge(pbqp *pbqp, pbqp_edge *edge)
        assert(src_node);
        assert(tgt_node);
 
-       if(pbqp->dump_file) {
+       if (pbqp->dump_file) {
                char txt[100];
                sprintf(txt, "Simplification of Edge n%d-n%d", src_node->index, tgt_node->index);
                dump_section(pbqp->dump_file, 3, txt);
@@ -279,7 +294,7 @@ void solve_pbqp_heuristical(pbqp *pbqp)
                        pbqp_edge *edge = edges[edge_index];
 
                        /* Simplify only once per edge. */
-                       if (node_index != edge->src->index) continue;
+                       if (node != edge->src) continue;
 
                        simplify_edge(pbqp, edge);
                }
@@ -314,7 +329,8 @@ void solve_pbqp_heuristical(pbqp *pbqp)
                assert(node);
 
                node->solution = vector_get_min_index(node->costs);
-               pbqp->solution += node->costs->entries[node->solution].data;
+               pbqp->solution = add(pbqp->solution,
+                               node->costs->entries[node->solution].data);
                if (pbqp->dump_file) {
                        fprintf(pbqp->dump_file, "node n%d is set to %d<br>\n", node->index, node->solution);
                        dump_node(pbqp, node);