SlideShare a Scribd company logo
1 of 37
Download to read offline
Dataflow Analysis
Miller Lee
June 8, 2013
Miller Lee Dataflow Analysis
Available Expression
Aim
An expression e is available at program point p if e have
already been computed, and not later modified, on all paths to
p.
Why we need AE analysis?
x = a + b;
y = a * b;
while y > a + b do
a = a + 1;
x = a + b;
end
x = a + b;
y = a * b;
while y > x do
a = a + 1;
x = a + b;
end
Test it at run-time is not efficient.
Miller Lee Dataflow Analysis
Let’s analyze it
1 List all expressions: a + b, a * b, a + 1.
2 How long is the life span of an expression?
When is an expression be generated??
When is an expression be killed??
3 How to automate the analysis?
Miller Lee Dataflow Analysis
The Basic Idea
Miller Lee Dataflow Analysis
Available Expression
x = a + b;
y = a * b;
while y > a + b do
a = a + 1;
x = a + b;
end
Miller Lee Dataflow Analysis
Solution
Miller Lee Dataflow Analysis
Here comes the problems
Why does it work?
How can we prove that this algorithm is correct?
Do this algorithm definitely stop?
Because it works, so it is correct, this reason is not accepeted.
There are two parts we can notice.
1 The relations between data
2 The characteristic of the transfer function
Miller Lee Dataflow Analysis
Dataflow and Lattices
Miller Lee Dataflow Analysis
Partial Order
Definition
Giving a Pair (P, R)
P is a set of elements.
R is a relation over P (R ⊆ PxP)
R is reflexive, anti-symmetric, and transitive.
Miller Lee Dataflow Analysis
Example
Figure : Partial Order, R = ⊆
Miller Lee Dataflow Analysis
Least Upper Bound
Given partial order (D, ≤), for each S ⊆ D
g is an upper bound of S if x ∈ D and ∀y ∈ S : y ≤ x
g ∈ V is a least upper bound. x, y ∈ S
1 x ≤ g
2 y ≤ g
3 If z is any element that x ≤ z and y ≤ z, then g ≤ z
Join Operation V
x V y is the least upper bound of {x, y}
Miller Lee Dataflow Analysis
Greatest Lower Bound
Given partial order (D, ≤), for each S ⊆ D
g is an lower bound of S if x ∈ D and ∀y ∈ S : x ≤ y
g ∈ V is a greatest lower bound. x, y ∈ S
1 g ≤ x
2 g ≤ y
3 If z is any element that z ≤ x and z ≤ y, then z ≤ g
Meet Operation ∧
x ∧ y is the greatest lower bound of {x, y}
Miller Lee Dataflow Analysis
Examples
Figure : ub = {a,b}, which is also a lub.
Miller Lee Dataflow Analysis
Examples
Figure : The viewpoint of teelung People
Miller Lee Dataflow Analysis
Lattice
Definition
A partial order is a lattice if every two elements of P have a
unique least upper bound and greatest lower bound.
1 idempotent: x ∧ x = x
2 commutative: x ∧ y = y ∧ x
3 associative: x ∧ (y ∧ z) = (x ∧ y) ∧ z
Special Elements
top element : for all x ∈ V , ∧ x = x.
bottom element ⊥: for all x ∈ V , ⊥ ∧x =⊥.
Semilattice
A join semi-lattice (meet semi-lattice) has only the join (meet)
operator defined.
Miller Lee Dataflow Analysis
Examples
R = ∪
= {a, b, c}
⊥ = {}
For any x ∈ P({a, b, c}),
{}∪x = x,
{a,b,c}∪x={a,b,c}.
Figure : P({a,b,c})
Miller Lee Dataflow Analysis
Examples
(2S
, ⊆) forms a lattice for any set S.
2S is a powerset of S, the set of all subsets of S.
if (S, ≤) is a semilattice, so is (S, ≥)
i.e., can ”flip” the lattice
Lattice for constant propagation
Miller Lee Dataflow Analysis
Algorithm for a forward data-flow problem
OUT[ENTRY] = VENTRY
for each basic block B other than ENTRY do
OUT[B] =
end
while changes to any OUT occur do
for each basic block B other than ENTRY do
IN[B] = ∧S a predecessor of BOUT[S];
OUT[B] = fB(IN[B]);
end
end
Miller Lee Dataflow Analysis
The Dataflow Equation of Available Expression
Let s be a statement
succs(s) = { immediate successor stmts of s }
pres(s) = { immediate predecessor stmts of s }
In(s) = program just before executing s
Out(s) = program just after executing s
In(s) = ∩s ∈preds(s) Out(s )
Out(s) = Gen(s)∪(In(S) - Kill(s))
Miller Lee Dataflow Analysis
Monotone Functions
Definition
If (D, ⊆) and (D , ⊆ ) are two posets and F : D → D is
function, the F is called monotone if and only if
F(x) ⊆ F(y) for any x, y ∈ D with x ⊆ y.
Observation
Functions for computing In(s) and Out(s) are monotonic
In(s) = ∩s ∈preds(s) Out(s )
Out(s) = Gen(s)∪(In(S) - Kill(s))
Extensivity
People think f is monotonic if x ≤ f (x). This is a different
property called extensivity.
Miller Lee Dataflow Analysis
Examples
Monotonic functions
x → {}
x → x ∪ {a}
x → x − {a}
Not monotone
x → {a} − x
Extensivity
x → x ∪ {a}
x → {a} − x
Figure : P({a,b,c})
Miller Lee Dataflow Analysis
Chain
Chain
Given a poset (D, ⊆), a chain in D is an infinite sequence
d0 ⊆ d1 ⊆ d2 ⊆ · · · ⊆ dn ⊆ . . . of elements in D, also written
using set notation as {dn|n ∈ N}.
Stationary
A chain is called stationary when there is some n ∈ N such
that dm = dm+1 for all m > n.
Miller Lee Dataflow Analysis
Examples
The sets N, Z, Q, R of natural numbers, integers,
rationals, and real numbers form chains under their usual
order.
Miller Lee Dataflow Analysis
The Fixed-Point Theorem
Theorem
Let (D, ⊆, ⊥) be a semilattice, let
F : (D, ⊆, ⊥) → (D, ⊆, ⊥) be a continuous function, and let
fix(F) be the lub of the chain {Fn
(⊥)|n ∈ N}. Then fix(F) is
the least fix-point of F.
Miller Lee Dataflow Analysis
Examples
For D = P({a,b,c}), so ⊥ is {}
Identity function: sequence is {},{},{}. . . so least
fixpoint is {}. And all the elements are fixpoints.
x → x ∪ {a}: sequence is {},{a},{a},{a},. . . so least
fixpoint is {a}.{a},{a,b},{a,b,c} are all fixpoints.
x → {a} − x: no fixpoints.
Miller Lee Dataflow Analysis
Observation
1 If Algorithm converges, the result is a solution to the
data-flow equations.
Miller Lee Dataflow Analysis
Observation
1 If Algorithm converges, the result is a solution to the
data-flow equations.
2 If the frame work is monotone, then the solution found is
the maximum fixedpoint of the data-flow equations.
Miller Lee Dataflow Analysis
Observation
1 If Algorithm converges, the result is a solution to the
data-flow equations.
2 If the frame work is monotone, then the solution found is
the maximum fixedpoint of the data-flow equations.
3 If the semilattice of the framework is monotone and of
finite height, then the algorithm is guaranteed to
converge.
Miller Lee Dataflow Analysis
Distributive
Definition
f (x ∧ y) = f (x) ∧ f (y) for all x and y in V and f in F.
Benefit
Joins lose no information
k(h(f(T)∧g(T)))
= k(h(f(T))∧h(g(T)))
= k(h(f(T)))∧k(h(g(T)))
Miller Lee Dataflow Analysis
Meaning of a Data-Flow Solution
The Ideal Solution
The Meet-Over-Paths Solution
Maximun Fixedpoint: the result of the iterative algorithm.
Miller Lee Dataflow Analysis
The Ideal Solution
Property
IDEAL[B] =∧P, a possible path from ENTRY to BfP(vENTRY )
In terms of the lattice-theoretic partial order ≤ for the
framework in question.
Any answer that is greater than IDEAL is incorrect.
Any value smaller than or equal to the ideal is
conservative, i.e., safe.
Miller Lee Dataflow Analysis
The Meet-Over-Paths Solution
Property
MOP[B]=∧P, a path from ENTRY to BfP(vENTRY ).
For all B we have MOP[B]≤IDEAL[B].
Too much information
If the transfer functions are distributive, produce the MFP
solution.
Miller Lee Dataflow Analysis
MFP v.s. MOP
The number of paths considered is unbounded if the flow
graph contains cycles.
→ the MOP does not lend itself to a direct algorithm.
Miller Lee Dataflow Analysis
MFP v.s. MOP
The number of paths considered is unbounded if the flow
graph contains cycles.
→ the MOP does not lend itself to a direct algorithm.
MOP ≤ IDEAL and MFP ≤ MOP, we know that
MFP ≤ IDEAL (SAVE)
MFP ≤ MOP, because the meet operator is applied at
the end in the definiton of MOP.
Miller Lee Dataflow Analysis
Non-distributive Example
Constant Propagation
In general, analysis of what the program computes is not
distributive.
MOP ≤ iterative dataflow solution.
Miller Lee Dataflow Analysis
The Drawback of Dataflow Analysis
We need to keep track of lots of irrelevant details at every
program point.
We need to consider all the path that the program will
execute.
Hard to analyze to pointers.
Miller Lee Dataflow Analysis
Example
Miller Lee Dataflow Analysis

