X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flower%2Flower_mux.c;h=99652687e669f9fc9bb4c62694ac958b4d63f199;hb=d543bd3efe5deadc0a34423cb8645db7ff9ce704;hp=af85428ed928a7e817f22086f8f794d600788159;hpb=aaee4db780fee1f862dae7cb8c79486d62fd4db9;p=libfirm diff --git a/ir/lower/lower_mux.c b/ir/lower/lower_mux.c index af85428ed..99652687e 100644 --- a/ir/lower/lower_mux.c +++ b/ir/lower/lower_mux.c @@ -1,5 +1,5 @@ /* - * 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. * @@ -21,7 +21,6 @@ * @file * @brief Replaces Mux nodes with control-flow * @author Olaf Liebe - * @version $Id$ */ #include "config.h" @@ -34,7 +33,7 @@ #include "irgwalk.h" #include "irgmod.h" #include "ircons.h" -#include "irvrfy.h" +#include "irpass_t.h" typedef struct walk_env { lower_mux_callback *cb_func; @@ -43,7 +42,7 @@ typedef struct walk_env { static void find_mux_nodes(ir_node *mux, void *ctx) { - walk_env_t *env = ctx; + walk_env_t *env = (walk_env_t*)ctx; /* Skip non-mux nodes. */ if (!is_Mux(mux)) @@ -60,15 +59,18 @@ static void find_mux_nodes(ir_node *mux, void *ctx) static void lower_mux_node(ir_node* mux) { - ir_node *upper_block; - ir_node *lower_block; - ir_node *cond; - ir_node *trueProj; - ir_node *falseProj; - ir_node *falseBlock; - ir_node *mux_jmps[2]; - ir_node *mux_values[2]; - ir_node *phi; + ir_node *upper_block; + ir_node *lower_block; + ir_node *cond; + ir_node *trueProj; + ir_node *falseProj; + ir_node *falseBlock; + ir_node *mux_jmps[2]; + ir_node *mux_values[2]; + ir_node *phi; + ir_graph *irg; + + irg = get_irn_irg(mux); /* Split the block in two halfs, with the mux in the upper block. */ lower_block = get_nodes_block(mux); @@ -81,9 +83,9 @@ static void lower_mux_node(ir_node* mux) * block in-between, so that the phi can be used to select the result * value from the old mux node in the lower block. */ cond = new_r_Cond(upper_block, get_Mux_sel(mux)); - trueProj = new_r_Proj(upper_block, cond, mode_X, pn_Cond_true); - falseProj = new_r_Proj(upper_block, cond, mode_X, pn_Cond_false); - falseBlock = new_r_Block(current_ir_graph, 1, &falseProj); + trueProj = new_r_Proj(cond, mode_X, pn_Cond_true); + falseProj = new_r_Proj(cond, mode_X, pn_Cond_false); + falseBlock = new_r_Block(irg, 1, &falseProj); mux_jmps[0] = trueProj; mux_jmps[1] = new_r_Jmp(falseBlock); @@ -111,7 +113,7 @@ static void lower_mux_node(ir_node* mux) void lower_mux(ir_graph *irg, lower_mux_callback *cb_func) { - int i, n_muxes; + size_t i, n_muxes; walk_env_t env; /* Scan the graph for mux nodes to lower. */ @@ -134,10 +136,33 @@ void lower_mux(ir_graph *irg, lower_mux_callback *cb_func) /* Cleanup, verify the graph. */ ir_free_resources(irg, resources); - set_irg_outs_inconsistent(irg); - set_irg_doms_inconsistent(irg); - set_irg_extblk_inconsistent(irg); - set_irg_loopinfo_inconsistent(irg); + clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE + | IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS); } DEL_ARR_F(env.muxes); } + +typedef struct pass_t { + ir_graph_pass_t pass; + lower_mux_callback *cb_func; +} pass_t; + +/** + * Wrapper to run ir_lower_mux() as an ir_graph pass + */ +static int pass_wrapper(ir_graph *irg, void *context) +{ + pass_t *pass = (pass_t*)context; + + lower_mux(irg, pass->cb_func); + return 0; +} + +ir_graph_pass_t *lower_mux_pass(const char *name, lower_mux_callback *cb_func) +{ + pass_t *pass = XMALLOCZ(pass_t); + + pass->cb_func = cb_func; + return def_graph_pass_constructor( + &pass->pass, name ? name : "lower_mux", pass_wrapper); +}