
Friday June 01, 2007
Compiler commentary support in Sun Studio compilers for x86/x64
Compiler commentary is a feature of the Sun Studio compilers and tools that allows the compiler to indicate to the user what transformations and optimizations were performed to generate code. Compiler commentary support for Sun Studio compiler for x86/x64 was introduced in Sun Studio 11. For the sparc platform, compiler commentary support in Sun Studio compiler has been available for several releases.
Compiler commentary messages can be viewed using the graphical user interface of the Sun Studio Analyzer or by using the command line utility er_src. Commentary messages will be interleaved with the source or disassembly. In order to generate compiler commentary, a program must be compiled with -g option.
The performance analyzer has a source and a disassembly tab to view annotated source and disassembly. If compiler commentary messages were generated, they will be highlighted with a blue color along with the source and/or disassembly of the executable. The following examples illustrates the use of er_src to view compiler commentary messages.
% cat example.c
#include <stdio.h> void foo () { printf ("foo\n"); } void bar () { foo(); printf ("bar\n"); }
int main (){ bar(); }
% cc -O4 -g example.c % er_src a.out Source file: ./commentary.c Object file: ./a.out Load Object: ./a.out
1. #include <stdio.h> 2. void foo () 3. { <Function: foo> 4. int i; 5. printf ("foo\n"); 6. } 7. void bar () 8. { <Function: bar> Function foo inlined from source file commentary.c into the code for the following line. 0 loops inlined 9. foo(); 10. printf ("bar\n"); 11. } 12. 13. int main (){ <Function: main> Function bar inlined from source file commentary.c into the code for the following line. 0 loops inlined Function foo inlined from source file commentary.c into inline copy of function bar. 0 loops inlined 14. bar(); 15. }
It is also possible to see commentary messages with source and disassembly together:
% er_src -disasm main a.out
Annotated disassembly --------------------------------------- Source file: ./commentary.c Object file: ./a.out Load Object: ./a.out
1. #include <stdio.h> 2. void foo () 3. { <Function: foo> [ 3] 80506f4: pushl %ebp [ 3] 80506f5: movl %esp,%ebp 4. printf ("foo\n"); [ 4] 80506f7: subl $0x14,%esp [ 4] 80506fa: pushl $0x80507a0 [ 4] 80506ff: call printf [ 0x80505bc, .-0x143 ] 5. } [ 5] 8050704: leave [ 5] 8050705: ret 6. void bar () 7. { <Function: bar> [ 7] 8050710: pushl %ebp [ 7] 8050711: movl %esp,%ebp [ 4] 8050713: subl $0x14,%esp [ 4] 8050716: pushl $0x80507a0 [ 4] 805071b: call printf [ 0x80505bc, .-0x15f ] Function foo inlined from source file commentary.c into the code for the following line. 0 loops inlined 8. foo(); 9. printf ("bar\n"); [ 9] 8050720: addl $4,%esp [ 9] 8050723: pushl $0x8050798 [ 9] 8050728: call printf [ 0x80505bc, .-0x16c ] 10. } [10] 805072d: leave [10] 805072e: ret 11. 12. int main (){ <Function: main> [12] 8050738: pushl %ebp [12] 8050739: movl %esp,%ebp [ 4] 805073b: subl $0x14,%esp [ 4] 805073e: pushl $0x80507a0 [ 4] 8050743: call printf [ 0x80505bc, .-0x187 ] [ 9] 8050748: addl $4,%esp [ 9] 805074b: pushl $0x8050798 [ 9] 8050750: call printf [ 0x80505bc, .-0x194 ] Function bar inlined from source file commentary.c into the code for the following line. 0 loops inlined Function foo inlined from source file commentary.c into inline copy of function bar. 0 loops inlined 13. bar(); 14. } [14] 8050755: xorl %eax,%eax [14] 8050757: leave [14] 8050758: ret
Besides the commentary message about inlining in the example above, a wide variety of messages about compiler transformations are generated. These messages can be broadly classified into the following categories:
* Frontend generated messages * Iropt (the intermediate level optimizer) generated messages - these messages are often about loop transformations such as unrolling, fusion, fission etc. Iropt also generates a class of messages about parallelization and also about inlining. * Code generator messages - the sparc code generator inserts about modulo scheduling and related pipelining and loop unrolling issues.
Presently on the x86 platform, Sun Studio compiler generates compiler commentary messages only from frontend and iropt. Messages about transformations done in the x86 code generator is a work in progress.
Some sample messages are shown below:
* Function <name> not inlined because it contains too many calls * Call to function <name> was tail-call optimized * <loop> not parallelized because it contains multiple exit points * <loop1> fused with <loop2>, new loop <loop3> * <loop> unrolled <number> times
Shown below is another sample example of a fortran 90 program on which microvectorization was performed:
% cat test.f90 subroutine add1(a,b,n) integer a(n), b(n) a(:) = b(:) + 1 end
% f90 -fast -xvector=simd test.f90 -g -c
% er_src test.o
Source file: ./test.f90 Object file: ./test.o Load Object: ./test.o
1. subroutine add1(a,b,n) 2. integer a(n), b(n) Array statement below generated loop L1 L1 is micro-vectorized L1 multi-versioned for microvectorizing. Specialized version is L2 L2 cloned for peeling. Clone is L4
L1 cloned for microvectorizing-epilog. Clone is L8 L4 cloned for microvectorizing-epilog. Clone is L6 L2 had iterations peeled off for better unrolling and/or parallelization 3. a(:) = b(:) + 1 4. end
Besides messages about what transformations were performed, commentary messages are also inserted about why certain optimization was not performed. The motivation being that the user can get a better understanding of how the compiler attempted to optimize a certain piece of code. If a certain desirable optimization was not performed, the user can take an informed decision about modifying certain part of the code or try a different compile time option.
Please read the man page for er_src to learn about various options for er_src. It is possible to view commentary about only a select subset of compiler transformations. The performance analyzer man pages and user manuals also have details about using er_src and viewing annotated source and disassembly.
Posted by x86be
( Jun 01 2007, 06:41:26 PM PDT )
Permalink
Trackback URL: http://blogs.sun.com/x86be/entry/compiler_commentary_support_in_sun
|