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