Loop Fission: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "Loop unrolling is an optimization technique that reduces the number of iterations in a loop by expanding its body to process multiple elements per iteration. This transformation decreases loop overhead, improves execution efficiency, and can enhance opportunities for parallelization. By reducing control flow instructions, loop unrolling minimizes branching and increases instruction-level parallelism, making it particularly useful for performance-critical applications. Wh...")
 
No edit summary
Line 1: Line 1:
Loop unrolling is an optimization technique that reduces the number of iterations in a loop by expanding its body to process multiple elements per iteration. This transformation decreases loop overhead, improves execution efficiency, and can enhance opportunities for parallelization. By reducing control flow instructions, loop unrolling minimizes branching and increases instruction-level parallelism, making it particularly useful for performance-critical applications. While it can lead to larger code size, the trade-off often results in significant runtime improvements.
Loop fission, also known as loop distribution, is an optimization technique that splits a single loop into multiple loops over the same iteration range, with each handling a subset of the original loop’s operations. This transformation improves data locality, enhances cache efficiency, and enables better parallelization by reducing dependencies within a loop body. By breaking down complex loops, loop fission can optimize memory access patterns and improve overall program performance while preserving the original computation logic.
==Loop Unrolling Transformation in emmtrix Studio==
==Loop Fission Transformation in emmtrix Studio==
emmtrix Studio implements loop unrolling using #pragma directives or via the GUI. Unrolling will reduce the iteration count and increase the body of the loop, processing statements from multiple iteration steps in a single iteration.
emmtrix Studio implements loop fission using #pragma directives or via the GUI. Loop fission is a transformation that breaks a loop into multiple loops over the same index range with each taking only a part of the original loop’s body.
===Typical Usage and Benefits===
===Typical Usage and Benefits===
Loop unrolling is used to reduce the overhead of the loops and to exploit parallelization on coarser parts.
Loop fission is used to achieve better utilization of locality of reference by breaking down a large loop body into smaller ones.
===Example===
===Example===
{| class="wikitable"
{| class="wikitable"
Line 10: Line 10:
/* The following code tests LoopUnroll transformation applied to a for loop: */   
/* The following code tests LoopUnroll transformation applied to a for loop: */   


int main(void) {
int main() {
     int i;
     int i, j;
     int a[4];
     int a[10], b, c, d;
     #pragma EMX_TRANSFORMATION LoopUnroll { ”unrollfactor”: 4}
     #pragma EMX_TRANSFORMATION LoopFission
     for (i = 0; i < 4; i++) {
     for (i = 0; i < 10; i++) {
         a[i] = i;
         d = 0;
        a[i] = i * i;
        c = 9;
        b = i;
        b = 8 + i * b;
        if (a[i] > 50) {
            c = c + a[i];
            printf(”Inside
                if, a[ % d] = % d and c = % d\ n”, i, a[i], c);
        } else {
            printf(”Inside
                else, c = % d\ n”, c);
            printf(”Inside
                else, a[ % d] = % d\ n”, i, a[i]);
        }
     }
     }
    return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
|<syntaxhighlight lang="c">
|<syntaxhighlight lang="c">
/* The generated code includes all four iterations of the loop transformed into four separate statements.
/* The generated code has multiple loops, each loop containing groups of statements from the old loop
* The loop unrolling is full and the loop is removed.
that have dependencies on one another: */
*/


int main(void) {
int main() {
     int i;
     int i;
     int a[4];
    int j;
     i = 0;
     int a[10];
     int b;
    int c;
    int d;
     {
     {
         a[i] = i;
         for (i = 0; i < 10; i = i + 1) {
    } {
            d = 0;
        a[i + 1 * 1] = i + 1 * 1;
        }
    } {
        for (i = 0; i < 10; i = i + 1) {
        a[i + 1 * 2] = i + 1 * 2;
            a[i] = i * i;
    } {
            c = 9;
        a[i + 1 * 3] = i + 1 * 3;
            if (a[i] > 50) {
                c = c + a[i];
                printf(”Inside
                    if, a[ % d] = % d and c = % d\ n”, i, a[i], c);
            } else {
                printf(”Inside
                    else, c = % d\ n”, c);
                printf(”Inside
                    else, a[ % d] = % d\ n”, i, a[i]);
            }
        }
        for (i = 0; i < 10; i = i + 1) {
            b = i;
            b = 8 + i * b;
        }
     }
     }
    return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
|}
|}
===Parameters===
[[Category:Code Transformation]]
Following parameters can be set (each description is followed by keyword in pragma-syntax and default value):
{| class="wikitable"
|+
!Id
!Default Value
!Description
|-
|<code>unrollfactor</code>
|max_unrollfactor
|'''Unroll factor''' - divide iteration count & multiply iterating variable. If equal to total number of iterations, loop-construct will be removed from code. If not integer divisor of total number of iterations, additional loop
processing last iterations will be added
|}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu