X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgraph.c;h=1d593a801f9e38c954d18c539f4573930673e2ff;hb=e570f00fb465d212dde403160e97ab45d36d1d7e;hp=b21bf0fa1e0e07554b13ef5c6c6d8d90df117990;hpb=dc38d7465e72f7037c458a08de362f27338a630a;p=libfirm diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index b21bf0fa1..1d593a801 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -1,12 +1,14 @@ -/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe -* All rights reserved. -* -* Authors: Martin Trapp, Christian Schaefer -* -* -*/ - -/* $Id$ */ +/* + * Project: libFIRM + * File name: ir/ir/irgraph.c + * Purpose: Entry point to the representation of procedure code. + * Author: Martin Trapp, Christian Schaefer + * Modified by: Goetz Lindenmaier + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 1998-2003 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ #ifdef HAVE_CONFIG_H # include @@ -21,9 +23,10 @@ # include "array.h" # include "irgmod.h" # include "mangle.h" +# include "irouts.h" ir_graph *current_ir_graph; -INLINE ir_graph *get_current_ir_graph() { +INLINE ir_graph *get_current_ir_graph(void) { return current_ir_graph; } INLINE void set_current_ir_graph(ir_graph *graph) { @@ -32,13 +35,18 @@ INLINE void set_current_ir_graph(ir_graph *graph) { bool interprocedural_view = false; -INLINE bool get_interprocedural_view() { +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_EXPLICIT_PHI_IN_STACK /* really defined in ircons.c */ typedef struct Phi_in_stack Phi_in_stack; @@ -63,6 +71,9 @@ new_ir_graph (entity *ent, int n_loc) ir_node *projX; res = (ir_graph *) malloc (sizeof (ir_graph)); + memset(res, 0, sizeof (ir_graph)); + res->kind=k_ir_graph; + current_ir_graph = res; add_irp_irg(res); /* remember this graph global. */ @@ -88,6 +99,7 @@ new_ir_graph (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 = (struct obstack *) xmalloc (sizeof (struct obstack)); obstack_init (res->obst); res->value_table = new_identities (); /* value table for global value @@ -99,6 +111,8 @@ new_ir_graph (entity *ent, int n_loc) res->pinned = pinned; res->outs_state = no_outs; res->dom_state = no_dom; + res->typeinfo_state = irg_typeinfo_none; + res->loopinfo_state = loopinfo_none; /** Type information for the procedure of the graph **/ res->ent = ent; @@ -106,8 +120,7 @@ new_ir_graph (entity *ent, int n_loc) /** 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); @@ -118,13 +131,13 @@ new_ir_graph (entity *ent, int n_loc) res->start_block = new_immBlock (); res->start = new_Start (); 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->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(); @@ -149,11 +162,13 @@ new_ir_graph (entity *ent, int n_loc) /* 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 *new_const_code_irg(void) { ir_graph *res; ir_node *projX; - res = (ir_graph *) malloc (sizeof (ir_graph)); + res = (ir_graph *) malloc (sizeof(*res)); + memset(res, 0, sizeof(*res)); + current_ir_graph = res; res->n_loc = 1; /* Only the memory. */ res->visited = 0; /* visited flag, for the ir walker */ @@ -161,6 +176,7 @@ ir_graph *new_const_code_irg() { #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; @@ -175,8 +191,9 @@ ir_graph *new_const_code_irg() { 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->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)); @@ -188,9 +205,14 @@ ir_graph *new_const_code_irg() { set_irn_visited(get_cur_block(), -1); set_Block_block_visited(get_cur_block(), -1); set_Block_block_visited(res->start_block, -1); + set_irn_visited(res->start_block, -1); + set_irn_visited(res->bad, -1); return res; } +/* Defined in iropt.c */ +void del_identities (pset *value_table); + /* 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. @@ -199,11 +221,17 @@ ir_graph *new_const_code_irg() { Does not free types, entities or modes that are used only by this graph, nor the entity standing for this graph. */ void free_ir_graph (ir_graph *irg) { - set_entity_irg(irg->ent, NULL); + if (irg->ent) set_entity_irg(irg->ent, NULL); /* not set in const code irg */ + free_End(irg->end); + if (irg->frame_type) free_type(irg->frame_type); + if (irg->value_table) del_identities(irg->value_table); + if (irg->outs_state != no_outs) free_outs(irg); + obstack_free(irg->obst,NULL); free(irg->obst); #if USE_EXPLICIT_PHI_IN_STACK free_Phi_in_stack(irg->Phi_in_stack); #endif + irg->kind = k_BAD; free(irg); } @@ -212,6 +240,15 @@ 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 @@ -332,6 +369,7 @@ set_irg_bad (ir_graph *irg, ir_node *node) irg->bad = node; } +/* GL removed: we need unknown with mode for analyses. ir_node * get_irg_unknown (ir_graph *irg) { @@ -343,6 +381,7 @@ set_irg_unknown (ir_graph *irg, ir_node *node) { irg->unknown = node; } +*/ ir_node * get_irg_current_block (ir_graph *irg) @@ -379,6 +418,7 @@ get_irg_frame_type (ir_graph *irg) void set_irg_frame_type (ir_graph *irg, type *ftp) { + assert(is_class_type(ftp)); irg->frame_type = ftp; } @@ -386,9 +426,14 @@ set_irg_frame_type (ir_graph *irg, 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 i; + if (is_class_type(ftp)) { + for (i = 0; i < get_irp_n_irgs(); i++) { + type *frame_tp = get_irg_frame_type(get_irp_irg(i)); + if (ftp == frame_tp) return true; + } + } + return false; } int @@ -411,6 +456,34 @@ set_irg_n_loc (ir_graph *irg, int n_loc) #endif } + + +/* 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 check 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; @@ -446,11 +519,45 @@ set_irg_dom_inconsistent(ir_graph *irg) { irg->dom_state = dom_inconsistent; } +irg_loopinfo_state +get_irg_loopinfo_state(ir_graph *irg) { + return irg->loopinfo_state; +} + +void set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) { + irg->loopinfo_state = s; +} + +void +set_irg_loopinfo_inconsistent(ir_graph *irg) { + if (irg->loopinfo_state == loopinfo_ip_consistent) + irg->loopinfo_state = loopinfo_ip_inconsistent; + else + irg->loopinfo_state = loopinfo_inconsistent; +} + INLINE void set_irg_pinned (ir_graph *irg, op_pinned p) { irg->pinned = p; } + +irg_callee_info_state get_irg_callee_info_state(ir_graph *irg) { + return irg->callee_info_state; +} + +void set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) { + irg->callee_info_state = s; +} + +irg_inline_property get_irg_inline_property(ir_graph *irg) { + return irg->inline_property; +} +void set_irg_inline_property(ir_graph *irg, irg_inline_property s) { + irg->inline_property = s; +} + + INLINE void set_irg_link (ir_graph *irg, void *thing) { irg->link = thing; @@ -490,9 +597,11 @@ inc_irg_visited (ir_graph *irg) 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))); + /* + 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; } @@ -503,9 +612,11 @@ void set_max_irg_visited(int 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))); + /* + 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; }