use confirm_irg_properties in lower_intrinsics
[libfirm] / ir / stat / statev.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Statistic events.
23  * @author      Sebastian Hack
24  * @date        17.06.2007
25  */
26
27 #ifndef FIRM_STATEVENT_H
28 #define FIRM_STATEVENT_H
29
30 #ifdef DISABLE_STATEV
31
32 #define stat_ev_enabled                          0
33 #define stat_ev_dbl(name, val)                   ((void)0)
34 #define stat_ev_int(name, val)                   ((void)0)
35 #define stat_ev(name)                            ((void)0)
36 #define stat_ev_emit(name, value)                ((void)0)
37
38 #define stat_ev_cnt_decl(var)                    ((void)0)
39 #define stat_ev_cnt_inc(var)                     ((void)0)
40 #define stat_ev_cnt_done(name, var)              ((void)0)
41 #define stat_ev_tim_push()                       ((void)0)
42 #define stat_ev_tim_pop(name)                    ((void)0)
43
44 #define stat_ev_ctx_push(key)                    ((void)0)
45 #define stat_ev_ctx_push_str(key, str)           ((void)0)
46 #define stat_ev_ctx_push_fmt(key, fmt, value)    ((void)0)
47 #define stat_ev_ctx_push_fobj(key, firm_object)  ((void)0)
48 #define stat_ev_ctx_pop(key)                     ((void)0)
49 #define stat_ev_flush()                          ((void)0)
50
51 #else
52
53 #include <stdio.h>
54 #include "stat_timing.h"
55
56 extern void           stat_ev_printf(char ev_type, const char *key, const char *fmt, ...);
57
58 extern int            stat_ev_enabled;
59 extern int            stat_ev_timer_sp;
60 extern timing_ticks_t stat_ev_timer_elapsed[];
61 extern timing_ticks_t stat_ev_timer_start[];
62
63 static inline void stat_ev_tim_push(void) {
64         timing_ticks_t temp;
65         int sp = stat_ev_timer_sp++;
66         timing_ticks(temp);
67         if (sp == 0) {
68                 timing_enter_max_prio();
69         } else {
70                 timing_ticks_sub(temp, stat_ev_timer_start[sp - 1]);
71                 timing_ticks_add(stat_ev_timer_elapsed[sp - 1], temp);
72         }
73         timing_ticks_init(stat_ev_timer_elapsed[sp]);
74         timing_ticks(stat_ev_timer_start[sp]);
75 }
76
77 static inline void stat_ev_tim_pop(const char *name) {
78         int sp;
79         timing_ticks_t temp;
80         timing_ticks(temp);
81         sp = --stat_ev_timer_sp;
82         timing_ticks_sub(temp, stat_ev_timer_start[sp]);
83         timing_ticks_add(stat_ev_timer_elapsed[sp], temp);
84         if (name != NULL && stat_ev_enabled)
85                 stat_ev_printf('E', name, "%g", timing_ticks_dbl(stat_ev_timer_elapsed[sp]));
86         if (sp == 0) {
87                 timing_leave_max_prio();
88         } else {
89                 timing_ticks(stat_ev_timer_start[sp - 1]);
90         }
91 }
92
93 #define stat_ev_ctx_push_fmt(key, fmt, value) \
94         do { \
95                 if (stat_ev_enabled) { \
96                         stat_ev_tim_push(); \
97                         stat_ev_printf('P', key, fmt, (value)); \
98                         stat_ev_tim_pop(NULL); \
99                 } \
100         } while(0)
101
102 #define stat_ev_ctx_pop(key) \
103         do { \
104                 if (stat_ev_enabled) { \
105                         stat_ev_tim_push(); \
106                         stat_ev_printf('O', key, NULL); \
107                         stat_ev_tim_pop(NULL); \
108                 } \
109         } while(0)
110
111 #define stat_ev_emit(name, value) \
112         do { \
113                 if (stat_ev_enabled) { \
114                         stat_ev_tim_push(); \
115                         stat_ev_printf('E', name, "%g", (double) (value)); \
116                         stat_ev_tim_pop(NULL); \
117                 } \
118         } while(0)
119
120 #define stat_ev_ctx_push_fobj(key, firm_object) stat_ev_ctx_push_fmt((key), "%+F", (firm_object))
121 #define stat_ev_ctx_push_str(key, str)          stat_ev_ctx_push_fmt((key), "%s", (str))
122 #define stat_ev_ctx_push(key)                   stat_ev_ctx_push_fmt((key), "X", NULL)
123
124 #define stat_ev_dbl(name, val)      stat_ev_emit((name), (val))
125 #define stat_ev_int(name, val)      stat_ev_dbl((name), (double) (val))
126 #define stat_ev(name)               stat_ev_emit((name), 0.0)
127
128 #define stat_ev_cnt_decl(var)       int stat_ev_cnt_var_ ## var = 0
129 #define stat_ev_cnt_inc(var)        do { ++stat_ev_cnt_var_ ## var; } while(0)
130 #define stat_ev_cnt_done(var, name) stat_ev_emit((name), stat_ev_cnt_var_ ## var)
131
132 /**
133  * Initialize the stat ev machinery.
134  * @param filename_prefix  The prefix of the filename (.ev or .ev.gz will be appended).
135  * @param filter           All pushes, pops and events will be filtered by this.
136  *                         If we have regex support, you can give an extended regex here.
137  *                         If not, each key will be matched against this.
138  *                         Matched means, we look if the key starts with @p filter.
139  *                         If NULL is given, each key passes, ie thefilter is always TRUE.
140  */
141 void stat_ev_begin(const char *filename_prefix, const char *filter);
142 void stat_ev_end(void);
143
144 #define stat_ev_flush()             do { if (stat_ev_enabled) fflush(stat_ev_enabled); } while(0)
145
146 #endif
147
148 #endif