Commit e89d2463 authored by Michael Beck's avatar Michael Beck
Browse files

Moved some helper functions from irgopt to irtools for reuse.

parent 8e4bc2eb
/*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
* Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
......@@ -51,6 +51,20 @@ void firm_clear_node_and_phi_links(ir_node *n, void *env)
set_Phi_next(n, NULL);
}
void firm_clear_block_phis(ir_node *node, void *env)
{
(void) env;
if (is_Block(node))
set_Block_phis(node, NULL);
}
void firm_collect_block_phis(ir_node *node, void *env)
{
(void) env;
if (is_Phi(node))
add_Block_phi(get_nodes_block(node), node);
}
void copy_irn_to_irg(ir_node *n, ir_graph *irg)
{
ir_op *op = get_irn_op(n);
......
......@@ -77,10 +77,23 @@ void firm_clear_link(ir_node *n, void *env);
* The famous clear_link_and_block_lists() walker-function.
* Sets all links fields of visited nodes to NULL.
* Additionally, clear all Phi-lists of visited blocks.
* Do not implement it by yourself, use this one
* Do not implement it by yourself, use this one.
*/
void firm_clear_node_and_phi_links(ir_node *n, void *env);
/**
* Walker function, sets all phi list heads fields of visited Blocks
* to NULL.
* Use in conjunction with firm_collect_block_phis().
*/
void firm_clear_block_phis(ir_node *node, void *env);
/**
* Walker function, links all visited Phi nodes into its block links.
* Use in conjunction with firm_clear_block_phis().
*/
void firm_collect_block_phis(ir_node *node, void *env);
/**
* Creates an exact copy of a node with same inputs and attributes in the
* same block.
......
......@@ -182,20 +182,6 @@ static void opt_walker(ir_node *n, void *env)
}
}
static void clear_block_phis(ir_node *node, void *env) {
(void) env;
if (is_Block(node)) {
set_Block_phis(node, NULL);
}
}
static void collect_block_phis(ir_node *node, void *env) {
(void) env;
if (is_Phi(node)) {
add_Block_phi(get_nodes_block(node), node);
}
}
static int count_non_bads(ir_node *node) {
int arity = get_irn_arity(node);
int count = 0;
......@@ -275,7 +261,7 @@ static void block_remove_bads(ir_node *block, int *changed) {
static int remove_Bads(ir_graph *irg) {
int changed = 0;
/* build phi list per block */
irg_walk_graph(irg, clear_block_phis, collect_block_phis, NULL);
irg_walk_graph(irg, firm_clear_block_phis, firm_collect_block_phis, NULL);
/* actually remove Bads */
irg_block_walk_graph(irg, NULL, (void (*)(struct ir_node *, void *)) block_remove_bads, &changed);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment