be: rework op_attr handling
[libfirm] / ir / be / belive.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       Interblock liveness analysis.
23  * @author      Sebastian Hack
24  * @date        06.12.2004
25  */
26 #ifndef FIRM_BE_BELIVE_H
27 #define FIRM_BE_BELIVE_H
28
29 #include <stdio.h>
30
31 #include "be_types.h"
32
33 #include "firm_types.h"
34 #include "pset.h"
35
36 #include "irlivechk.h"
37 #include "bearch.h"
38 #include "irnodeset.h"
39
40 typedef enum {
41         be_lv_state_in  = 1,
42         be_lv_state_end = 2,
43         be_lv_state_out = 4,
44 } be_lv_state_t;
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  * Free the liveness information.
54  */
55 void be_liveness_free(be_lv_t *lv);
56
57 /**
58  * Recompute the complete liveness information.
59  */
60 void be_liveness_recompute(be_lv_t *lv);
61
62 /**
63  * Update the liveness information for a single node.
64  * It is irrelevant if there is liveness information present for the node.
65  * The liveness information for the node is firstly deleted and then recomputed.
66  * If the node is fresh and never recorded inf the liveness information before,
67  * it is more efficient to call be_liveness_introduce().
68  */
69 void be_liveness_update(be_lv_t *lv, ir_node *irn);
70
71 /**
72  * Remove a node from the liveness information.
73  */
74 void be_liveness_remove(be_lv_t *lv, const ir_node *irn);
75
76 /**
77  * Introduce a new node to the liveness information.
78  * The new irn is not deleted from any block's liveness information, so it must be fresh!
79  * @param lv The liveness info.
80  * @param irn The node.
81  */
82 void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
83
84 /**
85  * Add all nodes which are missing in the current liveness data.
86  * The liveness data of the already existing nodes (in the liveness data) is not touched.
87  * @param The liveness info.
88  */
89 void be_liveness_add_missing(be_lv_t *lv);
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  * The liveness transfer function.
117  * Updates a live set over a single step from a given node to its predecessor.
118  * Everything defined at the node is removed from the set, the uses of the node get inserted.
119  * @param cls      The register class to consider.
120  * @param irn      The node at which liveness should be computed.
121  * @param live     The set of nodes live before @p irn. This set gets modified by updating it to
122  *                 the nodes live after irn.
123  * @return live.
124  */
125 void be_liveness_transfer(const arch_register_class_t *cls, ir_node *node,
126                           ir_nodeset_t *nodeset);
127
128 /**
129  * Put all node live at the end of a block into a set.
130  * @param cls      The register class to consider.
131  * @param bl       The block.
132  * @param live     The set to put them into.
133  * @return live.
134  */
135 void be_liveness_end_of_block(const be_lv_t *lv,
136                               const arch_register_class_t *cls,
137                               const ir_node *bl, ir_nodeset_t *nodeset);
138
139 /**
140  * Compute a set of nodes which are live at another node.
141  * BEWARE: This is the liveness immediately after the node,
142  *         so the node itself is alive but its operands maybe not.
143  * @param cls      The register class to consider.
144  * @param pos      The node.
145  * @param live     The set to put them into.
146  */
147 void be_liveness_nodes_live_at(const be_lv_t *lv,
148                                const arch_register_class_t *cls,
149                                const ir_node *pos, ir_nodeset_t *live);
150
151 /**
152  * Make sure the live sets are computed.
153  * @param lv The liveness information.
154  */
155 void be_liveness_assure_sets(be_lv_t *lv);
156
157 /**
158  * Make sure all information needed for liveness checks is available.
159  * @param lv The liveness information.
160  */
161 void be_liveness_assure_chk(be_lv_t *lv);
162
163 /**
164  * Invalidate the liveness information.
165  * You must call this if you modify the program and do not
166  * update the liveness with the be_liveness_{update,remove,introduce}
167  * functions.
168  * @param lv The liveness info.
169  */
170 void be_liveness_invalidate(be_lv_t *lv);
171
172 #endif /* FIRM_BE_BELIVE_H */