2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Interblock liveness analysis.
23 * @author Sebastian Hack
27 #ifndef FIRM_BE_BELIVE_H
28 #define FIRM_BE_BELIVE_H
32 #include "firm_types.h"
35 #include "irlivechk.h"
37 #include "irnodeset.h"
47 typedef struct _be_lv_t be_lv_t;
49 typedef struct _be_lv_info_t be_lv_info_t;
52 * Compute the inter block liveness for a graph.
53 * @param irg The graph.
55 be_lv_t *be_liveness(const struct be_irg_t *birg);
58 * Check the given liveness information against a freshly computed one.
60 void be_liveness_check(be_lv_t *lv);
63 * Free the liveness information.
65 void be_liveness_free(be_lv_t *lv);
68 * Recompute the complete liveness information.
70 void be_liveness_recompute(be_lv_t *lv);
73 * Update the liveness information for a single node.
74 * It is irrelevant if there is liveness information present for the node.
75 * The liveness information for the node is firstly deleted and then recomputed.
76 * If the node is fresh and never recorded inf the liveness information before,
77 * it is more efficient to call be_liveness_introduce().
79 void be_liveness_update(be_lv_t *lv, ir_node *irn);
82 * Remove a node from the liveness information.
84 void be_liveness_remove(be_lv_t *lv, const ir_node *irn);
87 * Introduce a new node to the liveness information.
88 * The new irn is not deleted from any block's liveness information, so it must be fresh!
89 * @param lv The liveness info.
90 * @param irn The node.
92 void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
95 * Add all nodes which are missing in the current liveness data.
96 * The liveness data of the already existing nodes (in the liveness data) is not touched.
97 * @param The liveness info.
99 void be_liveness_add_missing(be_lv_t *lv);
102 * Dump the liveness information for a graph.
103 * @param f The output.
104 * @param irg The graph.
106 void be_liveness_dump(const be_lv_t *lv, FILE *f);
109 * Dump the liveness information for a graph.
110 * @param irg The graph.
111 * @param cls_name A string used as substring in the filename.
113 void be_liveness_dumpto(const be_lv_t *lv, const char *cls_name);
116 * Check, if a node is live in at a block.
117 * @param block The block.
118 * @param irn The node to check for.
119 * @return 1, if @p irn is live at the entrance of @p block, 0 if not.
121 int (be_is_live_in)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
124 * Check, if a node is live out at a block.
125 * @param block The block.
126 * @param irn The node to check for.
127 * @return 1, if @p irn is live at the exit of @p block, 0 if not.
129 int (be_is_live_out)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
132 * Check, if a node is live at the end of a block.
133 * @param block The block.
134 * @param irn The node to check for.
135 * @return 1, if @p irn is live at the end of the block, 0 if not.
137 int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
140 * Check, if the SSA dominance property is fulfilled.
141 * @param irg The graph.
142 * @return 1 if dominance property is fulfilled, 0 otherwise
144 int be_check_dominance(ir_graph *irg);
147 * The liveness transfer function.
148 * Updates a live set over a single step from a given node to its predecessor.
149 * Everything defined at the node is removed from the set, the uses of the node get inserted.
150 * @param arch_env The architecture environment.
151 * @param cls The register class to consider.
152 * @param irn The node at which liveness should be computed.
153 * @param live The set of nodes live before @p irn. This set gets modified by updating it to
154 * the nodes live after irn.
157 void be_liveness_transfer(const arch_env_t *arch_env,
158 const arch_register_class_t *cls, ir_node *node,
159 ir_nodeset_t *nodeset);
162 * Put all node live at the end of a block into a set.
163 * @param arch_env The architecture environment.
164 * @param cls The register class to consider.
165 * @param bl The block.
166 * @param live The set to put them into.
169 void be_liveness_end_of_block(const be_lv_t *lv, const arch_env_t *arch_env,
170 const arch_register_class_t *cls,
171 const ir_node *bl, ir_nodeset_t *nodeset);
174 * Compute a set of nodes which are live at another node.
175 * BEWARE: This is the liveness immediately after the node,
176 * so the node itself is alive but it's operands maybe not.
177 * @param arch_env The architecture environment.
178 * @param cls The register class to consider.
179 * @param pos The node.
180 * @param live The set to put them into.
182 void be_liveness_nodes_live_at(const be_lv_t *lv, const arch_env_t *arch_env,
183 const arch_register_class_t *cls,
184 const ir_node *pos, ir_nodeset_t *live);
187 * Compute a set of nodes which are live at another node.
188 * BEWARE: This is the liveness immediately before the node,
189 * so the node itself is not alive but it's operands are.
190 * @param arch_env The architecture environment.
191 * @param cls The register class to consider.
192 * @param pos The node.
193 * @param live The set to put them into.
195 void be_liveness_nodes_live_at_input(const be_lv_t *lv,
196 const arch_env_t *arch_env,
197 const arch_register_class_t *cls,
198 const ir_node *pos, ir_nodeset_t *live);
201 * Make sure the live sets are computed.
202 * @param lv The liveness information.
204 void be_liveness_assure_sets(be_lv_t *lv);
207 * Make sure all information needed for liveness checks is available.
208 * @param lv The liveness information.
210 void be_liveness_assure_chk(be_lv_t *lv);
213 * Invalidate the liveness information.
214 * You must call this if you modify the program and do not
215 * update the liveness with the be_liveness_{update,remove,introduce}
217 * @param lv The liveness info.
219 void be_liveness_invalidate(be_lv_t *lv);
221 #endif /* FIRM_BE_BELIVE_H */