



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of Advanced Compiler Design which includes Flow of Control Checks, Uniqueness Checks, Name Related Checks, Type of Construct Matches, Integer Operands, Code Generation, Type Systems, Implicit Assumptions etc. Key important points are: Examples of Basic Blocks, Three-Address Statements, Address Code Translation, Example of Flow Graphs, Basic Blocks Algorithm, Set of Leaders, Leader By Rule, Statement of Basic Blocks
Typology: Slides
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Following sequence of three-address statements forms a basic block: t1 : = a * a t2 := a * b t3 := 2 * t t4 := t1+ t t5 := b * b t6 := t4 + t It computes: aa + 2ab + bb Given 3-AS x := y+z: -it defines X -it uses (reference) y and z Live name: A name is a basic block is said to be live at a given point if its value is used after that point in the program, perhaps in another basic block.** a b t6 t
a a 2 a b b b t t t t t t
C-code void quicksort(m,n) int m,n { int i,j; int v,x; if (n<=m) return; / fragment begins / i:=m-1; j=n ; v=a[n]; while(1) { do i=i+1; while(a[i]<v) do j=j-1; while(a[j]>v) if (i>=j) break; x=a[i];a[i]=a[n];a[n]=x;} x=a[i];a[i]=a[n];a[n]=x; / fragment ends / quicksort( m ,j); quicksort(l+1,n); } 3 Address Code. i = m-1; j = n ; v = a[n]; (1) i := m-l; j:=n; t1 := 4n; v := a[t1]; while(1) { do i = i + 1; while(a[i]<v) ; (5) i := i+1; t2 := 4i; t3 := a[t2]; (8) if t3<v goto(5) do j = j-1; while (a[j] > v); (9) j:=j+1; t4:=4j ; t5:=a[t4]; (12) if t5 >v goto (9) (13) if( i >=j) goto (23) x = a[i]; a[i] = a[n]; a[n]=x (14) t6 := 4i; x:=a[t6]; (16) t7 := 4i; x:=a[t6]; (18) t9:= a[t8]; a[t7]:=t9; (20) t10:= 4j; a[t10]:= x (22) goto(5) (23) ...
Input : A sequence of 3 address statements Output: A sequence of basic blocks with each 3A Statement in exactly one block. Method: (1) First determine a set of leaders, the 1st statement of basic blocks: a) The first statement is a leader b) Any statement that is a target of a conditional or unconditional goto is a leader c) Any statement that immediately follows a goto, or conditional goto statement is a leader. (2) For each leader its basic block consists of: a) The leader b) All statements upto but not including the next leader or the end of the program.
(1) prod : = 0 (2) i : = 1 (3) t1 : = 4 * i (4) t2 : = a[t1] (5) t3 : = 4 * i (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)