From: Michael Beck Date: Fri, 17 Jun 2005 12:13:22 +0000 (+0000) Subject: added statistics for float constants X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=fa30834881a4ae77c442877e46f5708074014d8c;p=libfirm added statistics for float constants [r6056] --- diff --git a/ir/stat/const_stat.c b/ir/stat/const_stat.c index 17b10ffc6..3fa94cc60 100644 --- a/ir/stat/const_stat.c +++ b/ir/stat/const_stat.c @@ -9,7 +9,7 @@ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ #include "firmstat_t.h" -#include "tv.h" +#include "tv_t.h" static stat_info_t *status; @@ -45,6 +45,35 @@ static unsigned log2(long value) { return res; } +/** + * classify the value of a float tarval + */ +static float_classify_t classify_float_value(tarval *tv) +{ + ir_mode *mode = get_tarval_mode(tv); + + if (tv == get_mode_null(mode)) + return STAT_FC_1; + else if (tv == get_mode_one(mode)) + return STAT_FC_1; + + return STAT_FC_OTHER; +} + +/* return a human readable name for an float classification */ +const char *stat_fc_name(float_classify_t classification) +{ + switch (classification) { + case STAT_FC_0: return "0.0"; + case STAT_FC_1: return "1.0"; + case STAT_FC_2: return "2.0"; + case STAT_FC_0_5: return "0.5"; + case STAT_FC_EXACT: return "exact"; + case STAT_FC_OTHER: return "other"; + default: return ""; + } +} + /** * update info on Consts * @@ -57,19 +86,24 @@ void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph) tarval *tv; unsigned bits; - /* we handle integer modes only here */ - if (! mode_is_int(mode)) { - cnt_inc(&status->const_info.others); - return; - } + if (mode_is_int(mode)) { + tv = get_Const_tarval(node); + bits = log2(get_tarval_long(tv)); - tv = get_Const_tarval(node); - bits = log2(get_tarval_long(tv)); + if (bits > ARR_SIZE(status->const_info.int_bits_count)) + bits = ARR_SIZE(status->const_info.int_bits_count); - if (bits > ARR_SIZE(status->const_info.bits_count)) - bits = ARR_SIZE(status->const_info.bits_count); + cnt_inc(&status->const_info.int_bits_count[bits]); + } + else if (mode_is_float(mode)) { + tv = get_Const_tarval(node); - cnt_inc(&status->const_info.bits_count[bits]); + cnt_inc(&status->const_info.floats[classify_float_value(tv)]); + } + else { + /* something different */ + cnt_inc(&status->const_info.others); + } } /* clears the const statistics for a new snapshot */ @@ -77,8 +111,12 @@ void stat_const_clear(stat_info_t *status) { int i; - for (i = 0; i < ARR_SIZE(status->const_info.bits_count); ++i) - cnt_clr(&status->const_info.bits_count[i]); + for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i) + cnt_clr(&status->const_info.int_bits_count[i]); + + for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i) + cnt_clr(&status->const_info.floats[i]); + cnt_clr(&status->const_info.others); }