Commit 23b71aba authored by Daniel Grund's avatar Daniel Grund
Browse files

Added clique walker

parent 000b44d4
......@@ -37,6 +37,12 @@ size_t (be_ifg_neighbours_iter_size)(const void *self)
return ifg->impl->neighbours_iter_size;
}
size_t (be_ifg_cliques_iter_size)(const void *self)
{
const be_ifg_t *ifg = self;
return ifg->impl->cliques_iter_size;
}
void (be_ifg_free)(void *self)
{
be_ifg_t *ifg = self;
......@@ -85,6 +91,24 @@ void (be_ifg_nodes_break)(const void *self, void *iter)
ifg->impl->nodes_break(self, iter);
}
int (be_ifg_cliques_begin)(const void *self, void *iter, ir_node **buf)
{
const be_ifg_t *ifg = self;
return ifg->impl->cliques_begin(self, iter, buf);
}
int (be_ifg_cliques_next)(const void *self, void *iter, ir_node **buf)
{
const be_ifg_t *ifg = self;
return ifg->impl->cliques_next(self, iter, buf);
}
void (be_ifg_cliques_break)(const void *self, void *iter)
{
const be_ifg_t *ifg = self;
ifg->impl->cliques_break(self, iter);
}
int (be_ifg_degree)(const void *self, const ir_node *irn)
{
const be_ifg_t *ifg = self;
......
......@@ -17,6 +17,7 @@ typedef struct _be_ifg_t be_ifg_t;
#define be_ifg_nodes_iter_alloca(self) (alloca(be_ifg_nodes_iter_size(self)))
#define be_ifg_neighbours_iter_alloca(self) (alloca(be_ifg_neighbours_iter_size(self)))
#define be_ifg_cliques_iter_alloca(self) (alloca(be_ifg_cliques_iter_size(self)))
size_t (be_ifg_nodes_iter_size)(const void *self);
size_t (be_ifg_neighbours_iter_size)(const void *self);
......@@ -28,6 +29,9 @@ void (be_ifg_neighbours_break)(const void *self, void *iter);
ir_node *(be_ifg_nodes_begin)(const void *self, void *iter);
ir_node *(be_ifg_nodes_next)(const void *self, void *iter);
void (be_ifg_nodes_break)(const void *self, void *iter);
int (be_ifg_cliques_begin)(const void *self, void *iter, ir_node **buf);
int (be_ifg_cliques_next)(const void *self, void *iter);
void (be_ifg_cliques_break)(const void *self, void *iter);
int (be_ifg_degree)(const void *self, const ir_node *irn);
#define be_ifg_foreach_neighbour(self, iter, irn, pos) \
......@@ -36,4 +40,9 @@ int (be_ifg_degree)(const void *self, const ir_node *irn);
#define be_ifg_foreach_node(self, iter, pos) \
for(pos = be_ifg_nodes_begin(self, iter); (pos); pos = be_ifg_nodes_next(self, iter))
#define be_ifg_foreach_clique(self, iter, buf, count) \
for(*(count) = be_ifg_cliques_begin(self, iter, buf); \
*(count) != -1 ; \
*(count) = be_ifg_cliques_next(self, iter))
#endif /* _BEIFG_H */
......@@ -200,6 +200,117 @@ static void ifg_std_neighbours_break(const void *self, void *iter)
neighbours_break(iter, 1);
}
typedef struct _cliques_iter_t {
struct obstack ob;
const be_chordal_env_t *cenv;
ir_node **buf;
ir_node **blocks;
int n_blocks, blk;
struct list_head *bor;
pset *living;
} cliques_iter_t;
static INLINE void free_clique_iter(cliques_iter_t *it) {
it->n_blocks = -1;
obstack_free(&it->ob, NULL);
del_pset(it->living);
}
static void get_blocks_dom_order(ir_node *blk, void *env) {
cliques_iter_t *it = env;
obstack_ptr_grow(&it->ob, blk);
}
#define pset_foreach(pset, irn) for(irn=pset_first(pset); irn; irn=pset_next(pset))
/**
* NOTE: Be careful when changing this function!
* First understand the control flow of consecutive calls.
*/
static INLINE int get_next_clique(cliques_iter_t *it) {
/* continue in the block we left the last time */
for (; it->blk < it->n_blocks; it->blk++) {
int output_on_shrink = 0;
struct list_head *head = get_block_border_head(it->cenv, it->blocks[it->blk]);
/* on entry to a new block set the first border ...
if (!it->bor)
it->bor = head->prev;
/* ... otherwise continue with the border we left the last time */
for (; it->bor != head; it->bor = it->bor->prev) {
border_t *b = list_entry(it->bor, border_t, list);
/* if its a definition irn starts living */
if (b->is_def) {
pset_insert_ptr(it->living, b->irn);
if (b->is_real)
output_on_shrink = 1;
} else
/* if its the last usage the irn dies */
{
/* before shrinking the set, return the current maximal clique */
if (output_on_shrink) {
int count = 0;
ir_node *irn;
/* fill the output buffer */
pset_foreach(it->living, irn)
it->buf[count++] = irn;
assert(count > 0 && "We have a 'last usage', so there must be sth. in it->living");
return count;
}
pset_remove_ptr(it->living, b->irn);
}
}
it->bor = NULL;
assert(0 == pset_count(it->living) && "Something has survived! (At the end of the block it->living must be empty)");
}
if (it->n_blocks != -1)
free_clique_iter(it);
return -1;
}
static int ifg_std_cliques_begin(const void *self, void *iter, ir_node **buf)
{
const ifg_std_t *ifg = self;
cliques_iter_t *it = iter;
ir_node *start_bl = get_irg_start_block(it->cenv->irg);
obstack_init(&it->ob);
dom_tree_walk(start_bl, get_blocks_dom_order, NULL, it);
it->cenv = ifg->env;
it->buf = buf;
it->n_blocks = obstack_object_size(&it->ob) / sizeof(void *);
it->blocks = obstack_finish(&it->ob);
it->blk = 0;
it->bor = NULL;
it->living = pset_new_ptr(2 * arch_register_class_n_regs(it->cenv->cls));
return get_next_clique(it);
}
static int ifg_std_cliques_next(const void *self, void *iter)
{
return get_next_clique(iter);
}
static void ifg_std_cliques_break(const void *self, void *iter)
{
free_clique_iter(iter);
}
static int ifg_std_degree(const void *self, const ir_node *irn)
{
adj_iter_t it;
......@@ -213,6 +324,7 @@ static int ifg_std_degree(const void *self, const ir_node *irn)
static const be_ifg_impl_t ifg_std_impl = {
sizeof(nodes_iter_t),
sizeof(adj_iter_t),
sizeof(cliques_iter_t),
ifg_std_free,
ifg_std_connected,
......@@ -222,6 +334,9 @@ static const be_ifg_impl_t ifg_std_impl = {
ifg_std_nodes_begin,
ifg_std_nodes_next,
ifg_std_nodes_break,
ifg_std_cliques_begin,
ifg_std_cliques_next,
ifg_std_cliques_break,
ifg_std_degree
};
......
......@@ -13,6 +13,7 @@
struct _be_ifg_impl_t {
size_t nodes_iter_size;
size_t neighbours_iter_size;
size_t cliques_iter_size;
void (*free)(void *self);
int (*connected)(const void *self, const ir_node *a, const ir_node *b);
......@@ -25,6 +26,10 @@ struct _be_ifg_impl_t {
ir_node *(*nodes_next)(const void *self, void *iter);
void (*nodes_break)(const void *self, void *iter);
int (*cliques_begin)(const void *self, void *iter, ir_node **buf);
int (*cliques_next)(const void *self, void *iter);
void (*cliques_break)(const void *self, void *iter);
int (*degree)(const void *self, const ir_node *irn);
};
......@@ -45,6 +50,9 @@ struct _be_ifg_t {
#define be_ifg_nodes_begin(self, iter) ((self)->impl->nodes_begin(self, iter))
#define be_ifg_nodes_next(self, iter) ((self)->impl->nodes_next(self, iter))
#define be_ifg_nodes_break(self, iter) ((self)->impl->nodes_break(self, iter))
#define be_ifg_cliques_begin(self, iter, buf) ((self)->impl->cliques_begin(self, iter, buf))
#define be_ifg_cliques_next(self, iter) ((self)->impl->cliques_next(self, iter))
#define be_ifg_cliques_break(self, iter) ((self)->impl->cliques_break(self, iter))
#define be_ifg_degree(self,irn) ((self)->impl->degree(self, irn))
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment