Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Code Generation and Code Optimization.

Similar presentations


Presentation on theme: "Final Code Generation and Code Optimization."— Presentation transcript:

1 Final Code Generation and Code Optimization

2

3

4

5

6

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

11

12

13

14

15

16

17

18

19

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

21

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

23

24

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

27

28


Download ppt "Final Code Generation and Code Optimization."

Similar presentations


Ads by Google