X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firgwalk_blk.c;h=f19a096ca2e780fdd3d08fae6d0b0528b20f968d;hb=945c6c2ceebef5e41c0486c31f49d2319cacb3da;hp=7ead8fe0eac377ecec3427a9f2406eb3103b8b7b;hpb=0fbcef83aa6060534172bb13e71cdadb04428806;p=libfirm diff --git a/ir/ir/irgwalk_blk.c b/ir/ir/irgwalk_blk.c index 7ead8fe0e..f19a096ca 100644 --- a/ir/ir/irgwalk_blk.c +++ b/ir/ir/irgwalk_blk.c @@ -1,37 +1,23 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** * @file * @brief Blockwise walker implementation * @author Michael Beck - * @version $Id$ */ #include "config.h" #include "irnode_t.h" -#include "irgraph_t.h" /* visited flag */ +#include "irgraph_t.h" #include "irgwalk.h" #include "pset.h" #include "irhooks.h" #include "array.h" #include "hashptr.h" +#include "ircons.h" #define _get_walk_arity(env, node) \ ((env)->follow_deps ? get_irn_ins_or_deps((node)) : get_irn_arity((node))) @@ -41,7 +27,7 @@ /** * Metadata for block walker */ -typedef struct _blk_collect_data_t { +typedef struct blk_collect_data_t { struct obstack obst; /**< obstack to allocate objects on */ pset *blk_map; /**< Hash map: Block -> List */ ir_node **blk_list; /**< the Block list */ @@ -51,7 +37,7 @@ typedef struct _blk_collect_data_t { /** * An entry for a block in the blk_map */ -typedef struct _block_entry_t { +typedef struct block_entry_t { ir_node *block; /**< the block */ ir_node **phi_list; /**< the list of Phi instruction */ ir_node **df_list; /**< the list of data flow instruction */ @@ -62,9 +48,10 @@ typedef struct _block_entry_t { /** * compare two block_entries */ -static int addr_cmp(const void *elt, const void *key) { - const block_entry_t *e1 = elt; - const block_entry_t *e2 = key; +static int addr_cmp(const void *elt, const void *key) +{ + const block_entry_t *e1 = (const block_entry_t*)elt; + const block_entry_t *e2 = (const block_entry_t*)key; return e1->block != e2->block; } @@ -78,11 +65,11 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx) block_entry_t *elem; key.block = block; - elem = pset_find(ctx->blk_map, &key, HASH_PTR(block)); + elem = (block_entry_t*)pset_find(ctx->blk_map, &key, hash_ptr(block)); if (elem) return elem; - elem = obstack_alloc(&ctx->obst, sizeof(*elem)); + elem = OALLOC(&ctx->obst, block_entry_t); elem->block = block; elem->phi_list = NEW_ARR_F(ir_node *, 0); @@ -90,27 +77,28 @@ static block_entry_t *block_find_entry(ir_node *block, blk_collect_data_t *ctx) elem->cf_list = NEW_ARR_F(ir_node *, 0); elem->entry_list = NEW_ARR_F(ir_node *, 0); - return pset_insert(ctx->blk_map, elem, HASH_PTR(block)); + return (block_entry_t*)pset_insert(ctx->blk_map, elem, hash_ptr(block)); } /** * Traverse a block in pre order. */ -static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_func *pre, void *env) { - int j; +static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_func *pre, void *env) +{ + size_t j; - for (j = ARR_LEN(entry->cf_list) - 1; j >= 0; --j) { - ir_node *node = entry->cf_list[j]; + for (j = ARR_LEN(entry->cf_list); j > 0;) { + ir_node *node = entry->cf_list[--j]; pre(node, env); } - for (j = ARR_LEN(entry->df_list) - 1; j >= 0; --j) { - ir_node *node = entry->df_list[j]; + for (j = ARR_LEN(entry->df_list); j > 0;) { + ir_node *node = entry->df_list[--j]; pre(node, env); } - for (j = ARR_LEN(entry->phi_list) - 1; j >= 0; --j) { - ir_node *node = entry->phi_list[j]; + for (j = ARR_LEN(entry->phi_list); j > 0;) { + ir_node *node = entry->phi_list[--j]; pre(node, env); } @@ -120,8 +108,10 @@ static void traverse_block_pre(ir_node *block, block_entry_t *entry, irg_walk_fu /** * Traverse a block in post order. */ -void traverse_block_post(ir_node *block, block_entry_t *entry, irg_walk_func *post, void *env) { - int j, n; +static void traverse_block_post(ir_node *block, block_entry_t *entry, + irg_walk_func *post, void *env) +{ + size_t j, n; post(block, env); @@ -144,11 +134,12 @@ void traverse_block_post(ir_node *block, block_entry_t *entry, irg_walk_func *po /** * traverse the pre order only, from End to Start */ -static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env) { - int i; +static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env) +{ + size_t i; - for (i = ARR_LEN(blks->blk_list) - 1; i >= 0; --i) { - ir_node *block = blks->blk_list[i]; + for (i = ARR_LEN(blks->blk_list); i > 0;) { + ir_node *block = blks->blk_list[--i]; block_entry_t *entry = block_find_entry(block, blks); traverse_block_pre(block, entry, pre, env); @@ -163,8 +154,9 @@ static void traverse_pre(blk_collect_data_t *blks, irg_walk_func *pre, void *env /** * traverse the post order only, from Start to End */ -static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *env) { - int i, k; +static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *env) +{ + size_t i, k; for (i = 0, k = ARR_LEN(blks->blk_list); i < k; ++i) { ir_node *block = blks->blk_list[i]; @@ -184,10 +176,10 @@ static void traverse_post(blk_collect_data_t *blks, irg_walk_func *post, void *e */ static void traverse_both(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env) { - int i; + size_t i; - for (i = ARR_LEN(blks->blk_list) - 1; i >= 0; --i) { - ir_node *block = blks->blk_list[i]; + for (i = ARR_LEN(blks->blk_list); i > 0;) { + ir_node *block = blks->blk_list[--i]; block_entry_t *entry = block_find_entry(block, blks); traverse_block_pre(block, entry, pre, env); @@ -200,7 +192,8 @@ static void traverse_both(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk /** * Do the traversal. */ -static void traverse_blocks(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env) { +static void traverse_blocks(blk_collect_data_t *blks, irg_walk_func *pre, irg_walk_func *post, void *env) +{ if (!post) traverse_pre (blks, pre, env); else if (!pre) traverse_post(blks, post, env); else traverse_both(blks, pre, post, env); @@ -216,8 +209,9 @@ typedef struct dom_traversal_t { /** * Dom block walker. Visit all nodes in pre oder. */ -static void dom_block_visit_pre(ir_node *block, void *env) { - dom_traversal_t *ctx = env; +static void dom_block_visit_pre(ir_node *block, void *env) +{ + dom_traversal_t *ctx = (dom_traversal_t*)env; block_entry_t *entry = block_find_entry(block, ctx->blks); traverse_block_pre(block, entry, ctx->pre, ctx->env); @@ -226,8 +220,9 @@ static void dom_block_visit_pre(ir_node *block, void *env) { /** * Dom block walker. Visit all nodes in post oder. */ -static void dom_block_visit_post(ir_node *block, void *env) { - dom_traversal_t *ctx = env; +static void dom_block_visit_post(ir_node *block, void *env) +{ + dom_traversal_t *ctx = (dom_traversal_t*)env; block_entry_t *entry = block_find_entry(block, ctx->blks); traverse_block_post(block, entry, ctx->post, ctx->env); @@ -236,8 +231,9 @@ static void dom_block_visit_post(ir_node *block, void *env) { /** * Dom block walker. Visit all nodes in pre oder, than in post order. */ -static void dom_block_visit_both(ir_node *block, void *env) { - dom_traversal_t *ctx = env; +static void dom_block_visit_both(ir_node *block, void *env) +{ + dom_traversal_t *ctx = (dom_traversal_t*)env; block_entry_t *entry = block_find_entry(block, ctx->blks); traverse_block_pre(block, entry, ctx->pre, ctx->env); @@ -247,7 +243,8 @@ static void dom_block_visit_both(ir_node *block, void *env) { /** * Do the traversal in the dominator tree in top-down order. */ -static void traverse_dom_blocks_top_down(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env) { +static void traverse_dom_blocks_top_down(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env) +{ dom_traversal_t ctx; ctx.blks = blks; @@ -256,11 +253,11 @@ static void traverse_dom_blocks_top_down(blk_collect_data_t* blks, irg_walk_func ctx.env = env; if (pre != NULL && post != NULL) - dom_tree_walk_irg(current_ir_graph, dom_block_visit_both, NULL, &ctx); + dom_tree_walk_irg(current_ir_graph, dom_block_visit_both, NULL, &ctx); else if (pre != NULL) - dom_tree_walk_irg(current_ir_graph, dom_block_visit_pre, NULL, &ctx); + dom_tree_walk_irg(current_ir_graph, dom_block_visit_pre, NULL, &ctx); else if (post != NULL) - dom_tree_walk_irg(current_ir_graph, dom_block_visit_post, NULL, &ctx); + dom_tree_walk_irg(current_ir_graph, dom_block_visit_post, NULL, &ctx); } /** @@ -274,7 +271,7 @@ static void collect_walk(ir_node *node, blk_collect_data_t *env) mark_irn_visited(node); - if (node->op == op_Block) { + if (is_Block(node)) { /* predecessors of a block are control flow nodes */ for (i = _get_walk_arity(env, node) - 1; i >= 0; --i) { ir_node *pred = _get_walk_irn_n(env, node, i); @@ -313,7 +310,7 @@ static void collect_walk(ir_node *node, blk_collect_data_t *env) collect_walk(pred, env); /* BEWARE: predecessors of End nodes might be blocks */ - if (is_no_Block(pred)) { + if (!is_Block(pred)) { ir_node *blk = get_nodes_block(pred); /* @@ -351,7 +348,7 @@ static void collect_blks_lists(ir_node *node, ir_node *block, ir_node *pred = _get_walk_irn_n(env, node, i); /* BEWARE: predecessors of End nodes might be blocks */ - if (is_no_Block(pred)) { + if (!is_Block(pred)) { ir_node *blk = get_nodes_block(pred); if (!irn_visited(pred)) { @@ -378,18 +375,18 @@ static void collect_blks_lists(ir_node *node, ir_node *block, */ static void collect_lists(blk_collect_data_t *env) { - int i, j; + size_t i, j; ir_node *block, *node; block_entry_t *entry; inc_irg_visited(current_ir_graph); - for (i = ARR_LEN(env->blk_list) - 1; i >= 0; --i) { - block = env->blk_list[i]; + for (i = ARR_LEN(env->blk_list); i > 0;) { + block = env->blk_list[--i]; entry = block_find_entry(block, env); - for (j = ARR_LEN(entry->entry_list) - 1; j >= 0; --j) { - node = entry->entry_list[j]; + for (j = ARR_LEN(entry->entry_list); j > 0;) { + node = entry->entry_list[--j]; /* a entry might already be visited due to Phi loops */ if (node->visited < current_ir_graph->visited) @@ -399,23 +396,17 @@ static void collect_lists(blk_collect_data_t *env) } /** - * Intraprozedural graph walker over blocks. + * Intra procedural graph walker over blocks. */ -static void -do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env, unsigned follow_deps, - void (*traverse)(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env)) +static void do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, + irg_walk_func *post, void *env, unsigned follow_deps, + void (*traverse)(blk_collect_data_t* blks, irg_walk_func *pre, irg_walk_func *post, void *env)) { ir_node *end_node = get_irg_end(irg); ir_node *end_blk = get_irg_end_block(irg); blk_collect_data_t blks; block_entry_t *entry; -#ifdef INTERPROCEDURAL_VIEW - /* switch off interprocedural view */ - int old_view = get_interprocedural_view(); - set_interprocedural_view(0); -#endif - obstack_init(&blks.obst); blks.blk_map = new_pset(addr_cmp, 1); blks.blk_list = NEW_ARR_F(ir_node *, 0); @@ -442,13 +433,11 @@ do_irg_walk_blk(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *en del_pset(blks.blk_map); obstack_free(&blks.obst, NULL); -#ifdef INTERPROCEDURAL_VIEW - set_interprocedural_view(old_view); -#endif ir_free_resources(irg, IR_RESOURCE_IRN_VISITED); } -void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post); @@ -457,7 +446,8 @@ void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *po current_ir_graph = rem; } -void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post); @@ -466,7 +456,8 @@ void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_wal current_ir_graph = rem; } -void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) { +void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) +{ ir_graph * rem = current_ir_graph; hook_irg_walk_blkwise(irg, (generic_func *)pre, (generic_func *)post);