belive.h 4.31 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

6
/**
Christian Würdig's avatar
Christian Würdig committed
7
8
9
10
 * @file
 * @brief       Interblock liveness analysis.
 * @author      Sebastian Hack
 * @date        06.12.2004
11
 */
Christian Würdig's avatar
Christian Würdig committed
12
13
14
#ifndef FIRM_BE_BELIVE_H
#define FIRM_BE_BELIVE_H

15
#include "be_types.h"
16
#include "irnodeset.h"
17

Sebastian Hack's avatar
Sebastian Hack committed
18
typedef enum {
19
20
21
22
	be_lv_state_none = 0,
	be_lv_state_in   = 1,
	be_lv_state_end  = 2,
	be_lv_state_out  = 4,
Sebastian Hack's avatar
Sebastian Hack committed
23
} be_lv_state_t;
24
ENUM_BITSET(be_lv_state_t)
Sebastian Hack's avatar
Sebastian Hack committed
25

26
27
28
29
/**
 * Compute the inter block liveness for a graph.
 * @param irg The graph.
 */
30
be_lv_t *be_liveness_new(ir_graph *irg);
Sebastian Hack's avatar
Sebastian Hack committed
31
32
33
34
35
36
37

/**
 * Free the liveness information.
 */
void be_liveness_free(be_lv_t *lv);

/**
38
 * (Re)compute the liveness information if necessary.
Sebastian Hack's avatar
Sebastian Hack committed
39
 */
40
41
42
43
44
45
46
47
48
49
50
51
52
void be_liveness_compute_sets(be_lv_t *lv);
void be_liveness_compute_chk(be_lv_t *lv);

/**
 * Invalidate the liveness information.
 * You must call this if you modify the program and do not
 * update the liveness with the be_liveness_{update,remove,introduce}
 * functions.
 * @note If changed the control flow then you must also call
 *       be_liveness_invalidate_chk()
 */
void be_liveness_invalidate_sets(be_lv_t *lv);
void be_liveness_invalidate_chk(be_lv_t *lv);
Sebastian Hack's avatar
Sebastian Hack committed
53
54
55
56

/**
 * Update the liveness information for a single node.
 * It is irrelevant if there is liveness information present for the node.
57
58
59
 * The liveness information for the node is firstly deleted and then recomputed.
 * If the node is fresh and never recorded inf the liveness information before,
 * it is more efficient to call be_liveness_introduce().
Sebastian Hack's avatar
Sebastian Hack committed
60
61
62
63
64
65
 */
void be_liveness_update(be_lv_t *lv, ir_node *irn);

/**
 * Remove a node from the liveness information.
 */
66
void be_liveness_remove(be_lv_t *lv, const ir_node *irn);
Sebastian Hack's avatar
Sebastian Hack committed
67
68
69
70
71
72
73
74

/**
 * Introduce a new node to the liveness information.
 * The new irn is not deleted from any block's liveness information, so it must be fresh!
 * @param lv The liveness info.
 * @param irn The node.
 */
void be_liveness_introduce(be_lv_t *lv, ir_node *irn);
75
76
77
78
79
80
81

/**
 * Check, if a node is live in at a block.
 * @param block The block.
 * @param irn The node to check for.
 * @return 1, if @p irn is live at the entrance of @p block, 0 if not.
 */
Sebastian Hack's avatar
Sebastian Hack committed
82
int (be_is_live_in)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
83
84
85
86
87
88
89

/**
 * Check, if a node is live out at a block.
 * @param block The block.
 * @param irn The node to check for.
 * @return 1, if @p irn is live at the exit of @p block, 0 if not.
 */
Sebastian Hack's avatar
Sebastian Hack committed
90
int (be_is_live_out)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
91

92
93
94
95
96
97
/**
 * Check, if a node is live at the end of a block.
 * @param block The block.
 * @param irn The node to check for.
 * @return 1, if @p irn is live at the end of the block, 0 if not.
 */
Sebastian Hack's avatar
Sebastian Hack committed
98
int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn);
Sebastian Hack's avatar
Sebastian Hack committed
99

Sebastian Hack's avatar
Sebastian Hack committed
100
101
102
103
104
105
106
107
108
109
/**
 * The liveness transfer function.
 * Updates a live set over a single step from a given node to its predecessor.
 * Everything defined at the node is removed from the set, the uses of the node get inserted.
 * @param cls      The register class to consider.
 * @param irn      The node at which liveness should be computed.
 * @param live     The set of nodes live before @p irn. This set gets modified by updating it to
 *                 the nodes live after irn.
 * @return live.
 */
110
void be_liveness_transfer(const arch_register_class_t *cls, ir_node *node,
111
                          ir_nodeset_t *nodeset);
112

Sebastian Hack's avatar
Sebastian Hack committed
113
114
115
116
117
118
119
/**
 * Put all node live at the end of a block into a set.
 * @param cls      The register class to consider.
 * @param bl       The block.
 * @param live     The set to put them into.
 * @return live.
 */
120
void be_liveness_end_of_block(const be_lv_t *lv,
121
122
                              const arch_register_class_t *cls,
                              const ir_node *bl, ir_nodeset_t *nodeset);
123

Matthias Braun's avatar
Matthias Braun committed
124
125
126
127
128
129
130
131
132
/**
 * Check, if two values interfere.
 * @param lv Liveness information
 * @param a The first value.
 * @param b The second value.
 * @return true, if a and b interfere, false if not.
 */
bool be_values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b);

Sebastian Hack's avatar
Sebastian Hack committed
133
/**
134
 * Compute a set of nodes which are live just before the given node.
Sebastian Hack's avatar
Sebastian Hack committed
135
136
137
138
 * @param cls      The register class to consider.
 * @param pos      The node.
 * @param live     The set to put them into.
 */
139
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);
Sebastian Hack's avatar
Sebastian Hack committed
140

141
#endif