2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Interblock liveness analysis.
9 * @author Sebastian Hack
12 #ifndef FIRM_BE_BELIVE_H
13 #define FIRM_BE_BELIVE_H
16 #include "irnodeset.h"
24 ENUM_BITSET(be_lv_state_t)
27 * Compute the inter block liveness for a graph.
28 * @param irg The graph.
30 be_lv_t *be_liveness_new(ir_graph *irg);
33 * Free the liveness information.
35 void be_liveness_free(be_lv_t *lv);
38 * (Re)compute the liveness information if necessary.
40 void be_liveness_compute_sets(be_lv_t *lv);
41 void be_liveness_compute_chk(be_lv_t *lv);
44 * Invalidate the liveness information.
45 * You must call this if you modify the program and do not
46 * update the liveness with the be_liveness_{update,remove,introduce}
48 * @note If changed the control flow then you must also call
49 * be_liveness_invalidate_chk()
51 void be_liveness_invalidate_sets(be_lv_t *lv);
52 void be_liveness_invalidate_chk(be_lv_t *lv);
55 * Update the liveness information for a single node.
56 * It is irrelevant if there is liveness information present for the node.
57 * The liveness information for the node is firstly deleted and then recomputed.
58 * If the node is fresh and never recorded inf the liveness information before,
59 * it is more efficient to call be_liveness_introduce().
61 void be_liveness_update(be_lv_t *lv, ir_node *irn);
64 * Remove a node from the liveness information.
66 void be_liveness_remove(be_lv_t *lv, const ir_node *irn);
69 * Introduce a new node to the liveness information.
70 * The new irn is not deleted from any block's liveness information, so it must be fresh!
71 * @param lv The liveness info.
72 * @param irn The node.
74 void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
77 * Check, if a node is live in at a block.
78 * @param block The block.
79 * @param irn The node to check for.
80 * @return 1, if @p irn is live at the entrance of @p block, 0 if not.
82 int (be_is_live_in)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
85 * Check, if a node is live out at a block.
86 * @param block The block.
87 * @param irn The node to check for.
88 * @return 1, if @p irn is live at the exit of @p block, 0 if not.
90 int (be_is_live_out)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
93 * Check, if a node is live at the end of a block.
94 * @param block The block.
95 * @param irn The node to check for.
96 * @return 1, if @p irn is live at the end of the block, 0 if not.
98 int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
101 * The liveness transfer function.
102 * Updates a live set over a single step from a given node to its predecessor.
103 * Everything defined at the node is removed from the set, the uses of the node get inserted.
104 * @param cls The register class to consider.
105 * @param irn The node at which liveness should be computed.
106 * @param live The set of nodes live before @p irn. This set gets modified by updating it to
107 * the nodes live after irn.
110 void be_liveness_transfer(const arch_register_class_t *cls, ir_node *node,
111 ir_nodeset_t *nodeset);
114 * Put all node live at the end of a block into a set.
115 * @param cls The register class to consider.
116 * @param bl The block.
117 * @param live The set to put them into.
120 void be_liveness_end_of_block(const be_lv_t *lv,
121 const arch_register_class_t *cls,
122 const ir_node *bl, ir_nodeset_t *nodeset);
125 * Compute a set of nodes which are live just before the given node.
126 * @param cls The register class to consider.
127 * @param pos The node.
128 * @param live The set to put them into.
130 void be_liveness_nodes_live_before(be_lv_t const *lv, arch_register_class_t const *cls, ir_node const *pos, ir_nodeset_t *live);