X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fstat%2Fdistrib.c;h=e145b3e6a8f2506ab99feda2cc360d685f866bbf;hb=3e889332cb054e5cee1a12bba6dd0209121100cf;hp=dbfa1c859c34620ec2864342ab609a0917d88895;hpb=e07b61c6ed5d198a484761f8a40a4f26520d964d;p=libfirm diff --git a/ir/stat/distrib.c b/ir/stat/distrib.c index dbfa1c859..e145b3e6a 100644 --- a/ir/stat/distrib.c +++ b/ir/stat/distrib.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2010 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -23,9 +23,7 @@ * @author Michael Beck * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include "hashptr.h" #include "irtools.h" @@ -35,31 +33,37 @@ /** * calculates a hash value for an address */ -static unsigned addr_hash(const void *object) { +static unsigned addr_hash(const void *object) +{ return HASH_PTR(object); } /** * calculates a hash value for an integer */ -static unsigned int_hash(const void *object) { +static unsigned int_hash(const void *object) +{ return (unsigned)PTR_TO_INT(object); } /** * compare function for integer distribution tables */ -static int int_cmp_fun(const void *elt, const void *key) { - const distrib_entry_t *p1 = elt; - const distrib_entry_t *p2 = key; - - return (char *)p1->object - (char *)p2->object; +static int int_cmp_fun(const void *elt, const void *key) +{ + const distrib_entry_t *p1 = (const distrib_entry_t*)elt; + const distrib_entry_t *p2 = (const distrib_entry_t*)key; + + if (p1->object == p2->object) + return 0; + return p1->object < p2->object ? -1 : 1; } /* * create a new distribution table */ -distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func) { +distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash_func) +{ distrib_tbl_t *res = XMALLOC(distrib_tbl_t); obstack_init(&res->cnts); @@ -75,7 +79,8 @@ distrib_tbl_t *stat_new_distrib_tbl(pset_cmp_fun cmp_func, distrib_hash_fun hash /* * create a new distribution table for an integer distribution */ -distrib_tbl_t *stat_new_int_distrib_tbl(void) { +distrib_tbl_t *stat_new_int_distrib_tbl(void) +{ distrib_tbl_t *res = stat_new_distrib_tbl(int_cmp_fun, int_hash); if (res) @@ -87,7 +92,8 @@ distrib_tbl_t *stat_new_int_distrib_tbl(void) { /* * destroy a distribution table */ -void stat_delete_distrib_tbl(distrib_tbl_t *tbl) { +void stat_delete_distrib_tbl(distrib_tbl_t *tbl) +{ if (tbl) { /* free all entries */ obstack_free(&tbl->cnts, NULL); @@ -100,30 +106,32 @@ void stat_delete_distrib_tbl(distrib_tbl_t *tbl) { /** * Returns the associates distrib_entry_t for an object */ -static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object) { +static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object) +{ distrib_entry_t key; distrib_entry_t *elem; key.object = object; - elem = pset_find(tbl->hash_map, &key, tbl->hash_func(object)); + elem = (distrib_entry_t*)pset_find(tbl->hash_map, &key, tbl->hash_func(object)); if (elem) return elem; - elem = obstack_alloc(&tbl->cnts, sizeof(*elem)); + elem = OALLOC(&tbl->cnts, distrib_entry_t); /* clear counter */ cnt_clr(&elem->cnt); elem->object = object; - return pset_insert(tbl->hash_map, elem, tbl->hash_func(object)); + return (distrib_entry_t*)pset_insert(tbl->hash_map, elem, tbl->hash_func(object)); } /* * adds a new object count into the distribution table */ -void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt) { +void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_t *cnt) +{ distrib_entry_t *elem = distrib_get_entry(tbl, object); cnt_add(&elem->cnt, cnt); @@ -132,14 +140,16 @@ void stat_add_distrib_tbl(distrib_tbl_t *tbl, const void *object, const counter_ /* * adds a new key count into the integer distribution table */ -void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt) { +void stat_add_int_distrib_tbl(distrib_tbl_t *tbl, int key, const counter_t *cnt) +{ stat_add_distrib_tbl(tbl, INT_TO_PTR(key), cnt); } /* * increases object count by one */ -void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object) { +void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object) +{ distrib_entry_t *elem = distrib_get_entry(tbl, object); cnt_inc(&elem->cnt); @@ -148,7 +158,8 @@ void stat_inc_distrib_tbl(distrib_tbl_t *tbl, const void *object) { /* * increases key count by one */ -void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key) { +void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key) +{ stat_inc_distrib_tbl(tbl, INT_TO_PTR(key)); } @@ -156,7 +167,8 @@ void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key) { * inserts a new object with count 0 into the distribution table * if object is already present, nothing happens */ -void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object) { +void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object) +{ /* executed for side effect */ (void)distrib_get_entry(tbl, object); } @@ -165,18 +177,20 @@ void stat_insert_distrib_tbl(distrib_tbl_t *tbl, const void *object) { * inserts a new key with count 0 into the integer distribution table * if key is already present, nothing happens */ -void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key) { +void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key) +{ stat_insert_distrib_tbl(tbl, INT_TO_PTR(key)); } /* * returns the sum over all counters in a distribution table */ -int stat_get_count_distrib_tbl(distrib_tbl_t *tbl) { +int stat_get_count_distrib_tbl(distrib_tbl_t *tbl) +{ distrib_entry_t *entry; counter_t cnt = ZERO_CNT; - foreach_pset(tbl->hash_map, entry) + foreach_pset(tbl->hash_map, distrib_entry_t*, entry) cnt_add(&cnt, &entry->cnt); return cnt_to_uint(&cnt); } @@ -184,7 +198,8 @@ int stat_get_count_distrib_tbl(distrib_tbl_t *tbl) { /* * calculates the mean value of a distribution */ -double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) { +double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) +{ distrib_entry_t *entry; unsigned count; double sum; @@ -193,7 +208,7 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) { /* integer distribution, need min, max */ int min, max; - entry = pset_first(tbl->hash_map); + entry = (distrib_entry_t*)pset_first(tbl->hash_map); if (! entry) return 0.0; @@ -203,7 +218,8 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) { sum = cnt_to_dbl(&entry->cnt); - for (entry = pset_next(tbl->hash_map); entry; entry = pset_next(tbl->hash_map)) { + for (entry = (distrib_entry_t*)pset_next(tbl->hash_map); entry != NULL; + entry = (distrib_entry_t*)pset_next(tbl->hash_map)) { int value = PTR_TO_INT(entry->object); if (value < min) @@ -217,7 +233,7 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) { } else { sum = 0.0; count = 0; - foreach_pset(tbl->hash_map, entry) { + foreach_pset(tbl->hash_map, distrib_entry_t*, entry) { sum += cnt_to_dbl(&entry->cnt); ++count; } @@ -229,7 +245,8 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) { /* * calculates the average value of a distribution */ -double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) { +double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) +{ distrib_entry_t *entry; unsigned count = 0; double sum = 0.0; @@ -238,12 +255,12 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) { if (pset_count(tbl->hash_map) <= 0) return 0.0; - foreach_pset(tbl->hash_map, entry) { + foreach_pset(tbl->hash_map, distrib_entry_t*, entry) { sum += cnt_to_dbl(&entry->cnt) * PTR_TO_INT(entry->object); count += cnt_to_uint(&entry->cnt); } } else { - foreach_pset(tbl->hash_map, entry) { + foreach_pset(tbl->hash_map, distrib_entry_t*, entry) { sum += cnt_to_dbl(&entry->cnt); ++count; } @@ -255,9 +272,10 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) { /** * iterates over all entries in a distribution table */ -void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env) { +void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env) +{ distrib_entry_t *entry; - foreach_pset(tbl->hash_map, entry) + foreach_pset(tbl->hash_map, distrib_entry_t*, entry) eval(entry, env); }