Sun Studio 12: C++ User's Guide

A.2.129 -xipo[={0|1|2}]

Performs interprocedural optimizations.

The -xipo option performs partial-program optimizations by invoking an interprocedural analysis pass. Unlike -xcrossfile, -xipo performs optimizations across all object files in the link step, and the optimizations are not limited to just the source files on the compile command. However, just like -xcrossfile, whole-program optimizations performed with -xipo do not include assembly (.s) source files.

The -xipo option is particularly useful when compiling and linking large multifile applications. Object files compiled with this flag have analysis information compiled within them that enables interprocedural analysis across source and precompiled program files. However, analysis and optimization is limited to the object files compiled with -xipo, and does not extend to object files or libraries.

A.2.129.1 Values

The -xipo option can have the following values.

Table A–35 The -xipo Values




Do not perform interprocedural optimizations 


Perform interprocedural optimizations 


Perform interprocedural aliasing analysis as well as optimizations of memory allocation and layout to improve cache performance 


If -xipo is not specified, -xipo=0 is assumed.

If only -xipo is specified, -xipo=1 is assumed.


The following example compiles and links in the same step.

example% CC -xipo -xO4 -o prog

The optimizer performs crossfile inlining across all three source files. This is done in the final link step, so the compilation of the source files need not all take place in a single compilation and could be over a number of separate compilations, each specifying the -xipo option.

The following example compiles and links in separate steps.

example% CC -xipo -xO4 -c
example% CC -xipo -xO4 -c
example% CC -xipo -xO4 -o prog part1.o part2.o part3.o

The object files created in the compile steps have additional analysis information compiled within them to permit crossfile optimizations to take place at the link step.


The -xipo option requires at least optimization level -xO4.

You cannot use both the -xipo option and the -xcrossfile option in the same compiler command line.


When compiling and linking are performed in separate steps, -xipo must be specified in both steps to be effective.

Objects that are compiled without -xipo can be linked freely with objects that are compiled with -xipo.

Libraries do not participate in crossfile interprocedural analysis, even when they are compiled with -xipo, as shown in this example.

example% CC -xipo -xO4
example% CC -xar -o mylib.a one.o two.o three.o
example% CC -xipo -xO4 -o myprog mylib.a

In this example, interprocedural optimizations will be performed between, and, and between and, but not between or and the routines in mylib.a. (The first compilation may generate warnings about undefined symbols, but the interprocedural optimizations will be performed because it is a compile and link step.)

The -xipo option generates significantly larger object files due to the additional information needed to perform optimizations across files. However, this additional information does not become part of the final executable binary file. Any increase in the size of the executable program will be due to the additional optimizations performed.

A.2.129.2 When Not To Use -xipo=2 Interprocedural Analysis

The compiler tries to perform whole-program analysis and optimizations as it works with the set of object files in the link step. The compiler makes the following two assumptions for any function (or subroutine) foo() defined in this set of object files:

Do not compile with -xipo=2, if assumption 1 is not true for the given application.

Do not compile with either -xipo=1 or -xipo=2, if assumption 2 is not true.

As an example, consider interposing on the function malloc() with your own version and compiling with -xipo=2. Consequently, all the functions in any library that reference malloc() that are linked with your code have to be compiled with -xipo=2 also and their object files need to participate in the link step. Since this might not be possible for system libraries, do not compile your version of malloc with -xipo=2.

As another example, suppose that you build a shared library with two external calls, foo() and bar() inside two different source files. Furthermore, suppose that bar() calls foo(). If there is a possibility that foo() could be interposed at runtime, then do not compile the source file for foo() or for bar() with -xipo=1 or -xipo=2. Otherwise, foo() could be inlined into bar(), which could cause incorrect results.

See Also