CIS570 Lecture 4 Introduction to Data-flow Analysis 3



Similar documents
Introduction to Data-flow analysis

Static Fairness Criteria in Telecommunications

5.2 The Master Theorem

Computer Networks Framing

Programming Basics - FORTRAN 77

Lecture 2 Introduction to Data Flow Analysis

Sebastián Bravo López

Fixed-income Securities Lecture 2: Basic Terminology and Concepts. Present value (fixed interest rate) Present value (fixed interest rate): the arb

An Enhanced Critical Path Method for Multiple Resource Constraints

Channel Assignment Strategies for Cellular Phone Systems

1.3 Complex Numbers; Quadratic Equations in the Complex Number System*

Chapter 1 Microeconomics of Consumer Theory

User s Guide VISFIT: a computer tool for the measurement of intrinsic viscosities

Computational Analysis of Two Arrangements of a Central Ground-Source Heat Pump System for Residential Buildings

CSE 504: Compiler Design. Data Flow Analysis

A Context-Aware Preference Database System

The Basics of International Trade: A Classroom Experiment

arxiv:astro-ph/ v2 10 Jun 2003 Theory Group, MS 50A-5101 Lawrence Berkeley National Laboratory One Cyclotron Road Berkeley, CA USA

The PageRank Citation Ranking: Bring Order to the Web

cos t sin t sin t cos t

Capacity at Unsignalized Two-Stage Priority Intersections

) ( )( ) ( ) ( )( ) ( ) ( ) (1)

Recovering Articulated Motion with a Hierarchical Factorization Method

WORKFLOW CONTROL-FLOW PATTERNS A Revised View

Improved SOM-Based High-Dimensional Data Visualization Algorithm

THERMAL TO MECHANICAL ENERGY CONVERSION: ENGINES AND REQUIREMENTS Vol. I - Thermodynamic Cycles of Reciprocating and Rotary Engines - R.S.

Classical Electromagnetic Doppler Effect Redefined. Copyright 2014 Joseph A. Rybczyk

Impedance Method for Leak Detection in Zigzag Pipelines

Open and Extensible Business Process Simulator

Performance Analysis of IEEE in Multi-hop Wireless Networks

Behavior Analysis-Based Learning Framework for Host Level Intrusion Detection

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

IEEE TRANSACTIONS ON DEPENDABLE AND SECURE COMPUTING, VOL. 9, NO. 3, MAY/JUNE

Outline. Planning. Search vs. Planning. Search vs. Planning Cont d. Search vs. planning. STRIPS operators Partial-order planning.

Neural network-based Load Balancing and Reactive Power Control by Static VAR Compensator

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

A Three-Hybrid Treatment Method of the Compressor's Characteristic Line in Performance Prediction of Power Systems

Lemon Signaling in Cross-Listings Michal Barzuza*

Intelligent Measurement Processes in 3D Optical Metrology: Producing More Accurate Point Clouds

How To Fator

Revista Brasileira de Ensino de Fsica, vol. 21, no. 4, Dezembro, Surface Charges and Electric Field in a Two-Wire

Electrician'sMathand BasicElectricalFormulas

Trade Information, Not Spectrum: A Novel TV White Space Information Market Model

BUILDING A SPAM FILTER USING NAÏVE BAYES. CIS 391- Intro to AI 1

Henley Business School at Univ of Reading. Pre-Experience Postgraduate Programmes Chartered Institute of Personnel and Development (CIPD)

Data Structure [Question Bank]

Job Creation and Job Destruction over the Life Cycle: The Older Workers in the Spotlight


Fig. 1.1 Rectangular foundation plan.

The Reduced van der Waals Equation of State

Optimal Allocation of Filters against DDoS Attacks

SLA-based Resource Allocation for Software as a Service Provider (SaaS) in Cloud Computing Environments

VOLTAGE CONTROL WITH SHUNT CAPACITANCE ON RADIAL DISTRIBUTION LINE WITH HIGH R/X FACTOR. A Thesis by. Hong-Tuan Nguyen Vu

Comay s Paradox: Do Magnetic Charges Conserve Energy?

From the Invisible Handshake to the Invisible Hand? How Import Competition Changes the Employment Relationship

To Coordinate Or Not To Coordinate? Wide-Area Traffic Management for Data Centers

