Hello,

I am trying to reorder certain basic blocks again after
rest_of_handle_reorder_blocks() (which in turn calls
reorder_basic_blocks).  What I do is this:


cfg_layout_initialize (flags);

reorder_selected_blocks(); // sets bb->rbi->next on them

/* Leave the rest as it was. */
  FOR_EACH_BB (bb)
    if ((bb->next_bb != EXIT_BLOCK_PTR) && (!bb->rbi->next))
      bb->rbi->next = bb->next_bb;

cfg_layout_finalize();


If I do that before rest_of_handle_partition_blocks, it works
just fine.  (btw. I ensure that all blocks I force to follow
one another belong to the same partition)  But then some of
them get repositioned, so I want to run the above again
after rest_of_handle_reorder_blocks() is done.

If I do that I run into an infinite loop in fixup_reorder_chain()
in its first for loop at:

  for (bb = ENTRY_BLOCK_PTR->next_bb, index = 0;
       bb != 0;
       bb = bb->rbi->next, index++)
    {
      if (bb->rbi->header)
        {
          if (insn)
            NEXT_INSN (insn) = bb->rbi->header;
          else
            set_first_insn (bb->rbi->header);
          PREV_INSN (bb->rbi->header) = insn;
          insn = bb->rbi->header;
          while (NEXT_INSN (insn))  <<<<<< HERE
            insn = NEXT_INSN (insn);
        }
....

I tried to debug it.  The insn's mode seems to be always VOIDmode,
and the u value seems to be increasing with each next insn.
There's not much else I can say about it, besides that it gets
effectively into an infinite loop.

I managed to isolate a case where moving a single BB would trigger
this behaviour.  (This is as far as I can tell by looking at the
original code and matching BB's to source code positions.  How do I get
a dump of insns of a BB into some textual form? Is there a utility
function for that?)

Original order and code:

BB1: // equiv. of: if (a == 5) && (b == 10) goto BB4
      if (a != 5) goto BB2:
      if (b == 10) goto BB4:
BB2:  a = 0
BB3:  // whatever follows
....
[ far away but still in the same partition ]
....
BB4:  a = b/c
      goto BB3;


Requested order:

BB1: // equiv. of: if (a == 5) && (b == 10) goto BB4
      if (a != 5) goto BB2:
      if (b == 10) goto BB4:
BB2:  a = b/c
      goto BB3;
BB4:  a = 0
BB3:  // whatever follows


It doesn't seem to be too tricky a reordering, but it does give me this
infinite loop, if I do the reordering after
rest_of_handle_reorder_blocks().

What can be the reason of it?  Might I be violating some unwritten(?)
rules of what moves can be applied to bbs?  By looking at cfg_layout_
initialize/finalize it seemed to me that I could make an arbitrary
reordering and it will be followed, sometimes at the cost of added jumps
and labels. [*]


Any help will be greatly appreciated,

                        Grzegorz B. Prokopski

[*] For the moment I ignore the issues like the max allowed distance to
a cond. jump target.


Reply via email to