Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Solving Systems of Linear Equations Graphically and Numerically
Angstrom Care 培苗社 Quadratic Equation II
AP STUDY SESSION 2.
1
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
We need a common denominator to add these fractions.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Break Time Remaining 10:00.
EE, NCKU Tien-Hao Chang (Darby Chang)
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Modern Programming Languages, 2nd ed.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Bright Futures Guidelines Priorities and Screening Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
How to convert a left linear grammar to a right linear grammar
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Note to the teacher: Was 28. A. to B. you C. said D. on Note to the teacher: Make this slide correct answer be C and sound to be “said”. to said you on.
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
Analyzing Genes and Genomes
Prof.ir. Klaas H.J. Robers, 14 July Graduation: a process organised by YOU.
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Types of selection structures
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Topic 16 Sorting Using ADTs to Implement Sorting Algorithms.
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
The Pumping Lemma for CFL’s
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Claus Brabrand, ITU, Denmark STATIC ANALYSIS (DATA-FLOW ANALYSIS)Apr 09, 2008 Static Analysis: Data-Flow Analysis IV Claus Brabrand ITU - IT University.
CS 536 Spring Global Optimizations Lecture 23.
Claus Brabrand, ITU, Denmark DATA-FLOW ANALYSISMar 25, 2009 Static Analysis: Data-Flow Analysis II Claus Brabrand IT University of Copenhagen (
Claus Brabrand, UFPE, Brazil Aug 09, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Presentation transcript:

Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and Semantics ))) IT University of Copenhagen A NALYSIS F LOW - D ATA [ HOW TO ANALYZE LANGUAGES AUTOMATICALLY ]

[ 2 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 3 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS

[ 4 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 5 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS All you need is…: int x = 1; int y = 3; x = x+2;x y; print(x,y); E. E[x  1 ] E. E[y  3 ] E. E[x  E(x)  2 ] E. E[x  E(y), y  E(x)] [, ]  ENV L [, ] x y... We (only) need 3 things:  A control-flow graph  A lattice  Transfer functions int x = 1; int y = 3; if (...) { x = x+2; } else { x y; } print(x,y); Given program:

[ 6 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Solve Equations :-) One big lattice: E.g., (L |VAR| ) |PP| 1 big abstract value vector: [,,..., ]  (L |VAR| ) |PP| 1 big transfer function: T : (L |VAR| ) |PP|  (L |VAR| ) |PP| Compute fixed-point (simply): Start with bottom value vector ( ) Iterate transfer function ‘T’ (until nothing changes) Done; print out (or use) solution…! :-) [, ] (L |VAR| ) |PP|

[ 7 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS x = 0; x = x+1; output x;  a = b = f x=0 (a) c = b d d = f x=x+1 (c) e = d The Entire Process :-) 3. Recursive equations: x = 0; do { x = x+1; } while (…); output x; Program: 1. Control-flow graph: T  4. one ”big” transfer function: T((a,b,c,d,e)) = (,f x=0 (a),b d,f x=x+1 (c),d) |VAR|*|PP| = 1*5 = 5 …over a ”big” power-lattice: T T T 0 ( ) T 1 ( ) T 2 ( ) T 3 ( ) T a = b = d = c = e = T 5 ( ) T = LEAST FIXED POINT ANOTHER FIXED POINT 5. Solve rec. equations…: 2. Transfer functions: solution T 4 ( ) T f x=0 ( l ) = f x=x+1 ( l ) = l  L

[ 8 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Exercise: Repeat this process for program (of two vars): i.e., determine…: 1) Control-flow graph 2) Transfer functions 3) Recursive equations 4) One ”big” transfer function 5) Solve recursive equations :-) x = 1; y = 0; while (v>w) { x y; } y = y+1; …using lattice:

