Commit e30e5834 authored by Matthias Braun's avatar Matthias Braun
Browse files

introduce more generic resource reservation debug helpers instead of old set_using_xxxx functions

[r21148]
parent 6af5001a
......@@ -512,31 +512,22 @@ void set_irg_block_visited(ir_graph *irg, unsigned long i);
* if 2 parties try to use the flags.
*/
#ifndef NDEBUG
void set_using_block_visited(ir_graph *irg);
void clear_using_block_visited(ir_graph *irg);
int using_block_visited(const ir_graph *irg);
void set_using_irn_visited(ir_graph *irg);
void clear_using_irn_visited(ir_graph *irg);
int using_irn_visited(const ir_graph *irg);
void set_using_irn_link(ir_graph *irg);
void clear_using_irn_link(ir_graph *irg);
int using_irn_link(const ir_graph *irg);
void set_using_block_mark(ir_graph *irg);
void clear_using_block_mark(ir_graph *irg);
int using_block_mark(const ir_graph *irg);
enum ir_resources_enum_t {
IR_RESOURCE_BLOCK_VISITED = 1 << 0,
IR_RESOURCE_BLOCK_MARK = 1 << 1,
IR_RESOURCE_IRN_VISITED = 1 << 2,
IR_RESOURCE_IRN_LINK = 1 << 3,
IR_RESOURCE_LOOP_LINK = 1 << 4,
};
typedef unsigned ir_resources_t;
void ir_reserve_resources(ir_graph *irg, ir_resources_t resources);
void ir_free_resources(ir_graph *irg, ir_resources_t resources);
ir_resources_t ir_resources_reserved(const ir_graph *irg);
#else
#define set_using_block_visited(irg)
#define clear_using_block_visited(irg)
#define using_block_visited(irg) 0
#define set_using_irn_visited(irg)
#define clear_using_irn_visited(irg)
#define using_irn_visited(irg) 0
#define set_using_irn_link(irg)
#define clear_using_irn_link(irg)
#define using_irn_link(irg) 0
#define set_using_block_mark(irg)
#define clear_using_block_mark(irg)
#define using_block_mark(irg) 0
#define ir_reserve_resources(irg,resources)
#define ir_free_resources(irg,resources)
#define ir_resources_reserved(irg) 0
#endif
/** Normalization: Move Proj nodes into the same block as its predecessors */
......
......@@ -606,11 +606,11 @@ static ir_entity **get_free_methods(int *length)
eset_insert(free_set, ent);
}
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
/* Find all method entities that gets "visible" through this graphs,
* for instance because their address is stored. */
irg_walk_graph(irg, firm_clear_link, free_ana_walker, free_set);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
}
/* insert all methods that are used in global variables initializers */
......
......@@ -361,7 +361,7 @@ static blocksched_entry_t *finish_block_schedule(blocksched_env_t *env)
ir_node *startblock = get_irg_start_block(irg);
blocksched_entry_t *entry = get_irn_link(startblock);
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(irg);
env->worklist = new_pdeq();
......@@ -369,7 +369,7 @@ static blocksched_entry_t *finish_block_schedule(blocksched_env_t *env)
assert(pdeq_empty(env->worklist));
del_pdeq(env->worklist);
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
return entry;
}
......@@ -712,8 +712,7 @@ static ir_node **create_extbb_block_schedule(ir_graph *irg, ir_exec_freq *execfr
list.end = NULL;
list.n_blks = 0;
set_using_irn_link(irg);
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
inc_irg_block_visited(irg);
create_block_list(get_irg_start_block(irg), &list);
......@@ -726,8 +725,7 @@ static ir_node **create_extbb_block_schedule(ir_graph *irg, ir_exec_freq *execfr
blk_list[i] = b;
}
clear_using_irn_link(irg);
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
return blk_list;
}
......
......@@ -301,9 +301,9 @@ void be_sched_fix_flags(be_irg_t *birg, const arch_register_class_t *flag_cls,
if(remat == NULL)
remat = &default_remat;
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
irg_block_walk_graph(irg, fix_flags_walker, NULL, birg->lv);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
if(changed) {
be_remove_dead_nodes_from_schedule(birg);
......
......@@ -245,7 +245,7 @@ int be_remove_empty_blocks(ir_graph *irg)
blocks_removed = 0;
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(irg);
remove_empty_block(get_irg_end_block(irg));
end = get_irg_end(irg);
......@@ -256,7 +256,7 @@ int be_remove_empty_blocks(ir_graph *irg)
continue;
remove_empty_block(pred);
}
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
if (blocks_removed) {
/* invalidate analysis info */
......
......@@ -453,23 +453,25 @@ static void be_spill_belady3(be_irg_t *birg, const arch_register_class_t *ncls)
{
ir_graph *irg = be_get_birg_irg(birg);
cls = ncls;
n_regs = cls->n_regs - be_put_ignore_regs(birg, cls, NULL);
cls = ncls;
n_regs = cls->n_regs - be_put_ignore_regs(birg, cls, NULL);
if(n_regs == 0)
/* shortcut for register classes with ignore regs only */
if (n_regs == 0)
return;
arch_env = be_get_birg_arch_env(birg);
exec_freq = be_get_birg_exec_freq(birg);
arch_env = be_get_birg_arch_env(birg);
exec_freq = be_get_birg_exec_freq(birg);
be_clear_links(irg);
set_using_irn_link(irg);
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
inc_irg_visited(irg);
obstack_init(&obst);
senv = be_new_spill_env(birg);
assure_cf_loop(irg);
/* do a post-order walk over the CFG to make sure we have a maximum number
* of preds processed before entering a block */
tentative_mode = 1;
......@@ -481,8 +483,7 @@ static void be_spill_belady3(be_irg_t *birg, const arch_register_class_t *ncls)
tentative_mode = 0;
irg_block_edges_walk(get_irg_start_block(irg), NULL, process_block, NULL);
clear_using_irn_link(irg);
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
be_insert_spills_reloads(senv);
......
......@@ -265,9 +265,8 @@ void be_ssa_construction_init(be_ssa_construction_env_t *env, be_irg_t *birg)
env->new_phis = NEW_ARR_F(ir_node*, 0);
env->worklist = new_waitq();
set_using_irn_visited(irg);
set_using_block_visited(irg);
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED
| IR_RESOURCE_BLOCK_VISITED | IR_RESOURCE_IRN_LINK);
/* we use the visited flag to indicate blocks in the dominance frontier
* and blocks that already have the relevant value at the end calculated */
......@@ -283,9 +282,8 @@ void be_ssa_construction_destroy(be_ssa_construction_env_t *env)
del_waitq(env->worklist);
DEL_ARR_F(env->new_phis);
clear_using_irn_visited(env->irg);
clear_using_block_visited(env->irg);
clear_using_irn_link(env->irg);
ir_free_resources(env->irg, IR_RESOURCE_IRN_VISITED
| IR_RESOURCE_BLOCK_VISITED | IR_RESOURCE_IRN_LINK);
stat_ev_tim_pop("bessaconstr_total_time");
stat_ev_ctx_pop("bessaconstr");
......
......@@ -560,8 +560,7 @@ void be_assure_state(be_irg_t *birg, const arch_register_t *reg, void *func_env,
ir_nodemap_init(&env.spill_infos);
assure_doms(irg);
set_using_irn_visited(irg);
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
inc_irg_visited(irg);
/* process blocks */
......@@ -570,8 +569,7 @@ void be_assure_state(be_irg_t *birg, const arch_register_t *reg, void *func_env,
/* fix block end_states that don't match the next blocks start_state */
irg_block_walk_graph(irg, fix_block_borders, NULL, &env);
clear_using_irn_visited(irg);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED | IR_RESOURCE_IRN_LINK);
/* reconstruct ssa-form */
info = env.spills;
......
......@@ -196,9 +196,9 @@ static void collect_phis(ir_node *irn, void *data)
void be_clear_links(ir_graph *irg)
{
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
irg_walk_graph(irg, firm_clear_link, NULL, NULL);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
}
void be_collect_phis(ir_graph *irg)
......
......@@ -2201,7 +2201,7 @@ void ia32_gen_routine(ia32_code_gen_t *ia32_cg, ir_graph *irg)
be_gas_emit_function_prolog(entity, ia32_cg_config.function_alignment);
/* we use links to point to target blocks */
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
irg_block_walk_graph(irg, ia32_gen_labels, NULL, &exc_list);
/* initialize next block links */
......@@ -2224,7 +2224,7 @@ void ia32_gen_routine(ia32_code_gen_t *ia32_cg, ir_graph *irg)
be_emit_char('\n');
be_emit_write_line();
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
/* Sort the exception table using the exception label id's.
Those are ascending with ascending addresses. */
......
......@@ -642,13 +642,13 @@ static ir_node **construct_block_lists(ir_graph *irg) {
#ifdef INTERPROCEDURAL_VIEW
int rem_view = get_interprocedural_view();
#endif
int walk_flag = using_irn_visited(irg);
int walk_flag = ir_resources_reserved(irg) & IR_RESOURCE_IRN_VISITED;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
if(walk_flag)
clear_using_irn_visited(current_ir_graph);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
for (i = get_irp_n_irgs() - 1; i >= 0; --i)
ird_set_irg_link(get_irp_irg(i), NULL);
......@@ -670,7 +670,7 @@ static ir_node **construct_block_lists(ir_graph *irg) {
#endif
if(walk_flag)
set_using_irn_visited(current_ir_graph);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
current_ir_graph = rem;
return ird_get_irg_link(irg);
......
......@@ -977,10 +977,10 @@ void irg_block_edges_walk(ir_node *node,
assert(edges_activated(current_ir_graph));
assert(is_Block(node));
set_using_block_visited(current_ir_graph);
ir_reserve_resources(current_ir_graph, IR_RESOURCE_BLOCK_VISITED);
inc_irg_block_visited(current_ir_graph);
irg_block_edges_walk2(node, pre, post, env);
clear_using_block_visited(current_ir_graph);
ir_free_resources(current_ir_graph, IR_RESOURCE_BLOCK_VISITED);
}
......@@ -191,7 +191,7 @@ void optimize_graph_df(ir_graph *irg) {
set_irg_doms_inconsistent(irg);
set_irg_loopinfo_inconsistent(irg);
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
end = get_irg_end(irg);
n_ka = get_End_n_keepalives(end);
......@@ -229,7 +229,7 @@ void optimize_graph_df(ir_graph *irg) {
del_pdeq(waitq);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
if (! state)
edges_deactivate(irg);
......
......@@ -485,7 +485,7 @@ ir_graph *create_irg_copy(ir_graph *irg) {
res->phase_state = irg->phase_state;
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
/* copy all nodes from the graph irg to the new graph res */
irg_walk_anchors(irg, copy_all_nodes, set_all_preds, res);
......@@ -512,7 +512,7 @@ ir_graph *create_irg_copy(ir_graph *irg) {
is different from the original one. */
res->estimated_node_count = irg->estimated_node_count;
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
return res;
}
......@@ -1043,62 +1043,21 @@ void *get_irg_loc_description(ir_graph *irg, int n) {
}
#ifndef NDEBUG
void set_using_block_visited(ir_graph *irg) {
assert(irg->using_block_visited == 0);
irg->using_block_visited = 1;
void ir_reserve_resources(ir_graph *irg, ir_resources_t resources)
{
assert((irg->reserved_resources & resources) == 0);
irg->reserved_resources |= resources;
}
void clear_using_block_visited(ir_graph *irg) {
assert(irg->using_block_visited == 1);
irg->using_block_visited = 0;
void ir_free_resources(ir_graph *irg, ir_resources_t resources)
{
assert((irg->reserved_resources & resources) == resources);
irg->reserved_resources &= ~resources;
}
int using_block_visited(const ir_graph *irg) {
return irg->using_block_visited;
}
void set_using_irn_visited(ir_graph *irg) {
assert(irg->using_irn_visited == 0);
irg->using_irn_visited = 1;
}
void clear_using_irn_visited(ir_graph *irg) {
assert(irg->using_irn_visited == 1);
irg->using_irn_visited = 0;
}
int using_irn_visited(const ir_graph *irg) {
return irg->using_irn_visited;
}
void set_using_irn_link(ir_graph *irg) {
assert(irg->using_irn_link == 0);
irg->using_irn_link = 1;
}
void clear_using_irn_link(ir_graph *irg) {
assert(irg->using_irn_link == 1);
irg->using_irn_link = 0;
}
int using_irn_link(const ir_graph *irg) {
return irg->using_irn_link;
}
void set_using_block_mark(ir_graph *irg) {
assert(irg->using_block_mark == 0);
irg->using_block_mark = 1;
}
void clear_using_block_mark(ir_graph *irg) {
assert(irg->using_block_mark == 1);
irg->using_block_mark = 0;
}
int using_block_mark(const ir_graph *irg) {
return irg->using_block_mark;
ir_resources_t ir_resources_reserved(const ir_graph *irg)
{
return irg->reserved_resources;
}
#endif /* NDEBUG */
......
......@@ -275,10 +275,10 @@ void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
pset_new_destroy(&irg_set);
} else {
#endif
set_using_irn_visited(current_ir_graph);
ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(current_ir_graph);
nodes_touched = irg_walk_2(node, pre, post, env);
clear_using_irn_visited(current_ir_graph);
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
#ifdef INTERPROCEDURAL_VIEW
}
#endif
......@@ -426,10 +426,10 @@ void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
if (get_interprocedural_view()) {
assert(0 && "This is not yet implemented.");
} else {
set_using_irn_visited(current_ir_graph);
ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(current_ir_graph);
nodes_touched = irg_walk_in_or_dep_2(node, pre, post, env);
clear_using_irn_visited(current_ir_graph);
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
}
......@@ -601,16 +601,17 @@ static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *p
flag, so that it can be interleaved with the other walker. */
void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph *irg = current_ir_graph;
ir_node *block, *pred;
int i;
hook_irg_block_walk(current_ir_graph, node, (generic_func *)pre, (generic_func *)post);
hook_irg_block_walk(irg, node, (generic_func *)pre, (generic_func *)post);
assert(node);
assert(!get_interprocedural_view()); /* interprocedural_view not implemented, because it
* interleaves with irg_walk */
set_using_block_visited(current_ir_graph);
inc_irg_block_visited(current_ir_graph);
ir_reserve_resources(irg, IR_RESOURCE_BLOCK_VISITED);
inc_irg_block_visited(irg);
block = is_Block(node) ? node : get_nodes_block(node);
assert(get_irn_op(block) == op_Block);
irg_block_walk_2(block, pre, post, env);
......@@ -636,7 +637,7 @@ void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
}
}
clear_using_block_visited(current_ir_graph);
ir_free_resources(irg, IR_RESOURCE_BLOCK_VISITED);
}
/*
......
......@@ -371,7 +371,7 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en
blks.follow_deps = follow_deps != 0;
/* first step: traverse the graph and fill the lists */
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(irg);
collect_walk(end_node, &blks);
......@@ -394,7 +394,7 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en
#ifdef INTERPROCEDURAL_VIEW
set_interprocedural_view(old_view);
#endif
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
}
void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
......
......@@ -510,10 +510,7 @@ struct ir_graph {
#endif
#ifndef NDEBUG
unsigned using_irn_visited : 1; /**< set to 1 if we are currently using the visited flag */
unsigned using_block_visited : 1; /**< set to 1 if we are currently using the block_visited flag */
unsigned using_irn_link : 1; /**< set to 1 if we are currently using the irn_link fields */
unsigned using_block_mark : 1; /**< set to 1 if we are currently using the block mark flags */
ir_resources_t reserved_resources;
#endif
};
......
......@@ -405,7 +405,8 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig)
{
config = *nconfig;
lowered_nodes = new_pdeq();
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
irg_walk_graph(irg, clear_links, NULL, NULL);
irg_walk_graph(irg, lower_mode_b_walker, NULL, NULL);
......@@ -416,5 +417,5 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig)
}
del_pdeq(lowered_nodes);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
}
......@@ -426,7 +426,7 @@ void opt_bool(ir_graph *const irg)
{
irg_walk_graph(irg, NULL, bool_walk, NULL);
set_using_block_mark(irg);
ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK);
irg_walk_graph(irg, clear_block_infos, collect_phis, NULL);
......@@ -437,5 +437,5 @@ void opt_bool(ir_graph *const irg)
set_irg_extblk_inconsistent(irg);
set_irg_loopinfo_inconsistent(irg);
clear_using_block_mark(irg);
ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK);
}
......@@ -712,7 +712,7 @@ void optimize_cf(ir_graph *irg) {
edges_deactivate(irg);
/* we use the mark flag to mark removable blocks */
set_using_block_mark(irg);
ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK);
restart:
env.changed = 0;
env.phis_moved = 0;
......@@ -740,12 +740,12 @@ restart:
}
}
set_using_irn_link(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
env.list = plist_new();
irg_walk(end, merge_blocks, collect_nodes, &env);
clear_using_irn_link(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
if (env.changed) {
/* Handle graph state if was changed. */
......@@ -782,7 +782,7 @@ restart:
/* in rare cases a node may be kept alive more than once, use the visited flag to detect this */
inc_irg_visited(irg);
set_using_irn_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
/* fix the keep alive */
for (i = j = 0; i < n; i++) {
......@@ -815,8 +815,7 @@ restart:
env.changed = 1;
}
clear_using_block_mark(irg);
clear_using_irn_visited(irg);
ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_IRN_VISITED);
if (env.phis_moved) {
/* Bad: when we moved Phi's, we might produce dead Phi nodes
......
Markdown is supported
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