Level 3 Optimizations [ HP C Programmer's Guide ] MPE/iX 5.0 Documentation
HP C Programmer's Guide
Level 3 Optimizations
Level 3 performs optimizations across all procedures within a single
source file. At level 3, all optimizations of the prior levels are
performed with the addition of inlining of certain functions within the
input file.
NOTE Level 3 optimizations are not available in HP C/iX.
Inlining within a Single Source File
Inlining substitutes functions calls with copies of the function's object
code. Only functions that meet the optimizer's criteria are inlined.
This may result in slightly larger executable files. However, this
increase in size is offset by the elimination of time-consuming procedure
calls and procedure returns.
Example of Inlining
The following is an example of inlining at the source code level. Before
inlining, the source file looks like this:
/* Return the greatest common divisor of two positive integers, */
/* int1 and int2, computed using Euclid's algorithm. (Return 0 */
/* if either is not positive.) */
int gcd(int1,int2)
int int1;
int int2;
{
int inttemp;
if ( ( int1 <= 0 ) || ( int2 <= 0 ) ) {
return(0);
}
do {
if ( int1 < int2 ) {
inttemp = int1;
int1 = int2;
int2 = inttemp;
}
int1 = int1 - int2;
} while (int1 > 0);
return(int2);
}
main()
{
int xval,yval,gcdxy;
/* statements before call to gcd */
gcdxy = gcd(xval,yval);
/* statements after call to gcd */
}
After inlining, the source file looks like this:
main()
{
int xval,yval,gcdxy;
/* statements before inlined version of gcd */
{
int int1;
int int2;
int1 = xval;
int2 = yval;
{
int inttemp;
if ( ( int1 <= 0 ) || ( int2 <= 0 ) ) {
gcdxy = ( 0 );
goto AA003;
}
do {
if ( int1 < int2 ) {
inttemp = int1;
int1 = int2;
int2 = inttemp;
}
int1 = int1 - int2;
} while ( int1 > 0 );
gcdxy = ( int2 );
}
}
AA003 : ;
/* statements after inlined version of gcd */
}
MPE/iX 5.0 Documentation