GCC has command line options to request that it unload its intermediate representation after any compilation step. Dumps of the tree are in the pseudo-C syntax and contain the information you need. For what you are trying to do, the dumps -fdump-tree-original and -fdump-tree-optimized occur at points of -fdump-tree-optimized in the optimization pipeline. I do not have an AVR compiler, so I modified your test script to be standalone and compiled with the compiler that I have:
typedef unsigned short uint16_t; const int F_CPU = 4000000; const uint16_t baudrate = 9600; extern uint16_t UBRRH, UBRRL; void setupUART(void) { uint16_t ubrr = ((F_CPU / (16 * (float) baudrate)) - 1 + .5); UBRRH = ubrr >> 8; UBRRL = ubrr & 0xff; }
and then
$ gcc -O2 -S -fdump-tree-original -fdump-tree-optimized test.c $ cat test.c.003t.original ;; Function setupUART (null) ;; enabled by -tree-original { uint16_t ubrr = 25; uint16_t ubrr = 25; UBRRH = (uint16_t) ((short unsigned int) ubrr >> 8); UBRRL = ubrr & 255; } $ cat test.c.149t.optimized ;; Function setupUART (setupUART, funcdef_no=0, decl_uid=1728, cgraph_uid=0) setupUART () { <bb 2>: UBRRH = 0; UBRRL = 25; return; }
You can see that constant-expression folding is done so early that it already happened in the “source” dump (which is the earliest acceptable dump you can have), and this optimization has further shifted the shift operations and masks into statements that write UBRRH and UBRRL.
The numbers in the file names (003t and 149t) are likely to be different for you. If you want to see all the tree-like dumps, use -fdump-tree-all . There are also “RTL” dumps that are not like C and probably not useful to you. If you're interested, -fdump-rtl-all on. In total, there are about 100 trees and 60 RTL dumps, so it is recommended to do this in the directory from scratch.
(Psssst: every time you put spaces inside your parentheses, God kills the kitten.)
zwol
source share