Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Target Code Generation
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Intermediate Code Generation
1 CS 201 Compiler Construction Machine Code Generation.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
Program Representations. Representing programs Goals.
From AST to Code Generation Professor Yihjia Tsai Tamkang University.
Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error.
Program Representations Xiangyu Zhang. CS590F Software Reliability Why Program Representations  Initial representations Source code (across languages).
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
PSUCS322 HM 1 Languages and Compiler Design II Basic Blocks Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Lecture 23 Basic Blocks Topics Code Generation Readings: 9 April 17, 2006 CSCE 531 Compiler Construction.
1 CS 201 Compiler Construction Lecture 1 Introduction.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
Flow Control Instructions
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Topic 6 -Code Generation Dr. William A. Maniatty Assistant Prof. Dept. of Computer Science University At Albany CSI 511 Programming Languages and Systems.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Data Flow Analysis Compiler Design Nov. 8, 2005.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
The Program Design Phases
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
Precision Going back to constant prop, in what cases would we lose precision?
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Advanced Compiler Design An Introduction to the Javali Compiler Framework Zoltán Majó 1.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
3D Puzzle Assignment #1 Programming Language, Spring 2003.
Intermediate Code Representations
Compilers Modern Compiler Design
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Final Code Generation and Code Optimization.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
Control Flow Analysis Compiler Baojian Hua
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Road Map Regular Exprs, Context-Free Grammars Regular Exprs, Context-Free Grammars LR parsing algorithm LR parsing algorithm Building LR parse tables Building.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Announcements/Reading
Simone Campanoni CFA Simone Campanoni
The Little man computer
Basic Program Analysis
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
White-Box Testing.
Topic 10: Dataflow Analysis
White-Box Testing.
Computer Science 210 Computer Organization
CS 201 Compiler Construction
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Static Single Assignment Form (SSA)
Control Flow Analysis (Chapter 7)
Final Code Generation and Code Optimization
Intermediate Code Generation
Compiler Construction
Taken largely from University of Delaware Compiler Notes
Bubble Sort begin; int A[10]; main(){ int i,j; Do 10 i = 0, 9, 1
CS 201 Compiler Construction
Presentation transcript:

Homework 4 Basic Blocks and Control Flow Graphs CS4430 Spring 2012 Due: April 2 nd by 2pm* * There will be absolutely no extensions for this assignment.

The Tuple Language Tuple  Asn | Add | Sub | Jmp | Label | Read | Write | Exit Asn  (ASSIGN,RegArg,Arg) Add  (ADDI,RegArg,Arg,Arg) Sub  (SUBI,RegArg,Arg,Arg) Jmp  (JUMP,Arg) Branch  (JNZ,RegArg,Arg) Label  (LABEL,Num) /* N.b., labels are Num ’s */ Read  (READI,RegArg) Write  (WRITEI,Arg) Exit  (EXIT) Arg  RegArg | Num Register  ‘R’ Num | SP | FP | BP RegArg  Register | M[Register] | M[Register + Num] Num  [1-9] Digit*

Homework 4, Question 1 Input: the abstract syntax for a Tuple program Input: the tuple parser in TuplePrettyPrinter.tar.gz Output: – Basic blocks for input program Extend it to produce a linked list of basic blocks. – You MUST define a new type called BasicBlock to represent each BB. – The code within the block MUST be represented as an array (and not a linked list) – Include in the definition of BasicBlock whatever else you need (i.e., figure that out). I suggest giving each block a unique id. – Difference from lecture slides: include any jump/branch instructions within the code array To check your results, print out a GraphViz representation of your basic blocks. Each node must contain the code in the block.

Tuple Pretty Printer Compile with Makefile in the tarball TuplePrettyPrinter.tar.gz – Available on the class webpage. Run it with file redirection; e.g., –./tuplec test1.gv – Takes a tuple file as input and produces GraphViz output file Requires bison and flex – you do not need to alter these files at all. – Just use the Makefile.

Question 2 Input: the output from problem 1 Construct a control flow graph representation for an input program. To check your work, produce a GraphViz representation of the control flow graph.

Review: Basic Block basic block is a instruction sequence with – one entry point only EP may be dest. of a jump/branch EP may be target of multiple jump/branch’s – one exit point, and – no jump instructions between EP and exit Last instruction in basic block may be a – jump instruction or – Instruction right before destination of jump instruction.

Review: Control Flow Graph Control flow graph (CFG) is a directed graph showing all possible paths during program execution – each node is a basic block/instruction – directed edges are control flow changes Entry block through which control enters into the flow graph, and the Exit block from which control flow leaves.

Given input on left, your solution should produce the graph on the right (READI, A) (READI, B) (GT,A,B,t1) (JUMP0,t1,L1) (ADDI,A,5,C) (JUMP,L2) (LABEL,L1) (ADDI,B,5,C) (LABEL,L2) (SUBI,C,1,t2) (MULTI,2,t2,t3) (WRITEI,t3) Control Flow Graph (CFG) generated by Graphviz Input Tuple program

Here’s the GraphViz code Cosmetic issues (color, font, etc.) don’t matter in your output graph N.b., if two different basic blocks have the same code, then you’ll have to ensure that they are different nodes in the GraphViz graph. N.b., also that the branch instruction is in the block (this differs from the lecture slides). Your solution must also retain the jumps and branches. digraph cfg { size="6,6"; node [color=yellow, style=filled, shape = box, fontname = "Courier New"]; "(READI, A)\l(READI, B)\l(GT,A,B,t1)\l(JUMP0,t1,L1)" -> "(ADDI,A,5,C)" [label="t1=0",len=1.00] ; "(READI, A)\l(READI, B)\l(GT,A,B,t1)\l(JUMP0,t1,L1)" -> "(LABEL,L1)\l(ADDI,B,5,C)" [label="t1!=0",len=1.00] ; "(ADDI,A,5,C)" -> "(LABEL,L2)\l(SUBI,C,1,t2)\l(MULTI,2,t2,t3)\l(WRITEI,t3)"; "(LABEL,L1)\l(ADDI,B,5,C)" -> "(LABEL,L2)\l(SUBI,C,1,t2)\l(MULTI,2,t2,t3)\l(WRITEI,t3)"; }