Lecture 2 Introduction to Data Flow Analysis

Similar documents
CSE 504: Compiler Design. Data Flow Analysis

Introduction to Data-flow analysis

Optimizations. Optimization Safety. Optimization Safety. Control Flow Graphs. Code transformations to improve program

Why have SSA? Birth Points (cont) Birth Points (a notion due to Tarjan)

Static Analysis. Find the Bug! : Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

Review; questions Discussion of Semester Project Arbitrary interprocedural control flow Assign (see Schedule for links)

2) Write in detail the issues in the design of code generator.

CIS570 Lecture 4 Introduction to Data-flow Analysis 3

Semantics and Verification of Software

A Survey of Static Program Analysis Techniques

Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007

GameTime: A Toolkit for Timing Analysis of Software

Automata-based Verification - I

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

Internet Firewall CSIS Packet Filtering. Internet Firewall. Examples. Spring 2011 CSIS net15 1. Routers can implement packet filtering

Address Taken FIAlias, which is equivalent to Steensgaard. CS553 Lecture Alias Analysis II 2

Design of LDPC codes

Project Scheduling by Critical Path Method (CPM)

Measuring the Performance of an Agent

Route Discovery Protocols

Reinforcement Learning

Reputation Management Algorithms & Testing. Andrew G. West November 3, 2008

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

INTERNATIONAL JOURNAL OF COMPUTER ENGINEERING & TECHNOLOGY (IJCET)

Software Pipelining - Modulo Scheduling

Scheduling Home Health Care with Separating Benders Cuts in Decision Diagrams

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

A Formal Model of Program Dependences and Its Implications for Software Testing, Debugging, and Maintenance

Linear Programming I

How To Trace

Module 6 Case Studies

CIS570 Modern Programming Language Implementation. Office hours: TDB 605 Levine

Linear Programming. Widget Factory Example. Linear Programming: Standard Form. Widget Factory Example: Continued.

Static Analysis of Virtualization- Obfuscated Binaries

Test Case Design Techniques

Notes V General Equilibrium: Positive Theory. 1 Walrasian Equilibrium and Excess Demand

LOGICAL TOPOLOGY DESIGN Practical tools to configure networks

Static Program Transformations for Efficient Software Model Checking

The Boundary Scan Test (BST) technology

Reinforcement Learning

The Analysis Method about Change Domain of Business Process Model Based on the Behavior Profile of Petri Net

Throughput constraint for Synchronous Data Flow Graphs

Software Testing. Jeffrey Carver University of Alabama. April 7, 2016


Module1. x y 800.

6.852: Distributed Algorithms Fall, Class 2

Lecture Notes on Static Analysis

Real Time Scheduling Basic Concepts. Radek Pelánek

Scientic Computing 2013 Computer Classes: Worksheet 11: 1D FEM and boundary conditions

Write Barrier Removal by Static Analysis

Algebraic Computation Models. Algebraic Computation Models

Algorithms are the threads that tie together most of the subfields of computer science.

Dynamic programming formulation

Integrated System Modeling for Handling Big Data in Electric Utility Systems

General Flow-Sensitive Pointer Analysis and Call Graph Construction

Lecture 8: Routing I Distance-vector Algorithms. CSE 123: Computer Networks Stefan Savage

Simulation-Based Security with Inexhaustible Interactive Turing Machines

Clustering through Decision Tree Construction in Geology

CIS 700: algorithms for Big Data

CS 688 Pattern Recognition Lecture 4. Linear Models for Classification

Instruction scheduling

Model Checking: An Introduction

Numerical Analysis An Introduction

EECS 583 Class 11 Instruction Scheduling Software Pipelining Intro

Introduction to LAN/WAN. Network Layer

Scheduling a sequence of tasks with general completion costs

Software Engineering. How does software fail? Terminology CS / COE 1530

5.1 Bipartite Matching

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

Part 1: Link Analysis & Page Rank

Satisfiability Checking

Lecture 6: Logistic Regression

