Next: Applying PRE, SR, DCE,
Up: Optimization Strategies for HPJava
Previous: Dead Code Elimination
Contents
Loop Unrolling
In conventional programming languages some loops have such a small
body that most of the time is spent to increment the loop-counter
variables and to test the loop-exit condition. We can make these loops
more efficient by unrolling them, putting two or more copies of
the loop body in a row. We call this technique, Loop Unrolling
(LU) [2].
Our experiments [29] didn't suggest that this is a
very useful source-level optimization for HPJava, except in one
special but important case. LU will be applied for overall
constructs in an HPJava Program of Laplace equation using red-black
relaxation. For example,
This overall generates a relatively expensive method call in the
translation:
The overall is repeated in every iteration of the loop
associated with the outer overall. This will be discussed again
in section 5.5.2. Because red-black iteration is a common
pattern, HPJava compiler should probably try to recognize this idiom.
If a nested overall includes expressions of the form
where expr is invariant with respect to the outer loop, this
should be taken as an indication to unroll the outer loop by 2. The
modulo expressions then become loop invariant and arguments of the
call to localBlock(), the whole invocation is a candidate to be
lifted out of the outer loop.
Next: Applying PRE, SR, DCE,
Up: Optimization Strategies for HPJava
Previous: Dead Code Elimination
Contents
Bryan Carpenter
2004-06-09