static analysis of accessed regions in recursive data
play

Static Analysis of Accessed Regions in Recursive Data Structures - PowerPoint PPT Presentation

Static Analysis of Accessed Regions in Recursive Data Structures Stephen Chong Radu Rugina Cornell University What This Talk is About Problem: Precise characterization of regions accessed by statements and procedures For recursive


  1. Static Analysis of Accessed Regions in Recursive Data Structures Stephen Chong Radu Rugina Cornell University

  2. What This Talk is About � Problem: Precise characterization of regions accessed by statements and procedures � For recursive programs with destructive updates � Fine-grained notion of regions: substructures within recursive data structures. • E.g. sublists within lists, sub trees within trees � How we do it: � Context sensitive interprocedural analysis algorithm � Precise shape information � Region access information � Uses: � Parallelization, Program Understanding, Correctness SAS'03 - June 2003 Static Analysis of Accessed Regions

  3. Quicksort Example � Sorts a sublist in place (i.e. with destructive updates) … … 5 2 8 6 3 first last SAS'03 - June 2003 Static Analysis of Accessed Regions

  4. Quicksort Example � Sorts a sublist in place (i.e. with destructive updates) … … 5 2 8 6 3 Sort these elements first last SAS'03 - June 2003 Static Analysis of Accessed Regions

  5. Quicksort Example � Chooses a pivot value � Partitions list into sublists destructively … … 5 2 8 6 3 Sort these elements first last … … 3 2 5 8 6 first last SAS'03 - June 2003 Static Analysis of Accessed Regions

  6. Quicksort Example: Partitioning … … 5 2 8 6 3 first last SAS'03 - June 2003 Static Analysis of Accessed Regions

  7. Quicksort Example: Partitioning … … 5 2 8 6 3 first mid last SAS'03 - June 2003 Static Analysis of Accessed Regions

  8. Quicksort Example: Partitioning … … 5 2 8 6 3 first mid prev crt last SAS'03 - June 2003 Static Analysis of Accessed Regions

  9. Quicksort Example: Partitioning … … 5 2 8 6 3 first mid prev crt last mid.val > crt.val ? Yes! SAS'03 - June 2003 Static Analysis of Accessed Regions

  10. Quicksort Example: Partitioning 2 … … 5 8 6 3 crt first mid prev last mid.val > crt.val ? Yes! SAS'03 - June 2003 Static Analysis of Accessed Regions

  11. Quicksort Example: Partitioning 2 … … 5 8 6 3 crt first mid prev last mid.val > crt.val ? Yes! SAS'03 - June 2003 Static Analysis of Accessed Regions

  12. Quicksort Example: Partitioning … … 2 5 8 6 3 first crt last mid prev mid.val > crt.val ? Yes! SAS'03 - June 2003 Static Analysis of Accessed Regions

  13. Quicksort Example: Partitioning … … 2 5 8 6 3 first crt last mid prev crt = prev-> next SAS'03 - June 2003 Static Analysis of Accessed Regions

  14. Quicksort Example: Partitioning … … 2 5 8 6 3 first crt last mid prev mid.val > crt.val ? No! SAS'03 - June 2003 Static Analysis of Accessed Regions

  15. Quicksort Example: Partitioning … … 2 5 8 6 3 first prev crt last mid crt = prev-> next SAS'03 - June 2003 Static Analysis of Accessed Regions

  16. Quicksort Example: Partitioning … … 3 2 5 8 6 first last mid SAS'03 - June 2003 Static Analysis of Accessed Regions

  17. Quicksort Example: Recursing … … 2 3 5 6 8 first last mid SAS'03 - June 2003 Static Analysis of Accessed Regions

  18. Quicksort Example: Accessed Regions … … 2 3 5 6 8 Modified these locations first last SAS'03 - June 2003 Static Analysis of Accessed Regions

  19. Quicksort Example: Accessed Regions … … 2 3 5 6 8 Modified these locations first last … … 2 3 5 6 8 Recursive call modified Recursive call modified these locations these locations first mid last SAS'03 - June 2003 Static Analysis of Accessed Regions

  20. Quicksort Example voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  21. Quicksort Example voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; i f ( m i d == l a s t ) r e t ur n; Base cases c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  22. Quicksort Example voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; List partitioning c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  23. Quicksort Example voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; Recursive calls qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  24. Quicksort Example voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; Goal: Automatically i f ( m i d == l a s t ) r e t ur n; determine that the c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; procedure accesses only the sublist between first whi l e ( c r t ! = l a s t ) { and last. i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  25. Quicksort Example: Abstraction voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; α β i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; first last whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  26. Quicksort Example: Abstraction voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; α β i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; first last whi l e ( c r t ! = l a s t ) { i f ( c r t - >va l > m i d- >va l ) { pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; first last f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

  27. Quicksort Example: Abstraction voi d qui c ks or t ( l i s t *f i r s t , l i s t *l a s t ) { l i s t *m i d, *c r t , *pr e v; m i d = pr e v = f i r s t - >ne xt ; α β i f ( m i d == l a s t ) r e t ur n; c r t = pr e v- >ne xt ; i f ( c r t == l a s t ) r e t ur n; first last whi l e ( c r t ! = l a s t ) { Effects: Reads: α i f ( c r t - >va l > m i d- >va l ) { Writes: α pr e v = c r t ; } e l s e { pr e v- >ne xt = c r t - >ne xt ; c r t - >ne xt = f i r s t - >ne xt ; f i r s t - >ne xt = c r t ; } c r t = pr e v- >ne xt ; } qui c ks or t ( f i r s t , m i d) ; qui c ks or t ( m i d, l a s t ) ; } Static Analysis of Accessed Regions

Recommend


More recommend