This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How to duplicate a loop including basic_blocks and edges?
- From: Benedikt Huber <benedikt dot huber at theobroma-systems dot com>
- To: GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 27 Jun 2014 16:14:02 +0200
- Subject: How to duplicate a loop including basic_blocks and edges?
- Authentication-results: sourceware.org; auth=none
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