Petri nets for the verification of Ubiquitous Systems with Transient Secure Association

Context-Sensitive Adjustments of Cognitive Control: Conflict-Adaptation Effects Are Modulated by Processing Demands of the Ongoing Task

protection p1ann1ng report

FOOD FOR THOUGHT Topical Insights from our Subject Matter Experts

Big Data Analysis and Reporting with Decision Tree Induction

Supply chain coordination; A Game Theory approach

Hierarchical Clustering and Sampling Techniques for Network Monitoring

Ranking Community Answers by Modeling Question-Answer Relationships via Analogical Reasoning

AngelCast: Cloud-based Peer-Assisted Live Streaming Using Optimized Multi-Tree Construction

10.1 The Lorentz force law

Marker Tracking and HMD Calibration for a Video-based Augmented Reality Conferencing System

OpenScape 4000 CSTA V7 Connectivity Adapter - CSTA III, Part 2, Version 4.1. Developer s Guide A31003-G9310-I D1

The Goldberg Rao Algorithm for the Maximum Flow Problem

Solving the Game of Awari using Parallel Retrograde Analysis

MATE: MPLS Adaptive Traffic Engineering

Information Security 201

Granular Problem Solving and Software Engineering

To the Graduate Council:

HEAT CONDUCTION. q A q T

Price-based versus quantity-based approaches for stimulating the development of renewable electricity: new insights in an old debate

Analysis of Binary Search algorithm and Selection Sort algorithm

Soft-Edge Flip-flops for Improved Timing Yield: Design and Optimization

Suggested Answers, Problem Set 5 Health Economics

Draft Notes ME 608 Numerical Methods in Heat, Mass, and Momentum Transfer

' R ATIONAL. :::~i:. :'.:::::: RETENTION ':: Compliance with the way you work PRODUCT BRIEF

In order to be able to design beams, we need both moments and shears. 1. Moment a) From direct design method or equivalent frame method

FIRE DETECTION USING AUTONOMOUS AERIAL VEHICLES WITH INFRARED AND VISUAL CAMERAS. J. Ramiro Martínez-de Dios, Luis Merino and Aníbal Ollero

A Robust Optimization Approach to Dynamic Pricing and Inventory Control with no Backorders

Optimal Sales Force Compensation

Scalable Hierarchical Multitask Learning Algorithms for Conversion Optimization in Display Advertising

The Application of Mamdani Fuzzy Model for Auto Zoom Function of a Digital Camera

NASDAQ Commodity Index Methodology

Deliverability on the Interstate Natural Gas Pipeline System

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Transcription:

Introdution to Data-flow Analysis Last Time Control flow analysis BT disussion Today Introdue iterative data-flow analysis Liveness analysis Introdue other useful onepts CIS570 Leture 4 Introdution to Data-flow Analysis Data-flow Analysis Idea Data-flow analysis derives information about the dynami behavior of a program by only examining the stati ode Example How many registers do we need for the program on the right? Easy bound: the number of variables used () Better answer is found by onsidering the dynami requirements of the program L1: b := a + 1 := + b 5 if a < 9 goto L1 CIS570 Leture 4 Introdution to Data-flow Analysis 1

Liveness Analysis Definition A variable is live at a partiular point in the program if its value at that point will be used in the future (dead, otherwise). To ompute liveness at a given point, we need to look into the future Motivation: Register Alloation A program ontains an unbounded number of variables Must exeute on a mahine with a bounded number of registers Two variables an use the same register if they are never in use at the same time (i.e, never simultaneously live). Register alloation uses liveness information CIS570 Leture 4 Introdution to Data-flow Analysis 4 Control Flow Graphs (CFGs) Simplifiation For now, we will use CFG s in whih nodes represent program statements rather than basi bloks Example 1 a = 0 L1: b := a + 1 := + b 5 if a < 9 goto L1 b = a + 1 = + b 4 a = b * 5 a<9 6 return CIS570 Leture 4 Introdution to Data-flow Analysis 5

