- ir_node *proj = NULL, *startbl;
- int i;
- if (get_Block_n_cfg_outs(get_irg_start_block(irg))) {
- startbl = get_irg_start_block(irg);
- for (i = 0; i < get_irn_n_outs(startbl); i++)
- if (get_irn_mode(get_irn_out(startbl, i)) == mode_X)
- proj = get_irn_out(startbl, i);
- if (get_irn_out(proj, 0) == startbl) {
- assert(get_irn_n_outs(proj) == 2);
- set_irn_out(proj, 0, get_irn_out(proj, 1));
- set_irn_out(proj, 1, startbl);
- }
- }
+ ir_node *proj = NULL;
+ ir_node *startbl = get_irg_start_block(irg);
+ int i;
+
+ if (get_Block_n_cfg_outs(startbl)) {
+ for (i = get_irn_n_outs(startbl) - 1; i >= 0; --i)
+ if (get_irn_mode(get_irn_out(startbl, i)) == mode_X) {
+ proj = get_irn_out(startbl, i);
+ break;
+ }
+
+ if (get_irn_out(proj, 0) == startbl) {
+ assert(get_irn_n_outs(proj) == 2);
+ set_irn_out(proj, 0, get_irn_out(proj, 1));
+ set_irn_out(proj, 1, startbl);
+ }
+ }
+}
+
+/* compute the outs for a given graph */
+void compute_irg_outs(ir_graph *irg) {
+ ir_graph *rem = current_ir_graph;
+ int n_out_edges = 0;
+ ir_node **end = NULL; /* Only for debugging */
+
+ current_ir_graph = irg;
+
+ /* Update graph state */
+ assert(get_irg_phase_state(current_ir_graph) != phase_building);
+
+ if (current_ir_graph->outs_state != outs_none)
+ free_irg_outs(current_ir_graph);
+
+ /* This first iteration counts the overall number of out edges and the
+ number of out edges for each node. */
+ n_out_edges = count_outs(irg);
+
+ /* allocate memory for all out edges. */
+ irg->outs = xcalloc(n_out_edges, sizeof(irg->outs[0]));
+#ifdef DEBUG_libfirm
+ irg->n_outs = n_out_edges;
+#endif /* defined DEBUG_libfirm */
+
+ /* The second iteration splits the irg->outs array into smaller arrays
+ for each node and writes the back edges into this array. */
+ end = set_out_edges(irg, irg->outs);
+
+ /* Check how much memory we have used */
+ assert (end == (irg->outs + n_out_edges));
+
+ /* We want that the out of ProjX from Start contains the next block at
+ position 1, the Start block at position 2. This is necessary for
+ the out block walker. */
+ fix_start_proj(irg);
+
+ current_ir_graph->outs_state = outs_consistent;
+ current_ir_graph = rem;
+}
+
+void assure_irg_outs(ir_graph *irg) {
+ if (get_irg_outs_state(irg) != outs_consistent)
+ compute_irg_outs(irg);
+}
+
+void compute_irp_outs(void) {
+ int i;
+ for (i = get_irp_n_irgs() -1; i >= 0; --i)
+ compute_irg_outs(get_irp_irg(i));
+}
+
+void free_irp_outs(void) {
+ int i;
+ for (i = get_irp_n_irgs() -1; i >= 0; --i)
+ free_irg_outs(get_irp_irg(i));