summaryrefslogtreecommitdiffhomepage
path: root/ir/be/beuses.c
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2014-05-16 14:04:51 +0200
committerMatthias Braun <matze@braunis.de>2014-05-16 18:28:23 +0200
commit45449d34b7b0a848023391274bea523d0d605401 (patch)
tree4640d44e6f56f59bd4babcfdf2fb54d401f372f4 /ir/be/beuses.c
parent4fb44f3d169029f44aa184f3b37f717bee04514f (diff)
cleanup, use C99
Diffstat (limited to 'ir/be/beuses.c')
-rw-r--r--ir/be/beuses.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/ir/be/beuses.c b/ir/be/beuses.c
index a0f82b2..ede56b9 100644
--- a/ir/be/beuses.c
+++ b/ir/be/beuses.c
@@ -35,23 +35,24 @@
#define UNKNOWN_OUTERMOST_LOOP ((unsigned)-1)
+DEBUG_ONLY(static firm_dbg_module_t *dbg;)
+
typedef struct be_use_t {
const ir_node *block;
const ir_node *node;
- unsigned outermost_loop;
- unsigned next_use;
- ir_visited_t visited;
+ unsigned outermost_loop;
+ unsigned next_use;
+ ir_visited_t visited;
} be_use_t;
/**
* The "uses" environment.
*/
struct be_uses_t {
- set *uses; /**< cache: contains all computed uses so far. */
- ir_graph *irg; /**< the graph for this environment. */
- const be_lv_t *lv; /**< the liveness for the graph. */
- ir_visited_t visited_counter; /**< current search counter. */
- DEBUG_ONLY(firm_dbg_module_t *dbg; /**< debug module for debug messages. */)
+ set *uses; /**< cache: contains all computed uses so far. */
+ ir_graph *irg; /**< the graph for this environment. */
+ const be_lv_t *lv; /**< the liveness for the graph. */
+ ir_visited_t visited_counter; /**< current search counter. */
};
/**
@@ -59,7 +60,7 @@ struct be_uses_t {
*/
static int cmp_use(const void *a, const void *b, size_t n)
{
- (void) n;
+ (void)n;
const be_use_t *p = (const be_use_t*)a;
const be_use_t *q = (const be_use_t*)b;
return p->block != q->block || p->node != q->node;
@@ -84,26 +85,26 @@ static const be_use_t *get_or_set_use_block(be_uses_t *env,
temp.block = block;
temp.node = def;
- unsigned hash = hash_combine(hash_irn(block), hash_irn(def));
+ unsigned hash = hash_combine(hash_irn(block), hash_irn(def));
be_use_t *result = set_find(be_use_t, env->uses, &temp, sizeof(temp), hash);
if (result == NULL) {
// insert templ first as we might end in a loop in the get_next_use
// call otherwise
- temp.next_use = USES_INFINITY;
+ temp.next_use = USES_INFINITY;
temp.outermost_loop = UNKNOWN_OUTERMOST_LOOP;
- temp.visited = 0;
+ temp.visited = 0;
result = set_insert(be_use_t, env->uses, &temp, sizeof(temp), hash);
}
if (result->outermost_loop == UNKNOWN_OUTERMOST_LOOP
- && result->visited < env->visited_counter) {
+ && result->visited < env->visited_counter) {
result->visited = env->visited_counter;
be_next_use_t next_use = get_next_use(env, sched_first(block), def, 0);
if (next_use.outermost_loop != UNKNOWN_OUTERMOST_LOOP) {
- result->next_use = next_use.time;
+ result->next_use = next_use.time;
result->outermost_loop = next_use.outermost_loop;
- DBG((env->dbg, LEVEL_5, "Setting nextuse of %+F in block %+F to %u (outermostloop %d)\n",
+ DBG((dbg, LEVEL_5, "Setting nextuse of %+F in block %+F to %u (outermostloop %d)\n",
def, block, result->next_use, result->outermost_loop));
}
}
@@ -121,15 +122,15 @@ static const be_use_t *get_or_set_use_block(be_uses_t *env,
* @return non-zero if the value is used in the given block as a Phi argument
* in one of its successor blocks.
*/
-static int be_is_phi_argument(const ir_node *block, const ir_node *def)
+static bool be_is_phi_argument(const ir_node *block, const ir_node *def)
{
if (get_irn_n_edges_kind(block, EDGE_KIND_BLOCK) < 1)
- return 0;
+ return false;
ir_node *const succ_block = get_first_block_succ(block);
if (get_Block_n_cfgpreds(succ_block) <= 1) {
/* no Phis in the successor */
- return 0;
+ return false;
}
/* find the index of block in its successor */
@@ -145,10 +146,10 @@ static int be_is_phi_argument(const ir_node *block, const ir_node *def)
const ir_node *arg = get_irn_n(node, i);
if (arg == def)
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/**
@@ -188,7 +189,6 @@ static be_next_use_t get_next_use(be_uses_t *env, ir_node *from,
ir_node *block = get_nodes_block(from);
foreach_out_edge(def, edge) {
ir_node *node = get_edge_src_irn(edge);
-
if (is_Anchor(node))
continue;
if (get_nodes_block(node) != block)
@@ -230,27 +230,25 @@ static be_next_use_t get_next_use(be_uses_t *env, ir_node *from,
be_next_use_t result;
result.before = NULL;
- ir_loop *loop = get_irn_loop(block);
- unsigned loopdepth = get_loop_depth(loop);
- bool found_visited = false;
- bool found_use = false;
- unsigned outermost_loop = loopdepth;
- unsigned next_use = USES_INFINITY;
+ ir_loop *loop = get_irn_loop(block);
+ unsigned loopdepth = get_loop_depth(loop);
+ bool found_visited = false;
+ bool found_use = false;
+ unsigned outermost_loop = loopdepth;
+ unsigned next_use = USES_INFINITY;
foreach_block_succ(block, edge) {
const ir_node *succ_block = get_edge_src_irn(edge);
- DBG((env->dbg, LEVEL_5,
- "Checking succ of block %+F: %+F (for use of %+F)\n", block,
- succ_block, def));
+ DBG((dbg, LEVEL_5, "Checking succ of block %+F: %+F (for use of %+F)\n",
+ block, succ_block, def));
if (!be_is_live_in(env->lv, succ_block, def)) {
//next_use = USES_INFINITY;
- DBG((env->dbg, LEVEL_5, " not live in\n"));
+ DBG((dbg, LEVEL_5, " not live in\n"));
continue;
}
const be_use_t *use = get_or_set_use_block(env, succ_block, def);
- DBG((env->dbg, LEVEL_5,
- "Found %u (loopdepth %u) (we're in block %+F)\n", use->next_use,
- use->outermost_loop, block));
+ DBG((dbg, LEVEL_5, "Found %u (loopdepth %u) (we're in block %+F)\n",
+ use->next_use, use->outermost_loop, block));
if (USES_IS_INFINITE(use->next_use)) {
if (use->outermost_loop == UNKNOWN_OUTERMOST_LOOP) {
found_visited = true;
@@ -264,7 +262,7 @@ static be_next_use_t get_next_use(be_uses_t *env, ir_node *from,
ir_loop *succ_loop = get_irn_loop(succ_block);
if (get_loop_depth(succ_loop) < loopdepth) {
unsigned factor = (loopdepth - get_loop_depth(succ_loop)) * 5000;
- DBG((env->dbg, LEVEL_5,
+ DBG((dbg, LEVEL_5,
"Increase usestep because of loop out edge %d -> %d (%u)\n",
factor));
// TODO we should use the number of nodes in the loop or so...
@@ -289,7 +287,8 @@ static be_next_use_t get_next_use(be_uses_t *env, ir_node *from,
// generally correct, so mark it
result.outermost_loop = UNKNOWN_OUTERMOST_LOOP;
}
- DBG((env->dbg, LEVEL_5, "Result: %d (outerloop: %u)\n", result.time, result.outermost_loop));
+ DBG((dbg, LEVEL_5, "Result: %d (outerloop: %u)\n", result.time,
+ result.outermost_loop));
return result;
}
@@ -309,7 +308,7 @@ be_next_use_t be_get_next_use(be_uses_t *env, ir_node *from,
*/
static void set_sched_step_walker(ir_node *block, void *data)
{
- (void) data;
+ (void)data;
unsigned step = 0;
sched_foreach(block, node) {
@@ -322,17 +321,17 @@ static void set_sched_step_walker(ir_node *block, void *data)
be_uses_t *be_begin_uses(ir_graph *irg, const be_lv_t *lv)
{
+ FIRM_DBG_REGISTER(dbg, "firm.be.uses");
+
assure_edges(irg);
/* precalculate sched steps */
irg_block_walk_graph(irg, set_sched_step_walker, NULL, NULL);
- be_uses_t *env = XMALLOC(be_uses_t);
+ be_uses_t *env = XMALLOCZ(be_uses_t);
env->uses = new_set(cmp_use, 512);
- env->irg = irg;
- env->lv = lv;
- env->visited_counter = 0;
- FIRM_DBG_REGISTER(env->dbg, "firm.be.uses");
+ env->irg = irg;
+ env->lv = lv;
return env;
}