more dataflow analysis
play

More dataflow analysis CSE 501 Spring 15 Reaching - PowerPoint PPT Presentation

More dataflow analysis CSE 501 Spring 15 Reaching Defini=ons Summary LaAce Sets of defini=ons represented by bit-vectors Transfer func=on OUT[B] =


  1. More ¡dataflow ¡analysis ¡ CSE ¡501 ¡ Spring ¡15 ¡

  2. Reaching ¡Defini=ons ¡Summary ¡ LaAce ¡ Sets ¡of ¡defini=ons ¡represented ¡by ¡ bit-­‑vectors ¡ Transfer ¡func=on ¡ OUT[B] ¡= ¡f b (IN[B]) ¡ f b (x) ¡= ¡(x ¡– ¡KILL[x]) ¡U ¡ ¡GEN[x] ¡ ¡ Meet ¡opera=on ¡ IN[B] ¡= ¡U ¡ ¡OUT[Predecessors] ¡ Boundary ¡ OUT[entry] ¡= ¡0….0 ¡ condi=on ¡ Ini=al ¡condi=on ¡ OUT[B] ¡= ¡0….0 ¡

  3. Ques=ons ¡ • Does ¡the ¡algorithm ¡halt? ¡ – yes, ¡because ¡transfer ¡func=on ¡is ¡monotonic ¡ – if ¡increase ¡IN, ¡increase ¡OUT ¡ – in ¡limit, ¡all ¡bits ¡are ¡1 ¡ • If ¡bit ¡is ¡0, ¡does ¡the ¡corresponding ¡defini=on ¡ever ¡ reach ¡basic ¡block? ¡ • If ¡bit ¡is ¡1, ¡does ¡the ¡corresponding ¡defini=on ¡always ¡ reach ¡the ¡basic ¡block? ¡

  4. Live ¡Variable ¡Analysis ¡ • A ¡variable ¡ v ¡is ¡live ¡at ¡program ¡point ¡ p ¡if ¡the ¡value ¡ of ¡ v ¡is ¡used ¡along ¡some ¡path ¡in ¡the ¡flow ¡graph ¡ from ¡ p ¡ • Otherwise ¡it ¡is ¡dead ¡ • For ¡each ¡basic ¡block, ¡ ¡ determine ¡which ¡variable ¡is ¡live ¡ • Use ¡bit ¡vector ¡to ¡represent ¡variables, ¡ ¡ one ¡bit ¡per ¡ variable ¡

  5. Live ¡Variable ¡Analysis ¡ • Insight: ¡look ¡BACKWARDS ¡to ¡trace ¡defini=ons ¡ from ¡uses! ¡ x ¡must ¡be ¡live ¡on ¡entry ¡to ¡basic ¡block! ¡ b = x; Not ¡true ¡for ¡b! ¡

  6. Transfer ¡Func=on ¡for ¡Live ¡Variable ¡ • For ¡statement ¡s: ¡ ¡x ¡= ¡y ¡+ ¡z ¡ – Generates ¡new ¡live ¡variables: ¡USE[s] ¡= ¡{y, ¡z} ¡ – Kills ¡previously ¡live ¡variables: ¡DEF[s] ¡= ¡x ¡ – Variables ¡that ¡were ¡not ¡killed ¡are ¡propagated: ¡ OUT[s] ¡– ¡DEF[s] ¡ – So: ¡IN[s] ¡= ¡USE[s] ¡U ¡(OUT[s] ¡– ¡DEF[s]) ¡ • Similarly ¡for ¡basic ¡block ¡B: ¡ – IN[B] ¡= ¡USE[B] ¡U ¡(OUT[B] ¡– ¡DEF[B]) ¡

  7. Set ¡up ¡ • Boundary ¡condi=on: ¡IN[exit] ¡= ¡Ø ¡ • Ini=al ¡condi=ons: ¡IN[B] ¡= ¡Ø ¡ • Meet ¡opera=on: ¡ – OUT[B] ¡= ¡U ¡ ¡IN[Successors] ¡

  8. IN[B] ¡= ¡(OUT[B] ¡– ¡DEF[B]) ¡U ¡USE[B] ¡ Example ¡ OUT[B] ¡= ¡U ¡ ¡IN[Successors] ¡ ¡ ¡ Block ¡ DEF ¡ USE ¡ entry Entry ¡ Ø ¡ Ø ¡ Ø ¡ B1 ¡ {a, ¡b} ¡ Ø ¡ a = 2 B1 ¡ B2 ¡ {c} ¡ {a, ¡b} ¡ b = 3 B3 ¡ Ø ¡ {a, ¡c} ¡ Ø ¡ {a, ¡b} ¡ B4 ¡ Ø ¡ Ø ¡ c = a + b B2 ¡ c > 100 Ø ¡ Are ¡we ¡done? ¡ Ø ¡ {a, ¡c} ¡ B3 ¡ print(a,c) Ø ¡ return B4 ¡ Ø ¡

  9. IN[B] ¡= ¡(OUT[B] ¡– ¡DEF[B]) ¡U ¡USE[B] ¡ Example ¡ OUT[B] ¡= ¡U ¡ ¡IN[Successors] ¡ ¡ ¡ Block ¡ DEF ¡ USE ¡ entry Entry ¡ Ø ¡ Ø ¡ Ø ¡ B1 ¡ {a, ¡b} ¡ Ø ¡ a = 2 B1 ¡ B2 ¡ {c} ¡ {a, ¡b} ¡ b = 3 B3 ¡ Ø ¡ {a, ¡c} ¡ {a, ¡b} ¡ {a, ¡b} ¡ B4 ¡ Ø ¡ Ø ¡ c = a + b B2 ¡ c > 100 {a, ¡c} ¡ Are ¡we ¡done? ¡ Ø ¡ {a, ¡c} ¡ B3 ¡ print(a,c) Ø ¡ return B4 ¡ Ø ¡

  10. IN[B] ¡= ¡(OUT[B] ¡– ¡DEF[B]) ¡U ¡USE[B] ¡ Example ¡ OUT[B] ¡= ¡U ¡ ¡IN[Successors] ¡ ¡ ¡ Block ¡ DEF ¡ USE ¡ entry Entry ¡ Ø ¡ Ø ¡ B1 ¡ {a, ¡b} ¡ Ø ¡ a = 2 B1 ¡ b = 3 B2 ¡ {c} ¡ {a, ¡b} ¡ B3 ¡ Ø ¡ {a, ¡c} ¡ B4 ¡ Ø ¡ Ø ¡ c = a + b B2 ¡ c > 100 Block ¡ IN ¡ OUT ¡ Entry ¡ Ø ¡ Ø ¡ B3 ¡ print(a,c) B1 ¡ Ø ¡ {a, ¡b} ¡ B2 ¡ {a, ¡b} ¡ {a, ¡b, ¡c} ¡ return B4 ¡ B3 ¡ {a, ¡c} ¡ Ø ¡ B4 ¡ Ø ¡ Ø ¡

  11. Live ¡Variables ¡Summary ¡ LaAce ¡ Sets ¡of ¡variables ¡represented ¡by ¡ bit-­‑vectors ¡ Transfer ¡func=on ¡ IN[B] ¡= ¡f b (OUT[B]) ¡ f b (x) ¡= ¡USE[x] ¡U ¡(x ¡– ¡DEF[x]) ¡ ¡ Meet ¡opera=on ¡ OUT[B] ¡= ¡U ¡ ¡IN[Successors] ¡ Boundary ¡ IN[exit] ¡= ¡Ø ¡ condi=on ¡ ¡ Ini=al ¡condi=on ¡ IN[B] ¡= ¡Ø ¡

  12. Two ¡analyses ¡ Live ¡Variables ¡ Reaching ¡ Defini=ons ¡ LaAce ¡ Sets ¡of ¡variables ¡ Sets ¡of ¡defini=ons ¡ represented ¡by ¡bit-­‑ represented ¡by ¡bit-­‑ vectors ¡ vectors ¡ Transfer ¡func=on ¡ IN[B] ¡= ¡f b (OUT[B]) ¡ OUT[B] ¡= ¡f b (IN[B]) ¡ f b (x) ¡= ¡ ¡ f b (x) ¡= ¡ ¡ USE[x] ¡U ¡(x ¡– ¡DEF[x]) ¡ (x ¡– ¡KILL[x]) ¡U ¡ ¡GEN[x] ¡ Backward ¡ Forward ¡ Meet ¡opera=on ¡ OUT[B] ¡= ¡ ¡ IN[B] ¡= ¡ ¡ U ¡IN[Successors] ¡ U ¡OUT[Predecessors] ¡ Boundary ¡ IN[exit] ¡= ¡Ø ¡ OUT[entry] ¡= ¡0….0 ¡ condi=on ¡ Ini=al ¡condi=on ¡ IN[B] ¡= ¡Ø ¡ OUT[B] ¡= ¡0….0 ¡

  13. Dataflow ¡Analysis: ¡Steps ¡ • Decide ¡on ¡flow ¡values ¡(laAce) ¡ • Forward ¡/ ¡backward? ¡ • Design ¡transfer ¡func=ons ¡ • Design ¡meet ¡opera=on ¡ • What ¡are ¡the ¡boundary ¡and ¡ini=al ¡condi=ons? ¡

  14. “Must-­‑Reach” ¡defini=ons ¡ ¡ • A ¡defini=on ¡ D ¡must ¡reach ¡a ¡program ¡point ¡ P ¡iff ¡ – D ¡ appears ¡at ¡least ¡once ¡along ¡all ¡paths ¡ ¡ that ¡leads ¡to ¡ P ¡ – D ¡is ¡not ¡redefined ¡along ¡any ¡path ¡aner ¡the ¡last ¡ appearance ¡of ¡ D ¡and ¡before ¡ P ¡ • How ¡do ¡we ¡design ¡a ¡dataflow ¡analysis ¡for ¡this? ¡

  15. Legal ¡solu=ons ¡ entry IN[1] ¡= ¡{} ¡ OUT[1] ¡= ¡{} ¡ IN[2] ¡= ¡{d1} ¡ OUT[2] ¡= ¡{d1} ¡ IN[3] ¡= ¡{d1} ¡ 1: b = 1 OUT[3] ¡= ¡{d1} ¡ IN[4] ¡= ¡{d1} ¡ return

  16. What ¡do ¡we ¡care ¡about? ¡ • Correctness ¡ • Precision ¡ • Convergence ¡ • Run=me ¡

  17. Back ¡to ¡Constant ¡Propaga=on ¡ ¡s ¡= ¡0; ¡ ¡ a ¡= ¡4; ¡ ¡ i ¡= ¡0; ¡ k ¡== ¡0 ¡ ¡ b ¡= ¡1; ¡ b ¡= ¡2; ¡ i ¡< ¡n ¡ s ¡= ¡s ¡+ ¡a*b; ¡ return ¡s ¡ i ¡= ¡i ¡+ ¡1; ¡ ¡

  18. Back ¡to ¡Constant ¡Propaga=on ¡ ¡s ¡= ¡0; ¡ ¡ a ¡= ¡4; ¡ ¡ i ¡= ¡0; ¡ k ¡== ¡0 ¡ ¡ a ¡= ¡4 ¡ a ¡= ¡4 ¡ s ¡= ¡0 ¡ s ¡= ¡0 ¡ What ¡about ¡b? ¡ i ¡= ¡0 ¡ ¡ i ¡= ¡0 ¡ ¡ b ¡= ¡1; ¡ b ¡= ¡2; ¡ i ¡< ¡n ¡ a ¡= ¡4 ¡ s ¡= ¡0 ¡ s ¡= ¡s ¡+ ¡a*b; ¡ i ¡= ¡0 ¡ ¡ return ¡s ¡ i ¡= ¡i ¡+ ¡1; ¡ ¡

  19. Constant ¡Propaga=on: ¡laAce ¡ • Undefined: ¡ ⊥ ¡ • Constant: ¡…, ¡-­‑10, ¡-­‑9, ¡…, ¡0, ¡1, ¡2, ¡… ¡42, ¡… ¡ • NAC: ¡ ⊤ ¡ ¡ • Undefined ¡and ¡NAC ¡are ¡not ¡the ¡same! ¡ – Undefined: ¡variable ¡has ¡not ¡been ¡ini=alized ¡ – NAC: ¡variable ¡definitely ¡has ¡a ¡value ¡(we ¡just ¡don’t ¡ know ¡what) ¡

  20. Constant ¡Propaga=on: ¡meet ¡ ¡ • Meet ¡rules: ¡ – constant ¡ ¡ ∧ ¡ ¡constant ¡= ¡constant ¡ ¡ ¡ ¡(if ¡equal) ¡ – constant ¡ ¡ ∧ ¡ ¡constant ¡= ¡ ⊤ ¡ ¡ (if ¡not ¡equal) ¡ – constant ¡ ¡ ∧ ¡ ¡ ⊥ ¡= ¡constant ¡ – constant ¡ ¡ ∧ ¡ ¡ ⊤ ¡ = ¡ ⊤ ¡

  21. Constant ¡Propaga=on ¡ ¡s ¡= ¡0; ¡ ¡ a ¡= ¡4; ¡ ¡ i ¡= ¡0; ¡ k ¡== ¡0 ¡ ¡ a ¡= ¡4 ¡ a ¡= ¡4 ¡ s ¡= ¡0 ¡ s ¡= ¡0 ¡ i ¡= ¡0 ¡ ¡ i ¡= ¡0 ¡ ¡ b ¡= ¡1; ¡ b ¡= ¡2; ¡ i ¡< ¡n ¡ a ¡= ¡4 ¡ s ¡= ¡0 ¡ i ¡= ¡0 ¡ ¡ s ¡= ¡s ¡+ ¡a*b; ¡ b ¡= ¡ ⊤ ¡ return ¡s ¡ i ¡= ¡i ¡+ ¡1; ¡ ¡

  22. How ¡about ¡this? ¡ a ¡= ¡2; ¡ a ¡= ¡3; ¡ b ¡= ¡3; ¡ b ¡= ¡2; ¡ Is ¡x ¡a ¡constant? ¡ x ¡= ¡a ¡+ ¡b ¡

  23. How ¡about ¡this? ¡ a ¡= ¡2; ¡ a ¡= ¡3; ¡ b ¡= ¡3; ¡ b ¡= ¡2; ¡ a ¡= ¡2 ¡ a ¡= ¡3 ¡ b ¡= ¡3 ¡ b ¡= ¡2 ¡ a ¡= ¡ ⊤ ¡ x ¡= ¡a ¡+ ¡b ¡ b ¡= ¡ ⊤ ¡ x ¡= ¡ ⊤ ¡ constant ¡ ¡ ∧ ¡ ¡constant ¡= ¡ ⊤ ¡ ¡ (if ¡not ¡equal) ¡!! ¡

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