summaryrefslogtreecommitdiffhomepage
path: root/ir/kaps
diff options
context:
space:
mode:
authorMichael Beck <mm.beck@gmx.net>2011-04-09 03:04:25 +0200
committerMichael Beck <mm.beck@gmx.net>2011-04-09 03:04:25 +0200
commit2f6a3ddc84e1023452e7b1301c321567fd3e7407 (patch)
treef0691b30021ef0568892cb5248a494e5027c2cd0 /ir/kaps
parent369cb4e1554b2088eecc48bc95de8e42f33b4328 (diff)
C99 features removed.
Diffstat (limited to 'ir/kaps')
-rw-r--r--ir/kaps/html_dumper.c12
-rw-r--r--ir/kaps/kaps.c6
-rw-r--r--ir/kaps/matrix.c42
-rw-r--r--ir/kaps/optimal.c3
-rw-r--r--ir/kaps/pbqp_edge.c9
-rw-r--r--ir/kaps/vector.c6
6 files changed, 47 insertions, 31 deletions
diff --git a/ir/kaps/html_dumper.c b/ir/kaps/html_dumper.c
index f29a88d..d0809ea 100644
--- a/ir/kaps/html_dumper.c
+++ b/ir/kaps/html_dumper.c
@@ -53,9 +53,9 @@ static const char *cost2a(num const cost)
static void dump_vector(FILE *f, vector_t *vec)
{
unsigned index;
+ unsigned len = vec->len;
fprintf(f, "<span class=\"vector\">( ");
- unsigned len = vec->len;
assert(len > 0);
for (index = 0; index < len; ++index) {
#if KAPS_ENABLE_VECTOR_NAMES
@@ -103,12 +103,13 @@ static void dump_edge_costs(pbqp_t *pbqp)
fputs("<p>", pbqp->dump_file);
for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
pbqp_node_t *src_node = get_node(pbqp, src_index);
+ unsigned edge_index;
+ unsigned len;
if (!src_node)
continue;
- unsigned edge_index;
- unsigned len = ARR_LEN(src_node->edges);
+ len = ARR_LEN(src_node->edges);
for (edge_index = 0; edge_index < len; ++edge_index) {
pbqp_edge_t *edge = src_node->edges[edge_index];
unsigned tgt_index = edge->tgt->index;
@@ -160,6 +161,8 @@ void pbqp_dump_graph(pbqp_t *pbqp)
for (src_index = 0; src_index < pbqp->num_nodes; ++src_index) {
pbqp_node_t *node = get_node(pbqp, src_index);
+ unsigned len;
+ unsigned edge_index;
if (!node)
continue;
@@ -167,8 +170,7 @@ void pbqp_dump_graph(pbqp_t *pbqp)
if (node_is_reduced(node))
continue;
- unsigned len = ARR_LEN(node->edges);
- unsigned edge_index;
+ len = ARR_LEN(node->edges);
for (edge_index = 0; edge_index < len; ++edge_index) {
pbqp_node_t *tgt_node = node->edges[edge_index]->tgt;
unsigned tgt_index = tgt_node->index;
diff --git a/ir/kaps/kaps.c b/ir/kaps/kaps.c
index 78b4c0d..63914d1 100644
--- a/ir/kaps/kaps.c
+++ b/ir/kaps/kaps.c
@@ -46,6 +46,8 @@ pbqp_edge_t *get_edge(pbqp_t *pbqp, unsigned src_index, unsigned tgt_index)
{
int i;
int len;
+ pbqp_node_t *src_node;
+ pbqp_node_t *tgt_node;
if (tgt_index < src_index) {
unsigned tmp = src_index;
@@ -53,8 +55,8 @@ pbqp_edge_t *get_edge(pbqp_t *pbqp, unsigned src_index, unsigned tgt_index)
tgt_index = tmp;
}
- pbqp_node_t *src_node = get_node(pbqp, src_index);
- pbqp_node_t *tgt_node = get_node(pbqp, tgt_index);
+ src_node = get_node(pbqp, src_index);
+ tgt_node = get_node(pbqp, tgt_index);
assert(tgt_node);
len = ARR_LEN(src_node->edges);
diff --git a/ir/kaps/matrix.c b/ir/kaps/matrix.c
index 47c1546..20e610b 100644
--- a/ir/kaps/matrix.c
+++ b/ir/kaps/matrix.c
@@ -35,13 +35,12 @@
pbqp_matrix_t *pbqp_matrix_alloc(pbqp_t *pbqp, unsigned rows, unsigned cols)
{
- assert(cols > 0);
- assert(rows > 0);
-
unsigned length = rows * cols;
-
pbqp_matrix_t *mat = (pbqp_matrix_t*)obstack_alloc(&pbqp->obstack, sizeof(*mat) + sizeof(*mat->entries) * length);
+ assert(cols > 0);
+ assert(rows > 0);
+
mat->cols = cols;
mat->rows = rows;
memset(mat->entries, 0, sizeof(*mat->entries) * length);
@@ -82,10 +81,11 @@ pbqp_matrix_t *pbqp_matrix_copy_and_transpose(pbqp_t *pbqp, pbqp_matrix_t *m)
void pbqp_matrix_transpose(pbqp_t *pbqp, pbqp_matrix_t *mat)
{
unsigned len;
+ pbqp_matrix_t *tmp;
len = mat->rows * mat->cols;
- pbqp_matrix_t *tmp = pbqp_matrix_copy_and_transpose(pbqp, mat);
+ tmp = pbqp_matrix_copy_and_transpose(pbqp, mat);
memcpy(mat, tmp, sizeof(*mat) + sizeof(*mat->entries) * len);
@@ -148,16 +148,18 @@ num pbqp_matrix_get_col_min(pbqp_matrix_t *matrix, unsigned col_index, vector_t
unsigned row_index;
num min = INF_COSTS;
- assert(matrix->rows == flags->len);
-
unsigned col_len = matrix->cols;
unsigned row_len = matrix->rows;
+ assert(matrix->rows == flags->len);
+
for (row_index = 0; row_index < row_len; ++row_index) {
+ num elem;
+
/* Ignore virtual deleted columns. */
if (flags->entries[row_index].data == INF_COSTS) continue;
- num elem = matrix->entries[row_index * col_len + col_index];
+ elem = matrix->entries[row_index * col_len + col_index];
if (elem < min) {
min = elem;
@@ -173,16 +175,18 @@ unsigned pbqp_matrix_get_col_min_index(pbqp_matrix_t *matrix, unsigned col_index
unsigned min_index = 0;
num min = INF_COSTS;
- assert(matrix->rows == flags->len);
-
unsigned col_len = matrix->cols;
unsigned row_len = matrix->rows;
+ assert(matrix->rows == flags->len);
+
for (row_index = 0; row_index < row_len; ++row_index) {
+ num elem;
+
/* Ignore virtual deleted columns. */
if (flags->entries[row_index].data == INF_COSTS) continue;
- num elem = matrix->entries[row_index * col_len + col_index];
+ elem = matrix->entries[row_index * col_len + col_index];
if (elem < min) {
min = elem;
@@ -223,15 +227,17 @@ num pbqp_matrix_get_row_min(pbqp_matrix_t *matrix, unsigned row_index, vector_t
unsigned col_index;
num min = INF_COSTS;
- assert(matrix->cols == flags->len);
-
unsigned len = flags->len;
+ assert(matrix->cols == len);
+
for (col_index = 0; col_index < len; ++col_index) {
+ num elem;
+
/* Ignore virtual deleted columns. */
if (flags->entries[col_index].data == INF_COSTS) continue;
- num elem = matrix->entries[row_index * len + col_index];
+ elem = matrix->entries[row_index * len + col_index];
if (elem < min) {
min = elem;
@@ -247,15 +253,17 @@ unsigned pbqp_matrix_get_row_min_index(pbqp_matrix_t *matrix, unsigned row_index
unsigned min_index = 0;
num min = INF_COSTS;
- assert(matrix->cols == flags->len);
-
unsigned len = flags->len;
+ assert(matrix->cols == len);
+
for (col_index = 0; col_index < len; ++col_index) {
+ num elem;
+
/* Ignore virtual deleted columns. */
if (flags->entries[col_index].data == INF_COSTS) continue;
- num elem = matrix->entries[row_index * len + col_index];
+ elem = matrix->entries[row_index * len + col_index];
if (elem < min) {
min = elem;
diff --git a/ir/kaps/optimal.c b/ir/kaps/optimal.c
index 3dfdd2f..94ccecc 100644
--- a/ir/kaps/optimal.c
+++ b/ir/kaps/optimal.c
@@ -1046,6 +1046,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;
@@ -1138,7 +1139,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);
diff --git a/ir/kaps/pbqp_edge.c b/ir/kaps/pbqp_edge.c
index 1a90497..da9ea5c 100644
--- a/ir/kaps/pbqp_edge.c
+++ b/ir/kaps/pbqp_edge.c
@@ -42,6 +42,9 @@ pbqp_edge_t *alloc_edge(pbqp_t *pbqp, int src_index, int tgt_index,
pbqp_matrix_t *costs)
{
int transpose = 0;
+ pbqp_edge_t *edge = OALLOC(&pbqp->obstack, pbqp_edge_t);
+ pbqp_node_t *src_node;
+ pbqp_node_t *tgt_node;
if (tgt_index < src_index) {
int tmp = src_index;
@@ -51,11 +54,9 @@ pbqp_edge_t *alloc_edge(pbqp_t *pbqp, int src_index, int tgt_index,
transpose = 1;
}
- pbqp_edge_t *edge = OALLOC(&pbqp->obstack, pbqp_edge_t);
-
- pbqp_node_t *src_node = get_node(pbqp, src_index);
+ src_node = get_node(pbqp, src_index);
- pbqp_node_t *tgt_node = get_node(pbqp, tgt_index);
+ tgt_node = get_node(pbqp, tgt_index);
if (transpose) {
edge->costs = pbqp_matrix_copy_and_transpose(pbqp, costs);
diff --git a/ir/kaps/vector.c b/ir/kaps/vector.c
index 4970d08..063265d 100644
--- a/ir/kaps/vector.c
+++ b/ir/kaps/vector.c
@@ -34,9 +34,11 @@
num pbqp_add(num x, num y)
{
+ num res;
+
if (x == INF_COSTS || y == INF_COSTS) return INF_COSTS;
- num res = x + y;
+ res = x + y;
#if !KAPS_USE_UNSIGNED
/* No positive overflow. */
@@ -56,8 +58,8 @@ num pbqp_add(num x, num y)
vector_t *vector_alloc(pbqp_t *pbqp, unsigned length)
{
- assert(length > 0);
vector_t *vec = (vector_t*)obstack_alloc(&pbqp->obstack, sizeof(*vec) + sizeof(*vec->entries) * length);
+ assert(length > 0);
vec->len = length;
memset(vec->entries, 0, sizeof(*vec->entries) * length);