use tv_t.h instead of tv.h
[libfirm] / ir / stat / const_stat.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/firmstat.c
4  * Purpose:     Statistics for Firm.
5  * Author:      Michael Beck
6  * Created:
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 2004 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  */
11 #include "firmstat_t.h"
12 #include "tv.h"
13
14 static stat_info_t *status;
15
16 /**
17  * calculated the dual logarithmus of |value|
18  */
19 static unsigned log2(long value) {
20   unsigned res = 0;
21
22   if (value < 0)
23     value = -value;
24
25   if (value > 0xFFFF) {
26     res += 16;
27     value >>= 16;
28   }
29   if (value > 0xFF) {
30     res += 8;
31     value >>= 8;
32   }
33   if (value > 0xF) {
34     res += 4;
35     value >>= 4;
36   }
37   if (value > 3) {
38     res += 2;
39     value >>= 2;
40   }
41   if (value > 1) {
42     res += 1;
43   }
44
45   return res;
46 }
47
48 /**
49  * update info on Consts
50  *
51  * @param node   The Const node
52  * @param graph  The graph entry containing the call
53  */
54 void stat_update_const(stat_info_t *status, ir_node *node, graph_entry_t *graph)
55 {
56   ir_mode *mode = get_irn_mode(node);
57   tarval *tv;
58   unsigned bits;
59
60   /* we handle integer modes only here */
61   if (! mode_is_int(mode)) {
62     cnt_inc(&status->const_info.others);
63     return;
64   }
65
66   tv   = get_Const_tarval(node);
67   bits = log2(get_tarval_long(tv));
68
69   if (bits > ARR_SIZE(status->const_info.bits_count))
70     bits = ARR_SIZE(status->const_info.bits_count);
71
72   cnt_inc(&status->const_info.bits_count[bits]);
73 }
74
75 /* clears the const statistics for a new snapshot */
76 void stat_const_clear(stat_info_t *status)
77 {
78   int i;
79
80   for (i = 0; i < ARR_SIZE(status->const_info.bits_count); ++i)
81     cnt_clr(&status->const_info.bits_count[i]);
82   cnt_clr(&status->const_info.others);
83 }
84
85 /* initialize the Const statistic. */
86 void stat_init_const_cnt(stat_info_t *status)
87 {
88 }