aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/loop.c39
-rw-r--r--gcc/loop.h3
-rw-r--r--gcc/unroll.c21
3 files changed, 26 insertions, 37 deletions
diff --git a/gcc/loop.c b/gcc/loop.c
index 3bbe74198ef..a72fdcbc427 100644
--- a/gcc/loop.c
+++ b/gcc/loop.c
@@ -91,15 +91,6 @@ int *loop_can_insert_bct;
int *loop_used_count_register;
-/* For each loop, remember its unrolling factor (if at all).
- contents of the array:
- 0/1: not unrolled.
- -1: completely unrolled - no further instrumentation is needed.
- >1: holds the exact amount of unrolling. */
-
-int *loop_unroll_factor;
-int *loop_unroll_iter;
-
/* loop parameters for arithmetic loops. These loops have a loop variable
which is initialized to loop_start_value, incremented in each iteration
by "loop_increment". At the end of the iteration the loop variable is
@@ -111,6 +102,13 @@ rtx *loop_start_value;
enum rtx_code *loop_comparison_code;
#endif /* HAIFA */
+/* For each loop, keep track of its unrolling factor.
+ Potential values:
+ 0: unrolled
+ 1: not unrolled.
+ -1: completely unrolled
+ >0: holds the unroll exact factor. */
+int *loop_unroll_factor;
/* Indexed by loop number, contains a nonzero value if the "loop" isn't
really a loop (an insn outside the loop branches into it). */
@@ -431,6 +429,12 @@ loop_optimize (f, dumpfile)
loop_number_exit_labels = (rtx *) alloca (max_loop_num * sizeof (rtx));
loop_number_exit_count = (int *) alloca (max_loop_num * sizeof (int));
+ /* This is initialized by the unrolling code, so we go ahead
+ and clear them just in case we are not performing loop
+ unrolling. */
+ loop_unroll_factor = (int *) alloca (max_loop_num *sizeof (int));
+ bzero ((char *) loop_unroll_factor, max_loop_num * sizeof (int));
+
#ifdef HAIFA
/* Allocate for BCT optimization */
loop_can_insert_bct = (int *) alloca (max_loop_num * sizeof (int));
@@ -439,12 +443,6 @@ loop_optimize (f, dumpfile)
loop_used_count_register = (int *) alloca (max_loop_num * sizeof (int));
bzero ((char *) loop_used_count_register, max_loop_num * sizeof (int));
- loop_unroll_factor = (int *) alloca (max_loop_num *sizeof (int));
- bzero ((char *) loop_unroll_factor, max_loop_num * sizeof (int));
-
- loop_unroll_iter = (int *) alloca (max_loop_num *sizeof (int));
- bzero ((char *) loop_unroll_iter, max_loop_num * sizeof (int));
-
loop_increment = (rtx *) alloca (max_loop_num * sizeof (rtx));
loop_comparison_value = (rtx *) alloca (max_loop_num * sizeof (rtx));
loop_start_value = (rtx *) alloca (max_loop_num * sizeof (rtx));
@@ -7277,12 +7275,9 @@ insert_bct (loop_start, loop_end)
return;
}
- /* make sure that the loop was not fully unrolled. */
- if (loop_unroll_factor[loop_num] == -1){
- if (loop_dump_stream)
- fprintf (loop_dump_stream, "insert_bct %d: was completely unrolled\n", loop_num);
+ /* It's impossible to instrument a competely unrolled loop. */
+ if (loop_unroll_factor [loop_num] == -1)
return;
- }
/* make sure that the last loop insn is a conditional jump .
This check is repeated from analyze_loop_iterations (),
@@ -7296,8 +7291,8 @@ insert_bct (loop_start, loop_end)
}
/* fix increment in case loop was unrolled. */
- if (loop_unroll_factor[loop_num] > 1)
- increment = GEN_INT ( INTVAL (increment) * loop_unroll_factor[loop_num] );
+ if (loop_unroll_factor [loop_num] > 1)
+ increment = GEN_INT ( INTVAL (increment) * loop_unroll_factor [loop_num] );
/* determine properties and directions of the loop */
increment_direction = (INTVAL (increment) > 0) ? 1:-1;
diff --git a/gcc/loop.h b/gcc/loop.h
index d8c83cdcab6..44e15002028 100644
--- a/gcc/loop.h
+++ b/gcc/loop.h
@@ -182,12 +182,11 @@ rtx final_giv_value PROTO((struct induction *, rtx, rtx));
void emit_unrolled_add PROTO((rtx, rtx, rtx));
int back_branch_in_range_p PROTO((rtx, rtx, rtx));
+extern int *loop_unroll_factor;
#ifdef HAIFA
/* variables for interaction between unroll.c and loop.c, for
the insertion of branch-on-count instruction. */
-extern int *loop_unroll_factor;
extern rtx *loop_start_value;
-extern int *loop_unroll_iter;
extern int loop_number();
#endif /* HAIFA */
diff --git a/gcc/unroll.c b/gcc/unroll.c
index ce6623c37cd..b9cbcfe6a48 100644
--- a/gcc/unroll.c
+++ b/gcc/unroll.c
@@ -1094,16 +1094,13 @@ unroll_loop (loop_end, insn_count, loop_start, end_insert_before,
/* Set unroll type to MODULO now. */
unroll_type = UNROLL_MODULO;
loop_preconditioned = 1;
+
#ifdef HAIFA
- if (loop_n_iterations > 0)
- loop_unroll_iter[ loop_number(loop_start, loop_end) ]
- = (loop_n_iterations
- - loop_n_iterations % (abs_inc * unroll_number));
- else
- /* inform loop.c about the new initial value */
- loop_start_value[loop_number(loop_start, loop_end)] = initial_value;
+ /* Fix the initial value for the loop as needed. */
+ if (loop_n_iterations <= 0)
+ loop_start_value [loop_number (loop_start, loop_end)]
+ = initial_value;
#endif
-
}
}
@@ -1118,13 +1115,11 @@ unroll_loop (loop_end, insn_count, loop_start, end_insert_before,
/* At this point, we are guaranteed to unroll the loop. */
-#ifdef HAIFA
- /* inform loop.c about the factor of unrolling */
+ /* Keep track of the unroll factor for each loop. */
if (unroll_type == UNROLL_COMPLETELY)
- loop_unroll_factor[ loop_number(loop_start, loop_end) ] = -1;
+ loop_unroll_factor [loop_number (loop_start, loop_end)] = -1;
else
- loop_unroll_factor[ loop_number(loop_start, loop_end) ] = unroll_number;
-#endif /* HAIFA */
+ loop_unroll_factor [loop_number (loop_start, loop_end)] = unroll_number;
/* For each biv and giv, determine whether it can be safely split into