Sun Studio 12: C++ User's Guide

A.2.139.1 Values

level sets the level of optimizations performed, and must be 0, 1, or 2. The optimization levels are:

Table A–38 The -xlinkopt Values

Value 

Meaning  

The link optimizer is disabled. (This is the default.) 

Perform optimizations based on control flow analysis, including instruction cache coloring and branch optimizations, at link time. 

Perform additional data flow analysis, including dead-code elimination and address computation simplification, at link time. 

If you compile in separate steps, -xlinkopt must appear on both compile and link steps:

example% cc -c -xlinkopt a.c b.c
example% cc -o myprog -xlinkopt=2 a.o

Note that the level parameter is only used when the compiler is linking. In the example above, the link optimizer level is 2 even though the object binaries are compiled with an implied level of 1.

Defaults

Specifying -xlinkopt without a level parameter implies -xlinkopt=1.

Interactions

This option is most effective when you use it to compile the whole program, and with profile feedback. Profiling reveals the most and least used parts of the code and building directs the optimizer to focus its effort accordingly. This is particularly important with large applications where optimal placement of code performed at link time can reduce instruction cache misses. Typically, this compiles as follows:


example% cc -o progt -xO5 -xprofile=collect:prog file.c
example% progt
example% cc -o prog -xO5 -xprofile=use:prog -xlinkopt file.c

For details on using profile feedback, see A.2.165 -xprofile=p.

Warnings

Do not use the -zcompreloc linker option when you compile with -xlinkopt.

Note that compiling with this option increases link time slightly. Object file sizes also increase, but the size of the executable remains the same. Compiling with -xlinkopt and -g increases the size of the executable by including debugging information.