X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fstat%2Fdistrib.c;h=ea9bd253d15a376135a10d06e66ad4bbc0c7a486;hb=69c991e03a0eb1b284e6d0c41623d340a8e26d16;hp=89eff58de446a179005c64f8e1b2e2953b942594;hpb=b674c665b7fab419ab30f83103298d64387e8e18;p=libfirm diff --git a/ir/stat/distrib.c b/ir/stat/distrib.c index 89eff58de..ea9bd253d 100644 --- a/ir/stat/distrib.c +++ b/ir/stat/distrib.c @@ -1,16 +1,29 @@ /* - * Project: libFIRM - * File name: ir/ir/distrib.c - * Purpose: Statistics for Firm. Distribution tables. - * Author: Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2004 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif + +/** + * @file + * @brief Statistics for Firm. Distribution tables. + * @author Michael Beck + * @version $Id$ + */ +#include "config.h" #include "hashptr.h" #include "irtools.h" @@ -20,24 +33,21 @@ /** * 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) -{ +static int int_cmp_fun(const void *elt, const void *key) { const distrib_entry_t *p1 = elt; const distrib_entry_t *p2 = key; @@ -47,11 +57,8 @@ static int int_cmp_fun(const void *elt, const void *key) /* * 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 *res; - - res = xmalloc(sizeof(*res)); +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); @@ -66,8 +73,7 @@ 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) @@ -79,8 +85,7 @@ 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); @@ -93,8 +98,7 @@ 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; @@ -117,8 +121,7 @@ static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *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); @@ -127,16 +130,14 @@ 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) -{ - stat_add_distrib_tbl(tbl, (const void *)key, 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); @@ -145,17 +146,15 @@ 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) -{ - stat_inc_distrib_tbl(tbl, (const void *)key); +void stat_inc_int_distrib_tbl(distrib_tbl_t *tbl, int key) { + stat_inc_distrib_tbl(tbl, INT_TO_PTR(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); } @@ -164,16 +163,14 @@ 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) -{ - stat_insert_distrib_tbl(tbl, (const void *)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; @@ -185,8 +182,7 @@ 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; @@ -201,23 +197,22 @@ double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) return 0.0; min = - max = (int)entry->object; + max = PTR_TO_INT(entry->object); sum = cnt_to_dbl(&entry->cnt); for (entry = pset_next(tbl->hash_map); entry; entry = pset_next(tbl->hash_map)) { - int value = (int)entry->object; + int value = PTR_TO_INT(entry->object); if (value < min) min = value; - if (value > max); + if (value > max) max = value; sum += cnt_to_dbl(&entry->cnt); } count = max - min + 1; - } - else { + } else { sum = 0.0; count = 0; foreach_pset(tbl->hash_map, entry) { @@ -232,8 +227,7 @@ 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; @@ -243,11 +237,10 @@ double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl) return 0.0; foreach_pset(tbl->hash_map, entry) { - sum += cnt_to_dbl(&entry->cnt) * (int)entry->object; + sum += cnt_to_dbl(&entry->cnt) * PTR_TO_INT(entry->object); count += cnt_to_uint(&entry->cnt); } - } - else { + } else { foreach_pset(tbl->hash_map, entry) { sum += cnt_to_dbl(&entry->cnt); ++count; @@ -260,8 +253,7 @@ 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)