X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgraph.c;h=7ffd10ac5980e97c37e64d2cc18bf9b02bb2edec;hb=9be70b7ef6120836707d76050372a89247cec2a6;hp=da6243348fe00463239479951b4fa3fe81997217;hpb=b4eb108c1ed94e9945ef56e7c89ac866594f7cb0;p=libfirm diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index da6243348..7ffd10ac5 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -12,17 +12,34 @@ # include #endif +# include + # include "ircons.h" # include "irgraph_t.h" -# include "irprog.h" +# include "irprog_t.h" # include "iropt_t.h" # include "array.h" # include "irgmod.h" # include "mangle.h" ir_graph *current_ir_graph; +INLINE ir_graph *get_current_ir_graph() { + return current_ir_graph; +} +INLINE void set_current_ir_graph(ir_graph *graph) { + current_ir_graph = graph; +} -#if USE_EXPICIT_PHI_IN_STACK + +bool interprocedural_view = false; +INLINE bool get_interprocedural_view() { + return interprocedural_view; +} +INLINE void set_interprocedural_view(bool state) { + interprocedural_view = state; +} + +#if USE_EXPLICIT_PHI_IN_STACK /* really defined in ircons.c */ typedef struct Phi_in_stack Phi_in_stack; Phi_in_stack *new_Phi_in_stack(); @@ -41,6 +58,7 @@ void free_Phi_in_stack(Phi_in_stack *s); ir_graph * new_ir_graph (entity *ent, int n_loc) { + int i; ir_graph *res; ir_node *first_block; ir_node *projX; @@ -67,7 +85,7 @@ new_ir_graph (entity *ent, int n_loc) res->visited = 0; /* visited flag, for the ir walker */ res->block_visited=0; /* visited flag, for the 'block'-walker */ -#if USE_EXPICIT_PHI_IN_STACK +#if USE_EXPLICIT_PHI_IN_STACK res->Phi_in_stack = new_Phi_in_stack(); /* A stack needed for automatic Phi generation */ #endif @@ -76,14 +94,23 @@ new_ir_graph (entity *ent, int n_loc) res->value_table = new_identities (); /* value table for global value numbering for optimizing use in iropt.c */ + res->outs = NULL; + + res->phase_state = phase_building; + res->pinned = pinned; + res->outs_state = no_outs; + res->dom_state = no_dom; - /** Type inforamtion for the procedure of the graph **/ + /** Type information for the procedure of the graph **/ res->ent = ent; set_entity_irg(ent, res); /** A type that represents the stack frame. A class type so that it can contain "inner" methods as in Pascal. **/ - res->frame_type = new_type_class(mangle(get_entity_ident(ent), id_from_str("frame_tp", 8))); + res->frame_type = new_type_class(mangle(get_entity_ident(ent), + id_from_str(FRAME_TP_SUFFIX, strlen(FRAME_TP_SUFFIX)))); + /* Remove type from type list. Must be treated differently than other types. */ + remove_irp_type_from_list(res->frame_type); /** Nodes needed in every graph **/ res->end_block = new_immBlock (); @@ -91,7 +118,8 @@ new_ir_graph (entity *ent, int n_loc) res->start_block = new_immBlock (); res->start = new_Start (); - res->bad = new_ir_node (res, res->start_block, op_Bad, mode_T, 0, NULL); + res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL); + res->unknown = new_ir_node (NULL, res, res->start_block, op_Unknown, mode_T, 0, NULL); /* Proj results of start node */ projX = new_Proj (res->start, mode_X, pns_initial_exec); @@ -115,6 +143,50 @@ new_ir_graph (entity *ent, int n_loc) return res; } + +/* Make a rudimentary ir graph for the constant code. + Must look like a correct irg, spare everything else. */ +ir_graph *new_const_code_irg() { + ir_graph *res; + ir_node *projX; + + res = (ir_graph *) malloc (sizeof (ir_graph)); + current_ir_graph = res; + res->n_loc = 1; /* Only the memory. */ + res->visited = 0; /* visited flag, for the ir walker */ + res->block_visited=0; /* visited flag, for the 'block'-walker */ +#if USE_EXPLICIT_PHI_IN_STACK + res->Phi_in_stack = NULL; +#endif + res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); + obstack_init (res->obst); + res->pinned = pinned; + res->value_table = new_identities (); /* value table for global value + numbering for optimizing use in + iropt.c */ + res->ent = NULL; + res->frame_type = NULL; + res->start_block = new_immBlock (); + res->end_block = new_immBlock (); + res->end = new_End (); + mature_block(get_cur_block()); + res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL); + res->unknown = new_ir_node (NULL, res, res->start_block, op_Unknown, mode_T, 0, NULL); + res->start = new_Start (); + /* Proj results of start node */ + projX = new_Proj (res->start, mode_X, pns_initial_exec); + set_store (new_Proj (res->start, mode_M, pns_global_store)); + add_in_edge(res->start_block, projX); + mature_block (res->current_block); + add_in_edge (new_immBlock (), projX); + mature_block(get_cur_block()); + /* Set the visited flag high enough that the block will never be visited. */ + set_irn_visited(get_cur_block(), -1); + set_Block_block_visited(get_cur_block(), -1); + set_Block_block_visited(res->start_block, -1); + return res; +} + /* Frees the passed irgraph. Deallocates all nodes in this graph and the ir_graph structure. Sets the field irgraph in the corresponding entity to NULL. @@ -125,7 +197,7 @@ new_ir_graph (entity *ent, int n_loc) void free_ir_graph (ir_graph *irg) { set_entity_irg(irg->ent, NULL); free(irg->obst); -#if USE_EXPICIT_PHI_IN_STACK +#if USE_EXPLICIT_PHI_IN_STACK free_Phi_in_stack(irg->Phi_in_stack); #endif free(irg); @@ -244,6 +316,18 @@ set_irg_bad (ir_graph *irg, ir_node *node) irg->bad = node; } +ir_node * +get_irg_unknown (ir_graph *irg) +{ + return irg->unknown; +} + +void +set_irg_unknown (ir_graph *irg, ir_node *node) +{ + irg->unknown = node; +} + ir_node * get_irg_current_block (ir_graph *irg) { @@ -282,18 +366,82 @@ set_irg_frame_type (ir_graph *irg, type *ftp) irg->frame_type = ftp; } + +/* To test for a frame type */ +int +is_frame_type(type *ftp) { + return ((is_class_type(ftp) || is_struct_type(ftp)) && + id_is_suffix(id_from_str(FRAME_TP_SUFFIX, strlen(FRAME_TP_SUFFIX)), + get_type_ident(ftp))); +} + int -get_irg_n_loc (ir_graph *irg) +get_irg_n_locs (ir_graph *irg) { - return irg->n_loc; +#if PRECISE_EXC_CONTEXT + return irg->n_loc - 1 - 1; +#else + return irg->n_loc - 1; +#endif } void set_irg_n_loc (ir_graph *irg, int n_loc) { - irg->n_loc = n_loc; +#if PRECISE_EXC_CONTEXT + irg->n_loc = n_loc + 1 + 1; +#else + irg->n_loc = n_loc + 1; +#endif } +irg_phase_state get_irg_phase_state (ir_graph *irg) { + return irg->phase_state; +} + +void set_irg_phase_low(ir_graph *irg) { + irg->phase_state = phase_low; +} + +op_pinned +get_irg_pinned (ir_graph *irg) { + return irg->pinned; +} + +irg_outs_state get_irg_outs_state(ir_graph *irg) { + return irg->outs_state; +} + +void set_irg_outs_inconsistent(ir_graph *irg) { + irg->outs_state = outs_inconsistent; +} + +irg_dom_state get_irg_dom_state(ir_graph *irg) { + return irg->dom_state; +} + +void set_irg_dom_inconsistent(ir_graph *irg) { + irg->dom_state = dom_inconsistent; +} + +INLINE void +set_irg_pinned (ir_graph *irg, op_pinned p) { + irg->pinned = p; +} + +INLINE void +set_irg_link (ir_graph *irg, void *thing) { + irg->link = thing; +} + +INLINE void * +get_irg_link (ir_graph *irg) { + return irg->link; +} + +/* maximum visited flag content of all ir_graph visited fields. */ +static int max_irg_visited = 0; + unsigned long get_irg_visited (ir_graph *irg) { @@ -304,12 +452,40 @@ void set_irg_visited (ir_graph *irg, unsigned long visited) { irg->visited = visited; + if (irg->visited > max_irg_visited) { + max_irg_visited = irg->visited; + } } void inc_irg_visited (ir_graph *irg) { - irg->visited = irg->visited++; + if (++irg->visited > max_irg_visited) { + max_irg_visited = irg->visited; + } +} + +unsigned long +get_max_irg_visited(void) +{ + int i; + //for(i = 0; i < get_irp_n_irgs(); i++) + // assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); + return max_irg_visited; +} + +void set_max_irg_visited(int val) { + max_irg_visited = val; +} + +unsigned long +inc_max_irg_visited(void) +{ + int i; + // for(i = 0; i < get_irp_n_irgs(); i++) + //assert(max_irg_visited >= get_irg_visited(get_irp_irg(i))); + max_irg_visited++; + return max_irg_visited; } unsigned long @@ -327,5 +503,5 @@ set_irg_block_visited (ir_graph *irg, unsigned long visited) void inc_irg_block_visited (ir_graph *irg) { - irg->block_visited = irg->block_visited++; + ++irg->block_visited; }