Inlining substitutes selected function calls with copies of the
function's object code. Only functions that meet the optimizer's
criteria are inlined. Inlining 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.
At +O3, inlining is performed
within a file; at +O4, it is performed
across files. Inlining is affected by the
+O[no]inline[=namelist]
and
+Oinline_budget=n
command-line options. See Chapter 7 “Controlling optimization” for more information.
Inlining within single source file
The following is an example of inlining at the source code
level. Before inlining, the C 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(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, main 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 */ . } |