Liveness by Example What is the live range of b? Variable b is read in statement 4, so b is live on the ( 4) edge Sine statement does not assign into b, b is also live on the ( ) edge Statement assigns b, so any value of b on the (1 ) and (5 ) edges are not needed, so b is dead along these edges b s live range is ( 4) 6 return 1 a = 0 b = a + 1 4 a = b * 5 = + b a<9 CIS570 Leture 4 Introdution to Data-flow Analysis 6 Liveness by Example (ont) Live range of a a is live from (1 ) and again from (4 5 ) a is dead from ( 4) 1 a = 0 b = a + 1 Live range of b b is live from ( 4) Live range of is live from (entry 1 4 5, 5 6) 6 return 5 = + b 4 a = b * a<9 Variables a and b are never simultaneously live, so they an share a register CIS570 Leture 4 Introdution to Data-flow Analysis 7

Terminology Flow Graph Terms A CFG node has out-edges that lead to suessor nodes and in-edges that ome from predeessor nodes pred[n] is the set of all predeessors of node n 1 a = 0 su[n] is the set of all suessors of node n Examples Out-edges of node 5: su[5] = pred[5] = pred[] = {,6} {4} {1,5} (5 6) and (5 ) 6 return 5 b = a + 1 = + b 4 a = b * a<9 CIS570 Leture 4 Introdution to Data-flow Analysis 8 Uses and Defs Def (or definition) An assignment of a value to a variable def[v] = set of CFG nodes that define variable v def[n] = set of variables that are defined at node n a = 0 Use A read of a variable s value use[v] = set of CFG nodes that use variable v use[n] = set of variables that are used at node n a < 9? v live def[v] More preise definition of liveness A variable v is live on a CFG edge if use[v] (1) a direted path from that edge to a use of v (node in use[v]), and () that path does not go through any def of v (no nodes in def[v]) CIS570 Leture 4 Introdution to Data-flow Analysis 9 4

The Flow of Liveness Data-flow Liveness of variables is a property that flows through the edges of the CFG Diretion of Flow Liveness flows bakwards through the CFG, beause the behavior at future nodes determines liveness at a given node Consider a Consider b Later, we ll see other properties that flow forward 4 5 b := a + 1 := + b a := b * a < 9? CIS570 Leture 4 Introdution to Data-flow Analysis 10 Liveness at des edges We have liveness on edges just before omputation How do we talk about a = 0 just after omputation liveness at nodes? Two More Definitions A variable is live-out at a node if it is live on any b of := that a node s + 1 outedges := + b n live-out out-edges 4 a := b * A variable is live-in at a node if it is live on any 5 of that a < node s 9? in-edges n live-in in-edges program points CIS570 Leture 4 Introdution to Data-flow Analysis 11 5

Computing Liveness Rules for omputing liveness (1) Generate liveness: If a variable is in use[n], it is live-in at node n Data-flow equations (1) in[n] = use[n] (out[n] def[n]) () n live-in use () Push liveness aross edges: If a variable is live-in at a node n then it is live-out at all nodes in pred[n] live-out () Push liveness aross nodes: If a variable is live-out at node n and not in def[n] then the variable is also live-in at n live-out n live-in live-out live-in n live-out pred[n] out[n] = in[s] s su[n] () CIS570 Leture 4 Introdution to Data-flow Analysis 1 Solving the Data-flow Equations Algorithm for eah node n in CFG in[n] = ; out[n] = repeat for eah node n in CFG in [n] = in[n] out [n] = out[n] in[n] = use[n] (out[n] def[n]) out[n] = in[s] s su[n] until in [n]=in[n] and out [n]=out[n] for all n initialize solutions save urrent results solve data-flow equations test for onvergene This is iterative data-flow analysis (for liveness analysis) CIS570 Leture 4 Introdution to Data-flow Analysis 1 6

Example node # 1 a a b b 5 a 1st nd rd 4th 5th 6th 7th use def in out in out in out in out in out in out in out 4 b a 6 a b b a a a a b b b b a a a a a b b b b a a a a a b b b b a a a a a b b b b a a a a a b b b b a a a a a b b b b a a a b := a + 1 := + b Data-flow Equations for Liveness in[n] = use[n] (out[n] def[n]) out[n] = in[s] s su[n] CIS570 Leture 4 Introdution to Data-flow Analysis 14 Example (ont) Data-flow Equations for Liveness in[n] = use[n] (out[n] def[n]) out[n] = in[s] s su[n] Improving Performane Consider the ( 4) edge in the graph: out[4] is used to ompute in[4] in[4] is used to ompute out[]... So we should ompute the sets in the order: out[4], in[4], out[], in[],... out[] in[4] out[4] b := a + 1 := + b The order of omputation should follow the diretion of flow CIS570 Leture 4 Introdution to Data-flow Analysis 15 7

