updated Header
[libfirm] / ir / be / belive.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  * Interblock liveness analysis.
22  * @author Sebastian Hack
23  * @date   6.12.2004
24  * @cvs-id $Id$
25  */
26 #ifndef FIRM_BELIVE_H
27 #define FIRM_BELIVE_H
28
29 #include "firm_types.h"
30 #include "pset.h"
31 #include "bearch.h"
32
33 #include <stdio.h>
34
35 typedef enum {
36         be_lv_state_in  = 1,
37         be_lv_state_end = 2,
38         be_lv_state_out = 4,
39 } be_lv_state_t;
40
41 typedef struct _be_lv_t be_lv_t;
42
43 typedef struct _be_lv_info_t be_lv_info_t;
44
45
46 /**
47  * Compute the inter block liveness for a graph.
48  * @param irg The graph.
49  */
50 be_lv_t *be_liveness(ir_graph *irg);
51
52 /**
53  * Check the given liveness information against a freshly computed one.
54  */
55 void be_liveness_check(be_lv_t *lv);
56
57 /**
58  * Free the liveness information.
59  */
60 void be_liveness_free(be_lv_t *lv);
61
62 /**
63  * Recompute the complete liveness information.
64  */
65 void be_liveness_recompute(be_lv_t *lv);
66
67 /**
68  * Update the liveness information for a single node.
69  * It is irrelevant if there is liveness information present for the node.
70  * The liveness information for the node is firstly deleted and then recomputed.
71  * If the node is fresh and never recorded inf the liveness information before,
72  * it is more efficient to call be_liveness_introduce().
73  */
74 void be_liveness_update(be_lv_t *lv, ir_node *irn);
75
76 /**
77  * Remove a node from the liveness information.
78  */
79 void be_liveness_remove(be_lv_t *lv, ir_node *irn);
80
81 /**
82  * Introduce a new node to the liveness information.
83  * The new irn is not deleted from any block's liveness information, so it must be fresh!
84  * @param lv The liveness info.
85  * @param irn The node.
86  */
87 void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
88
89 /**
90  * Add all nodes which are missing in the current liveness data.
91  * The liveness data of the already existing nodes (in the liveness data) is not touched.
92  * @param The liveness info.
93  */
94 void be_liveness_add_missing(be_lv_t *lv);
95
96 /**
97  * Dump the liveness information for a graph.
98  * @param f The output.
99  * @param irg The graph.
100  */
101 void be_liveness_dump(const be_lv_t *lv, FILE *f);
102
103 /**
104  * Dump the liveness information for a graph.
105  * @param irg The graph.
106  * @param cls_name A string used as substring in the filename.
107  */
108 void be_liveness_dumpto(const be_lv_t *lv, const char *cls_name);
109
110 /**
111  * Check, if a node is live in at a block.
112  * @param block The block.
113  * @param irn The node to check for.
114  * @return 1, if @p irn is live at the entrance of @p block, 0 if not.
115  */
116 int (be_is_live_in)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
117
118 /**
119  * Check, if a node is live out at a block.
120  * @param block The block.
121  * @param irn The node to check for.
122  * @return 1, if @p irn is live at the exit of @p block, 0 if not.
123  */
124 int (be_is_live_out)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
125
126 /**
127  * Check, if a node is live at the end of a block.
128  * @param block The block.
129  * @param irn The node to check for.
130  * @return 1, if @p irn is live at the end of the block, 0 if not.
131  */
132 int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
133
134 /**
135  * Check, if the SSA dominance property is fulfilled.
136  * @param irg The graph.
137  * @return   1 if dominance property is fulfilled, 0 otherwise
138  */
139 int be_check_dominance(ir_graph *irg);
140
141 /**
142  * The liveness transfer function.
143  * Updates a live set over a single step from a given node to its predecessor.
144  * Everything defined at the node is removed from the set, the uses of the node get inserted.
145  * @param arch_env The architecture environment.
146  * @param cls      The register class to consider.
147  * @param irn      The node at which liveness should be computed.
148  * @param live     The set of nodes live before @p irn. This set gets modified by updating it to
149  *                 the nodes live after irn.
150  * @return live.
151  */
152 pset *be_liveness_transfer(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *irn, pset *live);
153
154 /**
155  * Put all node live at the end of a block into a set.
156  * @param arch_env The architecture environment.
157  * @param cls      The register class to consider.
158  * @param bl       The block.
159  * @param live     The set to put them into.
160  * @return live.
161  */
162 pset *be_liveness_end_of_block(const be_lv_t *lv, const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *bl, pset *live);
163
164 /**
165  * Compute a set of nodes which are live at another node.
166  * BEWARE: This is the liveness immediately after the node,
167  *         so the node itself is alive but it's operands maybe not.
168  * @param arch_env The architecture environment.
169  * @param cls      The register class to consider.
170  * @param pos      The node.
171  * @param live     The set to put them into.
172  * @return live.
173  */
174 pset *be_liveness_nodes_live_at(const be_lv_t *lv, const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live);
175
176 /**
177  * Compute a set of nodes which are live at another node.
178  * BEWARE: This is the liveness immediately before the node,
179  *         so the node itself is not alive but it's operands are.
180  * @param arch_env The architecture environment.
181  * @param cls      The register class to consider.
182  * @param pos      The node.
183  * @param live     The set to put them into.
184  * @return live.
185  */
186 pset *be_liveness_nodes_live_at_input(const be_lv_t *lv, const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live);
187
188
189 /**
190  * FIXME: Need comment
191  */
192 void be_liveness_add_missing(be_lv_t *lv);
193
194 #endif /* _BELIVE_H */