Commit 97080a1a authored by Matthias Braun's avatar Matthias Braun
Browse files

get rid of get_irg_estimated_node_count

We have simpler code without it, and a heuristic based on
get_irg_last_idx() seems to work as well.
parent 3c6d2697
......@@ -485,11 +485,6 @@ FIRM_API void set_irg_loc_description(ir_graph *irg, int n, void *description);
/** Returns the description for local value n. */
FIRM_API void *get_irg_loc_description(ir_graph *irg, int n);
/** Returns a estimated node count of the irg. This count is updated
* after every irg_walk_graph().
*/
FIRM_API unsigned get_irg_estimated_node_cnt(const ir_graph *irg);
/** Returns the last irn index for this graph. */
FIRM_API unsigned get_irg_last_idx(const ir_graph *irg);
......
......@@ -251,8 +251,8 @@ FIRM_API void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre,
* Walker function which does not increase the visited flag before walking.
* Do not use this unless you know what you are doing.
*/
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env);
FIRM_API void irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env);
/** @} */
......
......@@ -542,7 +542,6 @@ static void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, const char *pref
ir_graph *irg = get_entity_irg(ent);
if (irg) {
fprintf(F, "%s estimated node count: %u\n", prefix, get_irg_estimated_node_cnt(irg));
fprintf(F, "%s maximum node index: %u\n", prefix, get_irg_last_idx(irg));
}
......
......@@ -153,7 +153,7 @@ void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind)
{
if (edges_activated_kind(irg, kind)) {
irg_edge_info_t *info = get_irg_edge_info(irg, kind);
size_t amount = irg->estimated_node_count * 2;
size_t amount = get_irg_last_idx(irg) * 5 / 4;
edges_used = 1;
if (info->allocated) {
......
......@@ -216,7 +216,6 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
set_r_cur_block(res, first_block);
res->method_execution_frequency = -1.0;
res->estimated_node_count = 0;
return res;
}
......@@ -383,10 +382,6 @@ ir_graph *create_irg_copy(ir_graph *irg)
/* Proj results of start node */
set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
/* Copy the node count estimation. Would be strange if this
is different from the original one. */
res->estimated_node_count = irg->estimated_node_count;
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
......@@ -703,11 +698,6 @@ ir_resources_t ir_resources_reserved(const ir_graph *irg)
}
#endif
unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg)
{
return get_irg_estimated_node_cnt_(irg);
}
unsigned get_irg_last_idx(const ir_graph *irg)
{
return irg->last_node_idx;
......
......@@ -76,7 +76,6 @@
#define set_irg_block_visited(irg, v) set_irg_block_visited_(irg, v)
#define inc_irg_block_visited(irg) inc_irg_block_visited_(irg)
#define dec_irg_block_visited(irg) dec_irg_block_visited_(irg)
#define get_irg_estimated_node_cnt(irg) get_irg_estimated_node_cnt_(irg)
#define get_irg_fp_model(irg) get_irg_fp_model_(irg)
#define get_idx_irn(irg, idx) get_idx_irn_(irg, idx)
#define irg_is_constrained(irg, constraints) irg_is_constrained_(irg, constraints)
......@@ -322,11 +321,6 @@ static inline void dec_irg_block_visited_(ir_graph *irg)
--irg->block_visited;
}
static inline unsigned get_irg_estimated_node_cnt_(const ir_graph *irg)
{
return irg->estimated_node_count;
}
/* Return the floating point model of this graph. */
static inline unsigned get_irg_fp_model_(const ir_graph *irg)
{
......
......@@ -44,13 +44,10 @@
/**
* specialized version of irg_walk_2, called if only pre callback exists
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env)
static void irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -60,25 +57,21 @@ static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env)
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_pre(pred, pre, env);
irg_walk_2_pre(pred, pre, env);
}
for (i = get_irn_arity(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_n(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_2_pre(pred, pre, env);
irg_walk_2_pre(pred, pre, env);
}
return cnt;
}
/**
* specialized version of irg_walk_2, called if only post callback exists
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void *env)
static void irg_walk_2_post(ir_node *node, irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -86,29 +79,24 @@ static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void *env)
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_post(pred, post, env);
irg_walk_2_post(pred, post, env);
}
for (i = get_irn_arity(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_n(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_2_post(pred, post, env);
irg_walk_2_post(pred, post, env);
}
post(node, env);
return cnt;
}
/**
* specialized version of irg_walk_2, called if pre and post callbacks exist
*
* @return number of visited nodes
*/
static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre,
static void irg_walk_2_both(ir_node *node, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -118,38 +106,33 @@ static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre,
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_2_both(pred, pre, post, env);
irg_walk_2_both(pred, pre, post, env);
}
for (i = get_irn_arity(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_n(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_2_both(pred, pre, post, env);
irg_walk_2_both(pred, pre, post, env);
}
post(node, env);
return cnt;
}
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
void irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
if (irn_visited(node))
return 0;
return;
if (!post) return irg_walk_2_pre (node, pre, env);
else if (!pre) return irg_walk_2_post(node, post, env);
else return irg_walk_2_both(node, pre, post, env);
if (!post) irg_walk_2_pre (node, pre, env);
else if (!pre) irg_walk_2_post(node, post, env);
else irg_walk_2_both(node, pre, post, env);
}
/* a counter */
static unsigned nodes_touched = 0;
void irg_walk_core(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
assert(is_ir_node(node));
nodes_touched = irg_walk_2(node, pre, post, env);
irg_walk_2(node, pre, post, env);
}
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
......@@ -173,7 +156,6 @@ void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void
hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post);
current_ir_graph = irg;
irg_walk(get_irg_end(irg), pre, post, env);
irg->estimated_node_count = nodes_touched;
current_ir_graph = rem;
}
......@@ -190,13 +172,10 @@ void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env)
/**
* specialized version of irg_walk_in_or_dep_2, called if only pre callback exists
*
* @return number of visited nodes
*/
static unsigned irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void *env)
static void irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -206,25 +185,21 @@ static unsigned irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_pre(pred, pre, env);
irg_walk_in_or_dep_2_pre(pred, pre, env);
}
for (i = get_irn_ins_or_deps(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_in_or_dep(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_pre(pred, pre, env);
irg_walk_in_or_dep_2_pre(pred, pre, env);
}
return cnt;
}
/**
* specialized version of irg_walk_in_or_dep_2, called if only post callback exists
*
* @return number of visited nodes
*/
static unsigned irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, void *env)
static void irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -232,28 +207,23 @@ static unsigned irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, vo
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_post(pred, post, env);
irg_walk_in_or_dep_2_post(pred, post, env);
}
for (i = get_irn_ins_or_deps(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_in_or_dep(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_post(pred, post, env);
irg_walk_in_or_dep_2_post(pred, post, env);
}
post(node, env);
return cnt;
}
/**
* specialized version of irg_walk_in_or_dep_2, called if pre and post callbacks exist
*
* @return number of visited nodes
*/
static unsigned irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
static void irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
int i;
unsigned cnt = 1;
ir_graph *irg = get_irn_irg(node);
set_irn_visited(node, irg->visited);
......@@ -263,28 +233,24 @@ static unsigned irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg
if (!is_Block(node)) {
ir_node *pred = get_nodes_block(node);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_both(pred, pre, post, env);
irg_walk_in_or_dep_2_both(pred, pre, post, env);
}
for (i = get_irn_ins_or_deps(node) - 1; i >= 0; --i) {
ir_node *pred = get_irn_in_or_dep(node, i);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_both(pred, pre, post, env);
irg_walk_in_or_dep_2_both(pred, pre, post, env);
}
post(node, env);
return cnt;
}
/**
* Intraprozedural graph walker. Follows dependency edges as well.
*
* @return number of visited nodes
*/
static unsigned irg_walk_in_or_dep_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
static void irg_walk_in_or_dep_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
if (irn_visited(node))
return 0;
return;
if (! post) return irg_walk_in_or_dep_2_pre (node, pre, env);
else if (! pre) return irg_walk_in_or_dep_2_post(node, post, env);
......@@ -297,7 +263,7 @@ void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
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);
irg_walk_in_or_dep_2(node, pre, post, env);
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
......@@ -308,7 +274,6 @@ void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *
hook_irg_walk(irg, (generic_func *)pre, (generic_func *)post);
current_ir_graph = irg;
irg_walk_in_or_dep(get_irg_end(irg), pre, post, env);
irg->estimated_node_count = nodes_touched;
current_ir_graph = rem;
}
......
......@@ -560,8 +560,6 @@ struct ir_graph {
ir_visited_t self_visited; /**< visited flag of the irg */
unsigned estimated_node_count; /**< estimated number of nodes in this graph,
updated after every walk */
irg_edges_info_t edge_info; /**< edge info for automatic outs */
ir_node **idx_irn_map; /**< Array mapping node indexes to nodes. */
......
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