More Related Content

What's hot

Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AIMegha Sharma
 
Production system in ai
Production system in aiProduction system in ai
Production system in aisabin kafle
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory ManagementAkmal Cikmat
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSwati Chauhan
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AIAmey Kerkar
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency controlBinte fatima
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization Hafiz faiz
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System ImplementationWayne Jones Jnr
 
software design principles
software design principlessoftware design principles
software design principlesCristal Ngo
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagramsAPU
 

What's hot (20)

Thread
ThreadThread
Thread
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Query processing
Query processingQuery processing
Query processing
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Production system in ai
Production system in aiProduction system in ai
Production system in ai
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
 
Lec 7 query processing
Lec 7 query processingLec 7 query processing
Lec 7 query processing
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AI
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
Parallel Processing Concepts
Parallel Processing Concepts Parallel Processing Concepts
Parallel Processing Concepts
 
Defuzzification
DefuzzificationDefuzzification
Defuzzification
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
software design principles
software design principlessoftware design principles
software design principles
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagrams
 

Similar to Dataflow Analysis

20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilersComputer Science Club
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisSilvio Cesare
 
phuong trinh vi phan d geometry part 2
phuong trinh vi phan d geometry part 2phuong trinh vi phan d geometry part 2
phuong trinh vi phan d geometry part 2Bui Loi
 