Largest Fixed-Aspect, Axis-Aligned Rectangle

CS Computer Networks 1: Routing Algorithms

Dimitris Chatzidimitriou. Corelab NTUA. June 28, 2013

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Software Modeling and Verification

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Automated Model Based Testing for an Web Applications

SYSM 6304: Risk and Decision Analysis Lecture 5: Methods of Risk Analysis

Dataflow approach to testing Java programs supported with DFC

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Transcription:

Lecture 2 Introduction to Data Flow Analysis I. Introduction II. Example: Reaching definition analysis III. Example: Liveness analysis IV. A General Framework (Theory in next lecture) Reading: Chapter 9.2 CS243: Intro to Data Flow 1

I. Compiler Organization CS243: Intro to Data Flow 2

Flow Graph Basic block = a maximal sequence of consecutive instructions s.t. flow of control only enters at the beginning flow of control can only leave at the end (no halting or branching except perhaps at end of block) Flow Graphs Nodes: basic blocks Edges B i --> B j, iff B j can follow B i immediately in execution CS243: Intro to Data Flow 3

What is Data Flow Analysis? Data flow analysis: Flow-sensitive: sensitive to the control flow in a function intraprocedural analysis Examples of optimizations: Constant propagation Common subexpression elimination Dead code elimination a = b + c d = 7 e = b + c a = 243 e = d+3 g = a Value of x? Which definition defines x? Is the definition still meaningful (live)? CS243: Intro to Data Flow 4

Static Program vs. Dynamic Execution Statically: Finite program Dynamically: Can have infinitely many possible execution paths Data flow analysis abstraction: For each point in the program: combines information of all the instances of the same program point. Example of a data flow question: Which definition defines the value used in statement b = a? CS243: Intro to Data Flow 5

Reaching Definitions B0 d0: y = 3 d1: x = 10 d2: y = 11 if e B1 d3: x = 1 d4: y = 2 d5: z = x d6: x = 4 B2 Every assignment is a definition A definition d reaches a point p if there exists path from the point immediately following d to p such that d is not killed (overwritten) along that path. Problem statement For each point in the program, determine if each definition in the program reaches the point A bit vector per program point, vector-length = #defs CS243: Intro to Data Flow 6

Data Flow Analysis Schema Build a flow graph (nodes = basic blocks, edges = control flow) Set up a set of equations between in[b] and out[b] for all basic blocks b Effect of code in basic block: Transfer function f b relates in[b] and out[b], for same b Effect of flow of control: relates out[b 1 ], in[b 2 ] if b 1 and b 2 are adjacent Find a solution to the equations CS243: Intro to Data Flow 7

Effects of a Statement in[b0] d0: y = 3 f d0 d1: x = 10 f d1 out[b0] d2: y = 11 f d2 f s : A transfer function of a statement abstracts the execution with respect to the problem of interest For a statement s (d: x = y + z) out[s] = f s (in[s]) = Gen[s] U (in[s]-kill[s]) Gen[s]: definitions generated: Gen[s] = {d} Propagated definitions: in[s] - Kill[s], where Kill[s]=set of all other defs to x in the rest of program CS243: Intro to Data Flow 8

Effects of a Basic Block in[b0] d0: y = 3 f d0 out[b0] d1: x = 10 f d1 f B = f d1 f d0 Transfer function of a statement s: out[s] = f s (in[s]) = Gen[s] U (in[s]-kill[s]) Transfer function of a basic block B: Composition of transfer functions of statements in B out[b] = f B (in[b]) = f d1 f d0 (in[b]) = Gen[d 1 ] U (Gen[d 0 ] U (in[b]-kill[d 0 ]))-Kill[d 1 ]) = (Gen[d 1 ] U (Gen[d 0 ] - Kill[d 1 ])) U in[b] - (Kill[d 0 ] U Kill[d 1 ]) = Gen[B] U (in[b] - Kill[B]) Gen[B]: locally exposed definitions (available at end of bb) Kill[B]: set of definitions killed by B CS243: Intro to Data Flow 9

