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
26 #ifndef FIRM_BE_BELIVE_H
27 #define FIRM_BE_BELIVE_H
33 #include "firm_types.h"
36 #include "irlivechk.h"
38 #include "irnodeset.h"
47 * Compute the inter block liveness for a graph.
48 * @param irg The graph.
50 be_lv_t *be_liveness_new(ir_graph *irg);
53 * Free the liveness information.
55 void be_liveness_free(be_lv_t *lv);
58 * (Re)compute the liveness information if necessary.
60 void be_liveness_compute_sets(be_lv_t *lv);
61 void be_liveness_compute_chk(be_lv_t *lv);
64 * Invalidate the liveness information.
65 * You must call this if you modify the program and do not
66 * update the liveness with the be_liveness_{update,remove,introduce}
68 * @note If changed the control flow then you must also call
69 * be_liveness_invalidate_chk()
71 void be_liveness_invalidate_sets(be_lv_t *lv);
72 void be_liveness_invalidate_chk(be_lv_t *lv);
75 * Update the liveness information for a single node.
76 * It is irrelevant if there is liveness information present for the node.
77 * The liveness information for the node is firstly deleted and then recomputed.
78 * If the node is fresh and never recorded inf the liveness information before,
79 * it is more efficient to call be_liveness_introduce().
81 void be_liveness_update(be_lv_t *lv, ir_node *irn);
84 * Remove a node from the liveness information.
86 void be_liveness_remove(be_lv_t *lv, const ir_node *irn);
89 * Introduce a new node to the liveness information.
90 * The new irn is not deleted from any block's liveness information, so it must be fresh!
91 * @param lv The liveness info.
92 * @param irn The node.
94 void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
97 * Add all nodes which are missing in the current liveness data.
98 * The liveness data of the already existing nodes (in the liveness data) is not touched.
99 * @param The liveness info.
101 void be_liveness_add_missing(be_lv_t *lv);
104 * Check, if a node is live in at a block.
105 * @param block The block.
106 * @param irn The node to check for.
107 * @return 1, if @p irn is live at the entrance of @p block, 0 if not.
109 int (be_is_live_in)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
112 * Check, if a node is live out at a block.
113 * @param block The block.
114 * @param irn The node to check for.
115 * @return 1, if @p irn is live at the exit of @p block, 0 if not.
117 int (be_is_live_out)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
120 * Check, if a node is live at the end of a block.
121 * @param block The block.
122 * @param irn The node to check for.
123 * @return 1, if @p irn is live at the end of the block, 0 if not.
125 int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
128 * The liveness transfer function.
129 * Updates a live set over a single step from a given node to its predecessor.
130 * Everything defined at the node is removed from the set, the uses of the node get inserted.
131 * @param cls The register class to consider.
132 * @param irn The node at which liveness should be computed.
133 * @param live The set of nodes live before @p irn. This set gets modified by updating it to
134 * the nodes live after irn.
137 void be_liveness_transfer(const arch_register_class_t *cls, ir_node *node,
138 ir_nodeset_t *nodeset);
141 * Put all node live at the end of a block into a set.
142 * @param cls The register class to consider.
143 * @param bl The block.
144 * @param live The set to put them into.
147 void be_liveness_end_of_block(const be_lv_t *lv,
148 const arch_register_class_t *cls,
149 const ir_node *bl, ir_nodeset_t *nodeset);
152 * Compute a set of nodes which are live at another node.
153 * BEWARE: This is the liveness immediately after the node,
154 * so the node itself is alive but its operands maybe not.
155 * @param cls The register class to consider.
156 * @param pos The node.
157 * @param live The set to put them into.
159 void be_liveness_nodes_live_at(const be_lv_t *lv,
160 const arch_register_class_t *cls,
161 const ir_node *pos, ir_nodeset_t *live);