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 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
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
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
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
Quicksort Example: Partitioning … … 5 2 8 6 3 first last SAS'03 - June 2003 Static Analysis of Accessed Regions
Quicksort Example: Partitioning … … 5 2 8 6 3 first mid last SAS'03 - June 2003 Static Analysis of Accessed Regions
Quicksort Example: Partitioning … … 5 2 8 6 3 first mid prev crt last SAS'03 - June 2003 Static Analysis of Accessed Regions
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
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
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
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
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
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
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
Quicksort Example: Partitioning … … 3 2 5 8 6 first last mid SAS'03 - June 2003 Static Analysis of Accessed Regions
Quicksort Example: Recursing … … 2 3 5 6 8 first last mid SAS'03 - June 2003 Static Analysis of Accessed Regions
Quicksort Example: Accessed Regions … … 2 3 5 6 8 Modified these locations first last SAS'03 - June 2003 Static Analysis of Accessed Regions
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
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
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
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
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
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
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
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
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