[ 9 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 10 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS f x=0 f x=x+1 LEAST FIXED POINT = Naïve Fixed-Point Algorithm Slow! Naïve Fixed-Point Algorithm: …uses intermediate ”results” from previous iteration: a = b = f x=0 (a) c = b d d = f x=x+1 (c) e = d f x=0 ( l ) = f x=x+1 ( l ) = l  L  solution f x=0 f x=x+1 f x=0 f x=x+1 f x=0 f x=x+1 f x=0 f x=x+1 a b d c e

[ 11 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Chaotic Iteration Algorithm Faster! Chaotic Iteration Algorithm: …exploits ”forward nature” of program control flow: a = b = f x=1 (a) c = b d d = f x=x+1 (c) e = d f x=1 ( l ) = f x=x+1 ( l ) = l  L  solution LEAST FIXED POINT (always uses ”latest” results) f x=0 f x=x+1 f x=0 f x=x+1 f x=0 f x=x+1 a b d c e

[ 12 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Work-list Algorithm Fastest! Work-list Algorithm: …uses a ”queue” to control (optimize) computation: a = b = f x=1 (a) c = b d d = f x=x+1 (c) e = d f x=1 ( l ) = f x=x+1 ( l ) = l  L  solution a b d c e [a] Queue:  [b]  [d,c]   Initialize queue with start point: Q := [a] Pop top element from queue and (re-)compute it; IF it changed THEN enqueue all points that depend on it’s value (if it isn’t already on the queue) Stop when queue is empty LEAST FIXED POINT [c,e]   [] … (in general) [c]

[ 13 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 14 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS The Language ’C--’ Syntactic Categories: Expressions ( E  EXP): Statements ( S  STM): (…assume we only have integer variables ‘ x ’, ‘ y ’, ‘ z ’) E : n | v | E + E’ | – E | E * E’ | E == E’ | input S : skip ; | v := E ; | output E ; | if E then S else S’ | while E do S | { var v; S 1 … S n }

[ 15 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Control-Flow Graph (for ’C--’) Inductively defined control-flow graph: if ( E ) S 1 else S 2 S1S1 E truefalse S2S2 confluence while ( E ) S S E true false confluence skip ; v := E 1 ; output E ; { var v; S 1 … S n } S1S1 SnSn var v; …

[ 16 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Sign Analysis: Lattice Lattice: ENV Lattice : Confluence operator: = ’(,, )’ (pairwise)   x y z    L SIGN |VAR| L SIGN :  VAR  L SIGN x y z  

[ 17 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Sign Analysis: Transfer F’s Transfer Functions: Env. Env[x  sign(Env, Exp )] x := Exp ; var x; Env. Env[x  ]   Env. Env output … ;

[ 18 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Inductive definition of ’ sign ’ in the syntactic structure of Exp Syntax: sign(Env, n ) = sign(Env, input ) = sign(Env, v ) = Env( v ) sign(Env, E 1 +E 2 ) = sign(Env, E 1 )  L sign(Env, E 2 ) sign(Env, -E ) = - L sign(Env, E ) … E : n | input | v | E + E’ | E * E’ | E == E’ | - E

[ 19 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Exercise: Come up with a program the analysis… A) can analyse precisely B) can’t analyse precisely

[ 20 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 21 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Const Propagation: Lattice Lattice: ENV Lattice : Confluence operator: = ’(,, )’ (pairwise)   x y z    L NUM |VAR|  VAR  L NUM L NUM :

[ 22 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Const Propagation: Transfer F’s Transfer Functions: Env. Env[x  eval(Env, Exp )] x := Exp ; var x; Env. Env[x  ]   Env. Env output … ;

[ 23 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Inductive definition of ’ eval ’ in the syntactic structure of Exp Syntax: eval(Env, n ) = n eval(Env, input ) = eval(Env, v ) = Env( v ) eval(Env, E 1 +E 2 ) = eval(Env, E 1 )  L eval(Env, E 2 ) eval(Env, -E ) = - L eval(Env, E ) … E : n | input | v | E + E’ | E * E’ | E == E’ | - E, if n =  m = n  L m =, if n =  m = r, o/w (where r = n + m) …i.e.:

[ 24 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Exercise: Come up with a program the analysis… A) can analyse precisely B) can’t analyse precisely

[ 25 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 26 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Initialized Variables Analysis Lattice: ENV Lattice : Confluence operator: = ’(,, )’ (pairwise) x y z  x y z    definitely initialized  possibly uninitialized Note: It’s always "safe" to answer "too high"

[ 27 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Initialized Variables Analysis Transfer Functions: Env. Env x := … ; output … ; var x; Env. Env[x  ] Env. Env[x  init(Env, Exp )]

[ 28 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Inductive definition of ’ init ’ in the syntactic structure of Exp Syntax: init(Env, n ) = init(Env, input ) = init(Env, v ) = Env( v ) init(Env, E 1 +E 2 ) = eval(Env, E 1 )  L eval(Env, E 2 ) init(Env, -E ) = - L eval(Env, E ) … E : n | input | v | E + E’ | E * E’ | E == E’ | - E LL

[ 29 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Note: Isomorphism! With value lattice: ENV-lattice is isomorphic to: …for every program point:  isomorphic ’x’’x’’y’’y’’z’’z’ Init VARS  { x, y, z } Vars that are possibly uninitialized

[ 30 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Initialized Variables Analysis (Revisited) ENV-lattice: Confluence operator: = ’  ’ (i.e., set union) Transfer Functions: S. S \ { x } S. S x := … ; output … ; var x; Vars that are possibly uninitialized S. S  { x }

[ 31 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Exercise: Come up with a program the analysis… A) can analyse precisely B) can’t analyse precisely

[ 32 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Set-based analyses… {may,must}  {forwards,backwards}

[ 34 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Forwards vs. Backwards? What you have seen: Forwards: Some analyses…: Backwards: Analyze info that depends on future behavior Analyze info that depends on past behavior x = 0; x = x+1; output x; y = 2*x; x = x+1; output x; E.g.: - Live Variables - Very Busy Expressions ’ y ’ dead here

[ 35 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS May vs. Must? What you have seen: Confluence: = ’  ’ (set union) Partial order: = ’  ’ (sub-set-eq) Some analyses…: Confluence: = ’  ’ (set intersection) Partial order: = ’  ’ (super-set-eq) Analyze info that must definitely be true  paths Analyze info that may possibly be true  paths E.g.: - Initialized Variables - Available Expressions - Very Busy Expressions E.g.: - Uninitialized Variables

[ 36 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS DUALITY: Lattice Lattice M: Confluence: M Partial order: M ” ”: W Confluence: W = M Partial order: W = M (M,  ) (W,  )  Lattice Stand on head

[ 37 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS DUALITY: Framework What we have done: Approximation: ”safe” to throw away info upwards With confluence: (least upper bound) Least fixed point: Computed as: ” ”: Approximation: ”safe” to throw away info downwards With confluence: ( greatest lower bound) Greatest fixed point: Computed as: Stand on head lfp(f) = f i ( ) i≥0 f( )... f(f( )) gfp(f) = f i ( ) i≥0 f( ) f(f( ))...

[ 38 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Agenda Quick recap (of everything so far): "Putting it all together"  Data-Flow Analysis Fixed-Point Iteration Strategies (3x) "Sign Analysis" "Constant Propagation Analysis" "Initialized Variables Analysis" Set-Based Analysis Framework WORKSHOP 3 Example Data-Flow Analyses

[ 39 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS WORKSHOP Reaching Definitions: '  '  '  ' (forward), '  ' (may / smallest set) Live Variables: '  '  '  ' (backward), '  ' (may / smallest set) Available Expressions: '  '  '  ' (forward), '  ' (must / largest set) Very Busy Expressions: '  '  '  ' (backward), '  ' (must / largest set)

[ 40 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Reaching Definitions Reaching Definitions: Example: int x = input; int y; while (x>1) { y = x / 2; if (y>2) x = x - y; } output y; int x = input; y = x / 2; x = x – y; x>1 y>2 output y; int y; DEF-USE graph: The reaching definitions (for a given program point) are those assignments that may have defined the current vals of vars

[ 41 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS WHY do we do this? ”Learning takes place through the active behavior of the student: it is what (s)he does that (s)he learns, not what the teacher does.” -- Ralph W. Tyler (1949)

[ 42 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS WORKSHOP 1) Define the problem 2) Show that the problem is undecidable 3) Define a Lattice Check that it is a lattice (and explain how) 4) Define monotone transfer functions Check that they are monotone (and explain how) 5) Pick a program the analysis can analyze Make a "The Entire Process” diagram (cf. slide #5) 6) Repeat 5) for program the analysis can’t… 7) Explain possible uses of the analysis

[ 43 ] Claus Brabrand, UFPE, Brazil Aug 11, 2010DATA-FLOW ANALYSIS Now, please: 3’ recap Please spend 3' on thinking about and writing down the main ideas and points from the lecture – now!: After 1 day After 1 week After 3 weeks After 2 weeks Immediately