1 / 25

Topic 5a Partial Redundancy Elimination and SSA Form

Topic 5a Partial Redundancy Elimination and SSA Form. References. Robert Kennedy, Sun Chan, Shin-ming Liu, Raymond Lo, Pend Tu, Fred Chow. Partial redundancy elimination in SSA Form . ACM Trans. On Programming Languages and Systems, 21(3), May 1999: 627-676.

denton
Download Presentation

Topic 5a Partial Redundancy Elimination and SSA Form

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. Topic 5aPartial Redundancy Elimination and SSA Form \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  2. References • Robert Kennedy, Sun Chan, Shin-ming Liu, Raymond Lo, Pend Tu, Fred Chow. Partial redundancy elimination in SSA Form. ACM Trans. On Programming Languages and Systems, 21(3), May 1999: 627-676. • Drechsler K. and Stadel M. A variation of Knoop, Ruthing, and Steffen’s lazy code motion. SIGPLAN Notices, 28(5), May, 1993: 29-38. • Keith Cooper, Linda Torczon. Engineering a compiler. 2004 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  3. Outline • Partial Redundancy Elimination (PRE) • SSAPRE (a short summary) \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  4. C++ Fortran C Front end • Source to IR (Scanner →Parser →RTL →WHIRL) fe90 gfec gfecc • VHO(Very High WHIRL Optimizer) • Standalone Inliner • W2C/W2F Middle end Very High WHIRL • IPA (inter-procedural analysis & opt) • LNO (Loop unrolling/fission/fusion/tiling/peeling etc) • PREOPT (point-to analysis etc) Machine Model High WHIRL • WOPT • - SSAPRE (Partial Redundancy Elimination) • - VNFRE (Value numbering based full redundancy elim.) • RVI-1 (Register Variable Identification) Middle WHIRL Low WHIRL • RVI-2 Back end • Some peephole opt Very Low WHIRL • Cflow (control flow opt) • EBO (extended block opt.) • PQS (predicate query system) • Loop Opt (Unrolling + SWP) • GCM(global code motion), HB sched(hyperblk schedule) • GRA/LRA(global/local register alloc) CGIR Asm file KCC Compiler Infrastructure \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  5. Important Observation • An operand of a  function is regarded as occurring at the end of its corresponding predecessor block. • The result of a function is regarded as occurring at the beginning of the block that contains it. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  6. Partial Redundancy Elimination Is the program in SSA form before and after PRE? tx*y a t a x*y B1 tx*y B2 X*y is partially redundant here b x*y b t B3 X*y is made redundant here \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  7. Problem Formulation for PRE • For an expression, identify its partially redundant occurrences • Safely insert occurrences (to new temporaries) at some points • Delete the original partially (now fully) redundant occurrences. Replace them by loads from a temporary variable. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  8. PRE Basics • Availability: An expression, say, x*y, is available at a program point p if • EVERY path from entry to p evaluates the expression before reaching p • And there are no assignments to x or y after the (last) evaluation but before p (on all paths). • Availability implies full redundancy. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  9. PRE Basics (Cont.) • Partial availability: An expression, say, x*y, is partially available at a program point p if • SOME paths from entry to p evaluates the expression before reaching p • And there are no assignments to x or y after the (last) such evaluation but before p. • Partial availability implies partial redundancy. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  10. B1 a x*y B3 b x*y PRE Basics (Cont.) • Anticipatability: An expression e is anticipatable ( “down-safe”) at a program point p if it appears (without redefinition) along ALL paths from • p to an exit of the program X*y is anticipatable here B2 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  11. Safe Placement - Safe insertion: If an inserted computation occurs at a point where the computation is anticipated. - Unsafe insertion: means that some original path in the program did not contain this computation. • May increase the execution time of the program • May cause exceptions \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  12. Safe Placement: Example x*y x*y This is called an “critical edge”. Allowable if we can insert computations on an edge. Otherwise, need split Safe Not safe \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  13. Optimal Placement (Cont’d) • Computationally optimal • If no other safe placement can result in fewer occurrences of the computation along any path from entry to exit in the program. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  14. Optimal Placement (cont’d) • Lifetime optimal • Minimize the lifetimes of the introduced temporaries. • Intuition: delay an expression to the latest point (Lazy Code Motion [KnoopEtal92, DrechslerStadel93]) \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  15. Outline • Partial redundancy elimination (PRE) • SSAPRE (a short summary) \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  16. SSAPRE \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  17. SSAPRE: Motivation • Traditional data flow analysis based on bit-vectors do not interface well with SSA representation \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  18. B1 a x*y B2 b x*y B3 Traditional Partial Redundancy Elimination Before PRE SSA form tx*y a t After PRE B1 tx*y B2 Not SSA form! b t B3 \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  19. SSAPRE: Motivation (Cont.) • Traditional PRE needs a postpass transform to turn the results into SSA form again. • SSA is based on variables, not on expressions \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  20. SSAPRE: Motivation (Cont.) • Representative occurrence • Given a partially redundant occurrence E0, we define the representative occurrence for E0 as the nearest to E0 among all occurrences that dominate E0. • Unique and well-defined \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  21. E E E E Control flow edge E =(E, E, ) Redundancy edge E E E E Factored FRG (Factored Redundancy Graph) Without factoring \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  22. t0 x*y t1 x*y t2(t0, t1 , t3) t2 t2 FRG (Factored Redundancy Graph) E E E =(E, E, ) E E Note: This is in SSA form Assume E=x*y \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  23. Observation • Every use-def edge of the temporary corresponds directly to a redundancy edge for the expression. \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  24. Intuition for SSAPRE • Construct FRG for each expression E • Refine redundant edges to form the use-def relation for each expression E’s temporary • Transform the program • For a definition, replace with tE • For a use, replace with t • Sometimes need also insert an expression \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt

  25. An Example a1 t1 a1+ b1 B1 a1 B1 t2(t4 , t1) a2(a4 , a1) a2(a4 , a1) B2 B2 t2 a3 t3a3+ b1 a2+b a3 B3 a4(a2, a3) a4+b t4(t2, t3)a4(a2, a3) t4 B4 B4 B5 exit \course\cpeg421-08s\Topic-5a.ppt\course\cpeg421-07s\Topic-7b.ppt exit

More Related