HPlogo HP C/HP-UX Programmer's Guide: HP 9000 Computers > Chapter 4 Optimizing HP C Programs

Level 4 Optimizations

» 

Technical documentation

Complete book in PDF

 » Table of Contents

Level 4 performs optimizations across all files in a program. At level 4, all optimizations of the prior levels are performed. Two additional optimizations are performed:

  • Inlining across multiple source files.

  • Global and static variable optimization.

Interprocedural global optimizations across all files within a program searches across function boundaries to produce better and faster code sequences. Normally, global optimizations are performed within individual functions or source code files. Interprocedural optimizations look at function interactions within a program and transform particular code sequences into faster code. Since information about every function within a program is required, this level of optimization must be performed at link time.

Inlining Across Multiple Files

Inlining at Level 4 is performed across all procedures within the program. Inlining at level 3 is done within one file.

Inlining substitutes function 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.

Global and Static Variable Optimization

Global and static variable optimizations look for ways to reduce the number of instructions required for accessing global and static variables. The compiler normally generates two machine instructions when referencing global variables. Depending on the locality of the global variables, single machine instructions may sometimes be used to access these variables. The linker rearranges the storage location of global and static data to increase the number of variables that can be referenced by single instructions.

Global Variable Optimization Coding Standards

Since this optimization rearranges the location and data alignment of global variables, avoid the following programming practices:

  • Making assumptions about the relative storage location of variables, such as generating a pointer by adding an offset to the address of another variable.

  • Relying on pointer or address comparisons between two different variables.

  • Making assumptions about the alignment of variables, such as assuming that a short integer is aligned the same as an integer.

© Hewlett-Packard Development Company, L.P.