1 / 28

Final Code Generation and Code Optimization

Final Code Generation and Code Optimization. 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 code. optimized code. tmp = &a[0]+offset ; e1 = *( tmp +i); e2 = *( tmp +j);.

Download Presentation

Final Code Generation and Code Optimization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Final Code Generation and Code Optimization

  2. 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 code optimized code

  3. tmp = &a[0]+offset; e1 = *(tmp +i); e2 = *(tmp +j); e1 = *(&a[0]+offset +i); e2 = *(&a[0]+offset +j); original code optimized code

  4. y = … x = y; b = x / 2; y = … b = y / 2; original code optimized code

  5. if (1) x = y; else x = z; x = y; original code optimized code

  6. Exercise: at which points are these variables live ? prod,i,t1,t2,t3,t4,t5,t6,t7

  7. 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

  8. read A D = A+1 read B D = D+B D = A+1 read C D = D+C print A,D Register Interference Graph nodes: symbolic registers edges: if nodes are simultaneously live A R1 R3 R2 B C k-coloring, where k is the number of registers D

  9. A A B C {empty graph} D D R1 R3 R2 A A R1 R1 B C {empty graph} R3 R3 D D R2 R2

More Related