Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.

Slides:



Advertisements
Similar presentations
Register Allocation Consists of two parts: Goal : minimize spills
Advertisements

How SAS implements structured programming constructs
Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
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.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
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.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
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.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Dataflow Analysis Introduction Guo, Yao Part of the slides are adapted from.
1 Data flow analysis Goal : collect information about how a procedure manipulates its data This information is used in various optimizations For example,
Foundations of Data-Flow Analysis. Basic Questions Under what circumstances is the iterative algorithm used in the data-flow analysis correct? How precise.
6/9/2015© Hal Perkins & UW CSEU-1 CSE P 501 – Compilers SSA Hal Perkins Winter 2008.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Program analysis Mooly Sagiv html://
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.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Data Flow Analysis Compiler Design Nov. 3, 2005.
From last time: reaching definitions For each use of a variable, determine what assignments could have set the value being read from the variable Information.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Program analysis Mooly Sagiv html://
Another example p := &x; *p := 5 y := x + 1;. Another example p := &x; *p := 5 y := x + 1; x := 5; *p := 3 y := x + 1; ???
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
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.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
Overview of program analysis Mooly Sagiv html://
Projects. Dataflow analysis Dataflow analysis: what is it? A common framework for expressing algorithms that compute information about a program Why.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Data flow analysis Emery Berger University.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
From last time: reaching definitions For each use of a variable, determine what assignments could have set the value being read from the variable Information.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis: Data-flow frameworks –Classic.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Constant Propagation. The constant propagation framework is different from all the data-flow problems discussed so far, in that It has an unbounded set.
1 CS 201 Compiler Construction Data Flow Analysis.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Static Program Analyses of DSP Software Systems Ramakrishnan Venkitaraman and Gopal Gupta.
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
Definition of Terms Software/Programs Programs that directs the operation of a computer system Set of instructions Codes Programming Process of planning,
1 Data Flow Analysis Data flow analysis is used to collect information about the flow of data values across basic blocks. Dominator analysis collected.
Compiler Principles Fall Compiler Principles Lecture 11: Loop Optimizations Roman Manevich Ben-Gurion University.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
CS 598 Scripting Languages Design and Implementation 9. Constant propagation and Type Inference.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
Optimization Simone Campanoni
DFA foundations Simone Campanoni
Data Flow Analysis Suman Jana
Dataflow analysis.
Structural testing, Path Testing
Dataflow Testing G. Rothermel.
Fall Compiler Principles Lecture 8: Loop Optimizations
Topic 10: Dataflow Analysis
Global optimizations.
University Of Virginia
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.
Dataflow analysis.
Optimizations using SSA
Fall Compiler Principles Lecture 10: Loop Optimizations
Data Flow Analysis Compiler Design
COMPILERS Liveness Analysis
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a set of assertions to each node/edge Approximation – Useful data-flow properties are never 100% accurate Rice’s Theorem, from 1953 – Lower approximation is called a MUST analysis Set of solutions found is smaller than the set of actual solutions – Upper approximation is called a MAY analysis Set of solutions found may be larger than the set of actual solutions

Data-Flow Analysis Framework Direction – Forwards: For each node/edge, computes information about past behavior – Backwards: For each node/edge, computes information about future behavior Transfer Functions – JOIN: Specifies how information from adjacent nodes /edges is propagated MAY: Union of adjacent edges MUST: Intersection of adjacent edges – GEN: Specifies which possible solutions are generated at the node/edge – KILL: Specifies which possible solutions are removed at that node/edge

Data-Flow Algorithm 1.Start at the top (bottom) of the CFG Forwards: top Backwards: bottom 2.At each node compute: (JOIN() – KILL(node)) U GEN(node) At each branch: Follow all paths, in any order, up to node where path merges Once all paths up to merge are complete, continue at merge node 3.If all JOIN edges are not yet computed, use empty set (MAY) universal set (MUST) 4.For loops: repeat until the solution for all nodes in loop doesn’t change Called the “fixed-point”

Liveness A variable is live at a node if its current value can be read during the remaining execution of the program Domain: program variables Backwards MAY analysis

Liveness Example

Liveness Transfer Functions Exit – GEN(exit) = { } – KILL(exit) = { } Conditions and Output – GEN(stmt) = Set of all variables appearing in the statement – KILL(stmt) = { } Assignment – GEN(assignment) = Set of all variables appearing on the right-hand side – KILL(assignment) = Set with variable being assigned to Declaration – GEN(declaration) = { } – KILL(declaration) = Set of variables being declared Other – GEN(other) = { } – KILL(other) = { }

Liveness Example { } { x } {x, z} {x} {x, y} {x} {x, z} { } true false true false START END

Liveness Application Memory Allocation – Since y and z are never live at the same time, they can share the same memory location Performance Optimization – Assignment, z = z – 1, is never used

Liveness Application Bug Checking (z = z – 1) is dead on assignment – FindBugs says : “This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used. “

Data-Flow Framework Summary Generic framework for different analyses Each analysis defines – Domain – Approximation – Direction – Transfer Functions Used for optimization, verification, and testing

Reaching Definitions An assignment statement that may have defined the value of a variable at a particular node Domain: assignment statements Forwards MAY analysis

Reaching Definitions Transfer Functions Assignments – GEN(assignment) = the statement itself – KILL(assignment) = Statements that assigned to the same variable Declaration – GEN(decl) = the statement itself – KILL(decl) = 0 Other – GEN(other) = 0 – KILL(other) = 0

Reaching Definitions Example

{a1, a2, a3, a5, a6} Reaching Definitions Example x = input output x x = x - y y > 3 x > 1 y = x/2 z = x - 4 x = x/2 z > 0 z = z - 1 { } a1 a2 a3 a4 a5 a6 {a1} {a1, a2} {a1, a2, a3, a4, a5} {a2, a4, a5} {a1, a2, a3, a5, a6} {a2, a3, a6} {a1, a2, a3, a5, a6} {a2, a3} {a1, a2, a3, a4} START END {…}

Reaching Definitions Applications FindBugs: “NP: Possible null pointer dereference” Debugging – “Slicing” tools Following chains of Reaching Definitions backwards to track down bugs Basis for Information Flow Security – Discuss in lectures on Security

Exercise Compute the reaching definitions for each node, using the iterative dataflow algorithm. Show solutions for each loop iteration. 1:function test(r1, r2, r3, r4, r5) { 2:while(r1 < 10) { 3: r1 = r1 + 1; 4: r5 = r1 * 2; 5: if((r1 % 2) == 0) 6: r2 = 0; 7: else 8: r2 = r2 + 1; 9: r4 = r2 + r1; 10:} 11:return r4 + r5; 12: }