slides3 - Principles of Program Analysis Control 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: Control Flow Analysis Transparencies based on Chapter 3 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 3 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 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
The Dynamic Dispatch Problem . . . [ call p( p1 ,1,v) ] ` 1 c ` 1 r . . . [ call p( p2 ,2,v) ] ` 2 c ` 2 r . . . proc p( procval q , val x, res y) is ` n . . . [ call q (x,y) ] ` p c ` p r which procedure is called? . . . end ` x These problems arise for: imperative languages with procedures as parameters object oriented languages functional languages PPA Chapter 3 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 2
Background image of page 2
Example: let f = fn x => x 1 ; g = fn y => y+2; h = fn z => z+3 in ( f g ) + ( f h ) The aim of Control Flow Analysis: For each function application, which functions may be applied? Control Flow Analysis computes the interprocedural flow relation used when formulating interprocedural Data Flow Analysis. PPA Chapter 3 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 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
Syntax of the Fun Language Syntactic categories: e Exp expressions (or labelled terms) t Term terms (or unlabelled expressions) f, x Var variables c Const constants op Op binary operators ` Lab labels Syntax: e ::= t ` t ::= c | x | fn x => e 0 | fun f x => e 0 | e 1 e 2 | if e 0 then e 1 else e 2 | let x = e 1 in e 2 | e 1 op e 2 (Labels correspond to program points or nodes in the parse tree.) PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 4
Background image of page 4
Examples: ( ( fn x => x 1 ) 2 ( fn y => y 3 ) 4 ) 5 ( let f = ( fn x => (x 1 1 2 ) 3 ) 4 ; in ( let g = ( fn y => y 5 ) 6 ; in ( let h = ( fn z => z 7 ) 8 in ( (f 9 g 10 ) 11 + (f 12 h 13 ) 14 ) 15 ) 16 ) 17 ) 18 ( let g = ( fun f x => ( f 1 ( fn y => y 2 ) 3 ) 4 ) 5 in ( g 6 ( fn z => z 7 ) 8 ) 9 ) 10 PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 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
Abstract 0-CFA Analysis Abstract domains Specification of the analysis Well-definedness of the analysis PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 6
Background image of page 6
Towards defining the Abstract Domains The result of a 0-CFA analysis is a pair ( b C , b ρ ): b C is the abstract cache associating abstract values with each labelled program point b ρ is the abstract environment associating abstract values with each variable PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 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
Example: ( ( fn x => x 1 ) 2 ( fn y => y 3 ) 4 ) 5 Three guesses of a 0-CFA analysis result: ( b C e , b ρ e ) ( b C 0 e , b ρ 0 e ) ( b C 00 e , b ρ 00 e ) 1 2 3 4 5 x y { fn y => y 3 } { fn x => x 1 } { fn y => y 3 } { fn y => y 3 } { fn y => y 3 } { fn y => y 3 } { fn x => x 1 } { fn y => y 3 } { fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } { fn x => x 1 , fn y => y 3 } PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004) 8
Background image of page 8
Example: ( let g = ( fun f x => ( f 1 ( fn y => y 2 ) 3 ) 4 ) 5 in ( g 6 ( fn z => z 7 ) 8 ) 9 ) 10 Abbreviations: f = fun f x => ( f 1 ( fn y => y 2 ) 3 ) 4 id y = fn y => y 2 id z = fn z => z 7 One guess of a 0-CFA analysis result: b C lp (1) = { f } b C lp (2) = b C lp (3) = { id y } b C lp (4) = b C lp (5) = { f } b C lp (6) = { f } b C lp (7) = b C lp (8) = { id z } b C lp (9) = b C lp (10) = b ρ lp ( f ) = { f } b ρ lp ( g ) = { f } b ρ lp ( x ) = { id y , id z } b ρ lp ( y ) = b ρ lp ( z ) = PPA Section 3.1 c ± F.Nielson & H.Riis Nielson & C.Hankin (Dec. 2004)
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.

This note was uploaded on 02/07/2012 for the course CSCI 5513 taught by Professor Gopalan during the Spring '10 term at Minnesota.

Page1 / 99

slides3 - Principles of Program Analysis Control 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