Inlining

Inlining replaces certain function calls with the actual code of the function and is performed before all other optimizations. Not only does inlining eliminate the linkage overhead, it also exposes the entire called function to the caller, which enables the compiler to better optimize your code.
Note: See Inlining under IPA for information on differences in inlining under IPA.
The following types of calls are not inlined:
  • A call where the number of parameters on the call does not match that on the function definition. An example of this is a variable argument function call.
  • A call that is directly recursive; the routine calls itself.
  • K&R style var_arg functions.

Consider the C examples CCNGOP1 and CCNGOP2, shown in Table 1. CCNGOP1 specifies the #pragma inline directive for the function which_group(). If you use the OPTIMIZE option when you compile CCNGOP1, the compiler determines that CCNGOP1 is equivalent to CCNGOP2.

Table 1. Examples of optimization
Sample program CCNGOP1 Sample program CCNGOP2
/* this example demonstrates optimization */

#include <stdio.h>
#pragma inline (which_group)
int which_group (int a) {
   if (a < 0) {
      printf("first group\n");
      return(99);
   }
   else if (a == 0) {
      printf("second group\n");
      return(88);
   }
   else {
      printf("third group\n");
      return(77);
   }
}

int main (void) {
   int j;

   j = which_group (7);

   return(j);
}
/* this example also demonstrates optimization */

#include <stdio.h>

int main(void) {

   printf("third group\n");   /* a lot less code 
                                 generation */

   return(77);
}