X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fifconv.c;h=ce71867ef95d5f5edd5fef71fa4fb8063516483e;hb=f3e1a3ae9b7950c4542b94fda4827c760aac41d1;hp=b61edfebe9c535da7fbfbd67357475a87a98f6e1;hpb=c046a33ef59e5ff97d868b22cec60f44f5e8eff6;p=libfirm diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index b61edfebe..ce71867ef 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -66,27 +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; - - -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; +static int can_empty_block(ir_node *block) { + return get_Block_mark(block) == 0; } @@ -188,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; @@ -197,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); @@ -218,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 { @@ -268,15 +253,15 @@ 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); for (i = 0; i < arity; ++i) { ir_node* pred0; - cdep* cdep; + 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); @@ -299,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; @@ -307,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", @@ -350,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); @@ -365,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; @@ -390,33 +380,27 @@ 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); } /** * Daisy-chain all phis in a block - * If a non-movable node is encountered set the has_pinned flag + * If a non-movable node is encountered set the has_pinned flag in its block. */ -static void collect_phis(ir_node *node, void *env) -{ +static void collect_phis(ir_node *node, void *env) { (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) { /* @@ -425,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); } } } @@ -543,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 */ @@ -559,11 +541,14 @@ void opt_if_conv(ir_graph *irg, const ir_settings_if_conv_t *params) compute_cdep(irg); assure_doms(irg); - obstack_init(&obst); - irg_block_walk_graph(irg, init_block_link, NULL, &obst); + set_using_block_mark(irg); + + 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_block_mark(irg); + local_optimize_graph(irg); irg_walk_graph(irg, NULL, optimise_psis_0, NULL); @@ -571,8 +556,11 @@ 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); + set_irg_loopinfo_inconsistent(irg); free_dom(irg); + free_cdep(irg); }