X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fkaps%2Foptimal.c;h=802534c589e22e653ba10f93d2290502aa86ee16;hb=2ee064e0f2a03bbdbdb51839cfd852b9fc6f1079;hp=3dfdd2f6e519ac914f45398e9ee669faeb025c2b;hpb=171a98cff2d5ae80ee5a4f4cf71ba2a0e75e611e;p=libfirm
diff --git a/ir/kaps/optimal.c b/ir/kaps/optimal.c
index 3dfdd2f6e..802534c58 100644
--- a/ir/kaps/optimal.c
+++ b/ir/kaps/optimal.c
@@ -22,7 +22,6 @@
* @brief Optimal reductions and helper functions.
* @date 28.12.2009
* @author Sebastian Buchwald
- * @version $Id$
*/
#include "config.h"
@@ -31,7 +30,7 @@
#include "error.h"
#include "bucket.h"
-#if KAPS_DUMP
+#if KAPS_DUMP
#include "html_dumper.h"
#endif
#include "kaps.h"
@@ -47,7 +46,7 @@
#include "timing.h"
pbqp_edge_t **edge_bucket;
-pbqp_edge_t **rm_bucket;
+static pbqp_edge_t **rm_bucket;
pbqp_node_t **node_buckets[4];
pbqp_node_t **reduced_bucket = NULL;
pbqp_node_t *merged_node = NULL;
@@ -271,7 +270,6 @@ static void merge_source_into_target(pbqp_t *pbqp, pbqp_edge_t *edge)
unsigned *mapping;
unsigned src_len;
unsigned tgt_len;
- unsigned src_index;
unsigned tgt_index;
unsigned edge_index;
unsigned edge_len;
@@ -296,6 +294,7 @@ static void merge_source_into_target(pbqp_t *pbqp, pbqp_edge_t *edge)
/* Check that each column has at most one zero entry. */
for (tgt_index = 0; tgt_index < tgt_len; ++tgt_index) {
unsigned onlyOneZero = 0;
+ unsigned src_index;
if (tgt_vec->entries[tgt_index].data == INF_COSTS)
continue;
@@ -325,11 +324,11 @@ static void merge_source_into_target(pbqp_t *pbqp, pbqp_edge_t *edge)
pbqp->num_rm++;
#endif
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
char txt[100];
sprintf(txt, "Merging n%d into n%d", src_node->index, tgt_node->index);
- dump_section(pbqp->dump_file, 3, txt);
+ pbqp_dump_section(pbqp->dump_file, 3, txt);
}
#endif
@@ -343,7 +342,6 @@ static void merge_source_into_target(pbqp_t *pbqp, pbqp_edge_t *edge)
vector_t *other_vec;
unsigned other_len;
unsigned other_index;
- unsigned tgt_index;
assert(old_edge);
if (old_edge == edge)
@@ -435,7 +433,6 @@ static void merge_target_into_source(pbqp_t *pbqp, pbqp_edge_t *edge)
unsigned src_len;
unsigned tgt_len;
unsigned src_index;
- unsigned tgt_index;
unsigned edge_index;
unsigned edge_len;
@@ -459,6 +456,7 @@ static void merge_target_into_source(pbqp_t *pbqp, pbqp_edge_t *edge)
/* Check that each row has at most one zero entry. */
for (src_index = 0; src_index < src_len; ++src_index) {
unsigned onlyOneZero = 0;
+ unsigned tgt_index;
if (src_vec->entries[src_index].data == INF_COSTS)
continue;
@@ -488,11 +486,11 @@ static void merge_target_into_source(pbqp_t *pbqp, pbqp_edge_t *edge)
pbqp->num_rm++;
#endif
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
char txt[100];
sprintf(txt, "Merging n%d into n%d", tgt_node->index, src_node->index);
- dump_section(pbqp->dump_file, 3, txt);
+ pbqp_dump_section(pbqp->dump_file, 3, txt);
}
#endif
@@ -506,7 +504,6 @@ static void merge_target_into_source(pbqp_t *pbqp, pbqp_edge_t *edge)
vector_t *other_vec;
unsigned other_len;
unsigned other_index;
- unsigned src_index;
assert(old_edge);
@@ -672,11 +669,11 @@ void simplify_edge(pbqp_t *pbqp, pbqp_edge_t *edge)
if (is_deleted(edge))
return;
-#if KAPS_DUMP
+#if KAPS_DUMP
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);
+ pbqp_dump_section(pbqp->dump_file, 3, txt);
}
#endif
@@ -690,25 +687,25 @@ void simplify_edge(pbqp_t *pbqp, pbqp_edge_t *edge)
mat = edge->costs;
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fputs("Input:
\n", pbqp->dump_file);
- dump_simplifyedge(pbqp, edge);
+ pbqp_dump_simplifyedge(pbqp, edge);
}
#endif
normalize_towards_source(edge);
normalize_towards_target(edge);
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fputs("
\nOutput:
\n", pbqp->dump_file);
- dump_simplifyedge(pbqp, edge);
+ pbqp_dump_simplifyedge(pbqp, edge);
}
#endif
if (pbqp_matrix_is_zero(mat, src_vec, tgt_vec)) {
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fputs("edge has been eliminated
\n", pbqp->dump_file);
}
@@ -732,10 +729,10 @@ void initial_simplify_edges(pbqp_t *pbqp)
ir_timer_start(t_int_simpl);
#endif
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
pbqp_dump_input(pbqp);
- dump_section(pbqp->dump_file, 1, "2. Simplification of Cost Matrices");
+ pbqp_dump_section(pbqp->dump_file, 1, "2. Simplification of Cost Matrices");
}
#endif
@@ -782,18 +779,18 @@ num determine_solution(pbqp_t *pbqp)
ir_timer_reset_and_start(t_det_solution);
#endif
-#if KAPS_DUMP
+#if KAPS_DUMP
FILE *file;
#endif
(void) pbqp;
-#if KAPS_DUMP
+#if KAPS_DUMP
file = pbqp->dump_file;
if (file) {
- dump_section(file, 1, "4. Determine Solution/Minimum");
- dump_section(file, 2, "4.1. Trivial Solution");
+ pbqp_dump_section(file, 1, "4. Determine Solution/Minimum");
+ pbqp_dump_section(file, 2, "4.1. Trivial Solution");
}
#endif
@@ -811,17 +808,17 @@ num determine_solution(pbqp_t *pbqp)
solution = pbqp_add(solution,
node->costs->entries[node->solution].data);
-#if KAPS_DUMP
+#if KAPS_DUMP
if (file) {
fprintf(file, "node n%d is set to %d
\n", node->index, node->solution);
- dump_node(file, node);
+ pbqp_dump_node(file, node);
}
#endif
}
-#if KAPS_DUMP
+#if KAPS_DUMP
if (file) {
- dump_section(file, 2, "Minimum");
+ pbqp_dump_section(file, 2, "Minimum");
#if KAPS_USE_UNSIGNED
fprintf(file, "Minimum is equal to %u.", solution);
#else
@@ -860,7 +857,7 @@ static void back_propagate_RI(pbqp_t *pbqp, pbqp_node_t *node)
node->solution = pbqp_matrix_get_row_min_index(mat, other->solution, vec);
}
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fprintf(pbqp->dump_file, "node n%d is set to %d
\n", node->index, node->solution);
}
@@ -935,7 +932,7 @@ static void back_propagate_RII(pbqp_t *pbqp, pbqp_node_t *node)
node->solution = vector_get_min_index(vec);
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fprintf(pbqp->dump_file, "node n%d is set to %d
\n", node->index, node->solution);
}
@@ -949,9 +946,9 @@ void back_propagate(pbqp_t *pbqp)
unsigned node_index;
unsigned node_len = node_bucket_get_length(reduced_bucket);
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
- dump_section(pbqp->dump_file, 2, "Back Propagation");
+ pbqp_dump_section(pbqp->dump_file, 2, "Back Propagation");
}
#endif
@@ -967,7 +964,6 @@ void back_propagate(pbqp_t *pbqp)
break;
default:
panic("Only nodes with degree one or two should be in this bucket");
- break;
}
}
}
@@ -996,16 +992,16 @@ void apply_RI(pbqp_t *pbqp)
other_node = edge->src;
}
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
char txt[100];
sprintf(txt, "RI-Reduction of Node n%d", node->index);
- dump_section(pbqp->dump_file, 2, txt);
+ pbqp_dump_section(pbqp->dump_file, 2, txt);
pbqp_dump_graph(pbqp);
fputs("
\nBefore reduction:
\n", pbqp->dump_file);
- dump_node(pbqp->dump_file, node);
- dump_node(pbqp->dump_file, other_node);
- dump_edge(pbqp->dump_file, edge);
+ pbqp_dump_node(pbqp->dump_file, node);
+ pbqp_dump_node(pbqp->dump_file, other_node);
+ pbqp_dump_edge(pbqp->dump_file, edge);
}
#endif
@@ -1018,10 +1014,10 @@ void apply_RI(pbqp_t *pbqp)
}
disconnect_edge(other_node, edge);
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fputs("
\nAfter reduction:
\n", pbqp->dump_file);
- dump_node(pbqp->dump_file, other_node);
+ pbqp_dump_node(pbqp->dump_file, other_node);
}
#endif
@@ -1046,6 +1042,7 @@ void apply_RII(pbqp_t *pbqp)
pbqp_matrix_t *tgt_mat;
pbqp_node_t *src_node;
pbqp_node_t *tgt_node;
+ pbqp_edge_t *edge;
pbqp_matrix_t *mat;
vector_t *vec;
vector_t *node_vec;
@@ -1055,7 +1052,6 @@ void apply_RII(pbqp_t *pbqp)
unsigned col_len;
unsigned row_index;
unsigned row_len;
- unsigned node_len;
assert(pbqp_node_get_degree(node) == 2);
@@ -1088,18 +1084,18 @@ void apply_RII(pbqp_t *pbqp)
tgt_is_src = tgt_edge->src == node;
}
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
char txt[100];
sprintf(txt, "RII-Reduction of Node n%d", node->index);
- dump_section(pbqp->dump_file, 2, txt);
+ pbqp_dump_section(pbqp->dump_file, 2, txt);
pbqp_dump_graph(pbqp);
fputs("
\nBefore reduction:
\n", pbqp->dump_file);
- dump_node(pbqp->dump_file, src_node);
- dump_edge(pbqp->dump_file, src_edge);
- dump_node(pbqp->dump_file, node);
- dump_edge(pbqp->dump_file, tgt_edge);
- dump_node(pbqp->dump_file, tgt_node);
+ pbqp_dump_node(pbqp->dump_file, src_node);
+ pbqp_dump_edge(pbqp->dump_file, src_edge);
+ pbqp_dump_node(pbqp->dump_file, node);
+ pbqp_dump_edge(pbqp->dump_file, tgt_edge);
+ pbqp_dump_node(pbqp->dump_file, tgt_node);
}
#endif
@@ -1112,7 +1108,6 @@ void apply_RII(pbqp_t *pbqp)
row_len = src_vec->len;
col_len = tgt_vec->len;
- node_len = node_vec->len;
mat = pbqp_matrix_alloc(pbqp, row_len, col_len);
@@ -1138,7 +1133,7 @@ void apply_RII(pbqp_t *pbqp)
}
}
- pbqp_edge_t *edge = get_edge(pbqp, src_node->index, tgt_node->index);
+ edge = get_edge(pbqp, src_node->index, tgt_node->index);
/* Disconnect node. */
disconnect_edge(src_node, src_edge);
@@ -1164,10 +1159,10 @@ void apply_RII(pbqp_t *pbqp)
reorder_node_after_edge_deletion(tgt_node);
}
-#if KAPS_DUMP
+#if KAPS_DUMP
if (pbqp->dump_file) {
fputs("
\nAfter reduction:
\n", pbqp->dump_file);
- dump_edge(pbqp->dump_file, edge);
+ pbqp_dump_edge(pbqp->dump_file, edge);
}
#endif
@@ -1231,14 +1226,12 @@ static void select_column(pbqp_edge_t *edge, unsigned col_index)
static void select_row(pbqp_edge_t *edge, unsigned row_index)
{
pbqp_matrix_t *mat;
- pbqp_node_t *src_node;
pbqp_node_t *tgt_node;
vector_t *tgt_vec;
unsigned tgt_len;
unsigned tgt_index;
unsigned new_infinity = 0;
- src_node = edge->src;
tgt_node = edge->tgt;
tgt_vec = tgt_node->costs;