Compiler Construction

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advanced Piloting Cruise Plot.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
Chapter 3: Top-Down Design with Functions Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
2010 fotografiert von Jürgen Roßberg © Fr 1 Sa 2 So 3 Mo 4 Di 5 Mi 6 Do 7 Fr 8 Sa 9 So 10 Mo 11 Di 12 Mi 13 Do 14 Fr 15 Sa 16 So 17 Mo 18 Di 19.
ZMQS ZMQS
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Outline Introduction Assumptions and notations
Data Structures Using C++
ABC Technology Project
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
15. Oktober Oktober Oktober 2012.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 Code Generation The target machine Instruction selection and register allocation Basic blocks and flow graphs A simple code generator Peephole optimization.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Intermediate Representations CS 671 February 12, 2008.
LO: Count up to 100 objects by grouping them and counting in 5s 10s and 2s. Mrs Criddle: Westfield Middle School.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Slippery Slope
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
Energy Generation in Mitochondria and Chlorplasts
CpSc 3220 Designing a Database
1 Undirected Graphical Models Graphical Models – Carlos Guestrin Carnegie Mellon University October 29 th, 2008 Readings: K&F: 4.1, 4.2, 4.3, 4.4,
Compiler Construction Sohail Aslam Lecture Code Generation  The code generation problem is the task of mapping intermediate code to machine code.
Target code Generation Made by – Siddharth Rakesh 11CS30036 Date – 12/11/2013.
Code Generation.
Presentation transcript:

Compiler Construction Sohail Aslam Lecture 43 gmu 540 compiler: Bottom-up Parsing

Control Flow Graph - CFG 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 5

Basic Blocks A basic block is a sequence of consecutive statements with single entry/single exit

Basic Blocks Flow of control only enters at the beginning Flow of control only leaves at the end Variants: single entry/multiple exit, multiple entry/single exit

Generating CFGs Partition intermediate code into basic blocks Add edges corresponding to control flow between blocks Unconditional goto Conditional goto – multiple edges No goto at end – control passes to first statement of next block

Generating CFGs Partition intermediate code into basic blocks Add edges corresponding to control flow between blocks Unconditional goto Conditional goto – multiple edges No goto at end – control passes to first statement of next block

Algorithm: Partition into basic blocks Input. sequence of three-address statements Output. A list of basic blocks with each three-address statements in exactly one block This is a note compiler: Bottom-up Parsing

The first statement is a leader Method. 1. Determine the set of leaders – the first statements of basic blocks. The rules are The first statement is a leader Any statement that is the target of a conditional or unconditional goto is a leader Any statement that immediately follows a goto or conditional goto is a leader This is a note compiler: Bottom-up Parsing

Method. 2. For each leader, its basic block consists of the leader and all statements up to but not including the next leader or the end of the program This is a note compiler: Bottom-up Parsing

Example Consider the C fragment for computing dot product aT b of two vectors a and b of length 20 a1 a2 ... a20 b1 = a1b1 + a2b2 b2 +......... . + a20b20 . b20 This is a note compiler: Bottom-up Parsing

Dot Product prod = 0; i = 1; do { prod = prod + a[i]*b[i]; i = i + 1; } while ( i <= 20 ); This is a note compiler: Bottom-up Parsing

Dot Product prod = 0 i = 1 t1 = 4*i /* offset */ t2 = a[t1] /* a[i] */ t4 = b[t3] /* b[i] */ t5 = t2*t4 t6 = prod+t5 prod = t6 t7 = i+1 i = t7 if i <= 20 goto (3) This is a note compiler: Bottom-up Parsing

Dot Product leader prod = 0 i = 1 t1 = 4*i /* offset */ t2 = a[t1] /* a[i] */ t3 = 4*i t4 = b[t3] /* b[i] */ t5 = t2*t4 t6 = prod+t5 prod = t6 t7 = i+1 i = t7 if i <= 20 goto (3) leader This is a note compiler: Bottom-up Parsing

Dot Product B1 prod = 0 i = 1 t1 = 4*i t2 = a[t1] B2 t3 = 4*i t5 = t2*t4 t6 = prod+t5 prod = t6 t7 = i+1 i = t7 if i <= 20 goto (3) B2 This is a note compiler: Bottom-up Parsing

B1 B2 prod = 0 i = 1 t1 = 4*i t2 = a[t1] t3 = 4*i t4 = b[t3] t5 = t2*t4 t6 = prod+t5 prod = t6 t7 = i+1 i = t7 if i <= 20 goto B2 B2 This is a note compiler: Bottom-up Parsing

