Commit 917ab466 authored by Andreas Zwinkau's avatar Andreas Zwinkau
Browse files

Add remove_tuples function

parent 2e9fdf88
...@@ -72,6 +72,15 @@ FIRM_API void remove_unreachable_code(ir_graph *irg); ...@@ -72,6 +72,15 @@ FIRM_API void remove_unreachable_code(ir_graph *irg);
*/ */
FIRM_API int remove_bads(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(). * Creates an ir_graph pass for optimize_graph_df().
* *
......
/*
* 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;
}
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