COP5621 Exam 4 - Spring 2005

Similar documents
COP5621 Exam 3 - Spring 2005

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Problem Score Max Score 1 Syntax directed translation & type

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

CSCI Compiler Design

CMSC430 Spring 2014 Midterm 2 Solutions

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

CSCI Compiler Design

Intermediate representation

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Tour of common optimizations

Today's Topics. CISC 458 Winter J.R. Cordy

CS 164 Handout 16. Final Examination. There are nine questions on the exam, some in multiple parts. You have 3 hours to work on the

COP4020 Fall 2006 Final Exam

Why Global Dataflow Analysis?

Midterm II CS164, Spring 2006

A main goal is to achieve a better performance. Code Optimization. Chapter 9

CS 406/534 Compiler Construction Putting It All Together

CSCE 531, Spring 2015 Final Exam Answer Key

Qualifying Exam in Programming Languages and Compilers

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

CS5363 Final Review. cs5363 1

Goals of Program Optimization (1 of 2)

Languages and Compiler Design II IR Code Optimization

Control flow graphs and loop optimizations. Thursday, October 24, 13

Name: CIS 341 Final Examination 10 December 2008

Final Exam Review Questions

Programming Language Processor Theory

Run-Time Environments

Principles of Compiler Design

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

PRINCIPLES OF COMPILER DESIGN

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

COP4020 Spring 2011 Midterm Exam

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

2. Reachability in garbage collection is just an approximation of garbage.

CSE3322 Programming Languages and Implementation

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

ELEC 876: Software Reengineering

Chapter 10. Implementing Subprograms ISBN

This test is not formatted for your answers. Submit your answers via to:

COMP-520 GoLite Tutorial

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016

INSTITUTE OF AERONAUTICAL ENGINEERING

Liveness Analysis and Register Allocation. Xiao Jia May 3 rd, 2013

Appendix A The DL Language

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CS 6353 Compiler Construction, Homework #3

Question Bank. 10CS63:Compiler Design

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER

Loops. Lather, Rinse, Repeat. CS4410: Spring 2013

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Programming Languages

More Code Generation and Optimization. Pat Morin COMP 3002

CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

CSCI 565: Compiler Design and Implementation Spring 2006

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Run-Time Environments

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00

The role of semantic analysis in a compiler

CSCE 531 Spring 2009 Final Exam

Intra-procedural Data Flow Analysis Introduction

SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA

Today's Topics. Last Time Modelling Scopes and Visibility The Run Stack, the Dynamic Pointer Stack, the Display (LL,ON) addressing

register allocation saves energy register allocation reduces memory accesses.

Syntax Directed Translation

Spring 2014 CSE Qualifying Exam Core Subjects

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Data Flow Analysis. Program Analysis

Chapter 9. Def: The subprogram call and return operations of a language are together called its subprogram linkage

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

VIVA QUESTIONS WITH ANSWERS

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

System Software Assignment 1 Runtime Support for Procedures

UNIT 3

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

Chapter 10 Implementing Subprograms

Compiler Design. Fall Data-Flow Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

G Programming Languages - Fall 2012

Loop Optimizations. Outline. Loop Invariant Code Motion. Induction Variables. Loop Invariant Code Motion. Loop Invariant Code Motion

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

CSE 504: Compiler Design. Runtime Environments

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Reverse Engineering Techniques

Spring 2013 CSE Qualifying Exam Core Subjects. March 23, 2013

Compiler Optimization and Code Generation

Intermediate Representations

Architectural-Level Synthesis. Giovanni De Micheli Integrated Systems Centre EPF Lausanne

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

CS143 Final Fall 2009

FORM 2 (Please put your name and form # on the scantron!!!!)

Intermediate Representations. Reading & Topics. Intermediate Representations CS2210

Transcription:

COP5621 Exam 4 - Spring 2005 Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full credit and helpful for partial credit). You can collect 100 points in total for this exam. A bonus question for an additional 15 points is included. If the total number of points for this exam exceed 100, the excess points are carried over to the next exams. 1. Match the terms below with the given sentences so as to best complete each sentence. Use no term more than once. Some terms will go unused. (10 points) (1) static link (7) stack pointer (2) access link (8) control link (3) state (9) environment (4) local (10) global (5) live (11) dead (6) code motion (12) reduction in strength (a) A transformation on a program is called if it can be performed by looking only at the statements in a basic block rather than an entire region of code. (b) An implementation of lexical scope for nested procedures is obtained by adding a pointer called to each activation record. (c) In liveness analysis, a variable is said to be (d) The loop optimization called if it has no next use. moves loop-invariant statements to the loop header. (e) In programming language semantics, the term refers to a function that maps a name to a storage location (i.e. to an l-value) and the term refers to a function that maps a storage location to the value held (i.e. to an r-value). 2. Name three peephole optimizations. (10 points) 1

3. Describe a typical calling sequence to invoke a function. (10 points) 4. Apply register allocation and assignment using graph coloring to the following CFG: a := read() b := read() if a>0 goto L1 a := 1 goto L2 L1: b := 1 L2: c := a * b c := c + b To determine a coloring, show the live ranges of the variables a, b, and c in the CFG, assuming that the variables are dead at the exit from the CFG Then draw the register-interference graph (conflict graph) for the variables and determine the minimum number of colors necessary to color the graph. (15 points) 2

5. Consider the following CFG: 1 2 3 4 5 6 (a) Draw the dominator tree of the CFG. (10 points) (b) Identify the natural loops. (5 points) (c) Is the CFG reducible? Explain why or why not. (5 points) 3

6. (a) Organize the following fragment of three-address code into basic blocks and construct the CFG. (10 points) L0: i := 0 L1: i := i+1 if i>m goto L2 n := n<<1 if n<k goto L1 L2: k := k-1 if k<=0 goto L3 goto L0 L3: goto L4 L4: halt (b) Apply branch chaining optimization followed by dead-code elimination. After these optimizations, draw the modified CFG with its three-address code. (10 points) 4

7. Consider the following program: program P(input, output) var n : integer; procedure Q(k : integer) procedure S(i : integer)... (* body of S *) end; S(k) end procedure R(j : integer); var m : integer Q(n + m) end; R(n) end (a) Program P calls R, R in turn calls Q, and Q in turn calls S. Draw the resulting stack layout with activation records. Show the arguments and local variables in each record and draw the access links. (10 points) (b) Which variables are visible (in scope) in the body of S and how many access links must be traversed to reach the nonlocal data? (5 points) Var visible (Y/N) #links i j k n m 5

8. (Bonus question). (a) Give the data-flow equations for reaching definitions as described in the book and illustrated in class for the four example programming constructs (assignment, statement composition, if-then-else, and do-while). (8 points) (b) Consider the following program: d 1 : i := 0; do d 2 : i := i + 1; d 3 : n := n << 1 while i<m and n<k; if n<k then d 4 : i := i - 1 else d 5 : i := -1 Annotate the syntax tree of the above program with in, gen, kill, and out bit-vectors: ; 00000 d1 00000 10000 01011 ; do if ; i<m and n<k n<k d4 d5 d2 d3 Note: compute the gen and kill vectors bottom-up first, i.e. start at the leaves. For example, gen=01000 and kill=10011 of d 2, because d 2 kills all other definitions of variable i (i.e. d 1, d 4, and d 5 ). Then, go up by applying the equations for reaching definitions. When the gen and kill sets are determined, compute the in and out vectors in a top-down, left-to-right traversal. (in is inherited, while out is synthesized.) (7 points) 6