+/*
+ * Sets the outedges for all nodes.
+ */
+void set_ip_outs(void) {
+ ir_node **outedge_array = get_irp_ip_outedges();
+ cg_walk(set_array_pointer, set_out_pointer, (void *) &outedge_array);
+}
+
+
+
+/*
+ * Counts the outedges, allocates memory to save the
+ * outedges and fills this outedge array in interprocedural
+ * view!
+ */
+void compute_ip_outs(void) {
+ int n_out_edges;
+ ir_node **out_edges;
+
+ assert(get_irp_ip_view_state() == ip_view_valid &&
+ "Cannot construct outs for invalid ip view.");
+
+ if (irp->outs_state != outs_none) {
+ free_ip_outs();
+ }
+
+ global_count = n_out_edges = count_ip_outs();
+ out_edges = XMALLOCNZ(ir_node*, n_out_edges);
+ set_irp_ip_outedges(out_edges);
+ set_ip_outs();
+}
+
+void free_ip_outs(void) {
+ ir_node **out_edges = get_irp_ip_outedges();
+ if (out_edges != NULL) {
+ free(out_edges);
+ set_irp_ip_outedges(NULL);
+ }
+ irp->outs_state = outs_none;
+}
+#endif
+
+
+void free_irg_outs(ir_graph *irg) {
+ /* current_ir_graph->outs_state = outs_none; */
+ irg->outs_state = outs_none;
+
+ if (irg->outs) {
+#ifdef DEBUG_libfirm
+ memset(irg->outs, 0, irg->n_outs);
+#endif /* defined DEBUG_libfirm */
+ free(irg->outs);
+ irg->outs = NULL;
+#ifdef DEBUG_libfirm
+ irg->n_outs = 0;
+#endif /* defined DEBUG_libfirm */
+ }
+
+#ifdef DEBUG_libfirm
+ /* when debugging, *always* reset all nodes' outs! irg->outs might
+ have been lying to us */
+ irg_walk_graph (irg, reset_outs, NULL, NULL);
+#endif /* defined DEBUG_libfirm */
+}
+
+static void check_out_edges(ir_node *irn, void *env) {
+ int i, j, pos;
+ int *pError = env;
+ int error = *pError;
+ int last = is_Block(irn) ? 0 : -1;
+
+ /* check forward: every input must have an out edge */
+ for (i = get_irn_arity(irn) - 1; i >= last; --i) {
+ ir_node *pred = get_irn_n(irn, i);
+
+ for (j = get_irn_n_outs(pred) - 1; j >= 0; --j) {
+ ir_node *user = get_irn_out_ex(pred, j, &pos);
+
+ if (user == irn && pos == i) {
+ break;
+ }
+ }
+ if (j < 0) {
+ ir_fprintf(stderr, "Missing out edge from %+F input %d to %+F", irn, i, pred);
+ ++error;
+ }
+ }
+
+ /* checking backward */
+ for (i = get_irn_n_outs(irn) - 1; i >= 0; --i) {
+ ir_node *user = get_irn_out_ex(irn, i, &pos);
+
+ if (get_irn_n(user, pos) != irn) {
+ ir_fprintf(stderr, "Spurious out edge from %+F output %d to %+F", irn, i, user);
+ ++error;
+ }
+ }
+ *pError = error;
+}
+
+/* verify outs edges. */
+void verify_outs(ir_graph *irg) {
+ int errors = 0;
+ irg_walk_graph(irg, NULL, check_out_edges, &errors);
+ if (errors > 0)
+ panic("Out edges are corrupt");