Iterating Through the Flow Graph Bakwards node # 1st nd rd use def out in out in out in 6 5 a a a a a a 4 b a a b a b a b b b b b b b b a b b a b a b a 1 a a a a Converges muh faster! b := a + 1 := + b CIS570 Leture 4 Introdution to Data-flow Analysis 16 Solving the Data-flow Equations (reprise) Algorithm for eah node n in CFG in[n] = ; out[n] = repeat for eah node n in CFG in reverse topsort order in [n] = in[n] Save urrent results out [n] = out[n] out[n] = in[s] s su[n] Solve data-flow equations in[n] = use[n] (out[n] def[n]) until in [n]=in[n] and out [n]=out[n] for all n Initialize solutions Test for onvergene CIS570 Leture 4 Introdution to Data-flow Analysis 17 8

Time Complexity Consider a program of size N Has N nodes in the flow graph (and at most N variables) Eah live-in or live-out set has at most N elements Eah set-union operation takes O(N) time The for loop body onstant # of set operations per node O(N) nodes O(N ) time for the loop Eah iteration of the repeat loop an only make the set larger Eah set an ontain at most N variables N iterations Worst ase: O(N 4 ) Typial ase: to iterations with good ordering & sparse sets O(N) to O(N ) CIS570 Leture 4 Introdution to Data-flow Analysis 18 More Performane Considerations Basi bloks Derease the size of the CFG by merging nodes that have a single predeessor and a single suessor into basi bloks 1 a := 0 b := a + 1 (requires loal analysis before and after global := + 1 analysis) a := b * + b a > 9? One variable at a time 4 a := b * Instead of omputing data-flow information return for all variables at one using sets, ompute a (simplified) analysis for eah variable separately Representation of sets For dense sets, use a bit vetor representation For sparse sets, use a sorted list (e.g., linked list) CIS570 Leture 4 Introdution to Data-flow Analysis 19 9

Conservative Approximation node # X Y Z use def in out in out in out 1 a a d ad a a b a b ad bd a b b b b bd bd b b 4 b a b a bd ad b a 5 a a a ad ad a a 6 b := a + 1 := + b Solution X Our solution as omputed on previous slides CIS570 Leture 4 Introdution to Data-flow Analysis 0 Conservative Approximation (ont) node # X Y Z use def in out in out in out 1 a a d ad a a b a b ad bd a b b b b bd bd b b 4 b a b a bd ad b a 5 a a a ad ad a a 6 b := a + 1 := + b Solution Y Carries variable d uselessly around the loop Does Y solve the equations? Is d live? Does Y lead to a orret program? Impreise onservative solutions sub-optimal but orret programs CIS570 Leture 4 Introdution to Data-flow Analysis 1 10

Conservative Approximation (ont) node # X Y Z use def in out in out in out 1 a a d ad a a b a b ad bd a b b b b bd bd b b 4 b a b a bd ad b a 5 a a a ad ad a a 6 b := a + 1 := + b Solution Z Does not identify as live in all ases Does Z solve the equations? Does Z lead to a orret program? n-onservative solutions inorret programs CIS570 Leture 4 Introdution to Data-flow Analysis The Need for Approximations Stati vs. Dynami Liveness In the following graph, b*b is always non-negative, so >= b is always true and a s value will never be used after node 1 a := b * b := a + b >= b? 4 return a 5 return Rule () for omputing liveness Sine a is live-in at node 4, it is live-out at nodes and This rule ignores atual ontrol flow ompiler an statially know all a program s dynami properties! CIS570 Leture 4 Introdution to Data-flow Analysis 11

Conepts Liveness Use in register alloation Generating liveness Flow and diretion Data-flow equations and analysis Complexity Improving performane (basi bloks, single variable, bit sets) Control flow graphs Predeessors and suessors Defs and uses Conservative approximation Stati versus dynami liveness CIS570 Leture 4 Introdution to Data-flow Analysis 4 Next Time Leture Generalizing data-flow analysis CIS570 Leture 4 Introdution to Data-flow Analysis 5 1