X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fifconv.c;h=ce71867ef95d5f5edd5fef71fa4fb8063516483e;hb=cfb6f31de9746a66a7aff7f64199730179d0d392;hp=f47344221541aae44efb8eb797f4a13fc990925f;hpb=331139406017cd6619cdbd9aae8d7d16703a9ad3;p=libfirm diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index f47344221..ce71867ef 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -66,25 +66,11 @@ static const ir_settings_if_conv_t default_info = { default_allow_ifconv }; -/** - * Additional block info. - */ -typedef struct block_info { - ir_node *phi; /**< head of the Phi list */ - int has_pinned; /**< set if the block contains instructions that cannot be moved */ -} block_info; - -/** Returns the additional block info of a block. */ -static INLINE block_info* get_block_blockinfo(const ir_node* block) { - return get_irn_link(block); -} - - /** * Returns non-zero if a Block can be emptied. */ static int can_empty_block(ir_node *block) { - return !get_block_blockinfo(block)->has_pinned; + return get_Block_mark(block) == 0; } @@ -186,7 +172,7 @@ static void split_block(ir_node* block, int i, int j) ir_node* pred_block = get_nodes_block(get_irn_n(block, i)); int arity = get_irn_arity(block); int new_pred_arity; - ir_node* phi; + ir_node *phi, *next; ir_node **ins; ir_node **pred_ins; int k; @@ -195,7 +181,7 @@ static void split_block(ir_node* block, int i, int j) NEW_ARR_A(ir_node*, ins, arity + 1); - for (phi = get_block_blockinfo(block)->phi; phi != NULL; phi = get_irn_link(phi)) { + for (phi = get_Block_phis(block); phi != NULL; phi = get_Phi_next(phi)) { ir_node* copy = copy_to(get_irn_n(phi, i), pred_block, j); for (k = 0; k < i; ++k) ins[k] = get_irn_n(phi, k); @@ -216,10 +202,11 @@ static void split_block(ir_node* block, int i, int j) new_pred_arity = get_irn_arity(pred_block) - 1; NEW_ARR_A(ir_node*, pred_ins, new_pred_arity); - for (phi = get_block_blockinfo(pred_block)->phi; phi != NULL; phi = get_irn_link(phi)) { + for (phi = get_Block_phis(pred_block); phi != NULL; phi = next) { for (k = 0; k < j; ++k) pred_ins[k] = get_irn_n(phi, k); for (; k < new_pred_arity; ++k) pred_ins[k] = get_irn_n(phi, k + 1); assert(k == new_pred_arity); + next = get_Phi_next(phi); if (new_pred_arity > 1) { set_irn_in(phi, new_pred_arity, pred_ins); } else { @@ -266,7 +253,7 @@ static void if_conv_walker(ir_node* block, void* env) int i; /* Bail out, if there are no Phis at all */ - if (get_block_blockinfo(block)->phi == NULL) return; + if (get_Block_phis(block) == NULL) return; restart: arity = get_irn_arity(block); @@ -274,7 +261,7 @@ restart: ir_node* pred0; ir_cdep* cdep; - pred0 = get_nodes_block(get_irn_n(block, i)); + pred0 = get_Block_cfgpred_block(block, i); for (cdep = find_cdep(pred0); cdep != NULL; cdep = cdep->next) { const ir_node* dependency = cdep->node; ir_node* projx0 = walk_to_projx(pred0, dependency); @@ -297,7 +284,7 @@ restart: ir_node* pred1; dbg_info* cond_dbg; - pred1 = get_nodes_block(get_irn_n(block, j)); + pred1 = get_Block_cfgpred_block(block, j); if (!is_cdep_on(pred1, dependency)) continue; @@ -305,7 +292,7 @@ restart: if (projx1 == NULL) continue; - phi = get_block_blockinfo(block)->phi; + phi = get_Block_phis(block); if (!opt_info->allow_ifconv(get_Cond_selector(cond), phi, i, j)) continue; DB((dbg, LEVEL_1, "Found Cond %+F with proj %+F and %+F\n", @@ -348,7 +335,7 @@ restart: DB((dbg, LEVEL_2, "Generating %+F for %+F\n", psi, phi)); } - next_phi = get_irn_link(phi); + next_phi = get_Phi_next(phi); if (arity == 2) { exchange(phi, psi); @@ -363,18 +350,23 @@ restart: exchange(get_nodes_block(get_irn_n(block, j)), psi_block); if (arity == 2) { + unsigned mark; #if 1 DB((dbg, LEVEL_1, "Welding block %+F and %+F\n", block, psi_block)); /* copy the block-info from the Psi-block to the block before merging */ - get_block_blockinfo(psi_block)->has_pinned |= get_block_blockinfo(block)->has_pinned; - set_irn_link(block, get_irn_link(psi_block)); + + mark = get_Block_mark(psi_block) | get_Block_mark(block); + set_Block_mark(block, mark); + set_Block_phis(block, get_Block_phis(psi_block)); set_irn_in(block, get_irn_arity(psi_block), get_irn_in(psi_block) + 1); exchange_cdep(psi_block, block); exchange(psi_block, block); #else DB((dbg, LEVEL_1, "Welding block %+F to %+F\n", block, psi_block)); - get_block_blockinfo(psi_block)->has_pinned |= get_block_blockinfo(block)->has_pinned; + mark = get_Block_mark(psi_block) | get_Block_mark(block); + /* mark both block just to be sure, should be enough to mark psi_block */ + set_Block_mark(psi_block, mark); exchange(block, psi_block); #endif return; @@ -388,16 +380,13 @@ restart: } /** - * Block walker: add additional data + * Block walker: clear block mark and Phi list */ static void init_block_link(ir_node *block, void *env) { - struct obstack *obst = env; - block_info *bi = obstack_alloc(obst, sizeof(*bi)); - - bi->phi = NULL; - bi->has_pinned = 0; - set_irn_link(block, bi); + (void)env; + set_Block_mark(block, 0); + set_Block_phis(block, NULL); } @@ -410,10 +399,8 @@ static void collect_phis(ir_node *node, void *env) { if (is_Phi(node)) { ir_node *block = get_nodes_block(node); - block_info *bi = get_block_blockinfo(block); - set_irn_link(node, bi->phi); - bi->phi = node; + add_Block_phi(block, node); } else { if (is_no_Block(node) && get_irn_pinned(node) == op_pin_state_pinned) { /* @@ -422,10 +409,9 @@ static void collect_phis(ir_node *node, void *env) { */ if (!is_cfop(node)) { ir_node *block = get_nodes_block(node); - block_info *bi = get_block_blockinfo(block); DB((dbg, LEVEL_2, "Node %+F in block %+F is unmovable\n", node, block)); - bi->has_pinned = 1; + set_Block_mark(block, 1); } } } @@ -540,7 +526,6 @@ static void optimise_psis_1(ir_node* psi, void* env) void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) { - struct obstack obst; ir_settings_if_conv_t p; /* get the parameters */ @@ -556,14 +541,13 @@ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) compute_cdep(irg); assure_doms(irg); - set_using_irn_link(irg); + set_using_block_mark(irg); - obstack_init(&obst); - irg_block_walk_graph(irg, init_block_link, NULL, &obst); + irg_block_walk_graph(irg, init_block_link, NULL, NULL); irg_walk_graph(irg, collect_phis, NULL, NULL); irg_block_walk_graph(irg, NULL, if_conv_walker, &p); - clear_using_irn_link(irg); + clear_using_block_mark(irg); local_optimize_graph(irg); @@ -572,8 +556,6 @@ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) irg_walk_graph(irg, NULL, optimise_psis_1, NULL); #endif - obstack_free(&obst, NULL); - /* TODO: graph might be changed, handle more graceful */ set_irg_outs_inconsistent(irg); set_irg_extblk_inconsistent(irg);