Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 201 Compiler Construction

Similar presentations


Presentation on theme: "CS 201 Compiler Construction"— Presentation transcript:

1 CS 201 Compiler Construction
Introduction

2 Instructor Information
Rajiv Gupta Office: WCH Room 408 Tel: (951) Office Hours: F, 2:00 pm - 4:00 pm Project Grader: Arash Alavi Office Hours: M & W, 3:00 pm - 4:00 pm

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

4 Course Overview CS 152 CS 201

5 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

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

7 Project Soot/LLVM infrastructure Code instrumentation
Execution Profiling

8 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

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

10 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

11 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.

12 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

13 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.

14 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


Download ppt "CS 201 Compiler Construction"

Similar presentations


Ads by Google