eecs 583 class 5 dataflow analysis intro
play

EECS 583 Class 5 Dataflow Analysis Intro University of Michigan - PowerPoint PPT Presentation

EECS 583 Class 5 Dataflow Analysis Intro University of Michigan September 17, 2014 Reading Material + Announcements Reminder HW 1 due Monday at midnight Before asking questions: 1) Read all threads on piazza, 2) Think a bit


  1. EECS 583 – Class 5 Dataflow Analysis Intro University of Michigan September 17, 2014

  2. Reading Material + Announcements ❖ Reminder – HW 1 due Monday at midnight » Before asking questions: 1) Read all threads on piazza, 2) Think a bit Ÿ Then, post question or talk to Chang-Hong if you are stuck ❖ Today’s class » Compilers: Principles, Techniques, and Tools , (2 nd edition) A. Aho, R. Sethi, and J. Ullman, Addison-Wesley . (Sections: 9.2) - 1 -

  3. Class Problems Find the traces. Assume a threshold probability of 60%. 100 BB1 60 40 BB2 BB3 50 10 5 135 100 BB4 BB5 BB6 25 15 35 BB7 25 75 BB8 100 - 2 -

  4. Class Problems 100 Create the superblocks, trace threshold is 60% BB1 20 80 BB2 BB3 80 20 BB4 51 49 BB5 BB6 10 41 49 BB7 BB8 450 41 10 BB9 - 3 -

  5. Class Problem Solution – Superblock Formation To convert trace 1-3-4 100 100 into a superblock, BB4 is duplicated and the Each color represents BB1 BB1 edge weights are adjusted a trace. 20 20 80 80 BB2 BB3 BB2 BB3 20 80 80 20 BB4’ BB4 BB4 9.8 40.8 39.2 51 49 10.2 BB5 BB6 BB5 BB6 10 10 41 41 49 49 BB7 BB8 BB7 BB8 450 450 41 41 10 10 Create the superblocks, trace BB9 BB9 threshold is 60% - 4 -

  6. Class Problem From Last Time - Answer BB CD if (a > 0) { BB1 1 - r = t + s 2 1 a > 0 a <= 0 3 -2 if (b > 0 || c > 0) 4 -3 BB2 u = v + 1 5 2,3 b <= 0 6 -4 else if (d > 0) b > 0 7 4 BB3 x = y + 1 8 - c > 0 else c <= 0 z = z + 1 BB4 BB5 } d <= 0 d > 0 p3 = 0 p1 = CMPP.UN (a > 0) if T BB6 BB7 r = t + s if p1 p2,p3 = CMPP.UC.ON (b > 0) if p1 p4,p3 = CMPP.UC.ON (c > 0) if p2 u = v + 1 if p3 BB8 p5,p6 = CMPP.UC.UN (d > 0) if p4 a. Draw the CFG x = y + 1 if p6 b. Compute CD z = z + 1 if p5 c. If-convert the code - 5 -

  7. When to Apply If-conversion? ❖ Positives 10 » Remove branch Ÿ No disruption to sequential fetch BB1 Ÿ No prediction or mispredict 90 80 20 » Increase potential for operation overlap: bigger BBs BB2 BB3 » Enable more aggressive compiler 80 20 xforms: Software pipelining BB4 ❖ Negatives » Instruction execution is additive for 10 all BBs that are if-converted, thus BB5 require more processor resources 90 » Executing or waiting for useless 10 operations BB6 10 - 6 -

  8. Control Flow Analysis Summary » Basic blocks » Control Flow Graphs » Dominator/immediate dominator/post dominator/dom tree » Identify natural loops: header, back edges » Regions (beyond BBs): Ÿ Trace Ÿ Super blocks » Alternatives to branches: predicated execution Ÿ If conversion Ÿ Control Dependence Graphs - 7 -

  9. Next Topic: Dataflow Analysis + Optimization

  10. Looking Inside the Basic Blocks: Dataflow Analysis + Optimization ❖ Control flow analysis r1 = r2 + r3 » Treat BB as black box r6 = r4 – r5 » Just care about branches ❖ Now » Start looking at ops in BBs » What’s computed and where ❖ Classical optimizations r4 = 4 r6 = 8 » Want to make the computation more efficient ❖ Ex: Common Subexpression Elimination (CSE) » Is r2 + r3 redundant? r6 = r2 + r3 r7 = r4 – r5 » Is r4 – r5 redundant? » What if there were 1000 BB’s » Dataflow analysis !! - 9 -

  11. Dataflow Analysis Introduction Dataflow analysis – Collection of information that summarizes the creation/destruction of r1 = r2 + r3 values in a program. Used to identify legal r6 = r4 – r5 optimization opportunities. Pick an arbitrary point in the program Which VRs contain useful data values? (liveness or upward r4 = 4 exposed uses) r6 = 8 Which definitions may reach this point? (reaching defns) Which definitions are guaranteed r6 = r2 + r3 to reach this point? (available defns) r7 = r4 – r5 - 10 -

  12. Live Variable (Liveness) Analysis ❖ Defn: For each point p in a program and each variable y, determine whether y can be used before being redefined starting at p » In other words, there is a use of the variable y along some path from the point p to the exit. » Example: x =… … =x x= … » Useful for dead code elimination » Example: a = b + c b = c d = a - 11 -

  13. ❖ Algorithm sketch » For each BB, y is live if it is used before defined in the BB or it is live leaving the block » Backward dataflow analysis as propagation occurs from uses upwards to defs ❖ 4 sets » IN = set of variables that are live at the entry point of a BB » OUT = set of variables that are live at the exit point of a BB » GEN = set of external variables consumed in the BB » KILL = set of external variable uses killed by the BB Ÿ equivalent to set of variables defined by the BB ❖ Transfer function and Meet function - 12 -

  14. Computing GEN/KILL Sets For Each BB for each basic block in the procedure, X, do GEN(X) = 0 KILL(X) = 0 for each operation in reverse sequential order in X, op, do for each destination operand of op, dest, do GEN(X) -= dest KILL(X) += dest endfor for each source operand of op, src, do GEN(X) += src KILL(X) -= src endfor endfor endfor - 13 -

  15. Compute IN/OUT Sets for all BBs initialize IN(X) to 0 for all basic blocks X change = 1 while (change) do change = 0 for each basic block in procedure, X, do old_IN = IN(X) OUT(X) = Union(IN(Y)) for all successors Y of X IN(X) = GEN(X) + (OUT(X) – KILL(X)) if (old_IN != IN(X)) then change = 1 endif endfor endfor - 14 -

  16. Example – Liveness Computation GEN -= dest OUT = Union(IN(succs)) BB1 GEN += src 1. r1 = MEM[r2+0] IN = GEN + (OUT – KILL ) KILL += dest 2. r2 = MEM[r1 + 1] KILL -= src 3. r8 = r1 * r2 BB2 BB3 4. r1 = r1 + 5 7. r2 = 0 5. r3 = r5 – r1 8. r7 = r1 + r2 6. r7 = r3 * 2 9: r3 = 4 BB4 10: r3 = r3 + r7 11: r1 = r2 – r8 12: r3 = r1 * 2 - 15 -

  17. Class Problem Compute liveness Calculate GEN/KILL for each BB 1. r1 = 3 Calculate IN/OUT for each BB 2. r2 = r3 3. r3 = r4 4. r1 = r1 + 1 5. r7 = r1 * r2 6. r4 = r4 + 1 7. r4 = r3 + r2 8. r8 = 8 9. r9 = r7 + r8 - 16 -

  18. Reaching Definition Analysis (rdefs) ❖ A definition of a variable x is an operation that assigns, or may assign, a value to x ❖ A definition d reaches a point p if there is a path from the point immediately following d to p such that d is not “killed” along that path ❖ A definition of a variable is killed between 2 points when there is another definition of that variable along the path » r1 = r2 + r3 kills previous definitions of r1 ❖ Liveness vs Reaching defs » Liveness à variables (e.g., virtual registers), don’t care about specific users » Reaching defs à operations, each def is different » Forward dataflow analysis as propagation occurs from defs downwards (liveness was backward analysis) - 17 -

  19. Compute Rdef GEN/KILL Sets for each BB GEN = set of definitions created by an operation KILL = set of definitions destroyed by an operation - Assume each operation only has 1 destination for simplicity so just keep track of “ops”.. for each basic block in the procedure, X, do GEN(X) = 0 KILL(X) = 0 for each operation in sequential order in X, op, do for each destination operand of op, dest, do G = op K = {all ops which define dest – op} GEN(X) = G + (GEN(X) – K) KILL(X) = K + (KILL(X) – G) endfor endfor endfor - 18 -

  20. Compute Rdef IN/OUT Sets for all BBs IN = set of definitions reaching the entry of BB OUT = set of definitions leaving BB initialize IN(X) = 0 for all basic blocks X initialize OUT(X) = GEN(X) for all basic blocks X change = 1 while (change) do change = 0 for each basic block in procedure, X, do old_OUT = OUT(X) IN(X) = Union(OUT(Y)) for all predecessors Y of X OUT(X) = GEN(X) + (IN(X) – KILL(X)) if (old_OUT != OUT(X)) then change = 1 endif endfor endfor - 19 -

  21. Example Rdef Calculation G = op K = {all ops which define dest – op} BB1 1. r1 = MEM[r2+0] GEN(X) = G + (GEN(X) – K) 2. r2 = MEM[r1 + 1] KILL(X) = K + (KILL(X) – G) 3. r8 = r1 * r2 IN = Union(OUT(preds)) OUT = GEN + (IN – KILL ) BB2 BB3 4. r1 = r1 + 5 7. r2 = 0 5. r3 = r5 – r1 8. r7 = r1 + r2 6. r7 = r3 * 2 9. r3 = 4 BB4 10. r3 = r3 + r7 11. r1 = r2 – r8 12. r3 = r1 * 2 - 20 -

  22. Class Problem Compute reaching defs Calculate GEN/KILL for each BB 1. r1 = 3 Calculate IN/OUT for each BB 2. r2 = r3 3. r3 = r4 4. r1 = r1 + 1 5. r7 = r1 * r2 6. r4 = r4 + 1 7. r4 = r3 + r2 8. r8 = 8 9. r9 = r7 + r8 - 21 -

  23. DU/UD Chains ❖ Convenient way to access/use reaching defs info ❖ Def-Use chains » Given a def, what are all the possible consumers of the operand produced » Maybe consumer ❖ Use-Def chains » Given a use, what are all the possible producers of the operand consumed » Maybe producer - 22 -

  24. Example – DU/UD Chains 1. r1 = 3 2. r2 = r3 3. r3 = r4 4. r1 = r1 + 1 5. r7 = r1 * r2 6. r4 = r4 + 1 7. r4 = r3 8. r8 = 8 9. r9 = r7 + r8 - 23 -

  25. To Be Continued…

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