+/* Access predecessor n, ignore keep-alives. */
+ir_node *get_Block_cfg_out(const ir_node *bl, int pos)
+{
+ int i;
+ assert(bl && is_Block(bl));
+#ifdef DEBUG_libfirm
+ assert(bl->out_valid);
+#endif /* defined DEBUG_libfirm */
+ for (i = 1; i <= bl->out[0].pos; ++i) {
+ ir_node *succ = bl->out[i].use;
+ if (get_irn_mode(succ) == mode_X && !is_End(succ)) {
+ int n_outs = succ->out[0].pos;
+ if (pos < n_outs)
+ return succ->out[pos + 1].use;
+ else
+ pos -= n_outs;
+ }
+ }
+ return NULL;
+}
+
+/* Access predecessor n, honor keep-alives. */
+ir_node *get_Block_cfg_out_ka(const ir_node *bl, int pos)
+{
+ int i, n_outs;
+ assert(bl && is_Block(bl));
+#ifdef DEBUG_libfirm
+ assert (bl->out_valid);
+#endif /* defined DEBUG_libfirm */
+ for (i = 1; i <= bl->out[0].pos; ++i) {
+ ir_node *succ = bl->out[i].use;
+ if (get_irn_mode(succ) == mode_X) {
+ if (is_End(succ)) {
+ ir_node *end_bl = get_nodes_block(succ);
+ if (end_bl == bl) {
+ /* ignore End if we are in the Endblock */
+ continue;
+ }
+ if (pos == 0) {
+ /* handle keep-alive here: return the Endblock instead of the End node */
+ return end_bl;
+ } else
+ --pos;
+ } else {
+ n_outs = succ->out[0].pos;
+ if (pos < n_outs)
+ return succ->out[pos + 1].use;
+ else
+ pos -= n_outs;
+ }
+ }
+ }
+ return NULL;
+}