We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions.

Similar documents
We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions.

Register allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices

Compiler Design. Fall Data-Flow Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

MIT Introduction to Dataflow Analysis. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

Data Flow Analysis. CSCE Lecture 9-02/15/2018

Data Flow Information. already computed

Dataflow analysis (ctd.)

Data Flow Analysis. Suman Jana. Adopted From U Penn CIS 570: Modern Programming Language Implementa=on (Autumn 2006)

Foundations of Dataflow Analysis

Dependence and Data Flow Models. (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1

Register allocation. CS Compiler Design. Liveness analysis. Register allocation. Liveness analysis and Register allocation. V.

Lecture 21 CIS 341: COMPILERS

Dependence and Data Flow Models. (c) 2007 Mauro Pezzè & Michal Young Ch 6, slide 1

CS577 Modern Language Processors. Spring 2018 Lecture Optimization

Data Flow Analysis. Program Analysis

CS553 Lecture Generalizing Data-flow Analysis 3

CS202 Compiler Construction

Compilation 2013 Liveness Analysis

Program Optimizations using Data-Flow Analysis

Lecture 6 Foundations of Data Flow Analysis

Compiler Optimisation

COSE312: Compilers. Lecture 20 Data-Flow Analysis (2)

Lecture 6 Foundations of Data Flow Analysis

CS202 Compiler Construction

Data-flow Analysis. Y.N. Srikant. Department of Computer Science and Automation Indian Institute of Science Bangalore

Why Data Flow Models? Dependence and Data Flow Models. Learning objectives. Def-Use Pairs (1) Models from Chapter 5 emphasized control

Data-flow Analysis - Part 2

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

20b -Advanced-DFA. J. L. Peterson, "Petri Nets," Computing Surveys, 9 (3), September 1977, pp

Page # 20b -Advanced-DFA. Reading assignment. State Propagation. GEN and KILL sets. Data Flow Analysis

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Lecture 4 Introduction to Data Flow Analysis

Why Global Dataflow Analysis?

Data Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions

CSCE 548 Building Secure Software Data Flow Analysis

Compiler Structure. Data Flow Analysis. Control-Flow Graph. Available Expressions. Data Flow Facts

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

Programming Language Processor Theory

A main goal is to achieve a better performance. Code Optimization. Chapter 9

An example of optimization in LLVM. Compiler construction Step 1: Naive translation to LLVM. Step 2: Translating to SSA form (opt -mem2reg)

Plan for Today. Concepts. Next Time. Some slides are from Calvin Lin s grad compiler slides. CS553 Lecture 2 Optimizations and LLVM 1

CIS 341 Final Examination 4 May 2017

Compiler Optimisation

Dependence and Data Flow Models

Review; questions Basic Analyses (2) Assign (see Schedule for links)

Lecture 2. Introduction to Data Flow Analysis

Example of Global Data-Flow Analysis

Introduction. Data-flow Analysis by Iteration. CSc 553. Principles of Compilation. 28 : Optimization III

More Dataflow Analysis

Liveness Analysis and Register Allocation

Compiler Optimization and Code Generation

Data Flow Analysis and Computation of SSA

Static Detection of Access Anomalies in Ada95

compile-time reasoning about the run-time ow represent facts about run-time behavior represent eect of executing each basic block

Program Static Analysis. Overview

Department of Computer Sciences CS502. Purdue University is an Equal Opportunity/Equal Access institution.

Middle End. Code Improvement (or Optimization) Analyzes IR and rewrites (or transforms) IR Primary goal is to reduce running time of the compiled code

Lecture Notes: Dataflow Analysis Examples

4/24/18. Overview. Program Static Analysis. Has anyone done static analysis? What is static analysis? Why static analysis?

Register allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices

Calvin Lin The University of Texas at Austin

Compiler Construction 2009/2010 SSA Static Single Assignment Form

ELEC 876: Software Reengineering

When we eliminated global CSE's we introduced copy statements of the form A:=B. There are many

(The complement of this set is a conservative approximation of the set of pairs that may occur in parallel.) In that work, it is assumed initially tha

This test is not formatted for your answers. Submit your answers via to:

Flow Analysis. Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM

Liveness Analysis and Register Allocation. Xiao Jia May 3 rd, 2013

Calvin Lin The University of Texas at Austin

Compiler construction in4303 answers

Introduction to Machine-Independent Optimizations - 4

An Approach to Regression Testing using Slicing

About These Slides. GDFA: Generic Data Flow Analyser for GCC. Part 1. Copyright. Outline. Uday Khedker

CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis

Chapter 10. Improving the Runtime Type Checker Type-Flow Analysis

Register allocation. instruction selection. machine code. register allocation. errors

Topic I (d): Static Single Assignment Form (SSA)

Compiler Construction 2010/2011 Loop Optimizations

Lecture 23 CIS 341: COMPILERS

CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion

Loops. Lather, Rinse, Repeat. CS4410: Spring 2013

What If. Static Single Assignment Form. Phi Functions. What does φ(v i,v j ) Mean?

CMSC430 Spring 2009 Midterm 2 (Solutions)

Flow Propagation Algorithm

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

We saw in the introduction how values used in one block ofaæow graph could be used in other blocks. offset := 4*j; value := baseëoffsetë

Homework Assignment #1 Sample Solutions

CIS 341 Final Examination 3 May 2011

Data Flow Analysis. Daqing Hou

Program analysis for determining opportunities for optimization: 2. analysis: dataow Organization 1. What kind of optimizations are useful? lattice al

Data-Flow Analysis Foundations

Example. Example. Constant Propagation in SSA

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University

EECS 583 Class 6 More Dataflow Analysis

CIS 341 Final Examination 30 April 2013

Recap. Juan Pablo Galeotti,Alessandra Gorla, Software Engineering Chair Computer Science Saarland University, Germany

Lecture 6. Register Allocation. I. Introduction. II. Abstraction and the Problem III. Algorithm

Name: CIS 341 Final Examination 10 December 2008

Geometry Pre AP Graphing Linear Equations

Transcription:

Available expressions Suppose we want to do common-subexpression elimination; that is, given a program that computes x y more than once, can we eliminate one of the duplicate computations? To find places where such optimizations are possible, the notion of available expressions is helpful. An expression x y is available at a node n in the flow graph if, on every path from the entry node of the graph to node n, x y is computed at least once and there are no definitions of x or y since the most recent occurrence of x y on that path. We can express this in dataflow equations using gen and kill sets, where the sets are now sets of expressions. Gen : Any node that computes x y generates {x y}. Kill : any definition of x or y kills {x y}. Table 8 summarizes the generate and kill effects. 1. t b + c generates the expression b + c, but b b + c does not generate b + c After b + c there is a subsequent definition of b. gen[s] = {b c} kill[s] 2. A store instruction (M[a] b) might modify any memory location, so it kills any fetch expression (M[x]). If we were sure that a x, we could be less conservative, and say that M[a] b does not kill M[x]. This is called alias analysis; Given gen and kill, we compute in and out almost as for reaching definitions, except that we compute the intersection of the out sets of the predecessors instead of a union. This reflects the fact that an expression is available only if it is computed on every path into the node. 14

Statement s gen[s] kill[s] t b c {b c} kill[s] expressions containing t t M[b] {M[b]} kill[s] expressions containing t M[a] b {} expressions of the form M[x] if a > b goto L 1 else goto L 2 {} {} goto L {} {} L : {} {} f(a 1,..., a n ) {} expressions of the form M[x] t f(a 1,..., a n ) {} expressions containing t, and expressions of the form M[x] Figure 8: Table: Gen and kill for available expressions. in[n] = out[p] p pred[n] out[n] = gen[n] (in[n] kill[n]) if n is not the start node To solve the dataflow equations by iteration, 1. we define the in set of the start node as empty, and 2. initialize all other sets to full (the set of all expressions), not empty. The intersection operator makes sets smaller, not bigger as the union operator does in the computation of reaching definitions. This algorithm then finds the greatest fixed point of the equations. in[ start node ] { } other than the start node in[n] { all expressions }; out[n] { all expressions } repeat in [n] in[n]; out [n] out[n] in[n] p pred[n] out[p] out[n] gen[n] (in[n] kill[n]) until in [n] = in[n] and out [n] = out[n] for all n 15

1 : x a + b 2 : if c > d goto L 1 3 : a p 4 : y a + b 5 : goto L 2 6 : L 1 : if e < f goto L 1 7 : L 2 : z a + b 1 : t a + b 1 : x t 2 : if c > d goto L 1 3 : a p 4 : t a + b 4 : y t 5 : goto L 2 6 : L 1 : if e < f goto L 1 7 : L 2 : z t Figure 9: Program We will take Program 9 as an example; Init Iter. 1 Iter. 2 n gen[n] kill[n] in[n] out[n] in[n] out[n] in[n] out[n] 1 a+b a+b a+b a+b 2 a+b a+b a+b a+b a+b a+b 3 a+b a+b a+b a+b a+b 4 a+b a+b a+b a+b a+b 5 a+b a+b a+b a+b a+b a+b 6 a+b a+b a+b a+b a+b a+b 7 a+b a+b a+b a+b a+b a+b a+b As a result, we can eliminate a + b at statement 7 by replacing it with temporary t introduced for statements 1 and 4. 16

Statement s gen[s] kill[s] t b c {b, c} {t} t M[b] {b} {t} M[a] b {b} {} if a > b goto L 1 else goto L 2 {a, b} {} goto L {} {} L : {} {} f(a 1,..., a n ) {a 1,..., a n } {} t f(a 1,..., a n ) {a 1,..., a n } {t} Liveness analysis Figure 10: Table: Gen and kill for liveness analysis. Two temporaries a and b can fit into the same register, if a and b are never in use at the same time. We say a variable is live if it holds a value that may be needed in the future. this analysis is called liveness analysis. Defs and uses of variable x Defs : assignments to variable/temporary x. Uses : assignments with occurrences of variable x on the right-hand sides of the assignments. A variable is live on an edge if there is a directed path from that edge to a use of the variable that does not go through any def. Gen and kill are defined as shown by Figure 10. Gen : any use of a variable generates liveness. Kill : any definition kills liveness. The equations for in and out are similar to the ones for reaching definition, but backward because liveness is a backward dataflow analysis: in[n] = gen[n] (out[n] kill[n]) out[n] = in[s] s succ[n] 17

To solve the dataflow equations by iteration, in[n] { }; out[n] { } repeat in [n] in[n]; out [n] out[n] out[n] s succ[n] in[s] in[n] gen[n] (out[n] kill[n]) until in [n] = in[n] and out [n] = out[n] for all n We will take Program 7 as an example. Iter. 1 Iter. 2 Iter. 3 n gen[n] kill[n] in[n] out[n] in[n] out[n] in[n] out[n] 1 a a a a 2 c a c,a a c,a a c,a 3 c,a c,a c,a c,a c,a c,a c,a 4 c c c c,a c,a c,a c,a 5 c,a c,a c,a c,a 6 c,a a c,a c,a c,a 7 c As a result, we can remove statements 6 and 7, because their results are never used. 18