cs293s gcse
play

CS293S GCSE Yufei Ding Review So far, we have seen Local Value - PowerPoint PPT Presentation

CS293S GCSE Yufei Ding Review So far, we have seen Local Value Numbering Finds redundancy, constants, & identities in a block Superlocal Value Numbering Extends local value numbering to EBBs Used SSA-like name space to


  1. CS293S GCSE Yufei Ding

  2. Review So far, we have seen � Local Value Numbering � Finds redundancy, constants, & identities in a block � Superlocal Value Numbering � Extends local value numbering to EBBs � Used SSA-like name space to simplify bookkeeping � Dominator Value Numbering � Extends scope to “almost” global � Uses dominance information to handle join points in CFG 2

  3. Example A m 0 ¬ a + b n 0 ¬ a + b B C p 0 ¬ c + d q 0 ¬ a + b r 0 ¬ c + d r 1 ¬ c + d D E e 0 ¬ b + 18 e 1 ¬ a + 17 s 0 ¬ a + b t 0 ¬ c + d u 0 ¬ e + f u 1 ¬ e + f F e 3 ¬ f (e 0 ,e 1 ) u 2 ¬ f (u 0 ,u 1 ) v 0 ¬ a + b This is in w 0 ¬ c + d SSA Form x 0 ¬ e + f G r 2 ¬ f (r 0 ,r 1 ) y 0 ¬ a + b z 0 ¬ c + d 3

  4. Examples x = a + b; f = c + d; e = c + d; c = a - b; g = c + d; 4

  5. Outline of This Class � Global Common Subexpression Elimination (GCSE) � The first data-flow problem � A global method 5

  6. Some Expression Sets For each block b Let A VAIL (b) be the set of expressions available on entry to b. Let E XPR K ILL (b) be the set of expressions killed in b. i.e. one or more operands of the expression are redefined in b. !!!! Must consider all expressions in the whole graph. Let DEE XPR (b) include the downward exposed expressions in b. i.e. expressions defined in b and not subsequently killed in b u = f + e l = b + u ExprKILL: {f+e, a-b} a = b + c DEExpr: {b+c} f = a AVAIL: {b+c, b+u} w = a - b ... 6

  7. Formula to Compute AVAIL Now, A VAIL (b) can be defined as: A VAIL (b) = Ç x Î pred(b) ( DEE XPR (x) È ( A VAIL (x) Ç E XPR K ILL (x) )) preds(b) is the set of b ’s predecessors in the control-flow graph. (Note that a predecessor is an immediate parent, not including other ancestors.) 7

  8. Computing Available Expressions The Big Picture 1. Build a control-flow graph 2. Gather the initial data: DEE XPR (b) & E XPR K ILL (b) 3. Propagate information around the graph, evaluating the equation Works for loops through an iterative algorithm: finding the fixed- point. All data-flow problems are solved, essentially, this way. 8

  9. Computing Available Expressions First step is to compute DEE XPR & E XPR K ILL assume a block b with operations o 1 , o 2 , …, o k V AR K ILL ¬ Ø // compute DEEx PR (b) DEE XPR (b) ¬ Ø for i = ??? (forward or backward) assume o i is “x ¬ y + z” ??? // compute E XPR K ILL (b) E XPR K ILL (b) ¬ Ø For each expression e // in the whole CFG for each variable v Î e ??? 9

  10. Computing Available Expressions First step is to compute DEE XPR & E XPR K ILL Many data-flow assume a block b with operations o 1 , o 2 , …, o k problems have initial information V AR K ILL ¬ Ø that costs less to DEE XPR (b) ¬ Ø Backward through block compute for i = k to 1 assume o i is “x ¬ y + z” O(k) steps add x to V AR K ILL if (y Ï V AR K ILL ) and (z Ï V AR K ILL ) then add “y + z” to DEE XPR (b) E XPR K ILL (b) ¬ Ø For each expression e for each variable v Î e O(N) steps if v Î V AR K ILL (b) then N is # operations E XPR K ILL (b) ¬ E XPR K ILL (b) È {e} 10

  11. Computing Available Expressions The worklist iterative algorithm Worklist ¬ { all blocks, b i } while (Worklist ¹ Ø) remove a block b from Worklist recompute A VAIL (b ) as A VAIL (b) = Ç x Î pred(b) (DEE XPR (x) È (A VAIL (x) Ç E XPR K ILL (x) )) if ??? then Worklist ¬ ??? 11

  12. Computing Available Expressions The worklist iterative algorithm Worklist ¬ { all blocks, b i } while (Worklist ¹ Ø) remove a block b from Worklist recompute A VAIL (b ) as A VAIL (b) = Ç x Î pred(b) (DEE XPR (x) È (A VAIL (x) Ç E XPR K ILL (x) )) if A VAIL (b ) changed then Worklist ¬ Worklist È successors(b ) • Finds fixed point solution to equation for A VAIL • That solution is unique 12

  13. Data-flow Analysis Data-flow analysis is a collection of techniques for compile-time reasoning about run-time flow of values Almost always involves building a graph � � Problems are trivial on a basic block � Global problems Þ control-flow graph (or derivative) � Whole program problems Þ call graph (or derivative) Usually formulated as a set of simultaneous equations � 13

  14. Making Theory Concrete Computing A VAIL for the example A VAIL (A) = Ø A m ¬ a + b A VAIL (B) = n ¬ a + b A VAIL (C) = A VAIL (D) = B C p ¬ c + d q ¬ a + b r ¬ c + d r ¬ c + d … A VAIL (G) = D E e ¬ b + 18 e ¬ a + 17 s ¬ a + b t ¬ c + d u ¬ e + f u ¬ e + f F v ¬ a + b w ¬ c + d x ¬ e + f G y ¬ a + b z ¬ c + d 14

  15. Making Theory Concrete Computing A VAIL for the example A VAIL (A) = Ø A m ¬ a + b A VAIL (B) = { a+b } È ( Ø Ç all ) n ¬ a + b = { a+b } A VAIL (C) = { a+b } B C p ¬ c + d q ¬ a + b r ¬ c + d r ¬ c + d A VAIL (D) = { a+b,c+d } È ({ a+b } Ç all ) = { a+b,c+d } D E e ¬ b + 18 e ¬ a + 17 A VAIL (E) = { a+b,c+d } s ¬ a + b t ¬ c + d u ¬ e + f u ¬ e + f A VAIL (F) = [{ b+18,a+b,e+f } È ({ a+b,c+d } Ç { all - e+f })] F v ¬ a + b w ¬ c + d Ç [{ a+17,c+d,e+f } È x ¬ e + f ({ a+b,c+d } Ç { all - e+f })] G = { a+b,c+d,e+f } y ¬ a + b z ¬ c + d A VAIL (G) = [ { c+d } È ({ a+b } Ç all )] Ç [{ a+b,c+d,e+f } È ({ a+b,c+d,e+f } Ç all )] = { a+b,c+d } 15

  16. Summary: GCSE 1. Analysis step: compute AVAIL sets for every basic block 2. Replacement step: replace common expressions with names. A VAIL (b) = Ç x Î pred(b) ( DEE XPR (x) È ( A VAIL (x) Ç E XPR K ILL (x) )) preds(b) is the set of b ’s predecessors in the control-flow graph. (Again, a predecessor is an immediate parent, not including other ancestors.) 1. Build a control-flow graph 2. Gather the initial data: DEE XPR (b) & E XPR K ILL (b) 3. Propagate information around the graph, evaluating the equation through the worklist iterative algorithm. 16

  17. Replacement step in GCSE � Limit to textually identical expressions (like DAG, unlike value numbering) B1 a <- b + c B2 a <- b + c f <- b + c d <- b AVAIL(B) ={b+c} AVAIL(B) ={b+c} e <- b + c e <- d + c B Should replace b+c with ? Cannot find or remove the redundancy! 17

  18. GCSE ( replacement step) � Compute a static mapping from expression to name � After analysis & before transformation � " block b, " expression e Î AVAIL(b), assign e a global name by hashing on e � During transformation step � Evaluation of e Þ insert copy name(e) ¬ e � (e is not available and needs to be evaluated) � Reference to e Þ replace e with name(e) � (e is available and should be replaced) 18

  19. Example t1 = a+b; B1 m=t1; B1 m=a+b; t2=c+d; t2=c+d; B3 n=c+d; p=c+d; B3 B2 n=t2; p=t2; B2 c = 17; c = 17; q=c+d; t2=c+d; AVAIL(B4) ={c+d; a+b} q=t2; r=c+d; B4 r=t2; B4 name expression t1 a+b t2 c+d

  20. GCSE ( replacement step) � The major problem with this approach � Inserts extraneous copies � At all definitions and uses of any e Î AVAIL(b), " b � Not a big issue � Those extra copies are dead and easy to remove � The useful ones often coalesce away 20

  21. Review So far, we have seen � Local Value Numbering � Finds redundancy, constants, & identities in a block � Superlocal Value Numbering � Extends local value numbering to EBBs � Used SSA-like name space to simplify bookkeeping � Dominator Value Numbering � Extends scope to “almost” global (no back edges) � Uses dominance information to handle join points in CFG � Global Common Subexpression Elimination (GCSE) � Applying data-flow analysis (AVAIL) to the problem 21

  22. Comparison The VN methods are ordered A m ¬ a + b • LVN ≤ SVN ≤ DVN n ¬ a + b LVN • GCSE is different B C o Based on names, not value p ¬ c + d q ¬ a + b SVN r ¬ c + d r ¬ c + d LVN o But for this particular example: DVN ≤ GCSE D E e ¬ b + 18 e ¬ a + 17 s ¬ a + b t ¬ c + d o Not always!!!! SVN SVN u ¬ e + f u ¬ e + f F v ¬ a + b DVN w ¬ c + d DVN x ¬ e + f GCSE G y ¬ a + b DVN z ¬ c + d GCSE 22

  23. Name operate on Scope on/offline replace basis of identity LVN SVN DVN GCSE 23

  24. 24

  25. Redundancy Elimination Wrap-up Conclusions � Redundancy elimination has some depth & subtlety � Variations on names, algorithms & analysis DVN is probably the method of choice � Results quite close to the global methods ( ± 1% ) � Cost is low 25

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