thses are best for college and university students
thses are best for college and university studentsthses are best for college and university students
thses are best for college and university studentssafdarhussainbhutta4
 
ch02edited.ppt
ch02edited.pptch02edited.ppt
ch02edited.pptBelaRillo
 
ch02edited is best for university students
ch02edited is best for university studentsch02edited is best for university students
ch02edited is best for university studentssafdarhussainbhutta4
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Reviewhassaanciit
 
Machine learning (1)
Machine learning (1)Machine learning (1)
Machine learning (1)NYversity
 
Universal Approximation Theorem
Universal Approximation TheoremUniversal Approximation Theorem
Universal Approximation TheoremJamie Seol
 
5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functionssmiller5
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
lecture 12
lecture 12lecture 12
lecture 12sajinsc
 
test pre
test pretest pre
test prefarazch
 
Efficient end-to-end learning for quantizable representations
Efficient end-to-end learning for quantizable representationsEfficient end-to-end learning for quantizable representations
Efficient end-to-end learning for quantizable representationsNAVER Engineering
 

Similar to Dataflow Analysis (20)

20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
 
3_MLE_printable.pdf
3_MLE_printable.pdf3_MLE_printable.pdf
3_MLE_printable.pdf
 
Algorithms DM
Algorithms DMAlgorithms DM
Algorithms DM
 
