CS 3220: Compilation Techniques for Parallel Systems Spring 2016 2016-2-11Pitt CS 32201.

Slides:



Advertisements
Similar presentations
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Course Outline Traditional Static Program Analysis Software Testing
Lecture 11: Code Optimization CS 540 George Mason University.
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 Lecture 3 Data Flow Analysis.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
SSA.
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-
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
Lecture 11 – Code Generation Eran Yahav 1 Reference: Dragon 8. MCD
Cpeg421-08S/final-review1 Course Review Tom St. John.
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.
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
1 CS 201 Compiler Construction Lecture 1 Introduction.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Register Allocation (via graph coloring)
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
Register Allocation (via graph coloring). Lecture Outline Memory Hierarchy Management Register Allocation –Register interference graph –Graph coloring.
Overview of program analysis Mooly Sagiv html://
Intermediate Code. Local Optimizations
1 Liveness analysis and Register Allocation Cheng-Chia Chen.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
4/29/09Prof. Hilfinger CS164 Lecture 381 Register Allocation Lecture 28 (from notes by G. Necula and R. Bodik)
1 CS 201 Compiler Construction Data Flow Analysis.
Data Flow Analysis Compiler Baojian Hua
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Optimization software for apeNEXT Max Lukyanov,  apeNEXT : a VLIW architecture  Optimization basics  Software optimizer for apeNEXT  Current.
RIT 08/11/47Chapter 11 Chapter 1: Introduction to Compiling Dr. Winai Wichaipanitch Rajamangala Institute of Technology Klong 6 Thanyaburi Pathumthani.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Register Allocation John Cavazos University.
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.
Data-Flow Analysis (Chapter 8). Outline What is Data-Flow Analysis? Structure of an optimizing compiler An example: Reaching Definitions Basic Concepts:
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
Intermediate Code Representations
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
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 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Machine-Independent Optimizations Ⅳ CS308 Compiler Theory1.
1 Liveness analysis and Register Allocation Cheng-Chia Chen.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Loops Simone Campanoni
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Data Flow Analysis Suman Jana
Mooly Sagiv html://
Static Single Assignment
Princeton University Spring 2016
Topic 10: Dataflow Analysis
University Of Virginia
Control Flow Analysis CS 4501 Baishakhi Ray.
Code Optimization Chapter 10
CS 201 Compiler Construction
Control Flow Analysis (Chapter 7)
Data Flow Analysis Compiler Design
Static Single Assignment
Compiler Construction
CS 201 Compiler Construction
Presentation transcript:

CS 3220: Compilation Techniques for Parallel Systems Spring Pitt CS 32201

2/11/2016 Pitt CS Phases of A Modern Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Code Optimizer Code Generation Source Program IF (a<b) THEN c=1*d; Token Sequence Syntax Tree 3-Address Code Optimized 3-Addr. Code Assembly Code IF( ID “a” < ID “b” THEN ID “c” = CONST “1” * ID “d” IF_stmt < a b cond_expr list assign_stmt c * lhs rhs 1 d GE a, b, L1 MUlT 1, d, c L1: GE a, b, L1 MOV d, c L1: loadi R1,a cmpi R1,b jge L1 loadi R1,d storei R1,c L1:

2/11/2016 Pitt CS Three-pass Compilation Front End Middle End Back End Source program IR machine code CS 2210CS 3220

Organization of CS 3220  Advanced compilation techniques  Dataflow analysis framework  Selected compilation techniques Pointer analysis, software pipelining, SSA, and more  Parallel architectures  Traditional parallel systems Multiprocessor, vector machine, VLIW  Chip-multiprocessor systems Challenges and opportunities  Student presentations Pitt CS

2/11/2016 Pitt CS Control Flow Graph (CFG) 1.A=4 2.T1=A*B 3.L1: T2 = T1/C 4.If T2<W goto L2 5.M=T1*K 6.T3=M+1 7.L2: H=I 8.M=T3-H 9.If T3>0 goto L3 10.GOTO L1 11.L3: halt 1. A=4 2. T1=A*B B1 3. L1: T2=T1/C 4. If T2<W goto L2 B2 5. M=T1*K 6. T3=M+1 B3 7. L2: H=I 8. M=T3-H 9. If T3>0 goto L3 B4 10. Goto L1 B5 11. L3: halt B6

2/11/2016 Pitt CS Dominators and Postdominators  Definition  Node a dominates b if and only if every possible execution path from the entry of the code to b include a. For example, B1 dominates B2, B3, …  Node a postdominates b if and only if every possible execution path from b to exit include a. For example, B4 postdominates B2

2/11/2016 Pitt CS Finding a Loop  Back edge  A back edge is an edge a  b and head b dominates its tail a That is, The edge B5  B2 in the previous example  Natural loops  A natural loop has Header: a single-entry node that dominates all nodes in the loop; Back edge: a back edge that enter from the header.

2/11/2016 Pitt CS Global Dataflow Analysis  Dataflow analysis framework  A standard technique for solving global analysis problems  A formal approach  Definition: a DFA consists of the following components  L: A set of partially ordered elements, the set can be infinite  Two special elements: top ┬ and bottom ┴  Two operators: meet  join   Dataflow functions: F: L  L

2/11/2016 Pitt CS Forward and Backward Analysis Forward Analysis Backward Analysis X_in X_out X_in X_out

2/11/2016 Pitt CS Example: Liveness Analysis  Once constants have been globally propagated, we would like to eliminate dead code After constant propagation, if x is not used elsewhere, “x:=3” is dead and can be removed X:=3 If B>0 Y:= Z+WY:= 0 A:= 2 * 3

2/11/2016 Pitt CS Global analysis – liveness x:= … (no other definition of x)x is live anywhere here … := x Two names interfere when their values cannot reside in the same register x:= … y:= … x interfere with y … := x-- they are both live simultaneously … := y

2/11/2016 Pitt CS Dataflow Equations for Liveness Analysis  X(i): dataflow property of basic block i  X_in(i): at the entry of basic block i  X_out(i): at the exit of basic block i  Liveness: LV_in(i) = ( LV_out(i) – DEF(i) )  USE(i) LV_out(i) =  LV_in(k) if k is successor basic block of i

2/11/2016 Pitt CS Using Liveness Information Register allocation a:= b+c d:= -a e:= d+f f:= 2*e b:= d+e e:= e -1 b:= f+c {b} { b,c,e,f } { c,d,e,f } { c,f } { c,e } { a,c,f } { c,d,e,f } { b,c,f } { c,d,f } { c,f } { b,c,f }

2/11/2016 Pitt CS Register Interference Graph (RIG)  For our example a f b e c d b, c can NOT be in the same register a, b, d can be in the same register

2/11/2016 Pitt CS Register Allocation Result  For our example a f b e c d There is no coloring with less than 4 colors There are 4 colorings of this graph R2 R1 R3 R4 R2

2/11/2016 Pitt CS After Register Allocation  Use this coloring the code becomes: r2:= r3+r4 r3:= -r2 r2:= r3+r1 r1:= 2*r2 r3:= r3+r2 r2:= r2 -1 r3:= r1+r4