+
+/**
+ * Post-block-walker: Find blocks containing only one jump and
+ * remove them.
+ */
+static void remove_empty_block(ir_node *block, void *data) {
+ const ir_edge_t *edge, *next;
+ ir_node *node;
+ int *changed = data;
+ ir_node *jump = NULL;
+
+ assert(is_Block(block));
+
+ if (get_Block_n_cfgpreds(block) != 1)
+ return;
+
+ sched_foreach(block, node) {
+ if (! is_Jmp(node))
+ return;
+ if (jump != NULL) {
+ /* we should never have 2 jumps in a block */
+ assert(0 && "We should never have 2 jumps in a block");
+ return;
+ }
+ jump = node;
+ }
+
+ if (jump == NULL)
+ return;
+
+ node = get_Block_cfgpred(block, 0);
+ foreach_out_edge_safe(jump, edge, next) {
+ ir_node *block = get_edge_src_irn(edge);
+ int pos = get_edge_src_pos(edge);
+
+ set_irn_n(block, pos, node);
+ }
+
+ set_Block_cfgpred(block, 0, new_Bad());
+ sched_remove(jump);
+ *changed = 1;
+}
+
+/* removes basic blocks that just contain a jump instruction */
+int be_remove_empty_blocks(ir_graph *irg) {
+ int changed = 0;
+
+ irg_block_walk_graph(irg, remove_empty_block, NULL, &changed);
+ if (changed) {
+ /* invalidate analysis info */
+ set_irg_doms_inconsistent(irg);
+ set_irg_extblk_inconsistent(irg);
+ set_irg_outs_inconsistent(irg);
+ }
+ return changed;
+}