























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























2
CFG = < V, E, Entry >, where V = vertices or nodes, representing an instruction or basic block (group of statements). E = (V x V) edges, potential flow of control Entry is an element of V, the unique program entry
(^1 2 3 4 )
4
Basic Blocks
5
Generating CFGs
7
8
Method.
i. The first statement is a leader
ii. Any statement that is the target of a conditional or unconditional goto is a leader
iii. Any statement that immediately follows a goto or conditional goto is a leader
10
11
13
1 prod = 0 2 i = 1 3 t1 = 4i / offset / 4 t2 = a[t1] / a[i] / 5 t3 = 4i 6 t4 = b[t3] /* b[i] / 7 t5 = t2t 8 t6 = prod+t 9 prod = t 10 t7 = i+ 11 i = t 12 if i <= 20 goto (3)
leader
leader
14
1 prod = 0 2 i = 1 3 t1 = 4i 4 t2 = a[t1] 5 t3 = 4i 6 t4 = b[t3] 7 t5 = t2*t 8 t6 = prod+t 9 prod = t 10 t7 = i+ 11 i = t 12 if i <= 20 goto (3)
16
void quicksort(int m, int n) { int i,j,v,x; if( n <= m ) return; i=m-1; j=n; v=a[n]; while(true) { do i=i+1; while( a[i] < v); do j=j-1; while( a[j] > v); i( i >= j ) break; x=a[i]; a[i]=a[j]; a[j]=x; } x=a[i]; a[i]=a[n]; a[n]=x; quicksort(m,j); quicksort(i+1,n); }
17
void quicksort(int m, int n) { int i,j,v,x; if( n <= m ) return; i=m-1; j=n; v=a[n]; while(true) { do i=i+1; while( a[i] < v); do j=j-1; while( a[j] > v); i( i >= j ) break; x=a[i]; a[i]=a[j]; a[j]=x; } x=a[i]; a[i]=a[n]; a[n]=x; quicksort(m,j); quicksort(i+1,n); }
19
(1) i := m – 1 (16) t7 := 4 * i (2) j := n (17) t8 := 4 * j (3) t1 := 4 * n (18) t9 := a[t8] (4) v := a[t1] (19) a[t7] := t (5) i := i + 1 (20) t10 := 4 * j (6) t2 := 4 * i (21) a[t10] := x (7) t3 := a[t2] (22) goto (5) (8) if t3 < v goto (5) (23) t11 := 4 * i (9) j := j - 1 (24) x := a[t11] (10) t4 := 4 * j (25) t12 := 4 * i (11) t5 := a[t4] (26) t13 := 4 * n (12) If t5 > v goto (9) (27) t14 := a[t13] (13) if i >= j goto (23) (28) a[t12] := t (14) t6 := 4i* (29) t15 := 4 * n (15) x := a[t6] (30) a[t15] := x
20
(1) i := m – 1 (16) t7 := 4 * i (2) j := n (17) t8 := 4 * j (3) t1 := 4 * n (18) t9 := a[t8] (4) v := a[t1] (19) a[t7] := t (5) i := i + 1 (20) t10 := 4 * j (6) t2 := 4 * i (21) a[t10] := x (7) t3 := a[t2] (22) goto (5) (8) if t3 < v goto (5) (23) t11 := 4 * i (9) j := j - 1 (24) x := a[t11] (10) t4 := 4 * j (25) t12 := 4 * i (11) t5 := a[t4] (26) t13 := 4 * n (12) If t5 > v goto (9) (27) t14 := a[t13] (13) if i >= j goto (23) (28) a[t12] := t (14) t6 := 4i* (29) t15 := 4 * n (15) x := a[t6] (30) a[t15] := x