- env_t env;
- ir_extblk *extbb, *next;
-
- if (irg->extbb_obst)
- obstack_free(irg->extbb_obst, NULL);
- else {
- irg->extbb_obst = xmalloc(sizeof(*irg->extbb_obst));
- }
- obstack_init(irg->extbb_obst);
-
- env.obst = irg->extbb_obst;
- env.head = NULL;
-
- if (! edges_activated(irg)) {
- /* we don't have edges */
- assure_irg_outs(irg);
- }
-
- /* we must mark nodes, so increase the visited flag */
- inc_irg_visited(irg);
- irg_block_walk_graph(irg, pre_walk_calc_extbb, post_walk_calc_extbb, &env);
-
- /*
- * Ok, we have now the list of all extended blocks starting with env.head
- * every extended block "knowns" the number of blocks in visited and
- * the blocks are linked in link.
- * Now we can create arrays that hold the blocks, some kind of "out" edges
- * for the extended block
- */
- for (extbb = env.head; extbb; extbb = next) {
- int i, len = (int)extbb->visited;
- ir_node *block;
-
- next = (ir_extblk *)extbb->blks;
-
- extbb->blks = NEW_ARR_D(ir_node *, env.obst, len);
-
- for (block = extbb->link, i = 0; i < len; ++i) {
- ir_node *nblock = get_irn_link(block);
-
- /* ensure that the leader is the first one */
- extbb->blks[len - 1 - i] = block;
- set_irn_link(block, NULL);
- block = nblock;
- }
-
- extbb->link = NULL;
- extbb->visited = 0;
-
-#ifdef NEED_SORT
- /* we want the blocks in scheduled order, so sort them */
- /* FIXME: is this really needed? Or generates the algorithm automagically ordered ones? */
- if (len > 1) {
- /* temporary remove the leader from the extended block to break loops */
- set_Block_extbb(extbb->blks[0], NULL);
- qsort(&extbb->blks[1], len-1, sizeof(extbb->blks[0]), block_order);
- set_Block_extbb(extbb->blks[0], extbb);
- }
+ env_t env;
+ ir_extblk *extbb, *next;
+
+ if (irg->extbb_obst)
+ obstack_free(irg->extbb_obst, NULL);
+ else
+ irg->extbb_obst = xmalloc(sizeof(*irg->extbb_obst));
+ obstack_init(irg->extbb_obst);
+
+ env.obst = irg->extbb_obst;
+ env.head = NULL;
+ env.start_block = get_irg_start_block(irg);
+
+ if (! edges_activated(irg)) {
+ /* we don't have edges */
+ assure_irg_outs(irg);
+ }
+
+ /* we must mark nodes, so increase the visited flag */
+ inc_irg_visited(irg);
+ irg_block_walk_graph(irg, pre_walk_calc_extbb, post_walk_calc_extbb, &env);
+
+ /*
+ * Ok, we have now the list of all extended blocks starting with env.head
+ * every extended block "knowns" the number of blocks in visited and
+ * the blocks are linked in link.
+ * Now we can create arrays that hold the blocks, some kind of "out" edges
+ * for the extended block
+ */
+ for (extbb = env.head; extbb; extbb = next) {
+ int i, len = (int)extbb->visited;
+ ir_node *block;
+
+ next = (ir_extblk *)extbb->blks;
+
+ extbb->blks = NEW_ARR_D(ir_node *, env.obst, len);
+
+ for (block = extbb->link, i = 0; i < len; ++i) {
+ ir_node *nblock = get_irn_link(block);
+
+ /* ensure that the leader is the first one */
+ extbb->blks[len - 1 - i] = block;
+ set_irn_link(block, NULL);
+ block = nblock;
+ }
+
+#ifndef NDEBUG
+ /* check it */
+ for (i = len - 1; i > 0; --i) {
+ ir_node *blk = extbb->blks[i];
+
+ if (get_Block_n_cfgpreds(blk) != 1) {
+ assert(!"Block for more than one predecessors is no leader");
+ } else if (get_Block_cfgpred_block(blk, 0) != extbb->blks[i - 1]) {
+ assert(!"extbb block order wrong");
+ }
+ }