Download presentation
Presentation is loading. Please wait.
1
Final Code Generation and Code Optimization
7
for ( i=0; i < N; i++) { base = &a[0]; crt = *(base + i); } base = &a[0]; for ( i=0; i < N; i++) { crt = *(base + i); } original codeoptimized code
8
e1 = *(&a[0]+offset +i); e2 = *(&a[0]+offset +j); tmp = &a[0]+offset; e1 = *(tmp +i); e2 = *(tmp +j); original codeoptimized code
9
y = … x = y; b = x / 2; y = … b = y / 2; original codeoptimized code
10
if (1) x = y; else x = z; x = y; original codeoptimized code
20
Exercise: at which points are these variables live ? prod,i,t1,t2,t3,t4,t5,t6,t7
22
Rationale – A value in a register can be accessed much more efficiently than one in memory, so we should try to keep (frequently used) values in registers… – …but CPUs have a very limited number of registers Techniques – Local register allocation – Global register allocation
25
read A D = A+1 read B D = D+B D = A+1 read C D = D+C print A,D A A B B C C D D Register Interference Graph nodes: symbolic registers edges: if nodes are simultaneously live R1R1 R1R1 R2R2 R2R2 R3R3 R3R3 k-coloring, where k is the number of registers
26
A A B B C C D D R1R1 R1R1 R2R2 R2R2 R3R3 R3R3 A A D D {empty graph} A A D D A A B B C C D D R1R1 R2R2 R1R1 R2R2 R3R3 R3R3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.