Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Fortran 90, Fortran 77, C, aC++: Exemplar Programming Guide > Chapter 3 Compiler optimizations

+O4 level optimization

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

At +O4, optimizations are performed across all files in the application that have been compiled with +O4. All optimizations of the previous levels are performed, and three additional optimizations are performed:

During +O4 optimizations, the compiler optimizes across the function boundaries (of all files that have been compiled with +O4) 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. Because information about every function within a program is required, this level of optimization must be performed at link time. Because analysis is done at link time, the compile time is generally shorter (than at lower optimization levels), but linking takes more time.

Inlining across multiple source files

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. See the section “Inlining within a single source file” for an example of inlining.

Inlining at +O4 is performed across all procedures within the program. Inlining at +O3 is done within one file.

Inlining is affected by the +O[no]inline[=namelist] and +Oinline_budget=n command-line options. See Appendix D, "Appendix D “Optimization options”," for more information.

Cloning across multiple source files

Cloning is the replacement of a call to a routine by a call to a clone of that routine. The clone is optimized differently than the original routine. Cloning can expose additional opportunities for interprocedural optimization.

Cloning at +O4 is performed across all procedures within the program. Cloning at +O3 is done within one file. Cloning is enabled by default; it can be disabled by specifying the +Onoinline command-line option.

Global and static variable optimizations

Global and static variable optimizations look for ways to reduce the number of instructions required for accessing global and static variables (COMMON and SAVE variables in Fortran; extern and static variables in C and C++). 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

Because this optimization rearranges the location and data alignment of global variables, follow the programming practices given below:

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

  • Do not rely on pointer or address comparisons between two different variables.

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

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.