1 CS 201 Compiler Construction Lecture 1 Introduction.

Slides:



Advertisements
Similar presentations
Compiler Construction
Advertisements

Target Code Generation
Target code Generation Made by – Siddharth Rakesh 11CS30036 Date – 12/11/2013.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
ANALYSIS OF PROG. LANG. PROGRAM ANALYSIS Instructors: Crista Lopes Copyright © Instructors. 1.
Intermediate Code Generation
Course Outline Traditional Static Program Analysis Software Testing
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
1 CS 201 Compiler Construction Machine Code Generation.
Jeffrey D. Ullman Stanford University. 2  A never-published Stanford technical report by Fran Allen in  Fran won the Turing award in  Flow.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
Loop invariant code removal CS 480. Our sample calculation for i := 1 to n for j := 1 to m c [i, j] := 0 for k := 1 to p c[i, j] := c[i, j] + a[i, k]
Dominators and CFGs Taken largely from University of Delaware Compiler Notes \course\cpeg421-05s\Topic2.ppt.
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
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.
Intermediate Code CS 471 October 29, CS 471 – Fall Intermediate Code Generation Source code Lexical Analysis Syntactic Analysis Semantic.
1 Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
Intermediate Code. Local Optimizations
Improving Code Generation Honors Compilers April 16 th 2002.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
ECE355 Fall 2004Software Reliability1 ECE-355 Tutorial Jie Lian.
CS412/413 Introduction to Compilers Radu Rugina Lecture 15: Translating High IR to Low IR 22 Feb 02.
What is Three Address Code? A statement of the form x = y op z is a three address statement. x, y and z here are the three operands and op is any logical.
1 Code Generation Part II Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 1 Developed By:
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)
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.
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.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
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.
High-level optimization Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CSC D70: Compiler Optimization
Control Flow Analysis CS 4501 Baishakhi Ray.
Three-Address Implementation
Unit IV Code Generation
Chapter 6 Intermediate-Code Generation
CS 201 Compiler Construction
CS 201 Compiler Construction
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Code Optimization Overview and Examples Control Flow Graph
Interval Partitioning of a Flow Graph
Data Flow Analysis Compiler Design
8 Code Generation Topics A simple code generator algorithm
Intermediate Code Generation
Compiler Construction
Taken largely from University of Delaware Compiler Notes
Code Generation Part II
Compiler Construction
Target Code Generation
TARGET CODE GENERATION
Review: What is an activation record?
Intermediate Code Generating machine-independent intermediate form.
Bubble Sort begin; int A[10]; main(){ int i,j; Do 10 i = 0, 9, 1
CS 201 Compiler Construction
Presentation transcript:

1 CS 201 Compiler Construction Lecture 1 Introduction

2 Instructor Information Rajiv Gupta Office: Engg.II Room Tel: (951) Office Hours: T, Th 1-2 pm

3 Course Requirements Grading: Test 1: 35 points Test 2: 35 points Project: 30 points

4 Course Overview

Three Address Intermediate Code Arithmetic Operations dst = src1 op src2 where op in {+, -, *, /, %} Relational Operators dst = src1 relop src2 where relop in { =,>} Logical Operations dst = src lop src2, where lop in {||,&&} dst = ! src 5

Three Address Intermediate Code Array Accesses dst = src [ index ] dst [ index ] = src Pointers dst = & src * dst = src Copy Assignment dst = src 6

Three Address Intermediate Code Branches unconditional: goto label conditional: if predicate goto label or if src1 relop src2 goto label labels: declared or instruction numbers 7

Examples 8 See handouts.

9 Control Flow Graph (CFG) Intermediate Code can be transformed from linear representation to a directed graph form called Control flow Graph: Nodes – Basic Blocks: Basic block consists of a sequence of intermediate code statements that must be entered at the top and exited at the bottom, i.e. once the block is entered, all intermediate code statements will be executed. Edges: directed edges connect basic blocks according to control flow. CFG representation will be used for program analysis and optimization.

CFG Construction Algorithm Identify Leaders: the first instruction in a basic block is a leader. –First instruction in the program –Target instruction of a conditional or unconditional branch –Instruction immediately following a conditional or unconditional branch Construct Basic Blocks: –Starting from the leader append subsequent instructions up to, but not including, the next leader or the end of the program 10

CFG Construction Algorithm Add Edges: add a directed edge from basic block B1 to basic block B2 if: –There is a conditional or unconditional branch from the last statement in B1 to the leader of B2; or –B2 immediately follows B1 in program order and B1 does not end in an unconditional branch. 11

Example 12 1.A = 4 2.T1 = A * B 3.T2 = T1 / C 4.If T2<W goto 7 5.M = T1 * K 6.T3 = M + I 7.H = I 8.M = T3 – H 9.If T3>= 0 goto goto 3 11.Halt