From 789a7c709a112b02a86f5401d1c5a19e64d5640d Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 15 Dec 2011 17:39:51 +0100 Subject: [PATCH] perform end/first block mature in libfirm The first block in a new ir_graph is not an immature block anymore. The end block is matured in irg_finalize_cons() now (since maturing blocks twice doesn't hurt this shouldn't break existing code). --- ir/ir/ircons.c | 14 ++++++++++++++ ir/ir/irgraph.c | 5 ++--- ir/ir/irio.c | 1 + ir/ir/irssacons.c | 4 ++-- ir/ir/irtypes.h | 1 + 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ir/ir/ircons.c b/ir/ir/ircons.c index 9e28bd11b..b49ae6fff 100644 --- a/ir/ir/ircons.c +++ b/ir/ir/ircons.c @@ -314,6 +314,7 @@ void mature_immBlock(ir_node *block) size_t n_preds; ir_node *next; ir_node *phi; + ir_node **new_in; ir_graph *irg; assert(is_Block(block)); @@ -340,6 +341,15 @@ void mature_immBlock(ir_node *block) set_Block_matured(block, 1); + /* create final in-array for the block */ + if (block->attr.block.dynamic_ins) { + new_in = NEW_ARR_D(ir_node*, irg->obst, n_preds+1); + memcpy(new_in, block->in, (n_preds+1) * sizeof(new_in[0])); + DEL_ARR_F(block->in); + block->in = new_in; + block->attr.block.dynamic_ins = false; + } + /* Now, as the block is a finished Firm node, we can optimize it. Since other nodes have been allocated since the block was created we can not free the node on the obstack. Therefore we have to call @@ -462,6 +472,7 @@ ir_node *new_rd_immBlock(dbg_info *dbgi, ir_graph *irg) res = new_ir_node(dbgi, irg, NULL, op_Block, mode_BB, -1, NULL); set_Block_matured(res, 0); + res->attr.block.dynamic_ins = true; res->attr.block.irg.irg = irg; res->attr.block.backedge = NULL; res->attr.block.in_cg = NULL; @@ -699,6 +710,9 @@ void ir_set_uninitialized_local_variable_func( void irg_finalize_cons(ir_graph *irg) { + ir_node *end_block = get_irg_end_block(irg); + mature_immBlock(end_block); + set_irg_phase_state(irg, phase_high); } diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index bae26bec6..c3b08605c 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -187,7 +187,7 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) res->anchor = new_r_Anchor(res); /*-- Nodes needed in every graph --*/ - set_irg_end_block (res, new_r_immBlock(res)); + set_irg_end_block(res, new_r_immBlock(res)); set_irg_end(res, new_r_End(res, 0, NULL)); start_block = new_r_Block_noopt(res, 0, NULL); @@ -213,9 +213,8 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) set_r_store(res, initial_mem); /*-- Make a block to start with --*/ - first_block = new_r_immBlock(res); + first_block = new_r_Block(res, 1, &projX); set_r_cur_block(res, first_block); - add_immBlock_pred(first_block, projX); res->method_execution_frequency = -1.0; res->estimated_node_count = 0; diff --git a/ir/ir/irio.c b/ir/ir/irio.c index a0dd0363a..726e900a5 100644 --- a/ir/ir/irio.c +++ b/ir/ir/irio.c @@ -2286,6 +2286,7 @@ static ir_graph *read_irg(read_env_t *env) ir_type *frame = read_type_ref(env); irg_inline_property prop = read_inline_property(env); unsigned props = read_unsigned(env); + irg_finalize_cons(irg); set_irg_frame_type(irg, frame); set_irg_inline_property(irg, prop); set_irg_additional_properties(irg, (mtp_additional_properties)props); diff --git a/ir/ir/irssacons.c b/ir/ir/irssacons.c index 2d78562e4..930fc7413 100644 --- a/ir/ir/irssacons.c +++ b/ir/ir/irssacons.c @@ -41,10 +41,10 @@ static void prepare_blocks(ir_node *block, void *env) { unsigned n_loc = current_ir_graph->n_loc; struct obstack *obst = current_ir_graph->obst; - (void)env; + (void)env; /* reset mature flag */ set_Block_matured(block, 0); - block->attr.block.graph_arr = NEW_ARR_D(ir_node *, obst, n_loc); + block->attr.block.graph_arr = NEW_ARR_D(ir_node *, obst, n_loc); memset(block->attr.block.graph_arr, 0, sizeof(ir_node*) * n_loc); set_Block_phis(block, NULL); } diff --git a/ir/ir/irtypes.h b/ir/ir/irtypes.h index 8f55b77b4..52ad943d1 100644 --- a/ir/ir/irtypes.h +++ b/ir/ir/irtypes.h @@ -201,6 +201,7 @@ typedef struct block_attr { ir_visited_t block_visited; /**< For the walker that walks over all blocks. */ /* Attributes private to construction: */ unsigned is_matured:1; /**< If set, all in-nodes of the block are fixed. */ + unsigned dynamic_ins:1; /**< if set in-array is an ARR_F on the heap. */ unsigned marked:1; /**< Can be set/unset to temporary mark a block. */ ir_node **graph_arr; /**< An array to store all parameters. */ /* Attributes holding analyses information */ -- 2.20.1