Constant Propagation Transformation: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 8: Line 8:
ConstPropagation is typically used to generate a clearer code, to reduce complexity for dependency analysis and increase potential for better optimization possibilities.
ConstPropagation is typically used to generate a clearer code, to reduce complexity for dependency analysis and increase potential for better optimization possibilities.
===Example===
===Example===
The following code tests ConstPropagation applied to main function. In the given example, variables a, b and c are known. They are propagated to the rest of the body of
{| class="wikitable"
! Input Code
!Result
|-
|The following code tests ConstPropagation applied to main function.
In the given example, variables a, b and c are known.
 
They are propagated to the rest of the body of main.
|The following code is the generated code after the transformation has been applied.
|-
|<syntaxhighlight lang="c">
#pragma EMX_TRANSFORMATION ConstPropagation
int main(void) {
    int a = 2;
    int b = a;
   
    int c, d;
    c = 2 + 2;
    d = b + c;
   
    return 0;
}
</syntaxhighlight>
|<pre>int main(void) {
int a = 2;
int b = a;
int c;
int d;
c = 4;
d = 6;
 
return 0;
}
</pre>
|-
|
|
|}The following code tests ConstPropagation applied to main function. In the given example, variables a, b and c are known. They are propagated to the rest of the body of


main. <syntaxhighlight lang="c">
main. <syntaxhighlight lang="c">
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu