Another example: constant prop Set D = 2 { x ! N | x 2 Vars Æ N 2 Z } x := N in out F x := N (in) = in – { x ! * } [ { x ! N } x := y op z in out F x :=

Slides:



Advertisements
Similar presentations
Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Advertisements

1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Program Representations. Representing programs Goals.
CSE 231 : Advanced Compilers Building Program Analyzers.
CSE 231 : Advanced Compilers Building Program Analyzers.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Worklist algorithm Initialize all d i to the empty set Store all nodes onto a worklist while worklist is not empty: –remove node n from worklist –apply.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Another example: constant prop Set D = 2 { x ! N | x ∊ Vars Æ N ∊ Z } x := N in out F x := N (in) = in – { x ! * } [ { x ! N } x := y op z in out F x :=
CS 536 Spring Global Optimizations Lecture 23.
Correctness. Until now We’ve seen how to define dataflow analyses How do we know our analyses are correct? We could reason about each individual analysis.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
From last time: live variables Set D = 2 Vars Lattice: (D, v, ?, >, t, u ) = (2 Vars, µ, ;,Vars, [, Å ) x := y op z in out F x := y op z (out) = out –
Administrative info Subscribe to the class mailing list –instructions are on the class web page, which is accessible from my home page, which is accessible.
From last time: Lattices A lattice is a tuple (S, v, ?, >, t, u ) such that: –(S, v ) is a poset – 8 a 2 S. ? v a – 8 a 2 S. a v > –Every two elements.
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.
Constraints for reaching definitions Using may-point-to information: out = in [ { x ! s | x 2 may-point-to(p) } Using must-point-to aswell: out = in –
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; ???
Back to lattice (D, v, ?, >, t, u ) = (2 A, ¶, A, ;, Å, [ ) where A = { x ! N | x 2 Vars Æ N 2 Z } What’s the problem with this lattice? Lattice is infinitely.
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.
Class canceled next Tuesday. Recap: Components of IR Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements.
Administrative stuff Office hours: After class on Tuesday.
Recap Let’s do a recap of what we’ve seen so far Started with worklist algorithm for reaching definitions.
Constraints for reaching definitions Using may-point-to information: out = in [ { x ! s | x 2 may-point-to(p) } Using must-point-to aswell: out = in –
San Diego October 4-7, 2006 Over 1,000 women in computing Events for undergraduates considering careers and graduate school Events for graduate students.
Project Project proposal due today (lots of projects have already sent theirs in!) I want some concrete results in 3 weeks! –for implementation projects,
Recap: Reaching defns algorithm From last time: reaching defns worklist algo We want to avoid using structure of the domain outside of the flow functions.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
From last lecture x := y op z in out F x := y op z (in) = in [ x ! in(y) op in(z) ] where a op b =
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Projects. Dataflow analysis Dataflow analysis: what is it? A common framework for expressing algorithms that compute information about a program Why.
Project web page
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
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.
From last lecture We want to find a fixed point of F, that is to say a map m such that m = F(m) Define ?, which is ? lifted to be a map: ? = e. ? Compute.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Even more formal To reason more formally about termination and precision, we re-express our worklist algorithm mathematically We will use fixed points.
Termination Still, it’s annoying to have to perform a join in the worklist algorithm It would be nice to get rid of it, if there is a property of the flow.
Rutgers University Relational Calculus 198:541 Rutgers University.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Precision Going back to constant prop, in what cases would we lose precision?
Example x := read() v := a + b x := x + 1 w := x + 1 a := w v := a + b z := x + 1 t := a + b.
Compiler Construction Lecture 16 Data-Flow Analysis.
Differentiating “Combined” Functions ---Part I Constant Multiples, Sums and Differences.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 12: Abstract Interpretation IV Roman Manevich Ben-Gurion University.
CS 614: Theory and Construction of Compilers Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Formalization of DFA using lattices. Recall worklist algorithm let m: map from edge to computed value at edge let worklist: work list of nodes for each.
Program Representations. Representing programs Goals.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
Semilattices presented by Niko Simonson, CSS 548, Autumn 2012 Semilattice City, © 2009 Nora Shader.
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2011 Yet More Data flow analysis John Cavazos.
Lub and glb Given a poset (S, · ), and two elements a 2 S and b 2 S, then the: –least upper bound (lub) is an element c such that a · c, b · c, and 8 d.
DFA foundations Simone Campanoni
Dataflow analysis.
Program Representations
Simone Campanoni DFA foundations Simone Campanoni
Global optimizations.
Another example: constant prop
Dataflow analysis.
Differentiating “Combined” Functions ---Part I
Selection Statements.
Differentiating “Combined” Functions ---Part I
Data Flow Analysis Compiler Design
ICT Programming Lesson 3:
7.1 – Functions of Several Variables
Formalization of DFA using lattices
Formalization of DFA using lattices
Formalization of DFA using lattices
Formalization of DFA using lattices
Presentation transcript:

Another example: constant prop Set D = 2 { x ! N | x 2 Vars Æ N 2 Z } x := N in out F x := N (in) = in – { x ! * } [ { x ! N } x := y op z in out F x := y op z (in) = in – { x ! * } [ { x ! N | ( y ! N 1 ) 2 in Æ ( z ! N 2 ) 2 in Æ N = N 1 op N 2 }

Another example: constant prop *x := y in out F *x := y (in) = in – { z ! * | z 2 may-point(x) } [ { z ! N | z 2 must-point-to(x) Æ y ! N 2 in } [ { z ! N | (y ! N) 2 in Æ (z ! N) 2 in } x := *y in out F x := *y (in) = in – { x ! * } [ { x ! N | 8 z 2 may-point-to(x). (z ! N) 2 in }

Another example: constant prop x := f(...) in out F x := f(...) (in) = ; *x := *y + *z in out F *x := *y + *z (in) = F a := *y;b := *z;c := a + b; *x := c (in)

Another example: constant prop s: if (...) in out[0]out[1] merge out in[0]in[1]

Lattice (D, ⊑, ⊥, ⊤, ⊔, ⊓ ) = (2 A, ¶, A, ;, Å, [ ) where A = { x ! N | x ∊ Vars Æ N ∊ Z }

Example x := 5 v := 2 x := x + 1 w := v + 1 w := 3 y := x * 2 z := y + 5 w := w * v

Back to lattice (D, ⊑, ⊥, ⊤, ⊔, ⊓ ) = (2 A, ¶, A, ;, Å, [ ) where A = { x ! N | x ∊ Vars Æ N ∊ Z } What’s the problem with this lattice?

Back to lattice (D, ⊑, ⊥, ⊤, ⊔, ⊓ ) = (2 A, ¶, A, ;, Å, [ ) where A = { x ! N | x ∊ Vars Æ N ∊ Z } What’s the problem with this lattice? Lattice is infinitely high, which means we can’t guarantee termination

Better lattice Suppose we only had one variable

Better lattice Suppose we only had one variable D = { ⊥, ⊤ } [ Z 8 i ∊ Z. ⊥ ⊑ i Æ i ⊑ ⊤ height = 3

For all variables Two possibilities Option 1: Tuple of lattices Given lattices (D 1, v 1, ? 1, > 1, t 1, u 1 )... (D n, v n, ? n, > n, t n, u n ) create: tuple lattice D n =

For all variables Two possibilities Option 1: Tuple of lattices Given lattices (D 1, v 1, ? 1, > 1, t 1, u 1 )... (D n, v n, ? n, > n, t n, u n ) create: tuple lattice D n = ((D 1 £... £ D n ), v, ?, >, t, u ) where ? = ( ? 1,..., ? n ) > = ( > 1,..., > n ) (a 1,..., a n ) t (b 1,..., b n ) = (a 1 t 1 b 1,..., a n t n b n ) (a 1,..., a n ) u (b 1,..., b n ) = (a 1 u 1 b 1,..., a n u n b n ) height = height(D 1 ) height(D n )

For all variables Option 2: Map from variables to single lattice Given lattice (D, v 1, ? 1, > 1, t 1, u 1 ) and a set V, create: map lattice V ! D = (V ! D, v, ?, >, t, u )

Back to example x := y op z in out F x := y op z (in) =

Back to example x := y op z in out F x := y op z (in) = in [ x ! in(y) op in(z) ] where a op b =

General approach to domain design Simple lattices: –boolean logic lattice –powerset lattice –incomparable set: set of incomparable values, plus top and bottom (eg const prop lattice) –two point lattice: just top and bottom Use combinators to create more complicated lattices –tuple lattice constructor –map lattice constructor

May vs Must Has to do with definition of computed info Set of x ! y must-point-to pairs –if we compute x ! y, then, then during program execution, x must point to y Set of x ! y may-point-to pairs –if during program execution, it is possible for x to point to y, then we must compute x ! y

May vs must MayMust most optimistic (bottom) most conservative (top) safe merge

May vs must MayMust most optimistic (bottom) empty setfull set most conservative (top) full setempty set safeoverly bigoverly small merge [Å

Common Sub-expression Elim Want to compute when an expression is available in a var Domain:

Common Sub-expression Elim Want to compute when an expression is available in a var Domain:

Flow functions X := Y op Z in out F X := Y op Z (in) = X := Y in out F X := Y (in) =

Example x := read() v := a + b x := x + 1 w := x + 1 a = w v = a + b z := x + 1 t = a + b