Fixed some bugs and started statistic code
[libfirm] / include / libfirm / irlivechk.h
1 /*
2  * Copyright (C) 1995-2007 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    irlivechk.h
22  * @author  Sebastian Hack
23  * @date    22.04.2007
24  * @version $Id$
25  * @summary
26  *
27  * Live in/end checks whose only precomputation concerns the structure of the CFG.
28  * Hence, nothing has to be updated if the program is modified unless the CFG is touched.
29  * See .c file for more comments.
30  */
31 #ifndef FIRM_ANA_IRLIVECHK_H
32 #define FIRM_ANA_IRLIVECHK_H
33
34 #include "irgraph.h"
35 #include "irnode.h"
36
37 typedef enum {
38         lv_chk_state_in  = 1,
39         lv_chk_state_end = 2,
40         lv_chk_state_out = 4,
41         lv_chk_state_through = lv_chk_state_in | lv_chk_state_out | lv_chk_state_end,
42 } lv_chk_state_t;
43
44 #define LV_CHK_MAX_BINS 32
45 typedef struct {
46         int dist_uses_per_var[LV_CHK_MAX_BINS]; /** distribution of uses per variable. */
47         int dist_iterations[LV_CHK_MAX_BINS];   /** distribution of loop iterations. */
48         int n_calls;                            /** number of total calls to the chk routine. */
49         int n_no_dominance;                     /** exists due to no existing dominance rel. */
50         int n_false;                            /** number of times the check returned false. */
51         int n_def_block;                        /** number of times the queried block was also
52                                                                                           the definition block of the variable. */
53 } lv_chk_stat_t;
54
55 typedef struct _lv_chk_t lv_chk_t;
56
57 /**
58  * Make a new liveness check environment.
59  * @param irg The graph.
60  * @return    The environment.
61  */
62 extern lv_chk_t *lv_chk_new(ir_graph *irg);
63
64 /**
65  * Get statistic data for the liveness check.
66  * @param lv   The liveness check.
67  * @return     A record with statistics data or NULL if stats were
68  *             not enabled.
69  */
70 extern const lv_chk_stat_t *lv_chk_get_stat(const lv_chk_t *lv);
71
72 /**
73  * Free liveness check information.
74  * @param lv The liveness check information.
75  */
76 extern void lv_chk_free(lv_chk_t *lv);
77
78 #define lv_chk_bl_end(lv, bl, irn) ((lv_chk_bl_xxx((lv), (bl), (irn)) & lv_chk_state_end) != 0)
79 #define lv_chk_bl_out(lv, bl, irn) ((lv_chk_bl_xxx((lv), (bl), (irn)) & lv_chk_state_out) != 0)
80 #define  lv_chk_bl_in(lv, bl, irn) ((lv_chk_bl_xxx((lv), (bl), (irn)) &  lv_chk_state_in) != 0)
81
82 /**
83  * Return liveness information for a node concerning a block.
84  * @param lv   The liveness environment.
85  * @param bl   The block to investigate.
86  * @param irn  The node to check for.
87  * @return     A bitmask of <code>lv_chk_state_t</code>.
88  */
89 extern unsigned lv_chk_bl_xxx(const lv_chk_t *lv, const ir_node *bl, const ir_node *irn);
90
91 #endif /* FIRM_ANA_IRLIVECHK_H */