Interprocedural analysis (IPA)

This topic provides an overview of the Interprocedural Analysis (IPA) processing that is available through the IPA option on the CRTPGM and CRTSRVPGM commands.

At compile time, the optimizing translator performs both intraprocedural and interprocedural analysis. Intraprocedural analysis is a mechanism for performing optimization for each function within a compilation unit, using only the information available for that function and compilation unit. Interprocedural analysis is a mechanism for performing optimization across function boundaries. The optimizing translator performs interprocedural analysis, but only within a compilation unit. Interprocedural analysis that is performed by the IPA compiler option improves on the limited interprocedural analysis described above. When you run interprocedural analysis through the IPA option, IPA performs optimizations across the entire program. It also performs optimizations not otherwise available at compile time with the optimizing translator. The optimizing translator or the IPA option performs the following types of optimizations:
  • Inlining across compilation units. Inlining replaces certain function calls with the actual code of the function. Inlining not only eliminates the overhead of the call, but also exposes the entire function to the caller and thus enables the compiler to better optimize your code.
  • Program partitioning. Program partitioning improves performance by reordering functions to exploit locality of reference. Partitioning places functions that call each other frequently in closer proximity in memory. For more information on program partitioning, see Partitions created by IPA.
  • Coalescing of global variables. The compiler puts global variables into one or more structures and accesses the variables by calculating the offsets from the beginning of the structures. This lowers the cost of variable access and exploits data locality.
  • Code straightening. Code straightening streamlines the flow of your program.
  • Unreachable code elimination. Unreachable code elimination removes unreachable code within a function.
  • Call graph pruning of unreachable functions. The call graph pruning of unreachable functions removes code that is 100% inlined or never referred to.
  • Intraprocedural constant propagation and set propagation. IPA propagates floating point and integer constants to their uses and computes constant expressions at compile time. Also, variable uses that are known to be one of several constants can result in the folding of conditionals and switches.
  • Intraprocedural pointer alias analysis. IPA tracks pointer definitions to their uses, resulting in more refined information about memory locations that a pointer dereference may use or define. This enables other parts of the compiler to better optimize code around such dereferences. IPA tracks data and function pointer definitions. When a pointer can only refer to a single memory location or function, IPA rewrites it to be an explicit reference to the memory location or function.
  • Intraprocedural copy propagation. IPA propagates expressions, and defines some variables to the uses of the variable. This creates additional opportunities for the folding of constant expressions. It also eliminates redundant variable copies.
  • Intraprocedural unreachable code and store elimination. IPA removes definitions of variables that it cannot reach, along with the computation that feeds the definition.
  • Conversion of reference (address) arguments to value arguments. IPA converts reference (address) arguments to value arguments when the formal parameter is not written in the called procedure.
  • Conversion of static variables to automatic (stack) variables. IPA converts static variables to automatic (stack) variables when their use is limited to a single procedure call.
The runtime for code that is optimized using IPA is normally faster than for code optimized only at compile time. Not all applications are suited for IPA optimization, however, and the performance gains that are realized from using IPA will vary. For certain applications, the performance of the application may not improve when using interprocedural analysis. In fact, in some rare cases, the performance of the application can actually degrade when you use interprocedural analysis. If this occurs, we suggest that you not use interprocedural analysis. The performance improvement realized by interprocedural analysis depends on the type of application. Applications that will most likely show performance gains are those that have the following characteristics:
  • Contain a large number of functions
  • Contain a large number of compilation units
  • Contain a large number of functions that are not in the same compilation units as their callers
  • Do not perform a large number of input and output operations
Interprocedural optimization is available only for ILE programs and service programs that meet the following conditions:
  • You created the modules bound into the program or service program specifically for V4R4M0 or later releases.
  • You compiled the modules bound into the program or service program with an optimization level of 20 (*BASIC) or higher.
  • The modules bound into the program or service program have IL data that is associated with them. Use the create module option MODCRTOPT(*KEEPILDTA) to keep intermediate language (IL) data with the module.
Note: Because of the optimization requirements, you should fully debug your programs before you use interprocedural analysis.