2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Contains some useful function for the backend.
9 * @author Sebastian Hack
26 #include "iredges_t.h"
32 void be_clear_links(ir_graph *irg)
34 irg_walk_graph(irg, firm_clear_link, NULL, NULL);
38 * Gets the Proj with number pn from irn.
40 ir_node *be_get_Proj_for_pn(const ir_node *irn, long pn)
43 assert(get_irn_mode(irn) == mode_T && "need mode_T");
45 foreach_out_edge(irn, edge) {
46 proj = get_edge_src_irn(edge);
48 if (is_Proj(proj) && get_Proj_proj(proj) == pn)
56 * Block-walker: adds the visited block to a flexible array.
58 static void add_to_postorder(ir_node *block, void *data)
60 ir_node ***list = (ir_node***) data;
61 ARR_APP1(ir_node*, *list, block);
64 ir_node **be_get_cfgpostorder(ir_graph *irg)
66 ir_node **list = NEW_ARR_F(ir_node*, 0);
67 ir_node *end_block = get_irg_end_block(irg);
69 /* end block may be unreachable in case of endless loops */
70 if (get_Block_n_cfgpreds(end_block) == 0)
71 ARR_APP1(ir_node*, list, end_block);
74 irg_block_edges_walk(get_irg_start_block(irg), NULL, add_to_postorder,
80 ir_node *get_first_block_succ(const ir_node *block)
82 const ir_edge_t *edge = get_irn_out_edge_first_kind(block, EDGE_KIND_BLOCK);
84 return get_edge_src_irn(edge);