1 / 40

Optimizing Compilers CISC 673 Spring 2009 More Data flow analysis

Optimizing Compilers CISC 673 Spring 2009 More Data flow analysis. John Cavazos University of Delaware. Overview. Last Time: Avail Expressions Using Sets Using Bit Vectors Additional Data Flow Problem Constant Propagation Generalization of Data Flow. Computing Available Expressions.

anneke
Download Presentation

Optimizing Compilers CISC 673 Spring 2009 More Data flow analysis

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. Optimizing CompilersCISC 673Spring 2009More Data flow analysis John Cavazos University of Delaware

  2. Overview • Last Time: Avail Expressions Using Sets • Using Bit Vectors • Additional Data Flow Problem • Constant Propagation • Generalization of Data Flow

  3. Computing Available Expressions AVAIL(b) = ppred(b)(DEEXPR(p) (AVAIL(p)  EXPRKILL(p) )) AVAIL(n0) = Ø where preds(b) is the set of b’s predecessors in the CFG Remember these!

  4. Avail Expressions Using Bit Vectors • 1 = avail; 0 = not • Boundary condition • Forward Flow on Entry • Backward Flow on Exit • Initial conditions • Merge operator

  5. Avail Expressions Using Bit Vectors Note: Empty entry and exit blocks added to CFG To save space not pictured here! 1=avail 0=not (A+B)(X+Y) 10 = (A+B) avail (X+Y) not 11 = both avail …

  6. Avail Expressions Using Bit Vectors What is Merge Operator? Remember original equation 1=avail 0=not (A+B)(X+Y) …

  7. Avail Expressions Using Bit Vectors What is Boundary Condition? Remember original algorithm 1=avail 0=not (A+B)(X+Y) Merge: and (⋀) …

  8. Avail Expressions Using Bit Vectors 00 Boundary Condition Now must initialize OUT of blocks. Initial Condition? 1=avail 0=not (A+B)(X+Y) Merge: and (⋀) …

  9. Initial Conditions? • What is needed so loops work? • Needs to be identify for merge function X ⋀ ? = X

  10. Initial Conditions? • What is needed so loops work? • Needs to be identify for merge function X ⋀ 1 = X

  11. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 (⋀) 2. 3. 11 11 4. ─ … gen and kill are constants! 11

  12. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. out1= ?? 11 (⋀) 2. 3. 11 11 4. … 11

  13. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= ?? (⋀) 2. 3. 11 11 4. … 11

  14. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (??⋀ ??) (⋀) 2. 3. 11 11 4. … 11

  15. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ ??) (⋀) 2. 3. 11 11 4. … 11

  16. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ 01) (⋀) 2. 3. = 01 out3= ?? 01 11 11 4. … 11

  17. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ 01) (⋀) 2. 3. = 01 01 out3= 01 ⋁ (??⋀ ??) 11 11 4. … 11

  18. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ 01) (⋀) 2. 3. = 01 out3= 01 ⋁ (11⋀ 11) 01 11 11 = 11 4. … 11

  19. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ 01) (⋀) 2. 3. = 01 out3= 01 ⋁ (11⋀ 11) 01 11 11 = 11 out4= ?? 4. … 11

  20. Avail Expressions Using Bit Vectors 00 in[b]=⋀p pred(b)out[p] 1=avail 0=not (A+B)(X+Y) Merge: and ─ out=gen ⋁ (in ⋀ kill) 1. 11 out1= 11 out2= 00 ⋁ (11⋀ 01) (⋀) 2. 3. = 01 out3= 01 ⋁ (11⋀ 11) 01 11 11 = 11 out4= 00 ⋁ (01⋀ 11) 4. … = 01 01 11

  21. Constant Propagation • Along every path to point p, • variable v has same “known” value • Specialize computation at p based on v’s value

  22. … -2 -1 0 1 2 ... The Lattice of CP Constant Propagation Hasse diagram • Lattice (V, ≤) • Top ⊤ • Not a Constant • Bottom ⊥ • Unknown

  23. Some Lattice Theory • Generalized Meet Operator ⊔ • Used at “merge” points • Avail Expression:  • Least Upper Bound (LUB) • X ⊔ Y = least element Z s.t. • X ≤ Z and Y ≤ Z

  24. {a+b,c+d,e+f,a+17,b+18}, {a+b,c+d,e+f,a+17} {a+b,c+d,e+f,b+18} {a+b,c+d,a+17,b+18} {a+b,e+f,a+17,b+18} {c+d,e+f,a+17,b+18} {a+b,c+d,e+f} {a+b,c+d,b+18} {a+b,c+d,a+17} {a+b,e+f,a+17} {a+b,e+f,b+18} {a+b,a+17,b+18} {c+d,e+f,a+17} {c+d,e+f,b+18} {c+d,a+17,b+18} {e+f,a+17,b+18}, {a+b,c+d} {a+b,a+17} {c+d,e+f} {c+d,b+18} {e+f,b+18} {a+b,e+f} {a+b,b+18} {c+d,a+17} {e+f,a+17} {a+17,b+18} {a+b} {c+d} {e+f} {a+17} {b+18} { } Concrete Example: Available Expressions meet

  25. … -2 -1 0 1 2 ... The Lattice of CP More Lattice Theory: Const Prop • ⊥ ≤ anything • ∀x ⊥ ⊔ x = x • anything ≤ ⊤ • ∀x x ⊔ ⊤= ⊤ • ∀x x ⊔ x = x

  26. Relate to Constant Prop?! • i and j are integer values • i ⊔ i = i • i ⊔ j = ⊤ if i ≠ j

  27. What is X in Block 3? 1. 2. 3.

  28. What is X in Block 3? 1. 2. 3. x is ⊤

  29. Top ⊤ versus Bottom ⊥ • ⊤ means definitely NOT a constant • Inputs are ⊤ • ⊥ means Undefined • Could be constant but we do not know!

  30. Constant Propagation Problem • Variable v has constant value c at point p, iff ∀ paths from entry to p, the most recently assigned value for v is c

  31. Constant Prop Example Meet Operator = ⊔ Identity= ? X ⊔ ? = X

  32. Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition?

  33. Constant Prop Example Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition? XYZ ⊥⊥⊥ ⊥⊥⊥ ⊥⊥⊥ ⊥⊥⊥

  34. Constant Prop Example ⊥⊥⊥ Meet Operator = ⊔ Identify= ⊥ X ⊔ ⊥ = X Initial Condition Boundary Condition XYZ 1. ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥

  35. Constant Prop Example ⊥⊥⊥ XYZ out1= ??? 1. ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥

  36. Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 4. ⊥⊥⊥

  37. Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 023 4. ⊥⊥⊥

  38. Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= 12⊥ out4= ??? 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ 12⊥ 023 4. ⊥⊥⊥

  39. Constant Prop Example ⊥⊥⊥ XYZ out1= 1⊥⊥ out2= 023 out3= 12⊥ out4= ⊤23 1. 1⊥⊥ ⊥⊥⊥ 2. 3. ⊥⊥⊥ ⊥⊥⊥ Does this make sense? 12⊥ 023 4. ⊥⊥⊥ ⊤23

  40. Next Time • Static-Single Assignment (SSA Form) • Read Efficiently computing static single assignment form and the control dependence graph, Cytron et al. http://portal.acm.org/citation.cfm?id=115320

More Related