From 88bad16c332b94f3ca6050a58e75eb38925e07c6 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Thu, 6 Apr 2006 12:09:25 +0000 Subject: [PATCH] Put all anchor nodes into an array: This makes the implementation of dead node elimination much simplier ... make irg state more generic [r7584] --- ir/ir/irgraph.c | 101 +++++++++++++++++++++++-------------------- ir/ir/irgraph.h | 13 ++++-- ir/ir/irgraph_t.h | 106 ++++++++++++++++++++++++---------------------- 3 files changed, 119 insertions(+), 101 deletions(-) diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index c24cc1a44..0a3bea242 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -130,8 +130,8 @@ ir_graph * new_r_ir_graph (entity *ent, int n_loc) { ir_graph *res; - ir_node *first_block; - ir_node *projX; + ir_node *first_block; + ir_node *end, *start, *start_block, *initial_mem, *projX; res = alloc_graph(); res->kind = k_ir_graph; @@ -202,30 +202,35 @@ new_r_ir_graph (entity *ent, int n_loc) res->frame_type = new_type_frame(mangle(get_entity_ident(ent), frame_type_suffix)); /*-- Nodes needed in every graph --*/ - res->end_block = new_immBlock(); - res->end = new_End(); - res->end_reg = res->end; - res->end_except = res->end; - - 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->no_mem = new_ir_node(NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL); + set_irg_end_block (res, new_immBlock()); + end = new_End(); + set_irg_end (res, end); + set_irg_end_reg (res, end); + set_irg_end_except(res, end); + + start_block = new_immBlock(); + set_irg_start_block(res, start_block); + set_irg_bad (res, new_ir_node(NULL, res, start_block, op_Bad, mode_T, 0, NULL)); + set_irg_no_mem (res, new_ir_node(NULL, res, start_block, op_NoMem, mode_M, 0, NULL)); + start = new_Start(); + set_irg_start (res, start); /* Proj results of start node */ - projX = new_Proj (res->start, mode_X, pn_Start_X_initial_exec); - res->frame = new_Proj (res->start, mode_P_data, pn_Start_P_frame_base); - res->globals = new_Proj (res->start, mode_P_data, pn_Start_P_globals); - res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M); - res->args = new_Proj (res->start, mode_T, pn_Start_T_args); + projX = new_Proj(start, mode_X, pn_Start_X_initial_exec); + 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_args (res, new_Proj(start, mode_T, pn_Start_T_args)); + initial_mem = new_Proj(start, mode_M, pn_Start_M); + set_irg_initial_mem(res, initial_mem); + + add_immBlock_pred(start_block, projX); + set_store(initial_mem); + #ifdef DEBUG_libfirm res->graph_nr = get_irp_new_node_nr(); #endif res->proj_args = NULL; - set_store(res->initial_mem); - - add_immBlock_pred(res->start_block, projX); /* * The code generation needs it. leave it in now. * Use of this edge is matter of discussion, unresolved. Also possible: @@ -256,7 +261,7 @@ new_ir_graph (entity *ent, int n_loc) Must look like a correct irg, spare everything else. */ ir_graph *new_const_code_irg(void) { ir_graph *res; - ir_node *projX; + ir_node *end, *start_block, *start, *projX; res = alloc_graph(); @@ -264,9 +269,9 @@ ir_graph *new_const_code_irg(void) { hook_new_graph(res, NULL); 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 */ + 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 @@ -286,33 +291,37 @@ ir_graph *new_const_code_irg(void) { res->frame_type = NULL; /* -- The end block -- */ - res->end_block = new_immBlock (); - res->end = new_End (); - res->end_reg = res->end; - res->end_except = res->end; + set_irg_end_block (res, new_immBlock()); + end = new_End(); + set_irg_end (res, end); + set_irg_end_reg (res, end); + set_irg_end_except(res, end); mature_immBlock(get_cur_block()); /* mature the end block */ /* -- The start block -- */ - res->start_block = new_immBlock (); - res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL); - res->no_mem = new_ir_node (NULL, res, res->start_block, op_NoMem, mode_M, 0, NULL); - res->start = new_Start (); + start_block = new_immBlock(); + set_irg_start_block(res, start_block); + set_irg_bad (res, new_ir_node (NULL, res, start_block, op_Bad, mode_T, 0, NULL)); + set_irg_no_mem (res, new_ir_node (NULL, res, start_block, op_NoMem, mode_M, 0, NULL)); + start = new_Start(); + set_irg_start (res, start); + /* Proj results of start node */ - res->initial_mem = new_Proj (res->start, mode_M, pn_Start_M); - projX = new_Proj (res->start, mode_X, pn_Start_X_initial_exec); - add_immBlock_pred (res->start_block, projX); - mature_immBlock (res->start_block); /* mature the start block */ + set_irg_initial_mem(res, new_Proj(start, mode_M, pn_Start_M)); + projX = new_Proj(start, mode_X, pn_Start_X_initial_exec); + add_immBlock_pred(start_block, projX); + mature_immBlock (start_block); /* mature the start block */ - add_immBlock_pred (new_immBlock (), projX); - mature_immBlock (get_cur_block()); /* mature the 'body' block for expressions */ + add_immBlock_pred(new_immBlock(), projX); + mature_immBlock (get_cur_block()); /* mature the 'body' block for expressions */ /* Set the visited flag high enough that the blocks 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); - set_irn_visited(res->start_block, -1); - set_irn_visited(res->bad, -1); - set_irn_visited(res->no_mem, -1); + set_Block_block_visited(start_block, -1); + set_irn_visited(start_block, -1); + set_irn_visited(get_irg_bad(res), -1); + set_irn_visited(get_irg_no_mem(res), -1); res->phase_state = phase_high; @@ -343,7 +352,7 @@ void free_ir_graph (ir_graph *irg) { set_entity_peculiarity (irg->ent, pec); } - free_End(irg->end); + free_End(get_irg_end(irg)); obstack_free(irg->obst,NULL); free(irg->obst); #if USE_EXPLICIT_PHI_IN_STACK @@ -422,7 +431,7 @@ ir_node * void set_irg_end_reg (ir_graph *irg, ir_node *node) { assert(get_irn_op(node) == op_EndReg || get_irn_op(node) == op_End); - irg->end_reg = node; + irg->anchors[anchor_end_reg] = node; } ir_node * @@ -432,7 +441,7 @@ 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); - irg->end_except = node; + irg->anchors[anchor_end_except] = node; } ir_node * @@ -598,8 +607,8 @@ irg_phase_state } void -(set_irg_phase_low)(ir_graph *irg) { - _set_irg_phase_low(irg); +(set_irg_phase_state)(ir_graph *irg, irg_phase_state state) { + _set_irg_phase_state(irg, state); } op_pin_state diff --git a/ir/ir/irgraph.h b/ir/ir/irgraph.h index 4ca81b4c9..587b2d02d 100644 --- a/ir/ir/irgraph.h +++ b/ir/ir/irgraph.h @@ -270,12 +270,12 @@ long get_irg_graph_nr(ir_graph *irg); /** The states of an ir graph. * - * state phase values: phase_building, phase_high, phase_low. + * state phase values: phase_building, phase_high, phase_low, phase_backend. * * The graph is in phase_building during construction of the irgraph. * The construction is finished by a call to finalize_cons(). * - * Finalize_cons() sets the state to phase_high. All Firm nodes are + * Finalize_cons() sets the state to phase_high. All stadard Firm nodes are * allowed. * * To get the irgraph into phase_low all Sel nodes must be removed and @@ -283,18 +283,23 @@ long get_irg_graph_nr(ir_graph *irg); * type tag nodes must be removed (@@@ really?). Initialization of * memory allocated by Alloc must be explicit. @@@ More conditions? * + * phase_backend is set if architecture specific machine nodes are inserted + * (and probally most standard Firm are removed). */ typedef enum { phase_building, phase_high, - phase_low + phase_low, + phase_backend } irg_phase_state; /** returns the phase_state of an IR graph. */ irg_phase_state get_irg_phase_state (const ir_graph *irg); /** sets the phase state of an IR graph. */ -void set_irg_phase_low(ir_graph *irg); +void set_irg_phase_state(ir_graph *irg, irg_phase_state state); + +#define set_irg_phase_low(irg) set_irg_phase_state(irg, phase_low) /** state: op_pin_state_pinned The graph is "op_pin_state_pinned" if all nodes are associated with a basic block. diff --git a/ir/ir/irgraph_t.h b/ir/ir/irgraph_t.h index d96bc2cca..da43d0258 100644 --- a/ir/ir/irgraph_t.h +++ b/ir/ir/irgraph_t.h @@ -51,6 +51,27 @@ typedef struct _irg_edge_info_t { unsigned activated : 1; } irg_edge_info_t; +/** + * Index constants for nodes that can be accessed through the graph itself. + */ +enum irg_anchors { + anchor_start_block = 0, /**< block the start node will belong to */ + anchor_start, /**< start node of this ir_graph */ + anchor_end_block, /**< block the end node will belong to */ + anchor_end, /**< end node of this ir_graph */ + anchor_end_reg, /**< end node of this ir_graph */ + anchor_end_except, /**< end node of this ir_graph */ + anchor_cstore, /**< constant store -- no more needed!! */ + anchor_frame, /**< method's frame */ + anchor_globals, /**< pointer to the data segment containing all + globals as well as global procedures. */ + anchor_initial_mem, /**< initial memory of this graph */ + anchor_args, /**< methods arguments */ + anchor_bad, /**< bad node of this ir_graph, the one and + only in this graph */ + anchor_no_mem, /**< NoMem node of this ir_graph, the one and only in this graph */ + anchor_max +}; /** ir_graph holds all information for a procedure */ struct ir_graph { @@ -59,27 +80,10 @@ struct ir_graph { entity *ent; /**< The entity of this procedure, i.e., the type of the procedure and the class it belongs to. */ - ir_type *frame_type; /**< A class type representing the stack frame. - Can include "inner" methods. */ - ir_node *start_block; /**< block the start node will belong to */ - ir_node *start; /**< start node of this ir_graph */ - ir_node *end_block; /**< block the end node will belong to */ - ir_node *end; /**< end node of this ir_graph */ - ir_node *end_reg; /**< end node of this ir_graph */ - ir_node *end_except; /**< end node of this ir_graph */ - ir_node *cstore; /**< constant store -- no more needed!! */ - ir_node *frame; /**< method's frame */ - ir_node *globals; /**< pointer to the data segment containing all - globals as well as global procedures. */ - ir_node *initial_mem; /**< initial memory of this graph */ - ir_node *args; /**< methods arguments */ - ir_node **proj_args; /**< projs of the methods arguments */ - ir_node *bad; /**< bad node of this ir_graph, the one and - only in this graph */ - ir_node *no_mem; /**< NoMem node of this ir_graph, the one and - only in this graph */ - /* GL removed: we need unknown with mode for analyses. */ - /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */ + ir_type *frame_type; /**< A class type representing the stack frame. + Can include "inner" methods. */ + ir_node *anchors[anchor_max]; /**< anchor nodes */ + ir_node **proj_args; /**< projs of the methods arguments */ struct obstack *obst; /**< obstack where all of the ir_nodes live */ ir_node *current_block; /**< block for newly gen_*()-erated ir_nodes */ struct obstack *extbb_obst; /**< obstack for extended basic block info */ @@ -200,102 +204,102 @@ _is_ir_graph(const void *thing) { /** Returns the start block of a graph. */ static INLINE ir_node * _get_irg_start_block(const ir_graph *irg) { - return irg->start_block; + return irg->anchors[anchor_start_block]; } static INLINE void _set_irg_start_block(ir_graph *irg, ir_node *node) { - irg->start_block = node; + irg->anchors[anchor_start_block] = node; } static INLINE ir_node * _get_irg_start(const ir_graph *irg) { - return irg->start; + return irg->anchors[anchor_start]; } static INLINE void _set_irg_start(ir_graph *irg, ir_node *node) { - irg->start = node; + irg->anchors[anchor_start] = node; } static INLINE ir_node * _get_irg_end_block(const ir_graph *irg) { - return irg->end_block; + return irg->anchors[anchor_end_block]; } static INLINE void _set_irg_end_block(ir_graph *irg, ir_node *node) { - irg->end_block = node; + irg->anchors[anchor_end_block] = node; } static INLINE ir_node * _get_irg_end(const ir_graph *irg) { - return irg->end; + return irg->anchors[anchor_end]; } static INLINE void _set_irg_end(ir_graph *irg, ir_node *node) { - irg->end = node; + irg->anchors[anchor_end] = node; } static INLINE ir_node * _get_irg_end_reg(const ir_graph *irg) { - return irg->end_reg; + return irg->anchors[anchor_end_reg]; } static INLINE ir_node * _get_irg_end_except (const ir_graph *irg) { - return irg->end_except; + return irg->anchors[anchor_end_except]; } static INLINE ir_node * _get_irg_cstore(const ir_graph *irg) { - return irg->cstore; + return irg->anchors[anchor_cstore]; } static INLINE void _set_irg_cstore(ir_graph *irg, ir_node *node) { - irg->cstore = node; + irg->anchors[anchor_cstore] = node; } static INLINE ir_node * _get_irg_frame(const ir_graph *irg) { - return irg->frame; + return irg->anchors[anchor_frame]; } static INLINE void _set_irg_frame(ir_graph *irg, ir_node *node) { - irg->frame = node; + irg->anchors[anchor_frame] = node; } static INLINE ir_node * _get_irg_globals(const ir_graph *irg) { - return irg->globals; + return irg->anchors[anchor_globals]; } static INLINE void _set_irg_globals(ir_graph *irg, ir_node *node) { - irg->globals = node; + irg->anchors[anchor_globals] = node; } static INLINE ir_node * _get_irg_initial_mem(const ir_graph *irg) { - return irg->initial_mem; + return irg->anchors[anchor_initial_mem]; } static INLINE void _set_irg_initial_mem(ir_graph *irg, ir_node *node) { - irg->initial_mem = node; + irg->anchors[anchor_initial_mem] = node; } static INLINE ir_node * _get_irg_args(const ir_graph *irg) { - return irg->args; + return irg->anchors[anchor_args]; } static INLINE void _set_irg_args(ir_graph *irg, ir_node *node) { - irg->args = node; + irg->anchors[anchor_args] = node; } static INLINE ir_node ** @@ -310,22 +314,22 @@ _set_irg_proj_args(ir_graph *irg, ir_node **nodes) { static INLINE ir_node * _get_irg_bad(const ir_graph *irg) { - return irg->bad; + return irg->anchors[anchor_bad]; } static INLINE void _set_irg_bad(ir_graph *irg, ir_node *node) { - irg->bad = node; + irg->anchors[anchor_bad] = node; } static INLINE ir_node * _get_irg_no_mem(const ir_graph *irg) { - return irg->no_mem; + return irg->anchors[anchor_no_mem]; } static INLINE void _set_irg_no_mem(ir_graph *irg, ir_node *node) { - irg->no_mem = node; + irg->anchors[anchor_no_mem] = node; } static INLINE ir_node * _get_irg_current_block(const ir_graph *irg) { @@ -356,7 +360,7 @@ _get_irg_frame_type(ir_graph *irg) { static INLINE void _set_irg_frame_type(ir_graph *irg, ir_type *ftp) { - assert(is_Class_type(ftp)); + assert(is_frame_type(ftp)); irg->frame_type = ftp; } @@ -372,8 +376,8 @@ _get_irg_phase_state(const ir_graph *irg) { } static INLINE void -_set_irg_phase_low(ir_graph *irg) { - irg->phase_state = phase_low; +_set_irg_phase_state(ir_graph *irg, irg_phase_state state) { + irg->phase_state = state; } static INLINE op_pin_state @@ -560,12 +564,12 @@ _get_irg_estimated_node_cnt(const ir_graph *irg) { #define set_irg_frame_type(irg, ftp) _set_irg_frame_type(irg, ftp) #define get_irg_obstack(irg) _get_irg_obstack(irg) #define get_irg_phase_state(irg) _get_irg_phase_state(irg) -#define set_irg_phase_low(irg) _set_irg_phase_low(irg) +#define set_irg_phase_state(irg, state) _set_irg_phase_state(irg, state) #define get_irg_pinned(irg) _get_irg_pinned(irg) #define get_irg_outs_state(irg) _get_irg_outs_state(irg) #define set_irg_outs_inconsistent(irg) _set_irg_outs_inconsistent(irg) -#define get_irg_extblk_state(irg) _get_irg_extblk_state(irg) -#define set_irg_extblk_inconsistent(irg) _set_irg_extblk_inconsistent(irg) +#define get_irg_extblk_state(irg) _get_irg_extblk_state(irg) +#define set_irg_extblk_inconsistent(irg) _set_irg_extblk_inconsistent(irg) #define get_irg_dom_state(irg) _get_irg_dom_state(irg) #define get_irg_postdom_state(irg) _get_irg_postdom_state(irg) #define set_irg_doms_inconsistent(irg) _set_irg_doms_inconsistent(irg) -- 2.20.1