2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Statistic functions for constant counting.
23 * @author Michael Beck
30 #include "firmstat_t.h"
34 * calculated the dual logarithm of |value|
36 static unsigned log2abs(long value) {
66 * classify the value of a float tarval
68 static float_classify_t classify_float_value(tarval *tv) {
69 ir_mode *mode = get_tarval_mode(tv);
71 if (tv == get_mode_null(mode))
73 else if (tv == get_mode_one(mode))
79 /* return a human readable name for an float classification */
80 const char *stat_fc_name(float_classify_t classification) {
81 switch (classification) {
82 case STAT_FC_0: return "0.0";
83 case STAT_FC_1: return "1.0";
84 case STAT_FC_2: return "2.0";
85 case STAT_FC_0_5: return "0.5";
86 case STAT_FC_EXACT: return "exact";
87 case STAT_FC_OTHER: return "other";
88 default: return "<UNKNOWN>";
92 /* update info on Consts */
93 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
95 ir_mode *mode = get_irn_mode(node);
100 if (mode_is_int(mode)) {
101 tv = get_Const_tarval(node);
104 if (! tarval_is_long(tv))
107 bits = log2abs(get_tarval_long(tv));
109 if (bits > ARR_SIZE(status->const_info.int_bits_count))
110 bits = ARR_SIZE(status->const_info.int_bits_count);
112 cnt_inc(&status->const_info.int_bits_count[bits]);
113 } else if (mode_is_float(mode)) {
114 tv = get_Const_tarval(node);
116 cnt_inc(&status->const_info.floats[classify_float_value(tv)]);
118 /* something different */
119 cnt_inc(&status->const_info.others);
123 /* clears the const statistics for a new snapshot */
124 void stat_const_clear(stat_info_t *status) {
127 for (i = 0; i < ARR_SIZE(status->const_info.int_bits_count); ++i)
128 cnt_clr(&status->const_info.int_bits_count[i]);
130 for (i = 0; i < ARR_SIZE(status->const_info.floats); ++i)
131 cnt_clr(&status->const_info.floats[i]);
133 cnt_clr(&status->const_info.others);
136 /* initialize the Const statistic. */
137 void stat_init_const_cnt(stat_info_t *status) {
139 /* currently nothing */