2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Statistic functions for constant counting.
13 #include "firmstat_t.h"
18 * calculated the dual logarithm of |value|
20 static unsigned log2abs(long value)
51 * classify the value of a float tarval
53 static float_classify_t classify_float_value(ir_tarval *tv)
55 ir_mode *mode = get_tarval_mode(tv);
57 if (tv == get_mode_null(mode))
59 else if (tv == get_mode_one(mode))
61 else if (tarval_is_finite(tv) && tarval_zero_mantissa(tv)) {
62 int exp = tarval_get_exponent(tv);
64 if (! tarval_is_negative(tv)) {
70 return STAT_FC_POWER_OF_TWO;
75 /* return a human readable name for an float classification */
76 const char *stat_fc_name(float_classify_t classification)
78 switch (classification) {
79 case STAT_FC_0: return "0.0";
80 case STAT_FC_1: return "1.0";
81 case STAT_FC_2: return "2.0";
82 case STAT_FC_0_5: return "0.5";
83 case STAT_FC_POWER_OF_TWO: return "2.0^x";
84 case STAT_FC_OTHER: return "other";
85 default: return "<UNKNOWN>";
89 /* update info on Consts */
90 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
92 ir_mode *mode = get_irn_mode(node);
97 if (mode_is_int(mode)) {
98 tv = get_Const_tarval(node);
101 if (! tarval_is_long(tv))
104 bits = log2abs(get_tarval_long(tv));
106 if (bits > ARRAY_SIZE(status->const_info.int_bits_count))
107 bits = ARRAY_SIZE(status->const_info.int_bits_count);
109 cnt_inc(&status->const_info.int_bits_count[bits]);
110 } else if (mode_is_float(mode)) {
111 tv = get_Const_tarval(node);
113 cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
115 /* something different */
116 cnt_inc(&status->const_info.others);
120 /* clears the const statistics for a new snapshot */
121 void stat_const_clear(stat_info_t *status)
125 for (i = 0; i < ARRAY_SIZE(status->const_info.int_bits_count); ++i)
126 cnt_clr(&status->const_info.int_bits_count[i]);
128 for (i = 0; i < ARRAY_SIZE(status->const_info.floats); ++i)
129 cnt_clr(&status->const_info.floats[i]);
131 cnt_clr(&status->const_info.others);
134 /* initialize the Const statistic. */
135 void stat_init_const_cnt(stat_info_t *status)
138 /* currently nothing */