Use foreach_pset().
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 13 Jul 2012 11:33:21 +0000 (13:33 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 13 Jul 2012 21:03:58 +0000 (23:03 +0200)
ir/adt/set.c
ir/ana/callgraph.c
ir/be/becopyilp2.c
ir/be/beifg.c
ir/stat/distrib.c
ir/stat/firmstat.c
ir/stat/pattern.c
ir/stat/stat_dmp.c

index a19e5e7..dc77b05 100644 (file)
@@ -438,7 +438,7 @@ void *(pset_insert) (SET *se, const void *key, unsigned hash)
 void pset_insert_pset_ptr(pset *target, pset *src)
 {
        void *elt;
-       for (elt = pset_first(src); elt; elt = pset_next(src)) {
+       foreach_pset(src, void*, elt) {
                pset_insert_ptr(target, elt);
        }
 }
index 813fb25..de5f9fb 100644 (file)
@@ -278,25 +278,23 @@ void compute_callgraph(void)
                count = pset_count(callee_set);
                irg->callees = NEW_ARR_F(cg_callee_entry *, count);
                irg->callee_isbe = NULL;
-               callee = (cg_callee_entry*) pset_first(callee_set);
-               for (j = 0; j < count; ++j) {
-                       irg->callees[j] = callee;
-                       callee = (cg_callee_entry*) pset_next(callee_set);
+               j = 0;
+               foreach_pset(callee_set, cg_callee_entry*, callee) {
+                       irg->callees[j++] = callee;
                }
                del_pset(callee_set);
-               assert(callee == NULL);
+               assert(j == count);
 
                caller_set = (pset *)irg->callers;
                count = pset_count(caller_set);
                irg->callers = NEW_ARR_F(ir_graph *, count);
                irg->caller_isbe =  NULL;
-               c = (ir_graph*) pset_first(caller_set);
-               for (j = 0; j < count; ++j) {
-                       irg->callers[j] = c;
-                       c = (ir_graph*) pset_next(caller_set);
+               j = 0;
+               foreach_pset(caller_set, ir_graph*, c) {
+                       irg->callers[j++] = c;
                }
                del_pset(caller_set);
-               assert(c == NULL);
+               assert(j == count);
        }
        set_irp_callgraph_state(irp_callgraph_consistent);
 }
index 664f559..ee7474a 100644 (file)
@@ -348,7 +348,7 @@ static inline void remove_edge(set *edges, ir_node *n1, ir_node *n2, size_t *cou
        }
 }
 
-#define pset_foreach(pset, irn)  for (irn=(ir_node*)pset_first(pset); irn; irn=(ir_node*)pset_next(pset))
+#define pset_foreach(pset, irn) foreach_pset((pset), ir_node*, (irn))
 
 /**
  * Search for an interference clique and an external node
index e59faa6..3a70c32 100644 (file)
@@ -247,8 +247,7 @@ static inline int get_next_clique(cliques_iter_t *it)
                                        ir_node *irn;
 
                                        /* fill the output buffer */
-                                       for (irn = (ir_node*)pset_first(it->living); irn != NULL;
-                                            irn = (ir_node*)pset_next(it->living)) {
+                                       foreach_pset(it->living, ir_node*, irn) {
                                                it->buf[count++] = irn;
                                        }
 
index 4c92957..758f85c 100644 (file)
@@ -205,20 +205,14 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
 
        if (tbl->int_dist) {
                /* integer distribution, need min, max */
-               int min, max;
-
-               entry = (distrib_entry_t*)pset_first(tbl->hash_map);
-
-               if (! entry)
+               if (pset_count(tbl->hash_map) == 0)
                        return 0.0;
 
-               min =
-               max = PTR_TO_INT(entry->object);
-               sum = cnt_to_dbl(&entry->cnt);
-
+               int min = INT_MAX;
+               int max = INT_MIN;
+               sum = 0.0;
 
-               for (entry = (distrib_entry_t*)pset_next(tbl->hash_map); entry != NULL;
-                    entry = (distrib_entry_t*)pset_next(tbl->hash_map)) {
+               foreach_pset(tbl->hash_map, distrib_entry_t*, entry) {
                        int value = PTR_TO_INT(entry->object);
 
                        if (value < min)
index 897f2a4..9e22abc 100644 (file)
@@ -2077,8 +2077,7 @@ void stat_dump_snapshot(const char *name, const char *phase)
                stat_dump_init(fname);
 
                /* calculate the graph statistics */
-               for (entry = (graph_entry_t*)pset_first(status->irg_hash);
-                     entry != NULL; entry = (graph_entry_t*)pset_next(status->irg_hash)) {
+               foreach_pset(status->irg_hash, graph_entry_t*, entry) {
                        if (entry->irg == NULL) {
                                /* special entry for the global count */
                                continue;
@@ -2097,8 +2096,7 @@ void stat_dump_snapshot(const char *name, const char *phase)
                }  /* while */
 
                /* dump per graph */
-               for (entry = (graph_entry_t*)pset_first(status->irg_hash);
-                    entry != NULL; entry = (graph_entry_t*)pset_next(status->irg_hash)) {
+               foreach_pset(status->irg_hash, graph_entry_t*, entry) {
                        if (entry->irg == NULL) {
                                /* special entry for the global count */
                                continue;
@@ -2137,8 +2135,7 @@ void stat_dump_snapshot(const char *name, const char *phase)
                {
                        node_entry_t *entry;
 
-                       for (entry = (node_entry_t*)pset_first(global->opcode_hash);
-                            entry != NULL; entry = (node_entry_t*)pset_next(global->opcode_hash)) {
+                       foreach_pset(global->opcode_hash, node_entry_t*, entry) {
                                opcode_clear_entry(entry);
                        }  /* for */
                        /* clear all global counter */
index d2c13c1..9f0a011 100644 (file)
@@ -746,7 +746,7 @@ static void store_pattern(const char *fname)
 {
        FILE *f;
        pattern_entry_t *entry;
-       size_t i, count = pset_count(status->pattern_hash);
+       size_t count = pset_count(status->pattern_hash);
 
        if (count <= 0)
                return;
@@ -760,9 +760,7 @@ static void store_pattern(const char *fname)
        fwrite("FPS1", 4, 1, f);
        fwrite(&count, sizeof(count), 1, f);
 
-       for (i = 0, entry = (pattern_entry_t*)pset_first(status->pattern_hash);
-            entry && i < count;
-            entry = (pattern_entry_t*)pset_next(status->pattern_hash), ++i) {
+       foreach_pset(status->pattern_hash, pattern_entry_t*, entry) {
                fwrite(entry, offsetof(pattern_entry_t, buf) + entry->len, 1, f);
        }  /* for */
        fclose(f);
@@ -844,10 +842,9 @@ static void pattern_output(const char *fname)
        dump = new_vcg_dumper(fname, 100);
 
        pattern_arr = XMALLOCN(pattern_entry_t*, count);
-       for (i = 0, entry = (pattern_entry_t*)pset_first(status->pattern_hash);
-            entry && i < count;
-            entry = (pattern_entry_t*)pset_next(status->pattern_hash), ++i) {
-               pattern_arr[i] =  entry;
+       i           = 0;
+       foreach_pset(status->pattern_hash, pattern_entry_t*, entry) {
+               pattern_arr[i++] =  entry;
        }  /* for */
        assert(count == i);
        count = i;
index 3790f11..0a7fb4d 100644 (file)
@@ -278,9 +278,7 @@ static void simple_dump_be_block_reg_pressure(dumper_t *dmp, graph_entry_t *entr
        fprintf(dmp->f, "\n");
 
        /* print the reg pressure for all blocks and register classes */
-       for (/* b_entry is already initialized */ ;
-            b_entry;
-            b_entry = (be_block_entry_t*)pset_next(entry->be_block_hash)) {
+       foreach_pset(entry->block_hash, be_block_entry_t*, b_entry) {
                fprintf(dmp->f, "BLK   %6ld", b_entry->block_nr);
 
                foreach_pset(b_entry->reg_pressure, reg_pressure_entry_t*, rp_entry)