Effects of the Edges (acyclic) Join node: a node with multiple predecessors meet operator ( ): U in[b] = out[p 1 ] U out[p 2 ] U... U out[p n ], where p 1,..., p n are all predecessors of b CS243: Intro to Data Flow 10

Cyclic Graphs Equations still hold out[b] = f b (in[b]) in[b] = out[p 1 ] U out[p 2 ] U... U out[p n ], p 1,..., p n pred. Find: fixed point solution CS243: Intro to Data Flow 11

Reaching Definitions: Iterative Algorithm input: control flow graph CFG = (N, E, Entry, Exit) // Boundary condition out[entry] = // Initialization for iterative algorithm For each basic block B other than Entry out[b] = // iterate While (Changes to any out[] occur) { For each basic block B other than Entry { in[b] = (out[p]), for all predecessors p of B out[b] = f B (in[b]) // out[b]=gen[b] (in[b]-kill[b]) } CS243: Intro to Data Flow 12

Summary of Reaching Definitions Reaching Definitions Domain Transfer function f b (x) Meet Operation Boundary Condition Initial interior points Sets of definitions forward: out[b] = f b (in[b]) f b (x) = Gen b (x -Kill b ) Gen b : definitions in b Kill b : killed defs in[b]= out[predecessors] out[entry] = out[b] = CS243: Intro to Data Flow 13

III. Live Variable Analysis Definition A variable v is live at point p if the value of v is used along some path in the flow graph starting at p. Otherwise, the variable is dead. Problem statement For each basic block determine if each variable is live in each basic block Size of bit vector: one bit for each variable CS243: Intro to Data Flow 14

Effects of a Basic Block (Transfer Function) Observation: Trace uses back to the definitions Direction: backward: in[b] = f b (out[b]) Transfer function for statement s: x = y + z generate live variables: Use[s] = {y, z} propagate live variables: out[s] - Def[s], Def[s] = x in[s] = Use[s] (out(s)-def[s]) Transfer function for basic block b: in[b] = Use[b] (out(b)-def[b]) Use[b], set of locally exposed uses in b, uses not covered by definitions in b Def[b]= set of variables defined in b. CS243: Intro to Data Flow 15

Across Basic Blocks Meet operator ( ): out[b] = in[s 1 ] in[s 2 ]... in[s n ], s 1,..., s n are successors of b Boundary condition: CS243: Intro to Data Flow 16

Example CS243: Intro to Data Flow 17

Liveness: Iterative Algorithm input: control flow graph CFG = (N, E, Entry, Exit) // Boundary condition in[exit] = // Initialization for iterative algorithm For each basic block B other than Exit in[b] = // iterate While (Changes to any in[] occur) { For each basic block B other than Exit { out[b] = (in[s]), for all successors s of B in[b] = f B (out[b]) // in[b]=use[b] (out[b]-def[b]) } CS243: Intro to Data Flow 18

IV. Framework Reaching Definitions Live Variables Domain Sets of definitions Sets of variables Direction forward: out[b] = f b (in[b]) in[b] = out[pred(b)] backward: in[b] = f b (out[b]) out[b] = in[succ(b)] Transfer function f b (x) = Gen b (x Kill b ) f b (x) = Use b (x -Def b ) Meet Operation ( ) Boundary Condition out[entry] = in[exit] = Initial interior points out[b] = in[b] = CS243: Intro to Data Flow 19

Thought Problem 1. Must-Reach Definitions A definition D (a = b+c) must reach point P iff D appears at least once along on all paths leading to P a is not redefined along any path after last appearance of D and before P How do we formulate the data flow algorithm for this problem? CS243: Intro to Data Flow 20

Problem 2: A legal solution to (May) Reaching Def? Will the worklist algorithm generate this answer? CS243: Intro to Data Flow 21

Problem 3. What are the algorithm properties? Correctness Precision: how good is the answer? Convergence: will the analysis terminate? Speed: how long does it take? CS243: Intro to Data Flow 22