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

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

  • View
    214

  • Download
    2

Embed Size (px)

Text of A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION Proseminar „Programmanalyse”, Prof. Dr. Heike...

  • Slide 1
  • A UNIFIED APPROACH TO GLOBAL PROGRAM OPTIMIZATION Proseminar Programmanalyse, Prof. Dr. Heike Wehrheim Universitt Paderborn, WS 2011/2012
  • Slide 2
  • 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. Find all expressions whose value is available at some point p. Available expressions
  • Slide 3
  • 3 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. Global Iterative Data Flow Analysis
  • Slide 4
  • 4 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 functions describe how information changes as it flows through a basic block Meet functions describe how information from multiple paths is combined. Global Iterative Data Flow Analysis
  • Slide 5
  • Constant propagation Common subexpression elimination CP and CSE 5
  • Slide 6
  • Constant propagation CONSTANT PROPAGATION begin integer i,a,b,c,d,e a:=1; c:=0; for i:=1 step 1 until 10 do begin b:=2; d:=a+b; e:=b+c; c:=4;... end end entry: a:=1 c:=0 b:=2 d:=a+b e:=b+c c:=4 A B C D E F P A = P B = {(a,1)} P C = {(a,1)} P D = {(a,1),(b,2)} P E = {(a,1),(b,2),(d,3)} P F = {(a,1),(b,2),(d,3)} 6 Problem: Determining the pool of propagated constants Pool of Constants
  • Slide 7
  • CONSTANT PROPAGATION entry: a:=1 A c:=0 B b:=2 C d:=a+b D e:=b+c E c:=4 F 7 = {(a,1),(b,2),(c,4),(d,3),(e,2)} Formally Determining the Pool of propagated constants at node E The first approximation for the path from A to E: (A,B,C,D,E) = {(a,1),(c,0),(b,2),(d,3)} The second approximation for the path (A,B,C,D,E,F,C,D,E)
  • Slide 8
  • final constant pool DATA FLOW ANALYSIS ALGORITHM {(a,1),(b,2),(d,3),(e,2),(c,4)} P = {(a,1),(b,2),(d,3),(e,2),(c,4)} = {(a,1)} 8 = {(a,1),(c,0)} = {(a,1),(c,0),(b,2)} = {(a,1),(c,0),(b,2),(d,3)} = {(a,1),(c,0),(b,2),(d,3),(e,2)} no changes anymore For instance: Formally: The constant pool resulting from F entering C: THE SECOND APPROXIMATIONTHE THIRD ONE = {(a,1),(b,2)} = {(a,1),(b,2),(d,3)} = {(a,1)}
  • Slide 9
  • 9 DATA FLOW ANALYSIS ALGORITHM INFORMAL a.Start with an entry node P i with a given entry pool usually only one entry node Usually entry pool is empty b.Process P i and produce optimizing function c.Intersect the incoming optimization pools (for the first time assume as the first approximation) d.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.
  • Slide 10
  • DATA FLOW ANALYSIS ALGORITHM f(A, ) = {(a,1)} f(B, {(a,1)}) = {(a,1),(c,0)} f(C, f(B, f(A, ))) = {(a,1), (c,0), (b,2)} 10 f : N P(U) P(U) f : N P P Homomorphism: Note f(N, x) < 1 and N analyzed set of nodes U = V C ordered pairs in any constant pool V set of variables C set of constants P(U) power set (the set of all subsets of U) So the function can be applied: Optimizing function f is defined
  • Slide 11
  • 11 1: [initialize]L 2: [terminate?]if L= then halt 3: [select node]Let L' L, L'=(N,P i ) for some N N and P i P, L L- {L'} 4: [traverse?]Let P N be the current approximate pool for node N (Initially, P N = 1). If P N P i then go to step 2 5: [set pool]P N P N P i, L L {N', f(N, P N | N I(N) 6: [loop]go to step 2: DATA FLOW ANALYSIS ALGORITHM
  • Slide 12
  • Common subexpression elimination r:=a+b; r+x (a+b)+X r:=a+b r+x (a+b)+x entry:A B C D Before A P A = Before B P B =P A = {a I b I a+b, r } Before C P C {a I b I a+b, r I x I x+r} Before D P D {a I b I a+b, r I x I x+r I (a+b)+x} (a+b)+x has the same evaluation as r+x {a I b I a+b, r I x I r+x, (a+b)+x} 12 Detect Eliminate Detect Eliminate Problem redundant expressions purpose
  • Slide 13
  • Optimizing function f(N,P) 13 redundant New class in P Consider computation e d:=e in N remove expression with d 1.Create e for each e in P 2.Place e in class of e COMMON SUBEXPRESSION ELIMINATION 1.Consider each partial computation e at node N 2.If the computation in class of P then e is redundant 3.Create new class, add all computation, which have operands equivalent to e 4.If N contains d:=e, remove from class expression with d as a sub expression
  • Slide 14
  • 14 CONSTANT PROPOGATION & COMMON SUBEXPRESSION ELIMINATIOM Optimizing function f 2 d:=e in N New class in P no further processing z:=e z in P combine z & e combine z & e Add z to e otherwise
  • Slide 15
  • QUESTIONS? 15