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"
14 static stat_info_t *status;
17 * calculated the dual logarithmus of |value|
19 static unsigned log2(long value) {
49 * classify the value of a float tarval
51 static float_classify_t classify_float_value(tarval *tv)
53 ir_mode *mode = get_tarval_mode(tv);
55 if (tv == get_mode_null(mode))
57 else if (tv == get_mode_one(mode))
63 /* return a human readable name for an float classification */
64 const char *stat_fc_name(float_classify_t classification)
66 switch (classification) {
67 case STAT_FC_0: return "0.0";
68 case STAT_FC_1: return "1.0";
69 case STAT_FC_2: return "2.0";
70 case STAT_FC_0_5: return "0.5";
71 case STAT_FC_EXACT: return "exact";
72 case STAT_FC_OTHER: return "other";
73 default: return "<UNKNOWN>";
78 * update info on Consts
80 * @param node The Const node
81 * @param graph The graph entry containing the call
83 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
85 ir_mode *mode = get_irn_mode(node);
89 if (mode_is_int(mode)) {
90 tv = get_Const_tarval(node);
93 if (! tarval_is_long(tv))
96 bits = log2(get_tarval_long(tv));
98 if (bits > ARR_SIZE(status->const_info.int_bits_count))
99 bits = ARR_SIZE(status->const_info.int_bits_count);
101 cnt_inc(&status->const_info.int_bits_count[bits]);
103 else if (mode_is_float(mode)) {
104 tv = get_Const_tarval(node);
106 cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
109 /* something different */
110 cnt_inc(&status->const_info.others);
114 /* clears the const statistics for a new snapshot */
115 void stat_const_clear(stat_info_t *status)
119 for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i)
120 cnt_clr(&status->const_info.int_bits_count[i]);
122 for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i)
123 cnt_clr(&status->const_info.floats[i]);
125 cnt_clr(&status->const_info.others);
128 /* initialize the Const statistic. */
129 void stat_init_const_cnt(stat_info_t *status)