AlgorithmAnalysis2.ppt
AlgorithmAnalysis2.pptAlgorithmAnalysis2.ppt
AlgorithmAnalysis2.ppt
 
phuong trinh vi phan d geometry part 2
phuong trinh vi phan d geometry part 2phuong trinh vi phan d geometry part 2
phuong trinh vi phan d geometry part 2
 
ch02edited.ppt
ch02edited.pptch02edited.ppt
ch02edited.ppt
 
thses are best for college and university students
thses are best for college and university studentsthses are best for college and university students
thses are best for college and university students
 
ch02edited.ppt
ch02edited.pptch02edited.ppt
ch02edited.ppt
 
ch02edited is best for university students
ch02edited is best for university studentsch02edited is best for university students
ch02edited is best for university students
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
Machine learning (1)
Machine learning (1)Machine learning (1)
Machine learning (1)
 
Lecture co3 math21-1
Lecture co3 math21-1Lecture co3 math21-1
Lecture co3 math21-1
 
Universal Approximation Theorem
Universal Approximation TheoremUniversal Approximation Theorem
Universal Approximation Theorem
 
5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
lecture 12
lecture 12lecture 12
lecture 12
 
R lecture co4_math 21-1
R lecture co4_math 21-1R lecture co4_math 21-1
R lecture co4_math 21-1
 
test pre
test pretest pre
test pre
 
Efficient end-to-end learning for quantizable representations
Efficient end-to-end learning for quantizable representationsEfficient end-to-end learning for quantizable representations
Efficient end-to-end learning for quantizable representations
 

