introduction to data flow analysis
play

Introduction to Data Flow Analysis GCC Resource Center - PowerPoint PPT Presentation

Workshop on Essential Abstractions in GCC Introduction to Data Flow Analysis GCC Resource Center (www.cse.iitb.ac.in/grc) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay 1 July 2012 1 July 2012


  1. Workshop on Essential Abstractions in GCC Introduction to Data Flow Analysis GCC Resource Center (www.cse.iitb.ac.in/grc) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay 1 July 2012

  2. 1 July 2012 Introduction to DFA: Outline 1/38 Outline • Motivation • Live Variables Analysis • Available Expressions Analysis • Pointer Analysis Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  3. Part 2 Motivation

  4. 1 July 2012 Introduction to DFA: Motivation 2/38 Dead Code Elimination B2 a 3 = 1; b 4 = 2 B2 a 3 = 1; b 4 = 2 B2 B2 c 5 = 3; n 6 = 6 c 5 = 3; n 6 = 6 • No uses for variables a 3 , b 4 , c 5 , and n 6 B4 a 1 = φ (1, a 7) B4 • Assignments to these variables if a 1 ≤ 6 can be deleted T F B3 a 7 = a 1 + 1 B5 if a 1 ≤ 11 T B6 D.1200 8 = a 1 + 2 B6 F a 9 = D.1200 8 + 3 How can we conclude this systematically? B7 a 2 = φ (a 1, a 9) return a 2 Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  5. 1 July 2012 Introduction to DFA: Motivation 3/38 Liveness Analysis of Variables Find out at each program point p , the variables that are used beyond p { a 7, a 9 } { a 7, a 9 } Which variables are used Which variables are used B2 a 3 = 1; b 4 = 2 beyond this point? B2 beyond this point? c 5 = 3; n 6 = 6 { a 7, a 9 } { a 7, a 9 } { a 7, a 9 } Which variables are used Which variables are used B4 a 1 = φ (1, a 7) beyond this point? B4 beyond this point? if a 1 ≤ 6 Which variables are used Which variables are used { a 1, a 9 } { a 1, a 9 } T beyond this point? { a 1 } beyond this point? Which variables are used F B3 a 7 = a 1 + 1 Which variables are used { a 1, a 9 } ∅ (Conservative assumption) ∅ (Conservative assumption) beyond this point? beyond this point? B5 if a 1 ≤ 11 { a 1, a 9 } { a 1, a 9 } { a 1 } T Which variables are used Which variables are used B6 D.1200 8 = a 1 + 2 beyond this point? F B6 beyond this point? a 9 = D.1200 8 + 3 { a 1, a 9 } { a 1, a 9 } { a 1, a 9 } Which variables are used B7 a 2 = φ (a 1, a 9) What about a 2? beyond this point? return a 2 ∅ ∅ Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  6. 1 July 2012 Introduction to DFA: Motivation 4/38 Liveness Analysis of Variables: Iteration 2 Find out at each program point p , the variables that are used beyond p { a 7, a 9 } B2 a 3 = 1; b 4 = 2 B2 c 5 = 3; n 6 = 6 { a 7, a 9 } B4 a 1 = φ (1, a 7) B4 if a 1 ≤ 6 { a 1, a 9 } T F B3 a 7 = a 1 + 1 ∅ (Conservative assumption) { a 7, a 9 } B5 if a 1 ≤ 11 { a 1, a 9 } T B6 D.1200 8 = a 1 + 2 F B6 a 9 = D.1200 8 + 3 { a 1, a 9 } B7 a 2 = φ (a 1, a 9) return a 2 ∅ Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  7. 1 July 2012 Introduction to DFA: Motivation 5/38 Using Liveness Analysis for Dead Code Elimination Find out at each program point p , the variables that are used beyond p { a 7, a 9 } B2 a 3 = 1; b 4 = 2 B2 a 3 = 1; b 4 = 2 B2 B2 c 5 = 3; n 6 = 6 c 5 = 3; n 6 = 6 { a 7, a 9 } B4 a 1 = φ (1, a 7) B4 if a 1 ≤ 6 • Values of a 3 , a 4 , c 5 , and n 6 are { a 1, a 9 } T guaranteed not to be used F B3 a 7 = a 1 + 1 • Why are the values of a 7 and a 9 { a 7, a 9 } meaningful at the exit of B2? B5 if a 1 ≤ 11 { a 1, a 9 } T • We have assumed a φ function to be an ordinary expression in which B6 D.1200 8 = a 1 + 2 F B6 operands are computed along every a 9 = D.1200 8 + 3 path reaching the computation { a 1, a 9 } B7 a 2 = φ (a 1, a 9) return a 2 ∅ Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  8. Part 3 Live Variables Analysis

  9. 1 July 2012 Introduction to DFA: Live Variables Analysis 6/38 Defining Live Variables Analysis A variable v is live at a program point p , if some Path based path from p to program exit contains an r-value oc- specification currence of v which is not preceded by an l-value occurrence of v . v is live at p v is not live at p v is live at p Start Start Start p p p v = a ∗ b v = a ∗ b a = v +2 v = a +2 v = v +2 v = v + 2 End End End Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  10. 1 July 2012 Introduction to DFA: Live Variables Analysis 7/38 Defining Data Flow Analysis for Live Variables Analysis Single statements or Maximal groups Basic Blocks ≡ of sequentially executed statements In k = Gen k ∪ ( Out k − Kill k ) In k = Gen k ∪ ( Out k − Kill k ) Gen k , Kill k Gen k , Kill k Out k = In i ∪ In j Out k = In i ∪ In j In j In j In i In i Gen i , Kill i Gen i , Kill i Gen j , Kill j Gen j , Kill j Out i Out i Out j Out j Local Data Flow Properties Control Transfer Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  11. 1 July 2012 Introduction to DFA: Live Variables Analysis 8/38 Local Data Flow Properties for Live Variables Analysis l-value occurrence r-value occurrence Value is modified e.g. y in Value is only read, e.g. x,y,z in y = x.lptr x.sum = y.data + z.data Gen n = { v | variable v is used in basic block n and is not preceded by a definition of v } Kill n = { v | basic block n contains a definition of v } within n anywhere in n Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  12. 1 July 2012 Introduction to DFA: Live Variables Analysis 9/38 Local Data Flow Properties for Live Variables Analysis • Gen n : Use not preceded by definition Upwards exposed use • Kill n : Definition anywhere in a block Stop the effect from being propagated across a block Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  13. 1 July 2012 Introduction to DFA: Live Variables Analysis 10/38 Defining Data Flow Analysis for Live Variables Analysis Edge based Global Data Flow Properties specifications In k = Gen k ∪ ( Out k − Kill k ) Gen k , Kill k Out k = In i ∪ In j In j In i Gen i , Kill i Gen j , Kill j Out i Out j Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  14. 1 July 2012 Introduction to DFA: Live Variables Analysis 11/38 Data Flow Equations For Live Variables Analysis ( Out n − Kill n ) ∪ Gen n In n =  n is End block BI  � = Out n otherwise In s  s ∈ succ ( n ) In n and Out n are sets of variables. Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  15. 1 July 2012 Introduction to DFA: Live Variables Analysis 12/38 Performing Live Variables Analysis { a 7 , a 9 } a 3 = 1; b 4 = 2 B2 c 5 = 3; n 6 = 6 { a 7 , a 9 } { a 7 , a 9 } a 1 = φ (1, a 7) B4 Gen Kill if a 1 ≤ 6 { a 1 , a 9 } { a 3, b 4, T B2 ∅ { a 1 , a 9 } { a 1 } c 5, n 6 } F B3 a 7 = a 1 + 1 B4 { a 7 } { a 1 } { a 1 , a 9 } ∅ { a 7 , a 9 } { a 1 } { a 7 } B3 if a 1 ≤ 11 B5 B5 { a 1 } ∅ { a 1 , a 9 } T B6 { a 1 } { a 9 } { a 1 } B6 D.1200 8 = a 1 + 2 F B6 B7 { a 1, a 9 } { a 2 } a 9 = D.1200 8 + 3 { a 1 , a 9 } { a 1 , a 9 } B7 a 2 = φ (a 1, a 9) return a 2 ∅ Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  16. 1 July 2012 Introduction to DFA: Live Variables Analysis 13/38 Strongly Live Variables Analysis A variable v is strongly live if it is used in • in statement other than assignment statement, or (this case is same as simple liveness analysis) • in defining other strongly live variables in an assignment statement (this case is different from simple liveness analysis) Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  17. 1 July 2012 Introduction to DFA: Live Variables Analysis 14/38 Understanding Strong Liveness Simple Strong Simple Strong Simple Strong Liveness Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } { z , x } { z } y = x y = x y = x { x } { x } { y } { y } { z } { z } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ ∅ Same Same Different Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  18. 1 July 2012 Introduction to DFA: Live Variables Analysis 15/38 Comparision of Simple and Strong Liveness for our Example Simple Liveness Strong Liveness { a 7 , a 9 } { a 7 } a 3 = 1; b 4 = 2 a 3 = 1; b 4 = 2 B2 B2 c 5 = 3; n 6 = 6 c 5 = 3; n 6 = 6 { a 7 , a 9 } { a 7 } { a 7 , a 9 } { a 7 } a 1 = φ (1, a 7) a 1 = φ (1, a 7) B4 B4 { a 1 , a 9 } if a 1 ≤ 6 { a 1 } if a 1 ≤ 6 T T { a 1 , a 9 } { a 1 } ∅ F F B3 a 7 = a 1 + 1 B3 a 7 = a 1 + 1 { a 1 , a 9 } { a 1 } { a 7 } ∅ { a 7 , a 9 } if a 1 ≤ 11 B5 if a 1 ≤ 11 B5 { a 1 , a 9 } T T ∅ D.1200 8 = a 1 + 2 { a 1 } D.1200 8 = a 1 + 2 ∅ F F B6 a 9 = D.1200 8 + 3 B6 B6 a 9 = D.1200 8 + 3 B6 { a 1 , a 9 } print ”Hello” print ”Hello” ∅ { a 1 , a 9 } ∅ B7 a 2 = φ (a 1, a 9) B7 a 2 = φ (a 1, a 9) print ”Hi” print ”Hi” ∅ ∅ Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  19. 1 July 2012 Introduction to DFA: Live Variables Analysis 16/38 Using Data Flow Information of Live Variables Analysis • Used for register allocation. If variable x is live in a basic block b , it is a potential candidate for register allocation. • Used for dead code elimination. If variable x is not live after an assignment x = . . . , then the assginment is redundant and can be deleted as dead code. Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  20. Part 4 Available Expressions Analysis

Recommend


More recommend