slides2 - Principles of Program Analysis: Data Flow...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Principles of Program Analysis: Data Flow Analysis Transparencies based on Chapter 2 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis . Springer Verlag 2005. c ± Flemming Nielson & Hanne Riis Nielson & Chris Hankin. PPA Chapter 2 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example Language Syntax of While-programs a ::= x | n | a 1 op a a 2 b ::= true | false | not b | b 1 op b b 2 | a 1 op r a 2 S ::= [ x := a ] ` | [ skip ] ` | S 1 ; S 2 | if [ b ] ` then S 1 else S 2 | while [ b ] ` do S Example: [ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) Abstract syntax – parentheses are inserted to disambiguate the syntax PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 2
Background image of page 2
Building an “Abstract Flowchart” Example: [ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) init ( ··· ) = 1 final ( ) = { 2 } labels ( ) = { 1 , 2 , 3 , 4 } flow ( ) = { (1 , 2) , (2 , 3) , (3 , 4) , (4 , 2) } flow R ( ) = { (2 , 1) , (2 , 4) , (3 , 2) , (4 , 3) } [ x:=x-1 ] 4 [ z:=z*y ] 3 [ x>0 ] 2 [ z:=1 ] 1 ? ? ? - ? ? yes no PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Initial labels init ( S ) is the label of the first elementary block of S : init : Stmt Lab init ([ x := a ] ` ) = ` init ([ skip ] ` ) = ` init ( S 1 ; S 2 ) = init ( S 1 ) init ( if [ b ] ` then S 1 else S 2 ) = ` init ( while [ b ] ` do S ) = ` Example: init ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = 1 PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 4
Background image of page 4
Final labels final ( S ) is the set of labels of the last elementary blocks of S : final : Stmt → P ( Lab ) final ([ x := a ] ` ) = { ` } final ([ skip ] ` ) = { ` } final ( S 1 ; S 2 ) = final ( S 2 ) final ( if [ b ] ` then S 1 else S 2 ) = final ( S 1 ) final ( S 2 ) final ( while [ b ] ` do S ) = { ` } Example: final ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = { 2 } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Labels labels ( S ) is the entire set of labels in the statement S : labels : Stmt → P ( Lab ) labels ([ x := a ] ` ) = { ` } labels ([ skip ] ` ) = { ` } labels ( S 1 ; S 2 ) = labels ( S 1 ) labels ( S 2 ) labels ( if [ b ] ` then S 1 else S 2 ) = { ` } ∪ labels ( S 1 ) labels ( S 2 ) labels ( while [ b ] ` do S ) = { ` } ∪ labels ( S ) Example labels ([ z:=1 ] 1 ; while [ x>0 ] 2 do ( [ z:=z*y ] 3 ;[ x:=x-1 ] 4 ) ) = { 1 , 2 , 3 , 4 } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 6
Background image of page 6
Flows and reverse flows flow ( S ) and flow R ( S ) are representations of how control flows in S : flow , flow R : Stmt → P ( Lab × Lab ) flow ([ x := a ] ` ) = flow ([ skip ] ` ) = flow ( S 1 ; S 2 ) = flow ( S 1 ) flow ( S 2 ) ∪ { ( `, init ( S 2 )) | ` final ( S 1 ) } flow ( if [ b ] ` then S 1 else S 2 ) = flow ( S 1 ) flow ( S 2 ) ∪ { ( `, init ( S 1 )) , ( `, init ( S 2 )) } flow ( while [ b ] ` do S ) = flow ( S ) ∪ { ( `, init ( S )) } ∪ { ( ` 0 ,` ) | ` 0 final ( S ) } flow R ( S ) = { ( `,` 0 ) | ( ` 0 ) flow ( S ) } PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Elementary blocks A statement consists of a set of elementary blocks blocks : Stmt → P ( Blocks ) blocks ([ x := a ] ` ) = { [ x := a ] ` } blocks ([ skip ] ` ) = { [ skip ] ` } blocks ( S 1 ; S 2 ) = blocks ( S 1 ) blocks ( S 2 ) blocks ( if [ b ] ` then S 1 else S 2 ) = { [ b ] ` } ∪ blocks ( S 1 ) blocks ( S 2 ) blocks ( while [ b ] ` do S ) = { [ b ] ` } ∪ blocks ( S ) A statement S is label consistent if and only if any two elementary statements [ S 1 ] ` and [ S 2 ] ` with the same label in S are equal: S 1 = S 2 A statement where all labels are unique is automatically label consistent PPA Section 2.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 8
Background image of page 8
Intraprocedural Analysis Classical analyses: Available Expressions Analysis Reaching Definitions Analysis
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 151

slides2 - Principles of Program Analysis: Data Flow...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online