From: Andreas Zwinkau Date: Wed, 26 Oct 2011 14:14:15 +0000 (+0200) Subject: Add remove_tuples function X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=917ab46635e6c68aa98c69f6801caf36df29d9c5;p=libfirm Add remove_tuples function --- diff --git a/include/libfirm/irgopt.h b/include/libfirm/irgopt.h index f7f9e1f24..8bde4b997 100644 --- a/include/libfirm/irgopt.h +++ b/include/libfirm/irgopt.h @@ -72,6 +72,15 @@ FIRM_API void remove_unreachable_code(ir_graph *irg); */ FIRM_API int remove_bads(ir_graph *irg); +/** + * Removes all Tuple nodes from a graph. + * + * @param irg The graph to be optimized. + * + * @return non-zero if at least one Tuple was removed, otherwise 0 + */ +FIRM_API int remove_tuples(ir_graph *irg); + /** * Creates an ir_graph pass for optimize_graph_df(). * diff --git a/ir/ir/rm_tuples.c b/ir/ir/rm_tuples.c new file mode 100644 index 000000000..8fc4e2d05 --- /dev/null +++ b/ir/ir/rm_tuples.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 Karlsruhe Institute of Technology. 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. + */ + +/** + * @brief Remove all Tuple nodes from ir graph + * @author Andreas Zwinkau + */ +#include "config.h" + +#include "irnode_t.h" +#include "irgopt.h" +#include "irgmod.h" +#include "irgwalk.h" +#include "irtools.h" +#include "irgopt.h" + +/** Transforms: + * a + * | + * Tuple + * | => + * Proj x a + */ +static void exchange_tuple_projs(ir_node *node, void *env) +{ + bool *changed = (bool*)env; + ir_node *pred; + int proj; + + if (!is_Proj(node)) return; + + pred = get_Proj_pred(node); + proj = get_Proj_proj(node); + + if (!is_Tuple(pred)) return; + + pred = get_Tuple_pred(pred, proj); + exchange(node, pred); + *changed = true; +} + +/* Remove Tuple nodes from an ir graph. + * + * Postcondition: No Tuple nodes. + */ +int remove_tuples(ir_graph *irg) +{ + bool changed = 0; + irg_walk_graph(irg, exchange_tuple_projs, NULL, &changed); + return changed; +}