Quick Sort 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); This is a note compiler: Bottom-up Parsing

Quick Sort 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); This is a note compiler: Bottom-up Parsing

(1) i := m – 1 (16) t7 := 4 * i j := n (17) t8 := 4 * j t1 := 4 * n (18) t9 := a[t8] v := a[t1] (19) a[t7] := t9 i := i + 1 (20) t10 := 4 * j t2 := 4 * i (21) a[t10] := x t3 := a[t2] (22) goto (5) if t3 < v goto (5) (23) t11 := 4 * i j := j - 1 (24) x := a[t11] t4 := 4 * j (25) t12 := 4 * i t5 := a[t4] (26) t13 := 4 * n If t5 > v goto (9) (27) t14 := a[t13] if i >= j goto (23) (28) a[t12] := t14 t6 := 4*i (29) t15 := 4 * n x := a[t6] (30) a[t15] := x

(1) i := m – 1 (16) t7 := 4 * i j := n (17) t8 := 4 * j t1 := 4 * n (18) t9 := a[t8] v := a[t1] (19) a[t7] := t9 i := i + 1 (20) t10 := 4 * j t2 := 4 * i (21) a[t10] := x t3 := a[t2] (22) goto (5) if t3 < v goto (5) (23) t11 := 4 * i j := j - 1 (24) x := a[t11] t4 := 4 * j (25) t12 := 4 * i t5 := a[t4] (26) t13 := 4 * n If t5 > v goto (9) (27) t14 := a[t13] if i >= j goto (23) (28) a[t12] := t14 t6 := 4*i (29) t15 := 4 * n x := a[t6] (30) a[t15] := x

(1) i := m – 1 (16) t7 := 4 * i j := n (17) t8 := 4 * j t1 := 4 * n (18) t9 := a[t8] v := a[t1] (19) a[t7] := t9 i := i + 1 (20) t10 := 4 * j t2 := 4 * i (21) a[t10] := x t3 := a[t2] (22) goto (5) if t3 < v goto (5) (23) t11 := 4 * i j := j - 1 (24) x := a[t11] t4 := 4 * j (25) t12 := 4 * i t5 := a[t4] (26) t13 := 4 * n If t5 > v goto (9) (27) t14 := a[t13] if i >= j goto (23) (28) a[t12] := t14 t6 := 4*i (29) t15 := 4 * n x := a[t6] (30) a[t15] := x

B1 B5 B2 B6 B3 B4 i = m-1 t11 = 4*i j = n x = a[t11] t1 = 4*n v = a[t1] t11 = 4*i x = a[t11] t12 = 4*i t13 = 4*n t14 = a[t13] a[t12] = t14 t15 = 4*n a[t15] = x B2 i = i+1 t2 = 4*i t3 = a[t2] if t3 < v goto B2 B6 B3 t6 = 4*i x = a[t6] t7 = 4*i t8 = 4*j t9 = a[t8] a[t7] = t9 t10 = 4*j a[t10] = x goto B2 j = j-1 t4 = 4*j t5 = a[t4] if t5 > v goto B3 This is a note B4 if i >= j goto B6 compiler: Bottom-up Parsing

Basic Block Code Generation Algorithms: Basic - using liveness information Using DAGS - node numbering Register Allocation

Basic Code Generation Deal with each basic block individually. Generate code for the block using liveness information. At end, generate code that saves any live values left in registers.

Basic Code Generation Deal with each basic block individually. Generate code for the block using liveness information. At end, generate code that saves any live values left in registers.

Basic Code Generation Deal with each basic block individually. Generate code for the block using liveness information. At end, generate code that saves any live values left in registers.

Computing Live/Next Use Information For the statement: x = y + z x has a next use if there is a statement s that references x and there is some way for control to flow from the original statement to s.

Computing Live/Next Use Information x = y + z ...... s t1 = x – t3 next use

Computing Live/Next Use Information A variable is live at a given point in time if it has a next use. Liveness tells us whether we care about the value held by a variable.

Computing Live/Next Use Information x = y + z ...... s t1 = x – t3 live!

Computing live status Input: A basic block. Output: For each statement, set of live variables

Method: 1. Initially all non-temporary variables go into live set. 2. for i = last statement to first statement: for statement i: x = y op z attach to statement i, current live set. remove x from set. add y and z to set.