* @brief Extended basis block support.
* @author Michael Beck
* @date 5.2005
- * @version $Id$
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
#include "irextbb_t.h"
#include "irgwalk.h"
#include "xmalloc.h"
#include "irprintf.h"
-typedef struct _env {
+/**
+ * Environment for extbb construction.
+ */
+typedef struct env {
struct obstack *obst; /**< the obstack where allocations took place */
ir_extblk *head; /**< head of the list of all extended blocks */
ir_node *start_block; /**< the start block of the current graph */
} env_t;
-int (is_ir_extbb)(const void *thing) {
+int (is_ir_extbb)(const void *thing)
+{
return _is_ir_extbb(thing);
}
/**
* allocate a new extended block header.
*/
-static void allocate_extblk(ir_node *block, env_t *env) {
- ir_extblk *extblk = obstack_alloc(env->obst, sizeof(*extblk));
+static void allocate_extblk(ir_node *block, env_t *env)
+{
+ ir_extblk *extblk = OALLOC(env->obst, ir_extblk);
extblk->kind = k_ir_extblk;
extblk->visited = 1;
* Returns the number of block successors.
* we are interested only in 1, 2 and >2.
*/
-static int get_block_n_succs(ir_node *block) {
+static int get_block_n_succs(ir_node *block)
+{
if (edges_activated(current_ir_graph)) {
const ir_edge_t *edge;
/**
* Pre block-walker. Calculates the extended block info.
*/
-static void pre_walk_calc_extbb(ir_node *block, void *ctx) {
+static void pre_walk_calc_extbb(ir_node *block, void *ctx)
+{
int n = get_Block_n_cfgpreds(block);
- env_t *env = ctx;
+ env_t *env = (env_t*) ctx;
if (n <= 0 || n > 1 || block == env->start_block) {
/*
*/
ir_node *cf_op = skip_Proj(get_Block_cfgpred(block, 0));
- if (irn_not_visited(cf_op)) {
+ if (!irn_visited_else_mark(cf_op)) {
ir_node *pred_bl = get_nodes_block(cf_op);
if (get_block_n_succs(pred_bl) > 2) {
/* More than two successors means we have a jump table.
*/
set_Block_extbb(block, NULL);
}
- mark_irn_visited(cf_op);
} else {
/* already marked, so begin a new extended block here */
allocate_extblk(block, env);
static void post_walk_calc_extbb(ir_node *block, void *ctx)
{
ir_extblk *extbb = get_Block_extbb(block);
- env_t *env = ctx;
+ env_t *env = (env_t*) ctx;
ir_extblk *sentinel = &_sentinel;
if (! extbb) {
/* replace all sentinels by the extbb info */
prev = block;
list = NULL;
- while (1) {
+ for (;;) {
if (get_Block_extbb(prev) != sentinel)
break;
set_irn_link(prev, list);
}
/* arg, the list is in wrong order, turn around and add to the extbb list */
for (curr = list; curr; curr = prev) {
- prev = get_irn_link(curr);
+ prev = (ir_node*) get_irn_link(curr);
set_irn_link(curr, extbb->link);
extbb->link = curr;
set_Block_extbb(curr, extbb);
}
}
-/*
- * Compute the extended basic blocks for a graph
- */
-void compute_extbb(ir_graph *irg) {
+void compute_extbb(ir_graph *irg)
+{
env_t env;
ir_extblk *extbb, *next;
extbb->blks = NEW_ARR_D(ir_node *, env.obst, len);
- for (block = extbb->link, i = 0; i < len; ++i) {
- ir_node *nblock = get_irn_link(block);
+ for (block = (ir_node*) extbb->link, i = 0; i < len; ++i) {
+ ir_node *nblock = (ir_node*) get_irn_link(block);
/* ensure that the leader is the first one */
extbb->blks[len - 1 - i] = block;
extbb->visited = 0;
}
- irg->extblk_state = extblk_valid;
+ set_irg_state(irg, IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS);
}
-/* free all extended block info. */
-void free_extbb(ir_graph *irg) {
+void free_extbb(ir_graph *irg)
+{
if (irg->extbb_obst) {
obstack_free(irg->extbb_obst, NULL);
xfree(irg->extbb_obst);
irg->extbb_obst = NULL;
}
- irg->extblk_state = extblk_none;
+ clear_irg_state(irg, IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS);
}
-/* Return the extended block of a node. */
-ir_extblk *get_nodes_extbb(ir_node *node) {
- ir_node *block = is_Block(node) ? node : get_irn_n(node, -1);
+ir_extblk *get_nodes_extbb(const ir_node *node)
+{
+ const ir_node *block = is_Block(node) ? node : get_nodes_block(node);
return get_Block_extbb(block);
}
-/* Gets the visited counter of an extended block. */
-ir_visited_t (get_extbb_visited)(const ir_extblk *blk) {
+ir_visited_t (get_extbb_visited)(const ir_extblk *blk)
+{
return _get_extbb_visited(blk);
}
-/* Sets the visited counter of an extended block. */
-void (set_extbb_visited)(ir_extblk *blk, ir_visited_t visited) {
+void (set_extbb_visited)(ir_extblk *blk, ir_visited_t visited)
+{
_set_extbb_visited(blk, visited);
}
-/* Mark an extended block as visited in a graph. */
-void (mark_extbb_visited)(ir_extblk *blk) {
+void (mark_extbb_visited)(ir_extblk *blk)
+{
_mark_extbb_visited(blk);
}
-/* Returns non-zero if an extended was visited. */
-int (extbb_visited)(const ir_extblk *blk) {
+int (extbb_visited)(const ir_extblk *blk)
+{
return _extbb_visited(blk);
}
-/* Returns non-zero if an extended block was NOT visited. */
-int (extbb_not_visited)(const ir_extblk *blk) {
+int (extbb_not_visited)(const ir_extblk *blk)
+{
return _extbb_not_visited(blk);
}
-/* Returns the link field of an extended block. */
-void *(get_extbb_link)(const ir_extblk *blk) {
+void *(get_extbb_link)(const ir_extblk *blk)
+{
return _get_extbb_link(blk);
}
-/* Sets the link field of an extended block. */
-void (set_extbb_link)(ir_extblk *blk, void *link) {
+void (set_extbb_link)(ir_extblk *blk, void *link)
+{
_set_extbb_link(blk, link);
}
-/* Return the number of basic blocks of an extended block */
-int (get_extbb_n_blocks)(const ir_extblk *blk) {
+int (get_extbb_n_blocks)(const ir_extblk *blk)
+{
return _get_extbb_n_blocks(blk);
}
-/* Return the i'th basic block of an extended block */
-ir_node *(get_extbb_block)(ir_extblk *blk, int pos) {
+ir_node *(get_extbb_block)(const ir_extblk *blk, int pos)
+{
return _get_extbb_block(blk, pos);
}
-/* Return the leader basis block of an extended block. */
-ir_node *(get_extbb_leader)(ir_extblk *blk) {
+ir_node *(get_extbb_leader)(const ir_extblk *blk)
+{
return _get_extbb_leader(blk);
}
-/* Return the node number of an extended block. */
-long get_extbb_node_nr(ir_extblk *blk) {
+long get_extbb_node_nr(const ir_extblk *blk)
+{
return get_irn_node_nr(get_extbb_leader(blk));
}
-static void irg_extblock_walk_2(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env) {
+static void irg_extblock_walk_2(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env)
+{
int i;
ir_node *node;
}
}
-/* walks only over extended Block nodes in the graph. Has it's own visited
- flag, so that it can be interleaved with the other walker. */
-void irg_extblock_walk(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env) {
+void irg_extblock_walk(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env)
+{
ir_node *pred, *start_bl = get_irg_start_block(current_ir_graph);
ir_extblk *start_blk = get_Block_extbb(start_bl);
int i;
pre(start_blk, env);
}
-/* Walks only over reachable Extended Basic Block nodes in the graph. */
-void irg_extblock_walk_graph(ir_graph *irg, extbb_walk_func *pre, extbb_walk_func *post, void *env) {
+void irg_extblock_walk_graph(ir_graph *irg, extbb_walk_func *pre, extbb_walk_func *post, void *env)
+{
ir_node *endbl = get_irg_end_block(irg);
ir_extblk *blk = get_Block_extbb(endbl);
ir_graph *rem = current_ir_graph;