1 CS 201 Compiler Construction Lecture 8 Code Optimizations: Partial Dead Code Elimination.

Slides:



Advertisements
Similar presentations
Example of Constructing the DAG (1)t 1 := 4 * iStep (1):create node 4 and i 0 Step (2):create node Step (3):attach identifier t 1 (2)t 2 := a[t 1 ]Step.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Overview Structural Testing Introduction – General Concepts
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
7. Optimization Prof. O. Nierstrasz Lecture notes by Marcus Denker.
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.
Data Flow Analysis. Goal: make assertions about the data usage in a program Use these assertions to determine if and when optimizations are legal Local:
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
1 Introduction to Data Flow Analysis. 2 Data Flow Analysis Construct representations for the structure of flow-of-data of programs based on the structure.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Partial Redundancy Elimination Guo, Yao.
1 Data flow analysis Goal : collect information about how a procedure manipulates its data This information is used in various optimizations For example,
1 CS 201 Compiler Construction Lecture 10 SSA-Based Sparse Conditional Constant Propagation.
1 CS 201 Compiler Construction Lecture 12 Global Register Allocation.
1 CS 201 Compiler Construction Lecture 5 Code Optimizations: Copy Propagation & Elimination.
1 Data flow analysis Goal : –collect information about how a procedure manipulates its data This information is used in various optimizations –For example,
CS 536 Spring Global Optimizations Lecture 23.
1 CS 201 Compiler Construction Lecture 13 Instruction Scheduling: Trace Scheduler.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
CS 201 Compiler Construction
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
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.
1 Copy Propagation What does it mean? – Given an assignment x = y, replace later uses of x with uses of y, provided there are no intervening assignments.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
1 CS 201 Compiler Construction Data Flow Analysis.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Computer Science & Engineering, Indian Institute of Technology, Bombay Code optimization by partial redundancy elimination using Eliminatability paths.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Final Code Generation and Code Optimization.
More on Loop Optimization Data Flow Analysis CS 480.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
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.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1 Software Testing & Quality Assurance Lecture 13 Created by: Paulo Alencar Modified by: Frank Xu.
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
CS 598 Scripting Languages Design and Implementation 9. Constant propagation and Type Inference.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
1 CS 201 Compiler Construction Code Optimizations: Partial Dead Code Elimination.
Code Optimization Overview and Examples
Lecture 5 Partial Redundancy Elimination
EQUATION IN TWO VARIABLES:
Programming Fundamentals Lecture #6 Program Control
1. Reaching Definitions Definition d of variable v: a statement d that assigns a value to v. Use of variable v: reference to value of v in an expression.
1) C program development 2) Selection structure
The University of Texas – Pan American
CS 201 Compiler Construction
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Topic 5a Partial Redundancy Elimination and SSA Form
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Optimizations using SSA
Final Code Generation and Code Optimization
SSA-based Optimizations
Python While Loops.
CS 201 Compiler Construction
Presentation transcript:

1 CS 201 Compiler Construction Lecture 8 Code Optimizations: Partial Dead Code Elimination

Dead Code Elimination Dead Code is code that is either never executed or, if it is executed, its result is never used by the program. Therefore dead code can be eliminated from the program. 2 dead code dead code

Dead Code: More Examples 3 Values used only by dead statements.

Partially Dead Code Value computed by partially dead statement is sometimes used and sometimes not used. 4

Code Motion Reqd. for Elimination 5

Sometimes Code Motion Requires Code Restructuring 6

Removal of Code From Loops 7 = x

Critical Edges 8 = X X =

Second Order Effects 9 a=c+d cannot be moved till x=a+b is moved

Algorithm Repeat Perform dead/faint variable analysis to identify sinking candidates Perform delayability analysis for sinking candidates Place statements in new positions Until Program Stabilizes 10

Definitions Dead Code: S: x = t is dead, if x is dead following S, i.e. every path from S to every right hand side occurrence of x following S is preceded by a redefinition of x. Faint Code: S: x = t is faint, if x is faint following S, i.e. every path from S to every right hand side occurrence of x following S is either preceded by a redefinition of x or is in a statement whose left hand side variable is faint. 11

Local Predicates USED S (x) – x is rhs variable of statement s RELV-USED S (x) – x is a rhs variable of relevant statement s; relevant statements are those that cannot be eliminated – conditionals like if x<y and output statements like write x. ASSIGN-USED S (x) – x is a rhs variable of assignment statement s. MOD S (x) – x is lhs variable of statement s. 12

Dead Variable Analysis Bit vector analysis for all variables. 13

Faint Variable Analysis Not bit vector analysis. 14

Analysis of Equation 15 N-FAINT S (x) is false if any of the following conditions is true: 1.the statement s uses x and s cannot ever be marked faint, i.e. 2. the statement s does not modify x and x is not faint on exit, i.e. 3. x is used by statement s and lhs of s is not faint, i.e.

Elimination Following dead/faint variable analysis we can eliminate dead/faint code  Eliminate n: x=.. assignment x =.. If x is dead/faint at exit of n. The above elimination rule eliminates fully dead/faint code. To eliminate partially dead code, we develop delayability analysis  using this analysis partially dead statement is moved to program points where it is fully dead or fully live. Iterative application of dead/faint code elimination and delaying partially dead assignments leads to optimization. 16

Example 17

Delayability Analysis 18 LOCDELAYED n (α): αis a sinking candidate that ε n. LOCBLOCKED n (α): sinking of αis blocked by code in n. N-DELAYED n /X-DELAYED n indicate whether α can be delayed to the entry/exit point of n.

Contd.. 19 Placing αat its new positions. If N-INSERT n (α)/X-INSERT n (α) is true then place α at n’s entry/exit point. Essentially we are movingα to the latest points to which it can be delayed.