3 * File name: ir/ir/firmstat.c
4 * Purpose: Statistics for Firm.
8 * Copyright: (c) 2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
11 #include "firmstat_t.h"
15 * calculated the dual logarithmus of |value|
17 static unsigned log2abs(long value) {
47 * classify the value of a float tarval
49 static float_classify_t classify_float_value(tarval *tv)
51 ir_mode *mode = get_tarval_mode(tv);
53 if (tv == get_mode_null(mode))
55 else if (tv == get_mode_one(mode))
61 /* return a human readable name for an float classification */
62 const char *stat_fc_name(float_classify_t classification)
64 switch (classification) {
65 case STAT_FC_0: return "0.0";
66 case STAT_FC_1: return "1.0";
67 case STAT_FC_2: return "2.0";
68 case STAT_FC_0_5: return "0.5";
69 case STAT_FC_EXACT: return "exact";
70 case STAT_FC_OTHER: return "other";
71 default: return "<UNKNOWN>";
76 * update info on Consts
78 * @param status statistic status
79 * @param node The Const node
80 * @param graph The graph entry containing the call
82 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
84 ir_mode *mode = get_irn_mode(node);
88 if (mode_is_int(mode)) {
89 tv = get_Const_tarval(node);
92 if (! tarval_is_long(tv))
95 bits = log2abs(get_tarval_long(tv));
97 if (bits > ARR_SIZE(status->const_info.int_bits_count))
98 bits = ARR_SIZE(status->const_info.int_bits_count);
100 cnt_inc(&status->const_info.int_bits_count[bits]);
102 else if (mode_is_float(mode)) {
103 tv = get_Const_tarval(node);
105 cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
108 /* something different */
109 cnt_inc(&status->const_info.others);
113 /* clears the const statistics for a new snapshot */
114 void stat_const_clear(stat_info_t *status)
118 for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i)
119 cnt_clr(&status->const_info.int_bits_count[i]);
121 for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i)
122 cnt_clr(&status->const_info.floats[i]);
124 cnt_clr(&status->const_info.others);
127 /* initialize the Const statistic. */
128 void stat_init_const_cnt(stat_info_t *status)