This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How to duplicate a loop including basic_blocks and edges?


Hello everybody,

I want to make a copy of a loop, but it seems that the function duplicate_loop does not work the way I need it.
It does not copy basic_blocks and edges.

What I need is this transformation

// Original
int foo () {
  int i, b;
  i = 0;
  b = 50;
  for (; i <= b; ++b) {
    LOOP_BODY
  }
}

// By copying the loop,
// and adapting the first condition.
int foo () {
  int i, b;
  i = 0;
  b = 50;
  for (; i < b; ++b) {
    LOOP_BODY
  }
  for (; i <= b; ++b) {
    LOOP_BODY
  }
}

// Expected result, which is basically the same as above.
int foo () {
  int i, b;
  i = 0;
  b = 50;
  for (; i < b; ++b) {
    LOOP_BODY
  }
  if (i == b) {
    LOOP_BODY
    ++b;
  }
}

So it should peel the last iteration of the loop, which is possible
when we have a GE_EXPR or a LE_EXPR and the step is 1.
Is there some functions or similar code that I could use as an example?

tree_duplicate_sese_region cannot handle regions containing a loop (as far as I can tell).
duplicate_loop_to_header_edge peels from the beginning and not from the end.
I tried that with some postprocessing steps, that redirect some edges, without success so far.
I wonder if this is a good way to go or is there a better solution.
Or should I copy everything by hand with get_loop_body and then create new basic_blocks and edges?

Thank you and best regards,
Benedikt



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]