Recently uploaded

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Dataflow Analysis

  • 1. Dataflow Analysis Miller Lee June 8, 2013 Miller Lee Dataflow Analysis
  • 2. Available Expression Aim An expression e is available at program point p if e have already been computed, and not later modified, on all paths to p. Why we need AE analysis? x = a + b; y = a * b; while y > a + b do a = a + 1; x = a + b; end x = a + b; y = a * b; while y > x do a = a + 1; x = a + b; end Test it at run-time is not efficient. Miller Lee Dataflow Analysis
  • 3. Let’s analyze it 1 List all expressions: a + b, a * b, a + 1. 2 How long is the life span of an expression? When is an expression be generated?? When is an expression be killed?? 3 How to automate the analysis? Miller Lee Dataflow Analysis
  • 4. The Basic Idea Miller Lee Dataflow Analysis
  • 5. Available Expression x = a + b; y = a * b; while y > a + b do a = a + 1; x = a + b; end Miller Lee Dataflow Analysis
  • 7. Here comes the problems Why does it work? How can we prove that this algorithm is correct? Do this algorithm definitely stop? Because it works, so it is correct, this reason is not accepeted. There are two parts we can notice. 1 The relations between data 2 The characteristic of the transfer function Miller Lee Dataflow Analysis
  • 8. Dataflow and Lattices Miller Lee Dataflow Analysis
  • 9. Partial Order Definition Giving a Pair (P, R) P is a set of elements. R is a relation over P (R ⊆ PxP) R is reflexive, anti-symmetric, and transitive. Miller Lee Dataflow Analysis
  • 10. Example Figure : Partial Order, R = ⊆ Miller Lee Dataflow Analysis
  • 11. Least Upper Bound Given partial order (D, ≤), for each S ⊆ D g is an upper bound of S if x ∈ D and ∀y ∈ S : y ≤ x g ∈ V is a least upper bound. x, y ∈ S 1 x ≤ g 2 y ≤ g 3 If z is any element that x ≤ z and y ≤ z, then g ≤ z Join Operation V x V y is the least upper bound of {x, y} Miller Lee Dataflow Analysis
  • 12. Greatest Lower Bound Given partial order (D, ≤), for each S ⊆ D g is an lower bound of S if x ∈ D and ∀y ∈ S : x ≤ y g ∈ V is a greatest lower bound. x, y ∈ S 1 g ≤ x 2 g ≤ y 3 If z is any element that z ≤ x and z ≤ y, then z ≤ g Meet Operation ∧ x ∧ y is the greatest lower bound of {x, y} Miller Lee Dataflow Analysis
  • 13. Examples Figure : ub = {a,b}, which is also a lub. Miller Lee Dataflow Analysis
  • 14. Examples Figure : The viewpoint of teelung People Miller Lee Dataflow Analysis
  • 15. Lattice Definition A partial order is a lattice if every two elements of P have a unique least upper bound and greatest lower bound. 1 idempotent: x ∧ x = x 2 commutative: x ∧ y = y ∧ x 3 associative: x ∧ (y ∧ z) = (x ∧ y) ∧ z Special Elements top element : for all x ∈ V , ∧ x = x. bottom element ⊥: for all x ∈ V , ⊥ ∧x =⊥. Semilattice A join semi-lattice (meet semi-lattice) has only the join (meet) operator defined. Miller Lee Dataflow Analysis
  • 16. Examples R = ∪ = {a, b, c} ⊥ = {} For any x ∈ P({a, b, c}), {}∪x = x, {a,b,c}∪x={a,b,c}. Figure : P({a,b,c}) Miller Lee Dataflow Analysis
  • 17. Examples (2S , ⊆) forms a lattice for any set S. 2S is a powerset of S, the set of all subsets of S. if (S, ≤) is a semilattice, so is (S, ≥) i.e., can ”flip” the lattice Lattice for constant propagation Miller Lee Dataflow Analysis
  • 18. Algorithm for a forward data-flow problem OUT[ENTRY] = VENTRY for each basic block B other than ENTRY do OUT[B] = end while changes to any OUT occur do for each basic block B other than ENTRY do IN[B] = ∧S a predecessor of BOUT[S]; OUT[B] = fB(IN[B]); end end Miller Lee Dataflow Analysis
  • 19. The Dataflow Equation of Available Expression Let s be a statement succs(s) = { immediate successor stmts of s } pres(s) = { immediate predecessor stmts of s } In(s) = program just before executing s Out(s) = program just after executing s In(s) = ∩s ∈preds(s) Out(s ) Out(s) = Gen(s)∪(In(S) - Kill(s)) Miller Lee Dataflow Analysis
  • 20. Monotone Functions Definition If (D, ⊆) and (D , ⊆ ) are two posets and F : D → D is function, the F is called monotone if and only if F(x) ⊆ F(y) for any x, y ∈ D with x ⊆ y. Observation Functions for computing In(s) and Out(s) are monotonic In(s) = ∩s ∈preds(s) Out(s ) Out(s) = Gen(s)∪(In(S) - Kill(s)) Extensivity People think f is monotonic if x ≤ f (x). This is a different property called extensivity. Miller Lee Dataflow Analysis
  • 21. Examples Monotonic functions x → {} x → x ∪ {a} x → x − {a} Not monotone x → {a} − x Extensivity x → x ∪ {a} x → {a} − x Figure : P({a,b,c}) Miller Lee Dataflow Analysis
  • 22. Chain Chain Given a poset (D, ⊆), a chain in D is an infinite sequence d0 ⊆ d1 ⊆ d2 ⊆ · · · ⊆ dn ⊆ . . . of elements in D, also written using set notation as {dn|n ∈ N}. Stationary A chain is called stationary when there is some n ∈ N such that dm = dm+1 for all m > n. Miller Lee Dataflow Analysis
  • 23. Examples The sets N, Z, Q, R of natural numbers, integers, rationals, and real numbers form chains under their usual order. Miller Lee Dataflow Analysis
  • 24. The Fixed-Point Theorem Theorem Let (D, ⊆, ⊥) be a semilattice, let F : (D, ⊆, ⊥) → (D, ⊆, ⊥) be a continuous function, and let fix(F) be the lub of the chain {Fn (⊥)|n ∈ N}. Then fix(F) is the least fix-point of F. Miller Lee Dataflow Analysis
  • 25. Examples For D = P({a,b,c}), so ⊥ is {} Identity function: sequence is {},{},{}. . . so least fixpoint is {}. And all the elements are fixpoints. x → x ∪ {a}: sequence is {},{a},{a},{a},. . . so least fixpoint is {a}.{a},{a,b},{a,b,c} are all fixpoints. x → {a} − x: no fixpoints. Miller Lee Dataflow Analysis
  • 26. Observation 1 If Algorithm converges, the result is a solution to the data-flow equations. Miller Lee Dataflow Analysis
  • 27. Observation 1 If Algorithm converges, the result is a solution to the data-flow equations. 2 If the frame work is monotone, then the solution found is the maximum fixedpoint of the data-flow equations. Miller Lee Dataflow Analysis
  • 28. Observation 1 If Algorithm converges, the result is a solution to the data-flow equations. 2 If the frame work is monotone, then the solution found is the maximum fixedpoint of the data-flow equations. 3 If the semilattice of the framework is monotone and of finite height, then the algorithm is guaranteed to converge. Miller Lee Dataflow Analysis
  • 29. Distributive Definition f (x ∧ y) = f (x) ∧ f (y) for all x and y in V and f in F. Benefit Joins lose no information k(h(f(T)∧g(T))) = k(h(f(T))∧h(g(T))) = k(h(f(T)))∧k(h(g(T))) Miller Lee Dataflow Analysis
  • 30. Meaning of a Data-Flow Solution The Ideal Solution The Meet-Over-Paths Solution Maximun Fixedpoint: the result of the iterative algorithm. Miller Lee Dataflow Analysis
  • 31. The Ideal Solution Property IDEAL[B] =∧P, a possible path from ENTRY to BfP(vENTRY ) In terms of the lattice-theoretic partial order ≤ for the framework in question. Any answer that is greater than IDEAL is incorrect. Any value smaller than or equal to the ideal is conservative, i.e., safe. Miller Lee Dataflow Analysis
  • 32. The Meet-Over-Paths Solution Property MOP[B]=∧P, a path from ENTRY to BfP(vENTRY ). For all B we have MOP[B]≤IDEAL[B]. Too much information If the transfer functions are distributive, produce the MFP solution. Miller Lee Dataflow Analysis
  • 33. MFP v.s. MOP The number of paths considered is unbounded if the flow graph contains cycles. → the MOP does not lend itself to a direct algorithm. Miller Lee Dataflow Analysis
  • 34. MFP v.s. MOP The number of paths considered is unbounded if the flow graph contains cycles. → the MOP does not lend itself to a direct algorithm. MOP ≤ IDEAL and MFP ≤ MOP, we know that MFP ≤ IDEAL (SAVE) MFP ≤ MOP, because the meet operator is applied at the end in the definiton of MOP. Miller Lee Dataflow Analysis
  • 35. Non-distributive Example Constant Propagation In general, analysis of what the program computes is not distributive. MOP ≤ iterative dataflow solution. Miller Lee Dataflow Analysis
  • 36. The Drawback of Dataflow Analysis We need to keep track of lots of irrelevant details at every program point. We need to consider all the path that the program will execute. Hard to analyze to pointers. Miller Lee Dataflow Analysis