X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgraph.c;h=8e9125a356d1d8ad8f185bf2ad91833f2aef5e69;hb=10095ba5b312beeb57f0f0b587afc2b187dfcae7;hp=a8540052841b95a2a593654074724100f8c5aeaf;hpb=c13d7d771c9b2a78ceaefa7b5ad6c6814fcec758;p=libfirm diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index a85400528..8e9125a35 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -1,9 +1,9 @@ /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe -** All rights reserved. -** -** Authors: Martin Trapp, Christian Schaefer -** -** +* All rights reserved. +* +* Authors: Martin Trapp, Christian Schaefer +* +* */ /* $Id$ */ @@ -12,17 +12,39 @@ # 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(void) { + return current_ir_graph; +} +INLINE void set_current_ir_graph(ir_graph *graph) { + current_ir_graph = graph; +} + + +bool interprocedural_view = false; +INLINE bool get_interprocedural_view(void) { + return interprocedural_view; +} +INLINE void set_interprocedural_view(bool state) { + interprocedural_view = state; +} + +static ident* frame_type_suffix = NULL; +void init_irgraph(void) { + frame_type_suffix = id_from_str(FRAME_TP_SUFFIX, strlen(FRAME_TP_SUFFIX)); +} -#if USE_EXPICIT_PHI_IN_STACK +#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(); @@ -46,11 +68,13 @@ new_ir_graph (entity *ent, int n_loc) ir_node *projX; res = (ir_graph *) malloc (sizeof (ir_graph)); + res->kind=k_ir_graph; + current_ir_graph = res; add_irp_irg(res); /* remember this graph global. */ - /** Internal information for graph construction either held in the graph or - *** initialized for each graph. **/ +/** + * initialized for each graph. **/ #if PRECISE_EXC_CONTEXT res->n_loc = n_loc + 1 + 1; /* number of local variables that are never dereferenced in this graph plus one for @@ -67,10 +91,11 @@ 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 + res->kind = k_ir_graph; res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); obstack_init (res->obst); res->value_table = new_identities (); /* value table for global value @@ -83,14 +108,15 @@ new_ir_graph (entity *ent, int n_loc) 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_SUFFIX, strlen(FRAME_TP_SUFFIX)))); + res->frame_type = new_type_class(mangle(get_entity_ident(ent), frame_type_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 (); @@ -98,14 +124,19 @@ 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); set_store (new_Proj (res->start, mode_M, pns_global_store)); - res->frame = new_Proj (res->start, mode_p, pns_frame_base); - res->globals = new_Proj (res->start, mode_p, pns_globals); + res->frame = new_Proj (res->start, mode_P_mach, pns_frame_base); + res->globals = new_Proj (res->start, mode_P_mach, pns_globals); res->args = new_Proj (res->start, mode_T, pns_args); +#ifdef DEBUG_libfirm + res->graph_nr = get_irp_new_node_nr(); +#endif + add_in_edge(res->start_block, projX); /* @@ -134,11 +165,13 @@ ir_graph *new_const_code_irg() { 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_EXPICIT_PHI_IN_STACK +#if USE_EXPLICIT_PHI_IN_STACK res->Phi_in_stack = NULL; #endif + res->kind = k_ir_graph; res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); obstack_init (res->obst); + res->phase_state = phase_building; res->pinned = pinned; res->value_table = new_identities (); /* value table for global value numbering for optimizing use in @@ -149,7 +182,8 @@ ir_graph *new_const_code_irg() { res->end_block = new_immBlock (); res->end = new_End (); mature_block(get_cur_block()); - 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); res->start = new_Start (); /* Proj results of start node */ projX = new_Proj (res->start, mode_X, pns_initial_exec); @@ -175,7 +209,7 @@ ir_graph *new_const_code_irg() { 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); @@ -186,6 +220,27 @@ void free_ir_graph (ir_graph *irg) { {attr type} get_irg_{attribute name} (ir_graph *irg); void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */ +int +is_ir_graph(void *thing) { + assert(thing); + if (get_kind(thing) == k_ir_graph) + return 1; + else + return 0; +} + +/* Outputs a unique number for this node */ + +INLINE long +get_irg_graph_nr(ir_graph *irg) { + assert(irg); +#ifdef DEBUG_libfirm + return irg->graph_nr; +#else + return 0; +#endif +} + ir_node * get_irg_start_block (ir_graph *irg) { @@ -294,6 +349,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) { @@ -342,7 +409,7 @@ is_frame_type(type *ftp) { } int -get_irg_n_loc (ir_graph *irg) +get_irg_n_locs (ir_graph *irg) { #if PRECISE_EXC_CONTEXT return irg->n_loc - 1 - 1; @@ -361,11 +428,41 @@ set_irg_n_loc (ir_graph *irg, int n_loc) #endif } -irg_phase_state get_irg_phase_state (ir_graph *irg) { + + +/* Returns the obstack associated with the graph. */ +struct obstack *get_irg_obstack(ir_graph *irg) { + return irg->obst; +} + +/* + * Returns true if the node n is allocated on the storage of graph irg. + * + * Implementation is GLIBC specific as is uses the internal _obstack_chunk implementation. + */ +int node_is_in_irgs_storage(ir_graph *irg, ir_node *n) +{ + struct _obstack_chunk *p; + + /* + * checks wheater the ir_node pointer i on the obstack. + * A more sophisticated chaeck would test the "whole" ir_node + */ + for (p = irg->obst->chunk; p; p = p->prev) { + if (((char *)p->contents <= (char *)n) && ((char *)n < (char *)p->limit)) + return 1; + } + + return 0; +} + +irg_phase_state +get_irg_phase_state (ir_graph *irg) { return irg->phase_state; } -void set_irg_phase_low(ir_graph *irg) { +void +set_irg_phase_low(ir_graph *irg) { irg->phase_state = phase_low; } @@ -374,28 +471,44 @@ get_irg_pinned (ir_graph *irg) { return irg->pinned; } -irg_outs_state get_irg_outs_state(ir_graph *irg) { +irg_outs_state +get_irg_outs_state(ir_graph *irg) { return irg->outs_state; } -void set_irg_outs_inconsistent(ir_graph *irg) { +void +set_irg_outs_inconsistent(ir_graph *irg) { irg->outs_state = outs_inconsistent; } -irg_dom_state get_irg_dom_state(ir_graph *irg) { +irg_dom_state +get_irg_dom_state(ir_graph *irg) { return irg->dom_state; } -void set_irg_dom_inconsistent(ir_graph *irg) { +void +set_irg_dom_inconsistent(ir_graph *irg) { irg->dom_state = dom_inconsistent; } -inline void -set_irg_pinned (ir_graph *irg, op_pinned p) -{ +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) { @@ -406,12 +519,44 @@ 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 @@ -429,5 +574,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; }