Dataflow Analysis Lecture 2. Simple Constant Propagation. A sample program int fib10(void) {
|
|
- Shanna O’Connor’
- 5 years ago
- Views:
Transcription
1 -4 Lecture Dataflow Analysis Basic Blocks Related Optimizations Copyright Seth Copen Goldstein 00 Dataflow Analysis Last time we looked at code transformations Constant propagation Copy propagation Common sub-expression elimination Today, dataflow analysis: How to determine if it is legal to perform such an optimization (Not doing analysis to determine if it is beneficial) Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 A sample program int fib0(void) { } int n = 0; int older = 0; int old = ; intwhat result are = those 0; numbers? int i; if (n <= ) return n; for (i = ; i<n; i++) { result = old + older; older = old; old = result; } return result; A Comment about the IR : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 Simple Constant Propagation Can we do SCP? How do we recognize it? What aren t we doing? Metanote: keep opts simple! Use combined power : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 4
2 Reaching Definitions A definition of variable v at program point d reaches program point u if there exists a path of control flow edges from d to u that does not contain a definition of v : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 Reaching Definitions (ex) reaches,, and 4 reaches 4, Really? 8 Meta-notes: Older in 8 is reached by (almost) always conservative only know what we know Keep 9it simple: What opt(s), if run before this would help Tells What us about: which definitions : x <- 0reach a : if (false) x<- particular use (ud-info) : x Does reach? What opt changes this? : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 6 Calculating Reaching Definitions A definition of variable v at program point d reaches program point u if there exists a path of control flow edges from d to u that does not contain a definition of v. Build up RD stmt by stmt Stmt s, d: v <- x op y, generates d Stmt s, d: v <- x op y, kills all other defs(v) Or, Gen[s] = { d } Kill[s] = defs(v) { d } Lecture -4 Seth Copen Goldstein 00 Gen and kill for each stmt Gen : n <- 0 : older <- 0 9 : old <- 0 4: result < : if n <= goto 4 6: i <- 6 : if i > n goto 8: result <- old + older 8 4 9: older <- old 9 0: old <- result 0 : i <- i + 6 : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 8 kill How can we determine the defs that reach a node? We can use: control flow information gen and kill info
3 In[: Out[: Computing in[ and out[ in[ = out[ = the set of defs that reach the beginning of node n the set of defs that reach the end of node n U p pred[ out[ p] gen[ U ( in[ kill[ ) Initialize in[=out[={} for all n Solve iteratively Lecture -4 Seth Copen Goldstein 00 9 What is pred[? Pred[ are all nodes that can reach n in the control flow graph. E.g., pred[] = { 6, } : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 0 What order to eval nodes? Does it matter? Lets do:,,,4,,4,6,,,8,9,0,, : n <- 0 : older <- 0 : old <- 4: result <- 0 : if n <= goto 4 6: i <- : if i > n goto 8: result <- old + older 9: older <- old 0: old <- result : i <- i + : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00 : Order:,,,4,,4,6,,,8,9,0,, in[ out[ p] = U out[ = gen[ U ( in[ kill[ ) p pred[ Gen kill in out : n <- 0 : older <- 0 9, : old <- 0,, -4 4: result < : if n <= goto 4 6: i <- 6 : if i > n goto 8: result <- old + older 8 4 9: older <- old 9 0: old <- result 0 : i <- i + 6 : JUMP : return result 4: return n Lecture -4 Seth Copen Goldstein 00
4 (pass ) Order:,,,4,,4,6,,,8,9,0,, in[ out[ p] = U out[ = gen[ U ( in[ kill[ ) p pred[ Gen kill in out : n <- 0 : older <- 0 9, : old <- 0,,, 4: result < : if n <= goto : i < ,6 : if i > n goto -4,6-4,6 8: result <- old + older 8 4-4,6 -,6,8 9: older <- old 9 -,6,8,,6,8,9 0: old <- result 0,,6,8,9,6,8-0 : i <- i + 6,6,8-0,8- : JUMP,8-,8- : return result -4,6-4,6 4: return n -4-4 (pass ) Order:,,,4,,4,6,,,8,9,0,, in[ out[ p] = U out[ = gen[ U ( in[ kill[ ) p pred[ Gen kill in out : n <- 0 : older <- 0 9, : old <- 0,,, 4: result < : if n <= goto : i < ,6 : if i > n goto -4,6,8- -4,6,8-8: result <- old + older 8 4-4,6,8- -,6,8-9: older <- old 9 -,6,8-,,6,8-0: old <- result 0,,6,8-,6,8- : i <- i + 6,6,8-,8- : JUMP,8-,8- : return result -4,6-4,6 4: return n -4-4 Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 4 An Improvement: Basic Blocks No need to compute this one stmt at a time For straight line code: In[s; s] = in[s] Out[s; s] = out[s] Can we combine the gen and kill sets into one set per BB? Gen kill Gen[BB]={,,4,} Kill[BB]={,8,} Gen[s;s]= Kill[s;s]= : i <- 8,4 : j <- : k <- + i 4: i <- j 4,8 : m <- i + k Lecture -4 Seth Copen Goldstein BB sets Gen : n <- 0 : older <- 0 9 : old <- 0 4: result < : if n <= goto 4,,,4 8,9,0 6: i <- 6 6 : if i > n goto 8: result <- old + older 8 4 9: older <- old 9 0: old <- result 0 : i <- i + 6 : JUMP 8- -4,6 : return result 4: return n Lecture -4 Seth Copen Goldstein 00 6 kill
5 BB sets BB sets Gen={,,,4} Kill={8,9,0} In out,,,4 Gen={,,,4} Kill={8,9,0} In out,,,4 Gen={6} Kill={} Gen={6} Kill={},,,4,,,4, ,6,8- -4,6,8-6 Gen={8,9,0,} Kill={,,4,6} Gen={8,9,0,} Kill={,,4,6} 6-4,6,8-,8- Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 8 Forward Dataflow Reaching definitions is a forward dataflow problem: It propgates information from preds of a node to the node Defined by: Basic attributes: (gen and kill) Transfer function: out[b]=f bb (in[b]) Meet operator: in[b]=m(out[p]) for all p pred(b) Set of values (a lattice, in this case powerset of program points) Initial values for each node b Solve for fixed point solution How to implement? Values? Gen? Kill? F bb? Order to visit nodes? When are we done? In fact, do we know we terminate? Lecture -4 Seth Copen Goldstein 00 9 Lecture -4 Seth Copen Goldstein 00 0
6 Implementing RD Values: bits in a bit vector Gen: in each position generated, otherwise 0 Kill: 0 in each position killed, otherwise F bb : out[b] = (in[b] gen[b]) & kill[b] Init in[b]=out[b]=0 When are we done? What order to visit nodes? Does it matter? RD Worklist algorithm Initialize: in[b] = out[b] = Initialize: in[entry] = Work queue, W = all Blocks in topological order while ( W!= 0) { remove b from W old = out[b] in[b] = {over all pred(p) b} out[p] out[b] = gen[b] (in[b] - kill[b]) } if (old!= out[b]) W = W succ(b) Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 Storing Rd information Def-use chains are valuable too Use-def chains: for each use of var x in s, a list of definitions of x that reach s : n <- 0 : older <- 0, : old <-,,, 4: result < : if n <= goto : i <- -4-4,6 : if i > n goto -4,6,8- -4,6,8-8: result <- old + older -4,6,8- -,6,8-9: older <- old -,6,8-,,6,8-0: old <- result,,6,8-,6,8- : i <- i +,6,8-,8- : JUMP,8-,8- : return result -4,6-4,6 4: return n -4-4 Lecture -4 Seth Copen Goldstein 00 Def-use chain: for each definition of var x, a list of all uses of that definition Computed from liveness analysis, a backward dataflow problem Def-use is NOT symmetric to use-def z > x <- z > y x <- y <- x + z <- x + Lecture -4 Seth Copen Goldstein 00 4
7 Using RD for Simple Const. Prop. : n <- 0 : older <- 0, : old <-,,, 4: result < : if n <= goto : i <- -4-4,6 : if i > n goto -4,6,8- -4,6,8-8: result <- old + older -4,6,8- -,6,8-9: older <- old -,6,8-,,6,8-0: old <- result,,6,8-,6,8- : i <- i +,6,8-,8- : JUMP,8-,8- : return result -4,6-4,6 4: return n -4-4 Better Constant Propagation What about: x <- if (y > z) x <- a <- x Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 6 Better Constant Propagation Loop Invariant Code Motion What about: x <- if (y > z) x <- a <- x Use a better lattice -inf inf When can expression be moved out of a loop? x <- y + z Meet: a <- a top bot <- a bot c <- c c bot <- c d ( if c d) Init all vars to: bot or top? a <-.. x.. Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 8
8 Loop Invariant Code Motion Liveness (def-use chains) When can expression be moved out of a loop? When all reaching definitions of operands are outside of loop, expression is loop invariant Use ud-chains to detect Can du-chains be helpful? x <- y + z a <-.. x.. A variable x is live-out of a stmt s if x can be used along some path starting a s, otherwise x is dead. Why is this important? How can we frame this as a dataflow problem? Lecture -4 Seth Copen Goldstein 00 9 Lecture -4 Seth Copen Goldstein 00 0 Liveness as a dataflow problem Dead Code Elimination This is a backwards analysis A variable is live out if used by a successor Gen: For a use: indicate it is live coming into s Kill: Defining a variable v in s makes it dead before s (unless s uses v to define v) Lattice is just live (top) and dead (bottom) Values are variables In[ = variables live before n = out[ kill[ gen[ Out[ = variables live after n = U In[ s] Code is dead if it has no effect on the outcome of the program. When is code dead? s succ( n) Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00
9 Dead Code Elimination When can we do CSE? Code is dead if it has no effect on the outcome of the program. When is code dead? When the definition is dead, and When the instruction has no side effects So: run liveness Construct def-use chains Any instruction which has no users and has no side effects can be eliminated? a <- 4 + i b <- 4 + i Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 4 Available Expressions X+Y is available at statement S if x+y is computed along every path from the start to S AND neither x nor y is modified after the last evaluation of x+y a <- b+c b <- a-d c <- b+c Computing Available Expressions Forward or backward? Values? Lattice? gen[b] = kill[b] = in[b] = out[b] = initialization? d <- a-d Lecture -4 Seth Copen Goldstein 00 Lecture -4 Seth Copen Goldstein 00 6
10 Computing Available Expressions Forward Values: all expressions Lattice: available, not-avail gen[b] = if b evals expr e and doesn t define variables used in e kill[b] = if b assigns to x, then all exprs using x are killed. out[b] = in[b] kill[b] gen[b] in[b] = what to do at a join point? initialization? Lecture -4 Seth Copen Goldstein 00 Computing Available Expressions Forward Values: all expressions Lattice: available, not-avail gen[b] = if b evals expr e and doesn t define variables used in e kill[b] = if b assigns to x, exprs(x) are killed out[b] = in[b] kill[b] gen[b] in[b] = An expr is avail only if avail on ALL edges, so: in[b] = over all p pred(b), out[p] Initialization All nodes, but entry are set to ALL avail is set to NONE avail Lecture -4 Seth Copen Goldstein 00 8 Constructing Gen & Kill Constructing Gen & Kill Stmt Gen Kill Stmt Gen Kill t <- x op y {x op y}-kill[s] {exprs containing t} t <- x op y {x op y}-kill[s] {exprs containing t} t <- M[a] {M[a]}-kill[s] t <- M[a] {M[a]}-kill[s] {exprs containing t} M[a] <- b M[a] <- b {} {for all x, M[x]} f(a, ) {M[x] for all x} f(a, ) {} {for all x, M[x]} t <- f(a, ) t <- f(a, ) {} {exprs containing t for all x, M[x]} Lecture -4 Seth Copen Goldstein 00 9 Lecture -4 Seth Copen Goldstein 00 40
11 i <- c <- c* i <- c <- c* Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} g[i] <- a*c g[i] <- d*d g[i] <- a*c Gen={a*c} g[i] <- d*d Gen={d*d} i <- i+ br i>0 i <- i+ br i>0 Gen={i>0} Kill={i+} Lecture -4 Seth Copen Goldstein 00 4 Lecture -4 Seth Copen Goldstein 00 4 W={} In={} out={} out={a+b, a*c, d*d, c>d, c*, i>0, i+} out={a+b,a*c,d*d,c>d,c*,i>0,i+} out={a+b,a*c,d*d,c>d,c*,i>0,i+} i <- c <- c* 4Gen={a*c} g[i] <- a*c g[i] <- d*d out={a+b,a*c,d*d,c>d,c*,i>0,i+} i <- i+ 6 br i>0 Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} Gen={i>0} Kill={i+} Gen={d*d} Lecture -4 Seth Copen Goldstein 00 4 W={} out={a+b, a*c, d*d} In={} out={} out={a+b,a*c,d*d,c>d,c*,i>0,i+} out={a+b,a*c,d*d,c>d,c*,i>0,i+} i <- c <- c* 4Gen={a*c} g[i] <- a*c g[i] <- d*d out={a+b,a*c,d*d,c>d,c*,i>0,i+} i <- i+ 6 br i>0 Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} Gen={i>0} Kill={i+} Gen={d*d} Lecture -4 Seth Copen Goldstein 00 44
12 W={6} out={a+b, a*c, d*d} In={} out={} in={a+b, a*c, d*d} i <- c <- c* Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} 4Gen={a*c} g[i] <- a*c Gen={d*d} g[i] <- d*d out={a+b, d*d, c>d, a*c} i <- i+ 6 Gen={i>0} br i>0 out={a+b,a*c,d*d,c>d,c*,i>0,i+} Kill={i+} Lecture -4 Seth Copen Goldstein 00 4 W={,} out={a+b, a*c, d*d} In={} out={} in={a+b, a*c, d*d} i <- c <- c* Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} 4Gen={a*c} g[i] <- a*c Gen={d*d} g[i] <- d*d out={a+b, d*d, c>d, a*c} i <- i+ 6 Gen={i>0} br i>0 out={a+b, d*d, c>d, i>0} Kill={i+} Lecture -4 Seth Copen Goldstein W={} out={a+b, a*c, d*d} in={a+b, d*d} In={} out={} i <- c <- c* Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} 4Gen={a*c} g[i] <- a*c Gen={d*d} g[i] <- d*d out={a+b, d*d, c>d, a*c} i <- i+ 6 Gen={i>0} br i>0 out={a+b, d*d, c>d, i>0} Kill={i+} Lecture -4 Seth Copen Goldstein 00 4 CSE Calculate Available expressions For every stmt in program If expression, x op y, is available { Compute reaching expressions for x op y at this stmt foreach stmt in RE of the form t <- x op y rewrite at: t <- x op y t <- t } replace x op y in stmt with t } Lecture -4 Seth Copen Goldstein 00 48
13 W={} out={a+b, a*c, d*d} in={a+b, d*d} In={} out={} i <- c <- c* Gen={a+b,a*c,d*d} Kill={c>d,c*,i>0,i+} Gen={a+b,c>d} Kill={c*,M[x],a*c} 4Gen={a*c} g[i] <- a*c Gen={d*d} g[i] <- d*d out={a+b, d*d, c>d, a*c} i <- i+ 6 Gen={i>0} br i>0 out={a+b, d*d, c>d, i>0} Kill={i+} Lecture -4 Seth Copen Goldstein Calculating RE Could be dataflow problem, but not needed enough, so To find RE for x op y at stmt S traverse cfg backward from S until reach t <- x + y (& put into RE) reach definition of x or y Lecture -4 Seth Copen Goldstein 00 0 i <- f[i] <- t ;a+b c <- c* 4 g[i] <- a*c g[i] <- t ; d*d t <- a+b c <- t t <- d*d e <- t Forward Backward Dataflow Summary Union Reaching defs Live variables intersection Available exprs i <- i+ 6 br i>0 Lecture -4 Seth Copen Goldstein 00 Later in course we look at bidirectional dataflow Lecture -4 Seth Copen Goldstein 00
14 Dataflow Framework Lattice Universe of values Meet operator Basic attributes (e.g., gen, kill) Traversal order Transfer function Lecture -4 Seth Copen Goldstein 00
Dataflow Analysis. A sample program int fib10(void) { int n = 10; int older = 0; int old = 1; Simple Constant Propagation
-74 Lecture 2 Dataflow Analysis Basic Blocks Related Optimizations SSA Copyright Seth Copen Goldstein 200-8 Dataflow Analysis Last time we looked at code transformations Constant propagation Copy propagation
More informationLecture 5 Introduction to Data Flow Analysis
Lecture 5 Introduction to Data Flow Analysis I. Structure of data flow analysis II. III. IV. Example 1: Reaching definition analysis Example 2: Liveness analysis Framework Phillip B. Gibbons 15-745: Intro
More informationCompiler Design. Data Flow Analysis. Hwansoo Han
Compiler Design Data Flow Analysis Hwansoo Han Control Flow Graph What is CFG? Represents program structure for internal use of compilers Used in various program analyses Generated from AST or a sequential
More informationTopic-I-C Dataflow Analysis
Topic-I-C Dataflow Analysis 2012/3/2 \course\cpeg421-08s\topic4-a.ppt 1 Global Dataflow Analysis Motivation We need to know variable def and use information between basic blocks for: constant folding dead-code
More information(b). Identify all basic blocks in your three address code. B1: 1; B2: 2; B3: 3,4,5,6; B4: 7,8,9; B5: 10; B6: 11; B7: 12,13,14; B8: 15;
(a). Translate the program into three address code as defined in Section 6.2, dragon book. (1) i := 2 (2) if i > n goto (7) (3) a[i] := TRUE (4) t2 := i+1 (5) i := t2 (6) goto (2) (7) count := 0 (8) s
More informationLecture 4 Introduc-on to Data Flow Analysis
Lecture 4 Introduc-on to Data Flow Analysis I. Structure of data flow analysis II. Example 1: Reaching defini?on analysis III. Example 2: Liveness analysis IV. Generaliza?on 15-745: Intro to Data Flow
More informationData flow analysis. DataFlow analysis
Data flow analysis DataFlow analysis compile time reasoning about the runtime flow of values in the program represent facts about runtime behavior represent effect of executing each basic block propagate
More informationCMSC 631 Program Analysis and Understanding. Spring Data Flow Analysis
CMSC 631 Program Analysis and Understanding Spring 2013 Data Flow Analysis Data Flow Analysis A framework for proving facts about programs Reasons about lots of little facts Little or no interaction between
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 8.6 Live variables Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Last lecture Definition: A variable V is live at point P if there is a path
More informationGeneralizing Data-flow Analysis
Generalizing Data-flow Analysis Announcements PA1 grades have been posted Today Other types of data-flow analysis Reaching definitions, available expressions, reaching constants Abstracting data-flow analysis
More informationData Flow Analysis (I)
Compiler Design Data Flow Analysis (I) Hwansoo Han Control Flow Graph What is CFG? Represents program structure for internal use of compilers Used in various program analyses Generated from AST or a sequential
More informationData-Flow Analysis. Compiler Design CSE 504. Preliminaries
Data-Flow Analysis Compiler Design CSE 504 1 Preliminaries 2 Live Variables 3 Data Flow Equations 4 Other Analyses Last modifled: Thu May 02 2013 at 09:01:11 EDT Version: 1.3 15:28:44 2015/01/25 Compiled
More information3/11/18. Final Code Generation and Code Optimization
Final Code Generation and Code Optimization 1 2 3 for ( i=0; i < N; i++) { base = &a[0]; crt = *(base + i); } original code base = &a[0]; for ( i=0; i < N; i++) { crt = *(base + i); } optimized code e1
More informationAdventures in Dataflow Analysis
Adventures in Dataflow Analysis CSE 401 Section 9-ish Jack Eggleston, Aaron Johnston, & Nate Yazdani Announcements - Code Generation due Announcements - Code Generation due - Compiler Additions due next
More informationWe define a dataflow framework. A dataflow framework consists of:
So far been talking about various dataflow problems (e.g. reaching definitions, live variable analysis) in very informal terms. Now we will discuss a more fundamental approach to handle many of the dataflow
More informationDataflow analysis. Theory and Applications. cs6463 1
Dataflow analysis Theory and Applications cs6463 1 Control-flow graph Graphical representation of runtime control-flow paths Nodes of graph: basic blocks (straight-line computations) Edges of graph: flows
More informationCSC D70: Compiler Optimization Dataflow-2 and Loops
CSC D70: Compiler Optimization Dataflow-2 and Loops Prof. Gennady Pekhimenko University of Toronto Winter 2018 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip Gibbons
More informationMonotone Data Flow Analysis Framework
Monotone Data Flow Analysis Framework Definition. A relation R on a set S is (a) reflexive iff ( x S)[xRx], (b) antisymmetric iff [xry yrx x=y] (c) transitive iff ( x,y,z S) [xry yrz xrz] Definition. A
More informationScalar Optimisation Part 2
Scalar Optimisation Part 2 Michael O Boyle January 2014 1 Course Structure L1 Introduction and Recap 4-5 lectures on classical optimisation 2 lectures on scalar optimisation Last lecture on redundant expressions
More information: Compiler Design. 9.5 Live variables 9.6 Available expressions. Thomas R. Gross. Computer Science Department ETH Zurich, Switzerland
252-210: Compiler Design 9.5 Live variables 9.6 Available expressions Thomas R. Gross Computer Science Department ETH Zurich, Switzerland Outline Warp up reaching definifons Live variables Available expressions
More informationCSC D70: Compiler Optimization Static Single Assignment (SSA)
CSC D70: Compiler Optimization Static Single Assignment (SSA) Prof. Gennady Pekhimenko University of Toronto Winter 08 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip
More informationData Flow Analysis. Lecture 6 ECS 240. ECS 240 Data Flow Analysis 1
Data Flow Analysis Lecture 6 ECS 240 ECS 240 Data Flow Analysis 1 The Plan Introduce a few example analyses Generalize to see the underlying theory Discuss some more advanced issues ECS 240 Data Flow Analysis
More informationLecture 10: Data Flow Analysis II
CS 515 Programming Language and Compilers I Lecture 10: Data Flow Analysis II (The lectures are based on the slides copyrighted by Keith Cooper and Linda Torczon from Rice University.) Zheng (Eddy) Zhang
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 8.5 Reaching definitions Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Admin issues Brief reminder: Code review takes place today @ 15:15 You
More informationDepartment of Computer Science and Engineering, IIT Kanpur, INDIA. Code Optimization. Sanjeev K Aggarwal Code Optimization 1 of I
Code Optimization Sanjeev K Aggarwal Code Optimization 1 of 23 2007-08-I Code Optimization int a,b,c,d ldw a,r1 add r1,r2,r3 c = a+b ldw b,r2 add r3,1,r4 d = c+1 add r1,r2,r3 stw r3,c ldw c,r3 add r3,1,r4
More informationDataflow Analysis. Chapter 9, Section 9.2, 9.3, 9.4
Dataflow Analysis Chapter 9, Section 9.2, 9.3, 9.4 2 Dataflow Analysis Dataflow analysis is a sub area of static program analysis Used in the compiler back end for optimizations of three address code and
More informationDataflow Analysis. Dragon book, Chapter 9, Section 9.2, 9.3, 9.4
Dataflow Analysis Dragon book, Chapter 9, Section 9.2, 9.3, 9.4 2 Dataflow Analysis Dataflow analysis is a sub-area of static program analysis Used in the compiler back end for optimizations of three-address
More informationMIT Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Foundations of Dataflow Analysis Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Dataflow Analysis Compile-Time Reasoning About Run-Time Values of Variables
More informationStatic Program Analysis
Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem
More informationThe Meet-Over-All-Paths Solution to Data-Flow Problems
The Meet-Over-All-Paths Solution to Data-Flow Problems Consider a monotone dataflow framework (L,,F). Assume that the functions f B F represent the effect of a basic block on the sets conatining data for
More informationReading: Chapter 9.3. Carnegie Mellon
I II Lecture 3 Foundation of Data Flow Analysis Semi-lattice (set of values, meet operator) Transfer functions III Correctness, precision and convergence IV Meaning of Data Flow Solution Reading: Chapter
More informationWhat is SSA? each assignment to a variable is given a unique name all of the uses reached by that assignment are renamed
Another Form of Data-Flow Analysis Propagation of values for a variable reference, where is the value produced? for a variable definition, where is the value consumed? Possible answers reaching definitions,
More informationLecture 11: Data Flow Analysis III
CS 515 Programming Language and Compilers I Lecture 11: Data Flow Analysis III (The lectures are based on the slides copyrighted by Keith Cooper and Linda Torczon from Rice University.) Zheng (Eddy) Zhang
More informationIntroduction to data-flow analysis. Data-flow analysis. Control-flow graphs. Data-flow analysis. Example: liveness. Requirements
Data-flow analysis Michel Schinz based on material by Erik Stenman and Michael Schwartzbach Introduction to data-flow analysis Data-flow analysis Example: liveness Data-flow analysis is a global analysis
More informationScalar Optimisation Part 1
calar Optimisation Part 1 Michael O Boyle January, 2014 1 Course tructure L1 Introduction and Recap 4/5 lectures on classical optimisation 2 lectures on scalar optimisation Today example optimisations
More informationDataflow Analysis - 2. Monotone Dataflow Frameworks
Dataflow Analysis - 2 Monotone dataflow frameworks Definition Convergence Safety Relation of MOP to MFP Constant propagation Categorization of dataflow problems DataflowAnalysis 2, Sp06 BGRyder 1 Monotone
More informationStatic Analysis of Programs: A Heap-Centric View
Static Analysis of Programs: A Heap-Centric View (www.cse.iitb.ac.in/ uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay 5 April 2008 Part 1 Introduction ETAPS
More informationMIT Loop Optimizations. Martin Rinard
MIT 6.035 Loop Optimizations Martin Rinard Loop Optimizations Important because lots of computation occurs in loops We will study two optimizations Loop-invariant code motion Induction variable elimination
More informationComputing Static Single Assignment (SSA) Form
Computing Static Single Assignment (SSA) Form Overview What is SSA? Advantages of SSA over use-def chains Flavors of SSA Dominance frontiers revisited Inserting φ-nodes Renaming the variables Translating
More informationAST rewriting. Part I: Specifying Transformations. Imperative object programs. The need for path queries. fromentry, paths, toexit.
Part I: Specifying Transformations Oege de Moor Ganesh Sittampalam Programming Tools Group, Oxford focus AST rewriting To apply rule: rewrite(pat 0, pat 1 ) Match: focus = φ(pat 0 ) Replace: focus := φ(pat
More informationLecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation
1 Lecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation [Chapter 9] 2 SSA Revisited It is desirable to use
More informationCS 553 Compiler Construction Fall 2006 Homework #2 Dominators, Loops, SSA, and Value Numbering
CS 553 Compiler Construction Fall 2006 Homework #2 Dominators, Loops, SSA, and Value Numbering Answers Write your answers on another sheet of paper. Homework assignments are to be completed individually.
More informationLesson 3-1: Solving Linear Systems by Graphing
For the past several weeks we ve been working with linear equations. We ve learned how to graph them and the three main forms they can take. Today we re going to begin considering what happens when we
More informationGoal. Partially-ordered set. Game plan 2/2/2013. Solving fixpoint equations
Goal Solving fixpoint equations Many problems in programming languages can be formulated as the solution of a set of mutually recursive equations: D: set, f,g:dxd D x = f(x,y) y = g(x,y) Examples Parsing:
More informationCSE P 501 Compilers. Value Numbering & Op;miza;ons Hal Perkins Winter UW CSE P 501 Winter 2016 S-1
CSE P 501 Compilers Value Numbering & Op;miza;ons Hal Perkins Winter 2016 UW CSE P 501 Winter 2016 S-1 Agenda Op;miza;on (Review) Goals Scope: local, superlocal, regional, global (intraprocedural), interprocedural
More informationIterative Dataflow Analysis
Iterative Dataflow Analysis CS 352 9/24/07 Slides adapted from Nielson, Nielson, Hankin Principles of Program Analysis Key Ideas Need a mechanism to evaluate (statically) statements in a program Problem:
More informationOptimizing Finite Automata
Optimizing Finite Automata We can improve the DFA created by MakeDeterministic. Sometimes a DFA will have more states than necessary. For every DFA there is a unique smallest equivalent DFA (fewest states
More informationRegister Allocation. Maryam Siahbani CMPT 379 4/5/2016 1
Register Allocation Maryam Siahbani CMPT 379 4/5/2016 1 Register Allocation Intermediate code uses unlimited temporaries Simplifying code generation and optimization Complicates final translation to assembly
More informationAlgebra 1. Predicting Patterns & Examining Experiments. Unit 5: Changing on a Plane Section 4: Try Without Angles
Section 4 Examines triangles in the coordinate plane, we will mention slope, but not angles (we will visit angles in Unit 6). Students will need to know the definition of collinear, isosceles, and congruent...
More informationLecture Notes: Program Analysis Correctness
Lecture Notes: Program Analysis Correctness 15-819O: Program Analysis Jonathan Aldrich jonathan.aldrich@cs.cmu.edu Lecture 5 1 Termination As we think about the correctness of program analysis, let us
More informationMechanics of Static Analysis
Escuela 03 III / 1 Mechanics of Static Analysis David Schmidt Kansas State University www.cis.ksu.edu/~schmidt Escuela 03 III / 2 Outline 1. Small-step semantics: trace generation 2. State generation and
More informationModel Checking & Program Analysis
Model Checking & Program Analysis Markus Müller-Olm Dortmund University Overview Introduction Model Checking Flow Analysis Some Links between MC and FA Conclusion Apology for not giving proper credit to
More informationToday s class. Numerical differentiation Roots of equation Bracketing methods. Numerical Methods, Fall 2011 Lecture 4. Prof. Jinbo Bi CSE, UConn
Today s class Numerical differentiation Roots of equation Bracketing methods 1 Numerical Differentiation Finite divided difference First forward difference First backward difference Lecture 3 2 Numerical
More informationProbabilistic Model Checking and [Program] Analysis (CO469)
Probabilistic Model Checking and [Program] Analysis (CO469) Program Analysis Herbert Wiklicky herbert@doc.ic.ac.uk Spring 208 / 64 Overview Topics we will cover in this part will include:. Language WHILE
More informationClass 5. Review; questions. Data-flow Analysis Review. Slicing overview Problem Set 2: due 9/3/09 Problem Set 3: due 9/8/09
Class 5 Review; questions Assign (see Schedule for links) Slicing overview Problem Set 2: due 9/3/09 Problem Set 3: due 9/8/09 1 Data-flow Analysis Review Start at slide 21 of Basic Analysis 3 1 Static
More informationCS 373: Theory of Computation. Fall 2010
CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1 1 Normal Forms for CFG Normal Forms for Grammars It is typically easier to work with a context free language if given a CFG in a normal
More informationCS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018
CS 301 Lecture 18 Decidable languages Stephen Checkoway April 2, 2018 1 / 26 Decidable language Recall, a language A is decidable if there is some TM M that 1 recognizes A (i.e., L(M) = A), and 2 halts
More informationWorst-Case Execution Time Analysis. LS 12, TU Dortmund
Worst-Case Execution Time Analysis Prof. Dr. Jian-Jia Chen LS 12, TU Dortmund 02, 03 May 2016 Prof. Dr. Jian-Jia Chen (LS 12, TU Dortmund) 1 / 53 Most Essential Assumptions for Real-Time Systems Upper
More informationComputational Boolean Algebra. Pingqiang Zhou ShanghaiTech University
Computational Boolean Algebra Pingqiang Zhou ShanghaiTech University Announcements Written assignment #1 is out. Due: March 24 th, in class. Programming assignment #1 is out. Due: March 24 th, 11:59PM.
More informationAbstract Interpretation II
Abstract Interpretation II Semantics and Application to Program Verification Antoine Miné École normale supérieure, Paris year 2015 2016 Course 11 13 May 2016 Course 11 Abstract Interpretation II Antoine
More informationACS2: Decidability Decidability
Decidability Bernhard Nebel and Christian Becker-Asano 1 Overview An investigation into the solvable/decidable Decidable languages The halting problem (undecidable) 2 Decidable problems? Acceptance problem
More informationDFA of non-distributive properties
DFA of non-distributive properties The general pattern of Dataflow Analysis GA (p)= i if p E { GA (q) q F } otherwise GA (p)= f p ( GA (p) ) where : E is the set of initial/final points of the control-flow
More informationChapter 2 Linear Equations and Inequalities in One Variable
Chapter 2 Linear Equations and Inequalities in One Variable Section 2.1: Linear Equations in One Variable Section 2.3: Solving Formulas Section 2.5: Linear Inequalities in One Variable Section 2.6: Compound
More informationTopics on Compilers
Assignment 2 4541.775 Topics on Compilers Sample Solution 1. Test for dependences on S. Write down the subscripts. Which positions are separable, which are coupled? Which dependence test would you apply
More informationProgram Analysis. Lecture 5. Rayna Dimitrova WS 2016/2017
Program Analysis Lecture 5 Rayna Dimitrova WS 2016/2017 2/21 Recap: Constant propagation analysis Goal: For each program point, determine whether a variale has a constant value whenever an execution reaches
More informationNotes for Comp 497 (454) Week 10
Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free
More informationDO i 1 = L 1, U 1 DO i 2 = L 2, U 2... DO i n = L n, U n. S 1 A(f 1 (i 1,...,i, n ),...,f, m (i 1,...,i, n )) =...
15-745 Lecture 7 Data Dependence in Loops 2 Complex spaces Delta Test Merging vectors Copyright Seth Goldstein, 2008-9 Based on slides from Allen&Kennedy 1 The General Problem S 1 A(f 1 (i 1,,i n ),,f
More informationCS357: CTL Model Checking (two lectures worth) David Dill
CS357: CTL Model Checking (two lectures worth) David Dill 1 CTL CTL = Computation Tree Logic It is a propositional temporal logic temporal logic extended to properties of events over time. CTL is a branching
More informationSparse Analysis of Variable Path Predicates Based Upon SSA-Form
Sparse Analysis of Variable Path Predicates Based Upon SSA-Form Thomas S. Heinze and Wolfram Amme Institute of Computer Science, Friedrich Schiller University Jena, Germany {t.heinze,wolfram.amme}@uni-jena.de
More informationIntra-procedural Data Flow Analysis Backwards analyses
Live variables Dead code elimination Very Busy Expressions Code hoisting Bitvector frameworks Monotone frameworks Intra-procedural Data Flow Analysis Backwards analyses Hanne Riis Nielson and Flemming
More informationDO i 1 = L 1, U 1 DO i 2 = L 2, U 2... DO i n = L n, U n. S 1 A(f 1 (i 1,...,i, n ),...,f, m (i 1,...,i, n )) =...
15-745 Lecture 7 Data Dependence in Loops 2 Delta Test Merging vectors Copyright Seth Goldstein, 2008 The General Problem S 1 A(f 1 (i 1,,i n ),,f m (i 1,,i n )) = S 2 = A(g 1 (i 1,,i n ),,g m (i 1,,i
More informationEDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach
EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types
More informationSoftware Verification
Software Verification Grégoire Sutre LaBRI, University of Bordeaux, CNRS, France Summer School on Verification Technology, Systems & Applications September 2008 Grégoire Sutre Software Verification VTSA
More informationThe Reachability-Bound Problem. Gulwani and Zuleger PLDI 10
The Reachability-Bound Problem Gulwani and Zuleger PLDI 10 CS252r Spring 2011 The Reachability-Bound problem Find a symbolic worst case bound on the number of times a program point is reached Intra-procedural:
More informationProgram verification
Program verification Data-flow analyses, numerical domains Laure Gonnord and David Monniaux University of Lyon / LIP September 29, 2015 1 / 75 Context Program Verification / Code generation: Variables
More informationcs/ee/ids 143 Communication Networks
cs/ee/ids 143 Communication Networks Chapter 5 Routing Text: Walrand & Parakh, 2010 Steven Low CMS, EE, Caltech Warning These notes are not self-contained, probably not understandable, unless you also
More informationINF5390 Kunstig intelligens. Logical Agents. Roar Fjellheim
INF5390 Kunstig intelligens Logical Agents Roar Fjellheim Outline Knowledge-based agents The Wumpus world Knowledge representation Logical reasoning Propositional logic Wumpus agent Summary AIMA Chapter
More informationNotes for Comp 497 (Comp 454) Week 10 4/5/05
Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability
More informationCS 4100 // artificial intelligence. Recap/midterm review!
CS 4100 // artificial intelligence instructor: byron wallace Recap/midterm review! Attribution: many of these slides are modified versions of those distributed with the UC Berkeley CS188 materials Thanks
More informationSyntax Analysis, VI Examples from LR Parsing. Comp 412
COMP 412 FALL 2017 Syntax Analysis, VI Examples from LR Parsing Comp 412 source code IR IR target code Front End Optimizer Back End Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved.
More informationChapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 6.8 Shortest Paths Shortest Paths Shortest path problem. Given a directed graph G = (V,
More informationCSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015 Today Registration should be done. Homework 1 due 11:59pm next Wednesday, April 8 th. Review math
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 21 Single-Source Shortest Paths Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Single-Source
More informationSyntax Analysis, VII The Canonical LR(1) Table Construction. Comp 412
COMP 412 FALL 2018 Syntax Analysis, VII The Canonical LR(1) Table Construction Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights
More informationCS415 Compilers Syntax Analysis Top-down Parsing
CS415 Compilers Syntax Analysis Top-down Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Announcements Midterm on Thursday, March 13
More informationSaturday, April 23, Dependence Analysis
Dependence Analysis Motivating question Can the loops on the right be run in parallel? i.e., can different processors run different iterations in parallel? What needs to be true for a loop to be parallelizable?
More informationPath Testing and Test Coverage. Chapter 9
Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test
More informationRegister machines L2 18
Register machines L2 18 Algorithms, informally L2 19 No precise definition of algorithm at the time Hilbert posed the Entscheidungsproblem, just examples. Common features of the examples: finite description
More informationRegister Alloca.on. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class
Register Alloca.on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class 1 Register Alloca.on Intermediate code uses unlimited temporaries Simplifying code genera.on and op.miza.on
More informationCSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits
CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits Chris Calabro January 13, 2016 1 RAM model There are many possible, roughly equivalent RAM models. Below we will define one in the fashion
More informationReduced Ordered Binary Decision Diagrams
Reduced Ordered Binary Decision Diagrams Lecture #13 of Advanced Model Checking Joost-Pieter Katoen Lehrstuhl 2: Software Modeling & Verification E-mail: katoen@cs.rwth-aachen.de June 5, 2012 c JPK Switching
More informationPath Testing and Test Coverage. Chapter 9
Path Testing and Test Coverage Chapter 9 Structural Testing Also known as glass/white/open box testing Structural testing is based on using specific knowledge of the program source text to define test
More information6.001 Recitation 22: Streams
6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris
More informationExact Inference I. Mark Peot. In this lecture we will look at issues associated with exact inference. = =
Exact Inference I Mark Peot In this lecture we will look at issues associated with exact inference 10 Queries The objective of probabilistic inference is to compute a joint distribution of a set of query
More informationMathematics 220 Midterm Practice problems from old exams Page 1 of 8
Mathematics 220 Midterm Practice problems from old exams Page 1 of 8 1. (a) Write the converse, contrapositive and negation of the following statement: For every integer n, if n is divisible by 3 then
More informationSHORTEST PATHS READINGS? CHAPTER 28. Lecture 20 CS2110 Spring 2016
1 SHORTEST PATHS READINGS? CHAPTER 28 Lecture 20 CS2110 Spring 2016 About A6 2 We give you class ArrayHeaps for a reason: It shows the simplest way to write methods like bubble-up and bubble-down. It gives
More informationCOMP2111 Glossary. Kai Engelhardt. Contents. 1 Symbols. 1 Symbols 1. 2 Hoare Logic 3. 3 Refinement Calculus 5. rational numbers Q, real numbers R.
COMP2111 Glossary Kai Engelhardt Revision: 1.3, May 18, 2018 Contents 1 Symbols 1 2 Hoare Logic 3 3 Refinement Calculus 5 1 Symbols Booleans B = {false, true}, natural numbers N = {0, 1, 2,...}, integers
More informationCS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)
CS5371 Theory of Computation Lecture 18: Complexity III (Two Classes: P and NP) Objectives Define what is the class P Examples of languages in P Define what is the class NP Examples of languages in NP
More informationCausal Dataflow Analysis for Concurrent Programs
Causal Dataflow Analysis for Concurrent Programs Azadeh Farzan P. Madhusudan Department of Computer Science, University of Illinois at Urbana-Champaign. {afarzan,madhu}@cs.uiuc.edu Abstract. We define
More information(a) Definition of TMs. First Problem of URMs
Sec. 4: Turing Machines First Problem of URMs (a) Definition of the Turing Machine. (b) URM computable functions are Turing computable. (c) Undecidability of the Turing Halting Problem That incrementing
More information