1 Supposons que lon dispose de 4 registres ARM Considérons le code C suivant w = a + b; x = c + w; y = c + d;
2 Allocation Naïve Une variable est assignée à un registre : il nous faudrait 7 registres Comment améliorer ce résultat ? Construction du graphe de durée de vie des variables w = a + b; blabla … x = c + w; Durée de vie début fin de vie
3 Durée de vie des variables : 2 w = a + b; /*1*/ x = c + w; /*2*/ y = c + d; /*3*/ MAX = 3MAX
4 a b x w y c d Résoudre le problème dallocation
5 Coloriage de graphe - NP Problem a b x w y c d a b x w y c d
6 Durée de vie des variables AR0 BR1 C DR0 WR3 XR0 yR3 LDR R0,[p-a];load a into R0 using pointer to a (p-a) LDR R1,[p-b];load a into R1 ADD R3,R0,R1;compute a+b STR R3,[p-w];w=a+b LDR R1,[p-c];load c into R1 ADD R0,R1,R3;compute c+w, reusing R0 for x STR R0,[p-d];x=c+w LDR R0,[p-d];load d into R0 ADD R3,R1,R0;compute c+d, reusing R3 for y STR R3,[p-y];y=c+d LDR R0,[p-a];load a into R0 using pointer to a (p-a) LDR R1,[p-b];load a into R1 ADD R3,R0,R1;compute a+b STR R3,[p-w];w=a+b LDR R1,[p-c];load c into R1 ADD R0,R1,R3;compute c+w, reusing R0 for x STR R0,[p-d];x=c+w LDR R0,[p-d];load d into R0 ADD R3,R1,R0;compute c+d, reusing R3 for y STR R3,[p-y];y=c+d w = a + b; /*1*/ x = c + w; /*2*/ y = c + d; /*3*/ w = a + b; /*1*/ x = c + w; /*2*/ y = c + d; /*3*/
7 Problèmes interdépendants Allocation des registres Ordonnancement
8 Interdépendance avec lordonnancement w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ MAXMAX = 5
9 interdépendance On dispose que de 3 registres Recharger des variables
10 Comparaison LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w LDR R0,c LDR R1,d ADD R2,R0,R1 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b SUB R2,R1,R0 STR R2,z LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w LDR R0,c LDR R1,d ADD R2,R0,R1 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b SUB R2,R1,R0 STR R2,z w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/
11 Modification de lordonnancement w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/ w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/
12 Interdépendance avec lordonnancement w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/ w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/ MAX Modification de lordonnancement MAX = 3
13 Comparaison LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w SUB R2,R0,R1 STR R2,z LDR R0,c LDR R1,d ADD R2,R1,R0 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w SUB R2,R0,R1 STR R2,z LDR R0,c LDR R1,d ADD R2,R1,R0 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/ w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/
14 Comparaison LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w LDR R0,c LDR R1,d ADD R2,R0,R1 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b SUB R2,R1,R0 STR R2,z LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w LDR R0,c LDR R1,d ADD R2,R0,R1 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b SUB R2,R1,R0 STR R2,z w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ w = a + b; /*1*/ x = c + d; /*2*/ y = x + e; /*3*/ Z = a – b; /*4*/ LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w SUB R2,R0,R1 STR R2,z LDR R0,c LDR R1,d ADD R2,R1,R0 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y LDR R0,a LDR R1,b ADD R2,R0,R1 STR R2,w SUB R2,R0,R1 STR R2,z LDR R0,c LDR R1,d ADD R2,R1,R0 STR R2,x LDR R1,e ADD R0,R1,R2 STR R0,y w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/ w = a + b; /*1*/ Z = a – b; /*2*/ x = c + d; /*3*/ y = x + e; /*4*/