1 / 26

A Polynomial-Time Algorithm for Global Value Numbering

A Polynomial-Time Algorithm for Global Value Numbering. SAS 2004 Sumit Gulwani George C. Necula. Global Value Numbering. Goal: Discover equivalent expressions in procedures Applications: Compiler optimizations

tammy
Download Presentation

A Polynomial-Time Algorithm for Global Value Numbering

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 Polynomial-Time Algorithm for Global Value Numbering SAS 2004 Sumit Gulwani George C. Necula

  2. Global Value Numbering Goal: Discover equivalent expressions in procedures Applications: • Compiler optimizations • Copy propagation, Constant propagation, Common sub-expression elimination, Induction variable elimination etc. • Program verification • Discover loop invariants, verify program assertions • Discover equivalent computations across programs • Translation validation, Plagiarism detection tools

  3. x := a*b; If (b == 3) u := b*a; v := a*3; y := a*b; Global Value Numbering • Challenge: Undecidable Problem • Simplification Assumptions: • Operators are uninterpreted (will not discover u = x) • Conditionals are non-deterministic (will not discover v = x) • Will discover x = y

  4. Non-trivial Example * x := b; y := b; z := F(b); x := a; y := a; z := F(a); assert(x = y); assert(z = F(y));

  5. Related Work • Algorithms that work on SSA form of the program • AWZ Algorithm (POPL 1988) • Polynomial, Incomplete • RKS Algorithm (SAS 1999) • Polynomial, Incomplete, Improvement on AWZ • Dataflow analysis or Abstract interpretation based algorithm • Kildall’s Algorithm (POPL 1973) • Exponential, Complete • Our Algorithm (this paper) • Polynomial, Complete

  6. Non-trivial Example x = (a,b) y = (a,b) z = (F(a),F(b)) F(y) = F((a,b)) * x := b; y := b; z := F(b); x := a; y := a; z := F(a); assert(x = y); assert(z = F(y)); • AWZ Algorithm:  functions are uninterpreted • fails to discover second assertion • RKS Algorithm: uses rewrite rules for normalization • Does not discover all assertions in little more involved examples. • Rewrite rules not applied exhaustively (exp applications o.w.) • Rules are pessimistic in handling loops

  7. Outline • Strong Equivalence DAG (SED) • The Assignment Operation • The Join Operation • Pruning an SED • Fixed Point Computation

  8. Representing Equivalences a := 1; b := 2; x := F(1,2); { a,1 } { b,2 } { x, F(1,2) }

  9. Representing Equivalences a := 1; b := 2; x := F(1,2); { a,1 } { b,2 } { x, F(1,2), F(a,2), F(1,b), F(a,b) } Such an explicit representation can be exponential.

  10. Strong Equivalence DAG (SED) A data structure for representing equivalences. • Nodes n: <Set of variables, Type> • Type: c, ?, F(n1,n2) • For every variable x, exactly one node <V,t> s.t. x 2 V • called Node(x) • Terms(n): set of equivalent expressions • Terms(<V, ?>) = V • Terms(<V, c>) = V [ { c } • Terms(<V, F(n1,n2)>) = V [ { F(e1,e2) | e12 Terms(n1), e22 Terms(n2) }

  11. SED: Example Terms(n1) = { a, 2 } Terms(n2) = { b} Terms(n3) = { c, d, F(a,b), F(2,b) } Terms(n4) = {e, F(c,b), F(d,b), F(F(a,b),b), F(F(2,b),b)} Note that e = F(d,b) since F(d,b) 2 Terms(Node(e)) e, F d,c, F a, 2 b, ?

  12. Abstract Interpretation based algorithm G Assignment Node x := e G’ = Assignment(G,x := e) G Conditional Node * G2= G G1= G G2 G1 Join Node G = Join(G1, G2)

  13. G2 z, F G1 z, F x,y, 2 x,y, 1 G3 z, F x,y,? G4 u,z, F G3 = Join(G1,G2) x,y, ? G4 = Assignment(G3, u := F(x,y)) Example x := 1; y := 1; z := F(1,1); x := 2; y := 2; z := F(2,2); L1 L2 L3 u := F(x,y); L4 Assert(u = z);

  14. Outline • Strong equivalence DAG (SED) • The assignment operation • The join operation • Pruning an SED • Fixed point computation

  15. The Assignment Operation Assignment(G, x := e) It is the strongest postcondition of equivalences represented by G w.r.t the assignment x := e • Delete label x from Node(x) in G • Let n=<V,t> be the node in G s.t. e 2 Terms(n) (Add such a node to G if it does not already exists) Add x to node n.

  16. z, u, F z, F x, ? x, ? G Example: The Assignment Operation F u, F G0 = Assignment(G, u := F(z,x))

  17. Outline • Strong Equivalence DAG (SED) • The Assignment Operation • The Join Operation • Pruning an SED

  18. The Join Operation Join(G1, G2) Product Construction of G1 and G2 If n=<V1,t1> 2 G1 and m=<V2,t2> 2 G2, then (n,m) = <V1Å V2, t1t t2> 2 Join(G1,G2) Definition of t1t t2 c t c = c F(n1,n2) t F(m1,m2) = F ((n1,m1),(n2,m2)) t1t t2 = ?, otherwise

  19. y1, F y1, F y2, F y2, F F F F F y3,y4 y5,? y6,? y7,? y6,y7? y3,? y4,y5 ? Example: The Join Operation y1, F y2, F F F y7,? y6,? y4,y5? y3,? G1 G2 G = Join(G1,G2) G

  20. Outline • Strong equivalence DAG (SED) • The assignment operation • The join operation • Pruning an SED • Fixed point computation

  21. Motivation: The Prune Operation • If G=Join(G1,G2), then Size(G) can be Size(G1) £ Size(G2) • There are programs with n joins such that size of the SEDs after joins is exponential in n. Discovering equivalences among all expressions Discovering equivalences among program expressions vs. For the latter, it is sufficient to discover equivalences among all terms of size at most t at each program point (where t = #variables * size of program). Thus, SEDs can be pruned to have a small size (k £ t)

  22. The Prune Operation Prune(G,k) • For each node <V,t> such that V ;, check if it is a root of some DAG with all leaves labelled with at least one variable of size k. • If not, then delete all the nodes that are reachable from only <V,t>

  23. y1, G y1, G y2, F y2, ? F F y4,y5? y7,? y6,? y4,y5? y3,? Prune(G,2) G Example: The Prune Operation G

  24. Outline • Strong equivalence DAG (SED) • The assignment operation • The join operation • Pruning an SED • Fixed point computation

  25. Fixed Point Computation and Complexity • The lattice of sets of such equivalences has height at most k • Complexity • Dominated by the cost of join operations • Each join operation: O(k2£ N) • This requires doing pruning while computing join • # of join operations: O(j £ k) • Total cost: O(k3£ N £ j) k: # of variables N: size of program j: # of join points in program

  26. Conclusion • Discovering all

More Related