1 / 15

A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION

A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION. Proseminar „ Programmanalyse ”, Prof. Dr. Heike Wehrheim Universität Paderborn, WS 2011/2012. Different Data flow problems. Reaching definitions. For each use of a variable, find all definitions that reach it. Live variables.

berget
Télécharger la présentation

A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION Proseminar „Programmanalyse”, Prof. Dr. Heike Wehrheim Universität Paderborn, WS 2011/2012

  2. Different Data flow problems • Reaching definitions • For each use of a variable, find all definitions that reach it. • Live variables • For a point p and a variable v, determine whether v is live at p. • Upward exposed uses • For each definition of a variable, find all uses that it reaches. • Available expressions • Find all expressions whose value is available at some point p.

  3. Global Iterative Data Flow Analysis • Global: • Goal = to collect information at the beginning and end of each basic block • Iterative: • Construct data flow equations that describe how information flows through • each basic block and solve them by iteratively converging on a solution.

  4. Global Iterative Data Flow Analysis • Components of data flow equations • Sets containing collected information • in set: information coming into the BB from outside (following flow of dats) • gen set: information generated/collected within the BB • kill set: information that, due to action within the BB, will affect what has been collected outside the BB • out set: information leaving the BB • Functions (operations on these sets) • Transfer functionsdescribe how information changes as it flows through a basic block • Meet functionsdescribe how information from multiple paths is combined.

  5. Data flow analysis Constantpropagation CP and CSE Commonsubexpressionelimination

  6. CONSTANT PROPAGATION Problem: Determining the pool of propagated constants A entry: a:=1 B c:=0 Pool of Constants beginintegeri,a,b,c,d,ea:=1; c:=0; …fori:=1 step 1 until 10 dobegin b:=2; … d:=a+b; … e:=b+c; … c:=4; ...end end C b:=2 PA = ∅ PB = {(a,1)} PC = {(a,1)} PD = {(a,1),(b,2)} PE = {(a,1),(b,2),(d,3)} PF= {(a,1),(b,2),(d,3)} D d:=a+b E e:=b+c F c:=4 Constantpropagation

  7. CONSTANT PROPAGATION Determining the Pool of propagated constants at node E entry: A The first approximation for the path from A to E: (A,B,C,D,E) a:=1 B = {(a,1),(c,0),(b,2),(d,3)} c:=0 C The second approximation for the path (A,B,C,D,E,F,C,D,E) b:=2 = {(a,1),(b,2),(c,4),(d,3),(e,2)} D d:=a+b E e:=b+c Formally F c:=4

  8. DATA FLOW ANALYSIS ALGORITHM = {(a,1),(c,0)} For instance: = {(a,1),(c,0),(b,2)} = {(a,1),(c,0),(b,2),(d,3)} = {(a,1),(c,0),(b,2),(d,3),(e,2)} Formally: The constant pool resulting from F entering C: {(a,1),(b,2),(d,3),(e,2),(c,4)} P = {(a,1),(b,2),(d,3),(e,2),(c,4)} = {(a,1)} THE SECOND APPROXIMATION THE THIRD ONE no changes anymore = {(a,1),(b,2)} = {(a,1),(b,2),(d,3)} = {(a,1),(b,2),(d,3)} = {(a,1)} … … … final constant pool

  9. DATA FLOW ANALYSIS ALGORITHM INFORMAL Start with an entry node Pi with a given entry pool • usually only one entry node • Usually entry pool is empty Process Pi and produce optimizing function Intersect the incoming optimization pools(for the first time assume as the first approximation) Considering each successor node, if the amount of optimization information is reduced, then process the successor in the same manner as the initial entry node.

  10. DATA FLOW ANALYSIS ALGORITHM N analyzed set of nodes U = V × C ordered pairs in any constant pool V set of variables C set of constantsP(U) power set (the set of all subsets of U) f : N × P(U) P(U) f: N × PP “Optimizing function” f is defined Homomorphism: Note f(N,x) < 1 and So the function can be applied: f(A,∅) = {(a,1)} f(B, {(a,1)}) = {(a,1),(c,0)} f(C, f(B, f(A,∅))) = {(a,1), (c,0), (b,2)}

  11. DATA FLOW ANALYSIS ALGORITHM 1: [initialize] L ← ℇ 2: [terminate?] if L= ∅ then halt 3: [select node] Let L' ϵ L, L'=(N,Pi) forsome N ϵ Nand Pi ϵ P, L←L- {L'} 4: [traverse?] Let PN be the current approximate pool for node N (Initially, PN = 1). If PN ≤ Pithengotostep 2 5: [setpool] PN← PN∧ Pi, L←L {N', f(N, PN | N‘ ϵ I(N) 6: [loop] gotostep 2:

  12. Problem purpose Detect Eliminate redundant expressions … r:=a+b; … r+x …(a+b)+X … Before A PA = ∅ r:=a+b entry:A Before B PB =PA= {a I b I a+b, r } r+x Before C PC {a I b I a+b, r I x I x+r} B Before D PD{a I b I a+b, r I x I x+r I (a+b)+x} (a+b)+x C (a+b)+x has the same evaluation as r+x D {a I b I a+b, r I x I r+x, (a+b)+x} Commonsubexpressionelimination

  13. COMMON SUBEXPRESSION ELIMINATION Optimizing function f(N,P) Consider each partial computation e at node N If the computation in class of P then e is redundant Create new class, add all computation, which have operands equivalent to e If N contains d:=e, remove from class expression with d asa sub expression Consider computation e redundant New class in P d:=e in N remove expression with d Create e’’ for each e’ in P Place e’’ in class of e’

  14. CONSTANT PROPOGATION & COMMON SUBEXPRESSION ELIMINATIOM Optimizing function f2 otherwise … z:=e New class in P z in P d:=e in N combine z & e Add z to e … no further processing

  15. QUESTIONS?

More Related