X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgraph.c;h=6ae878cd7ebf5c89b5e57790669b26acf284d5b2;hb=afbbc0b1ccd684c4c24bfd43d0f994123245f39f;hp=465b30d078cc939982cbac87e0d0a963be39bd7a;hpb=2f500449b37a392471468c2924020098f95b2662;p=libfirm diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index 465b30d07..6ae878cd7 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -145,6 +145,33 @@ Phi_in_stack *new_Phi_in_stack(); void free_Phi_in_stack(Phi_in_stack *s); #endif +/** + * Set the number of locals for a given graph. + * + * @param irg the graph + * @param n_loc number of locals + */ +void irg_set_nloc(ir_graph *res, int n_loc) { + assert(res->phase_state == phase_building); + + if (get_opt_precise_exc_context()) { + res->n_loc = n_loc + 1 + 1; /* number of local variables that are never + dereferenced in this graph plus one for + the store plus one for links to fragile + operations. n_loc is not the number of + parameters to the procedure! */ + } else { + res->n_loc = n_loc + 1; /* number of local variables that are never + dereferenced in this graph plus one for + the store. This is not the number of parameters + to the procedure! */ + } + if (res->loc_descriptions) { + xfree(res->loc_descriptions); + res->loc_descriptions = NULL; + } +} + /* Allocates a list of nodes: - The start block containing a start node and Proj nodes for it's four results (X, M, P, Tuple). @@ -167,18 +194,12 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { current_ir_graph = res; /*-- initialized for each graph. --*/ - if (get_opt_precise_exc_context()) { - res->n_loc = n_loc + 1 + 1; /* number of local variables that are never - dereferenced in this graph plus one for - the store plus one for links to fragile - operations. n_loc is not the number of - parameters to the procedure! */ - } else { - res->n_loc = n_loc + 1; /* number of local variables that are never - dereferenced in this graph plus one for - the store. This is not the number of parameters - to the procedure! */ - } + res->kind = k_ir_graph; + res->obst = XMALLOC(struct obstack); + obstack_init(res->obst); + + res->phase_state = phase_building; + irg_set_nloc(res, n_loc); /* descriptions will be allocated on demand */ res->loc_descriptions = NULL; @@ -190,9 +211,6 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { res->Phi_in_stack = new_Phi_in_stack(); /* A stack needed for automatic Phi generation */ #endif - res->kind = k_ir_graph; - res->obst = xmalloc (sizeof(*res->obst)); - obstack_init(res->obst); res->extbb_obst = NULL; res->last_node_idx = 0; @@ -204,7 +222,6 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { res->inline_property = irg_inline_any; res->additional_properties = mtp_property_inherited; /* inherited from type */ - res->phase_state = phase_building; res->irg_pinned_state = op_pin_state_pinned; res->outs_state = outs_none; res->dom_state = dom_none; @@ -217,7 +234,7 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { res->extblk_state = ir_extblk_info_none; res->execfreq_state = exec_freq_none; res->fp_model = fp_model_precise; - res->adr_taken_state = ir_address_taken_not_computed; + res->entity_usage_state = ir_entity_usage_not_computed; res->mem_disambig_opt = aa_opt_inherited; /*-- Type information for the procedure of the graph --*/ @@ -246,8 +263,8 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { /* Proj results of start node */ projX = new_Proj(start, mode_X, pn_Start_X_initial_exec); + set_irg_initial_exec (res, projX); set_irg_frame (res, new_Proj(start, mode_P_data, pn_Start_P_frame_base)); - set_irg_globals (res, new_Proj(start, mode_P_data, pn_Start_P_globals)); set_irg_tls (res, new_Proj(start, mode_P_data, pn_Start_P_tls)); set_irg_args (res, new_Proj(start, mode_T, pn_Start_T_args)); set_irg_value_param_base(res, new_Proj(start, mode_P_data, pn_Start_P_value_arg_base)); @@ -303,7 +320,7 @@ ir_graph *new_const_code_irg(void) { #if USE_EXPLICIT_PHI_IN_STACK res->Phi_in_stack = NULL; #endif - res->obst = xmalloc(sizeof(*res->obst)); + res->obst = XMALLOC(struct obstack); obstack_init (res->obst); res->extbb_obst = NULL; @@ -369,7 +386,7 @@ ir_graph *new_const_code_irg(void) { * @param env The copied graph. */ static void copy_all_nodes(ir_node *n, void *env) { - ir_graph *irg = current_ir_graph; + ir_graph *irg = env; ir_op *op = get_irn_op(n); ir_node *nn; @@ -417,7 +434,7 @@ static void copy_all_nodes(ir_node *n, void *env) { static void set_all_preds(ir_node *irn, void *env) { int i; ir_node *nn, *pred; - ir_graph *clone_irg = env; + (void) env; nn = get_irn_link(irn); @@ -454,7 +471,7 @@ ir_graph *create_irg_copy(ir_graph *irg) { #if USE_EXPLICIT_PHI_IN_STACK res->Phi_in_stack = NULL; #endif - res->obst = xmalloc(sizeof(*res->obst)); + res->obst = XMALLOC(struct obstack); obstack_init(res->obst); res->extbb_obst = NULL; @@ -472,7 +489,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); @@ -499,7 +516,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; } @@ -516,6 +533,8 @@ ir_graph *create_irg_copy(ir_graph *irg) { void free_ir_graph(ir_graph *irg) { assert(is_ir_graph(irg)); + edges_deactivate(irg); + hook_free_graph(irg); if (irg->outs_state != outs_none) free_irg_outs(irg); @@ -624,28 +643,28 @@ ir_node * void (set_irg_end_except)(ir_graph *irg, ir_node *node) { - assert(get_irn_op(node) == op_EndExcept || get_irn_op(node) == op_End); + assert(get_irn_op(node) == op_EndExcept || is_End(node)); _set_irg_end_except(irg, node); } ir_node * -(get_irg_frame)(const ir_graph *irg) { - return _get_irg_frame(irg); +(get_irg_initial_exec)(const ir_graph *irg) { + return _get_irg_initial_exec(irg); } void -(set_irg_frame)(ir_graph *irg, ir_node *node) { - _set_irg_frame(irg, node); +(set_irg_initial_exec)(ir_graph *irg, ir_node *node) { + _set_irg_initial_exec(irg, node); } ir_node * -(get_irg_globals)(const ir_graph *irg) { - return _get_irg_globals(irg); +(get_irg_frame)(const ir_graph *irg) { + return _get_irg_frame(irg); } void -(set_irg_globals)(ir_graph *irg, ir_node *node) { - _set_irg_globals(irg, node); +(set_irg_frame)(ir_graph *irg, ir_node *node) { + _set_irg_frame(irg, node); } ir_node * @@ -906,18 +925,18 @@ void * return _get_irg_link(irg); } -unsigned long +ir_visited_t (get_irg_visited)(const ir_graph *irg) { return _get_irg_visited(irg); } #ifdef INTERPROCEDURAL_VIEW /** maximum visited flag content of all ir_graph visited fields. */ -static unsigned long max_irg_visited = 0; +static ir_visited_t max_irg_visited = 0; #endif /* INTERPROCEDURAL_VIEW */ void -set_irg_visited(ir_graph *irg, unsigned long visited) { +set_irg_visited(ir_graph *irg, ir_visited_t visited) { irg->visited = visited; #ifdef INTERPROCEDURAL_VIEW if (irg->visited > max_irg_visited) { @@ -938,13 +957,13 @@ inc_irg_visited(ir_graph *irg) { } #ifdef INTERPROCEDURAL_VIEW -unsigned long +ir_visited_t get_max_irg_visited(void) { - /* +#ifndef NDEBUG int i; for(i = 0; i < get_irp_n_irgs(); i++) - assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); - */ + assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); +#endif return max_irg_visited; } @@ -952,24 +971,24 @@ void set_max_irg_visited(int val) { max_irg_visited = val; } -unsigned long +ir_visited_t inc_max_irg_visited(void) { - /* +#ifndef NDEBUG int i; for(i = 0; i < get_irp_n_irgs(); i++) - assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); - */ + assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); +#endif return ++max_irg_visited; } #endif /* INTERPROCEDURAL_VIEW */ -unsigned long +ir_visited_t (get_irg_block_visited)(const ir_graph *irg) { return _get_irg_block_visited(irg); } void -(set_irg_block_visited)(ir_graph *irg, unsigned long visited) { +(set_irg_block_visited)(ir_graph *irg, ir_visited_t visited) { _set_irg_block_visited(irg, visited); } @@ -1016,7 +1035,7 @@ void set_irg_loc_description(ir_graph *irg, int n, void *description) { assert(0 <= n && n < irg->n_loc); if (! irg->loc_descriptions) - irg->loc_descriptions = xcalloc(sizeof(*irg->loc_descriptions), irg->n_loc); + irg->loc_descriptions = XMALLOCNZ(void*, irg->n_loc); irg->loc_descriptions[n] = description; } @@ -1028,50 +1047,23 @@ 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 clear_using_block_visited(ir_graph *irg) { - assert(irg->using_block_visited == 1); - irg->using_block_visited = 0; +void ir_reserve_resources(ir_graph *irg, ir_resources_t resources) +{ + assert((irg->reserved_resources & resources) == 0); + irg->reserved_resources |= resources; } -int using_block_visited(const ir_graph *irg) { - return irg->using_block_visited; +void ir_free_resources(ir_graph *irg, ir_resources_t resources) +{ + assert((irg->reserved_resources & resources) == resources); + irg->reserved_resources &= ~resources; } - -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; +ir_resources_t ir_resources_reserved(const ir_graph *irg) +{ + return irg->reserved_resources; } - -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; -} -#endif +#endif /* NDEBUG */ /* Returns a estimated node count of the irg. */ unsigned (get_irg_estimated_node_cnt)(const ir_graph *irg) {