1
play

1 UD Chains Role of Alternate Program Representations Definition - PowerPoint PPT Presentation

Data Dependence Example Definition Data dependences are constraints on the order in which statements may be executed s 1 a = b; We say statement s 2 depends on s 1 flow Flow (true) dependence : s 1 writes memory that s 2 later reads


  1. Data Dependence Example Definition – Data dependences are constraints on the order in which statements may be executed s 1 a = b; We say statement s 2 depends on s 1 flow – Flow (true) dependence : s 1 writes memory that s 2 later reads (RAW) s 2 b = c + d; – Anti-dependence : s 1 reads memory that s 2 later writes (WAR) anti – Output dependences : s 1 writes memory that s 2 later writes (WAW) s 3 e = a + d; output – Input dependences : s 1 reads memory that s 2 later reads (RAR) input s 4 b = 3; True dependences – Flow dependences represent actual flow of data s 5 f = b * 2; False dependences – Anti- and output dependences reflect reuse of memory, not actual data flow; can often be eliminated CS553 Lecture Static Single Assignment Form 3 CS553 Lecture Static Single Assignment Form 4 Representing Data Dependences DU Chains Implicitly Definition – Using variable defs and uses – du chains link each def to its uses – Pros: simple – Cons: hides data dependence (analyses must find this info) Example Def-use chains (du chains) s 1 a = b; – Link each def to its uses s 2 – Pros: explicit; therefore fast b = c + d; du chain – Cons: must be computed and updated, space consuming s 3 e = a + d; Alternate representations s 4 b = 3; – e.g., Static single assignment form (SSA), dependence flow graphs (DFG), value dependence graphs (VDG) s 5 f = b * 2; CS553 Lecture Static Single Assignment Form 5 CS553 Lecture Static Single Assignment Form 6 1

  2. UD Chains Role of Alternate Program Representations Definition Advantage – ud chains link each use to its defs – Allow analyses and transformations to be simpler & more efficient/effective Example Disadvantage – May not be “executable” (requires extra translations to and from) – May be expensive (in terms of time or space) s 1 a = b; s 2 b = c + d; Process ud chain s 3 e = a + d; Original Code (RTL) Optimized Code (RTL) s 4 b = 3; T1 T2 s 5 f = b * 2; SSA Code1 SSA Code2 SSA Code3 CS553 Lecture Static Single Assignment Form 7 CS553 Lecture Static Single Assignment Form 8 Static Single Assignment (SSA) Form SSA and Control Flow Idea Problem – Each variable has only one static definition – A use may be reached by several definitions – Makes it easier to reason about values instead of variables – Similar to the notion of functional programming 1 Transformation to SSA – Rename each definition v := ... v := ... 2 3 – Rename all uses reached by that assignment 1 Example 4 ...v... v := ... v 0 := ... v 0 :=... v 1 :=... ... := ... v ... ... := ... v 0 ... 2 3 v := ... v 1 := ... ... := ... v ... ... := ... v 1 ... 4 ...v?... What do we do when there’s control flow? CS553 Lecture Static Single Assignment Form 9 CS553 Lecture Static Single Assignment Form 10 2

  3. SSA and Control Flow (cont) Another Example Merging Definitions – φ -functions merge multiple reaching definitions Example 1 v := 1 1 v 0 := 1 1 2 v 0 :=... 3 v 1 :=... v := v+1 v 1 := φ (v 0 ,v 2 ) 2 2 v 2 := v 1 +1 v 2 := φ (v 0 ,v 1 ) 4 ...v 2 ... CS553 Lecture Static Single Assignment Form 11 CS553 Lecture Static Single Assignment Form 12 SSA vs. ud/du Chains SSA vs. ud/du Chains (cont) SSA form is more constrained Worst case du-chains? Advantages of SSA switch (c1) { – More compact case 1: x = 1; break; case 2: x = 2; break; – Some analyses become simpler when each use has only one def case 3: x = 3; break; – Value merging is explicit } – Easier to update and manipulate? x 4 = φ (x 1 , x 2 , x 3 ) Furthermore switch (c2) { – Eliminates false dependences (simplifying context) case 1: y1 = x; break; case 2: y2 = x; break; for (i=0; i<n; i++) case 3: y3 = x; break; A[i] = i; case 4: y4 = x; break; Unrelated uses of i are given for (i=0; i<n; i++) } different variable names m defs and n uses leads to m × n du chains print(foo(i)); CS553 Lecture Static Single Assignment Form 13 CS553 Lecture Static Single Assignment Form 14 3

  4. Where Do We Place φ -Functions? Transformation to SSA Form Two steps Basic Rule – Insert φ -functions – If two distinct (non-null) paths x → z and y → z converge at node z, and nodes x and y contain definitions of variable v, then a – Rename variables φ -function for v is inserted at z v 1 :=... v 2 :=... x y v 3 := φ (v 1 ,v 2 ) z ...v 3 ... CS553 Lecture Static Single Assignment Form 15 CS553 Lecture Static Single Assignment Form 16 Approaches to Placing φ -Functions Briggs Minimal vs. Pruned v = v = Minimal Briggs Minimal will add a = v = v – As few as possible subject to the basic rule φ function because v is live across the blue edge, but Pruned SSA will not because the φ Briggs-Minimal = v function is dead – Same as minimal, except v must be live across some edge of the CFG = φ (v 0 ,v 1 ) Pruned – Same as minimal, except dead φ -functions are not inserted v = v = Neither Briggs Minimal nor = v = v Pruned SSA will place a What’s the difference between Briggs Minimal and Pruned SSA? φ function in this case because v is not live across any CFG edge Why would we ever use Briggs Minimal instead of Pruned SSA? CS553 Lecture Static Single Assignment Form 17 CS553 Lecture Static Single Assignment Form 18 4

  5. Concepts Next Time Data dependences Assignments – Three kinds of data dependences – HW1 due – du-chains Alternate representations Lecture SSA form – SSA continued Conversion to SSA form – φ -function placement CS553 Lecture Static Single Assignment Form 19 CS553 Lecture Static Single Assignment Form 20 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend