Unformatted text preview:

359CS 701 Fall 2008©Very Busy ExpressionsThis is an interesting variant ofavailable expression analysis.An expression is very busy at a point ifit is guaranteed that the expressionwill be computed at some time in thefuture.Thus starting at the point in question,the expression must be reachedbefore its value changes.Very busy expression analysis is abackward flow analysis, since itpropagates information about futureevaluations backward to “earlier”points in the computation.360CS 701 Fall 2008©The meet lattice is:As initial values, at the end of all exitnodes, nothing is very busy. Hence,for a given expression,VeryBusyOut(blast) = FT (Expression is Very Busy)F (Expression is Not Very Busy)361CS 701 Fall 2008©The transfer function for e1in block bis defined as:If e1 is computed in b before any ofits operandsThen VeryBusyIn(b) = TElsif any of e1’s operands are changed before e1 is computed Then VeryBusyIn(b) = FElse VeryBusyIn(b) = VeryBusyOut(b)The meet operation (to combinesolutions) is: VeryBusyOut(b) =ANDs ∈ Succ(b)VeryBusyIn(s)362CS 701 Fall 2008©Example: e1=v+wstopv=2w=5v=3x=v+wu=v+wFFFFTT363CS 701 Fall 2008©stopv=2w=5v=3x=v+wu=v+wFFFFTTFFFFTTTFMove v+where?Or here?364CS 701 Fall 2008©Identifying IdenticalExpressionsWe can hash expressions, based onhash values assigned to operands andoperators. This makes recognizingpotentially redundant expressionsstraightforward.For example, if H(a) = 10, H(b) = 21and H(+) = 5, then (using a simpleproduct hash),H(a+b) = 10×21×5 Mod TableSize365CS 701 Fall 2008©Effects of Aliasing and CallsWhen looking for assignments tooperands, we must consider theeffects of pointers, formal parametersand calls.An assignment through a pointer(e.g,*p = val) kills all expressionsdependent on variablesp might pointtoo. Similarly, an assignment to aformal parameter kills all expressionsdependent on variables the formalmight be bound to.A call kills all expressions dependenton a variable changeable during thecall.Lacking careful alias analysis,pointers, formal parameters and callscan kill all (or most) expressions.366CS 701 Fall 2008©Very Busy Expressions andLoop InvariantsVery busy expressions are idealcandidates for invariant loop motion.If an expression, invariant in a loop, isalso very busy, we know it must beused in the future, and henceevaluation outside the loop must beworthwhile.367CS 701 Fall 2008©for (...) {if (...) a=b+c;else a=d+c;}for (...) {if (a>b+c) x=1;else x=0;}t=b+c t=b+ca=b+c a=d+ca>b+cTFFFFTb+c is not very busyat loop entranceb+c is very busyat loop entrance368CS 701 Fall 2008©Reaching DefinitionsWe have seen reaching definitionanalysis formulated as a set-valuedproblem. It can also be formulated ona per-definition basis.That is, we ask “What blocks does aparticular definition to v reach?”This is a boolean-valued, forwardflow data flow problem.369CS 701 Fall 2008©Initially, DefIn(b0) = false.For basic block b:DefOut(b) = If the definition being analyzed is the last definition to v in b Then TrueElsif any other definition to v occurs in b Then False Else DefIn(b)The meet operation (to combinesolutions) is: DefIn(b) =To get all reaching definition, we do aseries of single definition analyses.ORp ∈ Pred(b) DefOut(p)370CS 701 Fall 2008©Live Variable AnalysisThis is a boolean-valued, backwardflow data flow problem.Initially, LiveOut(blast) = false.For basic block b:LiveIn(b) = If the variable is used before it is defined in b Then True Elsif it is defined before it is used in b Then False Else LiveOut(b)The meet operation (to combinesolutions) is: LiveOut(b) =ORs ∈ Succ(b) LiveIn(s)371CS 701 Fall 2008©Bit Vectoring Data FlowProblemsThe four data flow problems we havejust reviewed all fit within a singleframework.Their solution values are Booleans(bits).The meet operation is And or OR.The transfer function is of the generalform Out(b) = (In(b) - Killb) U Genbor In(b) = (Out(b) - Killb) U Genbwhere Killbis true if a value is “killed”within b and Genbis true if a value is“generated” within b.372CS 701 Fall 2008©In Boolean terms:Out(b) = (In(b) AND Not Killb) OR GenborIn(b) = (Out(b) AND Not Killb) OR GenbAn advantage of a bit vectoring dataflow problem is that we can do a seriesof data flow problems “in parallel” usinga bit vector.Hence using ordinary word-level ANDs,ORs, and NOTs, we can solve 32 (or 64)problems simultaneously.373CS 701 Fall 2008©Example Do live variable analysis for u and v,using a 2 bit vector:We expect no variable to be live atthe start of b0. (Why?)v=1u=0a=uv=2print(u,v)Gen=0,0Kill=0,1Gen=0,0Gen=1,0Gen=0,0Gen=1,1Kill=1,0Kill=0,0Kill=0,1Kill=0,0Live=0,0Live=0,1Live=1,1Live=1,0Live=1,1374CS 701 Fall 2008©Reading Assignment• Read pages 31-62 of “AutomaticProgram Optimization,” by Ron Cytron.(Linked from the class Web page.)375CS 701 Fall 2008©Depth-First Spanning TreesSometimes we want to “cover” thenodes of a control flow graph with anacyclic structure.This allows us to visit nodes once,without worrying about cycles orinfinite loops.Also, a careful visitation order canapproximate forward control flow(very useful in solving forward dataflow problems).A Depth-First Spanning Tree (DFST) isa tree structure that covers the nodesof a control flow graph, with the startnode serving as root of the DFST.376CS 701 Fall 2008©Building a DFSTWe will visit CFG nodes in depth-firstorder, keeping arcs if the visited nodehasn’t be reached before.To create a DFST, T, from a CFG, G:1. T ← empty tree2. Mark all nodes in G as “unvisited.”3. Call DF(start node)DF (node) {1. Mark node as visited.2. For each successor, s, of node in G:If s is unvisited (a) Add node → s to T (b) Call DF(s)377CS 701 Fall 2008©ExampleABCDEFGHIJVisit order is A, B, C, D, E, G, H, I, J, F378CS 701 Fall 2008©The DFST isABCDEFGHIJ379CS 701 Fall 2008©Categorizing Arcs using aDFSTArcs in a CFG can be categorized byexamining the corresponding DFST.An arc A→B in a CFG is(a) An Advancing Edge if B is a proper descendent of A in the DFST.(b) A Retreating Edge if B is an ancestor of A in the DFST. (This includes the A→A case.)(c) A Cross Edge if B is neither a descendent nor an ancestor of A in the DFST.380CS 701 Fall 2008©ExampleABCDEFGHIJaaaaaaaaaarrrrc381CS 701 Fall 2008©Depth-First OrderOnce we have a DFST, we can labelnodes with a Depth-First Ordering(DFO).Let i = the number of nodes in a CFG(= the number of nodes in


View Full Document

UW-Madison COMPSCI 701 - Lecture 18 Notes

Download Lecture 18 Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 18 Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 18 Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?