CS 201 Compiler Construction

Slides:



Advertisements
Similar presentations
Compiler Construction
Advertisements

Target Code Generation
Target code Generation Made by – Siddharth Rakesh 11CS30036 Date – 12/11/2013.
1 Optimization Optimization = transformation that improves the performance of the target code Optimization must not change the output must not cause errors.
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.
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
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Code Generation Professor Yihjia Tsai Tamkang University.
1 CS 201 Compiler Construction Lecture 1 Introduction.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
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.
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.
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,
CSc 453 Final Code Generation Saumya Debray The University of Arizona Tucson.
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.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
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.
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.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
Chapter 8 Code Generation
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
High-level optimization Jakub Yaghob
Optimizing Compilers Background
CSC D70: Compiler Optimization
Topic 10: Dataflow Analysis
Control Flow Analysis CS 4501 Baishakhi Ray.
Three-Address Implementation
Unit IV Code Generation
Chapter 6 Intermediate-Code Generation
CS 201 Compiler Construction
TARGET CODE GENERATION
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
Static Single Assignment
8 Code Generation Topics A simple code generator algorithm
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Intermediate Code Generation
Compiler Construction
Taken largely from University of Delaware Compiler Notes
Code Generation Part II
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
Code Optimization.
CS 201 Compiler Construction
Presentation transcript:

CS 201 Compiler Construction Introduction

Instructor Information Rajiv Gupta Office: WCH Room 408 E-mail: gupta@cs.ucr.edu Tel: (951) 827-2558 Office Hours: F, 2:00 pm - 4:00 pm Project Grader: Arash Alavi Email: aalav003@ucr.edu Office Hours: M & W, 3:00 pm - 4:00 pm

Course Requirements Grading: Test 1: 30 points Test 2: 40 points Project: 30 points

Course Overview CS 152 CS 201

Exam I Control Flow Graph Representation - Control Flow Analysis - Data Flow Analysis - Selected Code Optimizations Static Single Assignment Representation - Control Flow Analysis - Selected Code Optimizations

Exam II Bidirectional Data Flow Analysis - Partial Redundancy Elimination - Partial Dead-code Elimination Interprocedural Data Flow Analysis Machine Code Generation - Register Allocation - Instruction Scheduling

Project Soot/LLVM infrastructure Code instrumentation Execution Profiling

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

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

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

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

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.

Example A = 4 T1 = A * B T2 = T1 / C If T2<W goto 7 M = T1 * K T3 = M + I H = I M = T3 – H If T3>= 0 goto 11 goto 3 Halt