Symbolic Bounds Analysis of Pointers, Array Indices, and Accessed Memory Regions

65
Symbolic Bounds Analysis of Pointers, Array Indices, and Accessed Memory Regions Radu Rugina and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

description

Symbolic Bounds Analysis of Pointers, Array Indices, and Accessed Memory Regions. Radu Rugina and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology. Outline. Examples Key Problem: Extracting Symbolic Bounds for Accessed Memory Regions - PowerPoint PPT Presentation

Transcript of Symbolic Bounds Analysis of Pointers, Array Indices, and Accessed Memory Regions

Page 1: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Symbolic Bounds Analysis of Pointers, Array Indices, and

Accessed Memory Regions

Radu Rugina and Martin RinardLaboratory for Computer Science

Massachusetts Institute of Technology

Page 2: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Outline• Examples

• Key Problem: Extracting Symbolic Bounds for Accessed Memory Regions

• Key Technology: Formulating and Solving Systems of Symbolic Inequality Constraints

• Results• Conclusion

Page 3: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Example - Divide and Conquer Sort

47 6 1 53 8 2

Page 4: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

8 2536 147

Example - Divide and Conquer Sort

47 6 1 53 8 2

Divide

Page 5: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

2 8531 674

8 2536 147

47 6 1 53 8 2

Example - Divide and Conquer Sort

Conquer

Divide

Page 6: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Example - Divide and Conquer Sort

2 8531 674 Conquer

8 2536 147 Divide

47 6 1 53 8 2

41 6 7 32 5 8Combine

Page 7: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Example - Divide and Conquer Sort

2 8531 674 Conquer

8 2536 147 Divide

47 6 1 53 8 2

41 6 7 32 5 8Combine

21 3 4 65 7 8

Page 8: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

“Sort n Items in d, Using t as Temporary Storage”

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

Page 9: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

“Sort n Items in d, Using t as Temporary Storage”

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n); Motivating ProblemExploit parallelism in this code

Page 10: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Recursively Sort Four Quarters of d”

Divide array into subarrays and recursively sort

subarrays

Page 11: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

47 6 1 53 8 2

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Recursively Sort Four Quarters of d”

dd+n/4d+n/2

d+3*(n/4)

Subproblems Identified

Using Pointers Into Middle of Array

Page 12: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

47 6 1 53 8 2

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Recursively Sort Four Quarters of d”

dd+n/4d+n/2

d+3*(n/4)

Page 13: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

74 1 6 53 2 8

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Recursively Sort Four Quarters of d”

dd+n/4d+n/2

d+3*(n/4)

Sorted Results Written Back Into

Input Array

Page 14: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Merge Sorted Quarters of d Into Halves of t”

74 1 6 53 2 8

41 6 7 32 5 8d

tt+n/2

Page 15: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Merge Sorted Halves of t Back Into d”

21 3 4 65 7 8

41 6 7 32 5 8d

tt+n/2

Page 16: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Use a Simple Sort for Small Problem Sizes”

47 6 1 53 8 2

dd+n

Page 17: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void sort(int *d, int *t, int n) if (n > CUTOFF) {

sort(d,t,n/4); sort(d+n/4,t+n/4,n/4);sort(d+2*(n/2),t+2*(n/2),n/4);sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));merge(d,d+n/4,d+n/2,t);merge(d+n/2,d+3*(n/

4),d+n,t+n/2);merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

“Use a Simple Sort for Small Problem Sizes”

47 1 6 53 8 2

dd+n

Page 18: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Parallel Sortvoid sort(int *d, int *t, int n) if (n > CUTOFF) {

spawn sort(d,t,n/4); spawn sort(d+n/4,t+n/4,n/4);spawn sort(d+2*(n/2),t+2*(n/2),n/4);spawn sort(d+3*(n/4),t+3*(n/4),n-

3*(n/4));sync;spawn merge(d,d+n/4,d+n/2,t);spawn

merge(d+n/2,d+3*(n/4),d+n,t+n/2);sync;merge(t,t+n/2,t+n,d);

} else insertionSort(d,d+n);

Page 19: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

What Do You Need To Know To Exploit This Form of Parallelism?

Page 20: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

What Do You Need To Know To Exploit This Form of Parallelism?

Symbolic Information About Accessed Memory Regions

Page 21: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Calls to sort access disjoint parts of d and tTogether, calls access [d,d+n-1] and [t,t+n-1]

sort(d,t,n/4);

sort(d+n/4,t+n/4,n/4);

sort(d+n/2,t+n/2,n/4);

sort(d+3*(n/4),t+3*(n/4), n-3*(n/4));

Information Needed To Exploit Parallelism

dt

dt

dt

dt

d+n-1t+n-1

d+n-1t+n-1

d+n-1t+n-1

d+n-1t+n-1

Page 22: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

First two calls to merge access disjoint parts of d,t

Together, calls access [d,d+n-1] and [t,t+n-1]

merge(d,d+n/4,d+n/2,t);

merge(d+n/2,d+3*(n/4), d+n,t+n/2);

merge(t,t+n/2,t+n,d);

dt

dt

d+n-1t+n-1

d+n-1t+n-1

dt

d+n-1t+n-1

Information Needed To Exploit Parallelism

Page 23: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

dt

d+n-1t+n-1

Information Needed To Exploit Parallelism

Calls to insertionSort access [d,d+n-1]

insertionSort(d,d+n);

Page 24: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

What Do You Need To Know To Exploit This Form of Parallelism?

sort(p,n) accesses [p,p+n-1]insertionSort(p,n) accesses [p,p+n-1]merge(l,m,h,d) accesses [l,h-1], [d,d+(h-l)-1]

Symbolic Information About Accessed Memory Regions:

Page 25: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

How Hard Is It To Figure These Things Out?

Page 26: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Challenging

How Hard Is It To Figure These Things Out?

Page 27: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

How Hard Is It To Figure These Things Out?

void insertionSort(int *l, int *h) {int *p, *q, k;for (p = l+1; p < h; p++) {

for (k = *p, q = p-1; l <= q && k < *q; q--)*(q+1) = *q;

*(q+1) = k;}

}Not immediately obvious that

insertionSort(l,h) accesses [l,h-1]

Page 28: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void merge(int *l1, int*m, int *h2, int *d) {int *h1 = m; int *l2 = m;while ((l1 < h1) && (l2 < h2))

if (*l1 < *l2) *d++ = *l1++;else *d++ = *l2++;

while (l1 < h1) *d++ = *l1++;while (l2 < h2) *d++ = *l2++;

}

Not immediately obvious that merge(l,m,h,d)

accesses [l,h-1] and [d,d+(h-l)-1]

How Hard Is It To Figure These Things Out?

Page 29: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Issues• Heavy Use of Pointers

• Pointers into Middle of Arrays• Pointer Arithmetic• Pointer Comparison

• Multiple Procedures• sort(int *d, int *t, n)• insertionSort(int *l, int *h)• merge(int *l, int *m, int *h, int *t)

• Recursion

Page 30: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

How the Compiler Does It

Page 31: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Compiler StructurePointer Analysis

Bounds Analysis

Region Analysis

Parallelization

Disambiguate References at Granularity of Allocation Blocks

Symbolic Upper and LowerBounds for Each Memory Access in Each Procedure

Symbolic Regions AccessedBy Execution of Each Procedure

Independent Procedure CallsThat Can Execute in Parallel

Page 32: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Example – Array Incrementvoid f(char *p, int n)

if (n > CUTOFF) {f(p, n/2); /* increment first half */f(p+n/2, n/2); /* increment second half */} else {/* base case: initialize small array */int i = 0;while (i < n) { *(p+i) += 1; i++; }}

Page 33: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Intra-procedural Bounds Analysis• For each integer variable at each program

point, derive lower and upper bounds

• Bounds are symbolic expressions• variables represent initial values of

parameters of enclosing procedure• bounds are linear combinations of

variables

• Example expression for f(p,n): p+n-1

Page 34: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

What are upper and lower bounds for region accessed by while loop in base

case?

int i = 0;while (i < n) { *(p+i) += 1; i++; }

Bounds Analysis

Page 35: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Bounds Analysis, Step 1Build control flow graph

i = 0

i < n

*(p+i) += 1

i = i+1

Page 36: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Set up bounds at beginning of basic blocks

Bounds Analysis, Step 2

l1 i u1i = 0

i < n

*(p+i) += 1

i = i+1

l2 i u2

l3 i u3

Page 37: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Compute transfer functionsBounds Analysis, Step 3

l1 i u1i = 0

i < n

*(p+i) += 1

i = i+1

l2 i u2

l3 i u3

0 i 0

l3 i u3

l3+1 i u3+1

Page 38: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

l2 i n-1 l2 i u2

l2 i u2

Compute transfer functionsBounds Analysis, Step 3

l1 i u1i = 0

i < n

*(p+i) += 1

i = i+1

l3 i u3

0 i 0

l3 i u3

l3+1 i u3+1

Page 39: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Set up constraints for boundsBounds Analysis, Step 4

l2 i n-1 l2 i u2

l2 i u2

l1 i u1i = 0

i < n

*(p+i) += 1

i = i+1

l3 i u3

0 i 0

l3 i u3

l3+1 i u3+1

l2 0l2 l3+1l3 l2

0 u2

u2+1 u2

n-1 u3

Page 40: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Set up constraints for boundsBounds Analysis, Step 4

l2 i n-1 l2 i u2

l2 i u2

- i +i = 0

i < n

*(p+i) += 1

i = i+1

l3 i u3

0 i 0

l3 i u3

l3+1 i u3+1

l2 0l2 l3+1l3 l2

0 u2

u2+1 u2

n-1 u3

Page 41: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Generate symbolic expressions for bounds

Goal: express bounds in terms of parametersl2 = c1p + c2n + c3

l3 = c4p + c5n + c6

Bounds Analysis, Step 5

u2 = c7p + c8n + c9

u3 = c10p + c11n + c12

Page 42: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

c1p + c2n + c3 0c1p + c2n + c3 c4p + c5n + c6 +1c4p + c5n + c6 c1p + c2n + c3

Substitute expressions into constraintsBounds Analysis, Step 6

0 c7p + c8n + c9

c10p + c11n + c12 +1 c7p + c8n + c9

c7p + c8n + c9 c10p + c11n + c12

Page 43: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Goal

Solve Symbolic Constraint Systemfind values for constraint variables c1, ..., c12 that satisfy the inequality constraints

Maximize Lower Bounds

Minimize Upper Bounds

Page 44: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Reduce symbolic inequalities to linear inequalities

c1p + c2n + c3 c4p + c5n + c6

if

c1 c4, c2 c5, and c3 c6

Bounds Analysis, Step 7

Page 45: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Apply reduction and generate a linear programc1 0 c2 0 c3 0c1 c4 c2 c5 c3 c6+1c4 c1 c5 c2 c6 c3

lower bounds upper bounds

Bounds Analysis, Step 7

Objective Function:max: (c1 + ••• + c6) - (c7 + ••• + c12)

0 c7 0 c8 0 c9

c10 c7 c11 c8 c12+1

c9

c7 c10 c8 c11 c9 c12

Page 46: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Apply reduction and generate a linear program

• This is a linear program (LP), not an integer linear program (ILP)

• The coefficients in the symbolic expressions are rational numbers

• Rational coefficients are needed for expressions like middle of an array: low+(high - low)/2

Bounds Analysis, Step 7

Page 47: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Solve linear program to extract boundsc1=0 c2 =0 c3 =0 c4=0 c5 =0 c6 =0 c7=0 c8 =1 c9 =0 c10=0 c11=1 c12=-1

Bounds Analysis, Step 8

u2 = 0u3 = n-1

l2 i n-1 l2 i u2

l2 i u2

- i +i = 0

i < n

*(p+i) += 1

i = i+1

l3 i u3

0 i 0

l3 i u3

l3+1 i u3+1

l2 = 0l3 = 0

Page 48: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Solve linear program to extract boundsBounds Analysis, Step 8

0 i n-1 0 i n

0 i n

- i +i = 0

i < n

*(p+i) += 1

i = i+1

0 i n-1

0 i 0

0 i n-1

1 i n

c1=0 c2 =0 c3 =0 c4=0 c5 =0 c6 =0 c7=0 c8 =1 c9 =0 c10=0 c11=1 c12=-1

u2 = 0u3 = n-1

l2 = 0l3 = 0

Page 49: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Solve linear program to extract boundsBounds Analysis, Step 8

0 i n-1 0 i n

0 i n

- i +i = 0

i < n

*(p+i) += 1

i = i+1

0 i n-1

0 i 0

0 i n-1

1 i n

c1=0 c2 =0 c3 =0 c4=0 c5 =0 c6 =0 c7=0 c8 =1 c9 =0 c10=0 c11=1 c12=-1

u2 = 0u3 = n-1

l2 = 0l3 = 0

Page 50: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Region AnalysisGoal: Compute Accessed Regions of Memory

• Intra-Procedural• Use bounds at each load or store• Compute accessed region

• Inter-Procedural• Use intra-procedural results• Set up another symbolic constraint

system• Solve to find regions accessed by entire

execution of the procedure

Page 51: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Basic Principle of Inter-Procedural Region Analysis

• For each procedure• Generate symbolic expressions for

upper and lower bounds of accessed regions

• Constraint System• Accessed regions include regions

accessed by statements in procedure• Accessed regions include regions

accessed by invoked procedures

Page 52: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

void f(char *p, int n) if (n > CUTOFF) {

f(p, n/2);

f(p+n/2, n/2);} else {

int i = 0;while (i < n) { *(p+i) += 1; i++; }

}

l(f,p,n) l(f,p,n/2)u(f,p,n) u(f,p,n/2)l(f,p,n) l(f,p+n/2,n/2)u(f,p,n) u(f,p+n/2,n/2)

l(f,p,n) pu(f,p,n) p+n-1

Inter-Procedural Constraints in Example

Accesses [ l(f,p,n), u(f,p,n) ]

Page 53: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Derive Constraint System• Generate symbolic expressions

l(f,p,n) = C1p + C2n + C3

u(f,p,n) = C4p + C5n + C6

• Build constraint systemC1p + C2n + C3 pC4p + C5n + C6 p + n -1C1p + C2n + C3 C1p + C2(n/2) + C3 C4p + C5n + C6 C4p + C5(n/2) + C6 C1p + C2n + C3 C1(p+n/2) + C2(n/2) + C3 C4p + C5n + C6 C4(p+n/2) + C5(n/2) + C6

Page 54: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

• Simplify Constraint SystemC1p + C2n + C3 pC4p + C5n + C6 p + n -1C2n C2(n/2)C5n C5(n/2) C2(n/2) C1(n/2)C5(n/2) C4(n/2)

• Generate and Solve Linear Programl(f,p,n) = pu(f,p,n) = p+n-1

• Access region: [p, p+n-1]

Solve Constraint System

Page 55: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Parallelization

• Dependence Testing of Two Calls• Do accessed regions intersect?• Based on comparing upper and lower

bounds of accessed regions

• Parallelization• Find sequences of independent calls• Execute independent calls in parallel

Page 56: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Details• Inter-procedural positivity analysis

• Verify that variables are positive• Required for correctness of reduction

• Correlation analysis• Integer division

• Basic idea : (n-1)/2 n/2 n/2• Generalized : (n-m+1)/m n/m

n/m• Linear system decomposition

Page 57: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Comparison to Dataflow Analysis

• Dataflow analysis:• Uses iterative algorithms• Cannot handle lattices with infinite

ascending chains, because termination is not guaranteed

• Our framework • Reduces the analysis to a linear program• Works for lattices with infinite ascending

chains like integers, rational numbers or polynomials

• No possibility of non-termination

Page 58: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Automatic ParallelizationOf Sequential Programs

Data Race DetectionFor Parallel Programs

Array Bounds CheckingFor Unsafe Programs

Bounds Checks EliminationFor Safe Programs

Transformations Verifications

Uses of Symbolic Bounds Information

Page 59: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Application of Analysis Framework

• Bitwidth Analysis:• Computes minimum number of bits

to represent computed values • Important for hardware synthesis

from high level languages

• For our framework:• Bitwidth analysis is a special case:

Compute precise numeric bounds• Constraint system = linear program

Page 60: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Experimental Results• Implementation - SUIF, lp_solve, Cilk

• Parallelization speedups:

Application

Number of Processors1 2 4 6 8

Fibonacci 0.76 1.52 3.03 4.55 6.04Quicksort 1.00 1.99 3.89 5.68 7.36Mergesort 1.00 2.00 3.90 5.70 7.41Heat 1.03 2.02 3.89 5.53 6.83BlockMul 0.97 1.86 3.84 5.70 7.54NoTempMul

1.02 2.01 4.03 6.02 8.02

LU 0.98 1.95 3.89 5.66 7.39

Page 61: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

• Implementation - SUIF, lp_solve, Cilk

• Parallelization speedups:• Close to linear speedups• Most of parallelism detected

Experimental Results

Page 62: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

• Implementation - SUIF, lp_solve, Cilk

• Parallelization speedups:• Close to linear speedups• Most of parallelism detected

• Compiler also verified that:• Parallel versions were free of data races• Benchmarks do not violate the array bounds

Experimental Results

Page 63: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Experimental Results• Implementation - SUIF, lp_solve

• Bitwidth reduction:

0

20

40

60

80

100

percentage ofeliminatedregister bitspercentage ofeliminatedmemory bits

Page 64: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Context• Mainstream parallelizing compilers

• Loop nests, dense matrices• Affine access functions

• Our framework focuses on:• Recursion, dynamically allocated arrays• Pointers, pointer arithmetic• Key problems: pointer analysis, symbolic

region analysis, solving linear programs

Page 65: Symbolic Bounds Analysis  of Pointers, Array Indices, and  Accessed Memory Regions

Conclusion• Novel framework for symbolic bounds

analysis• Uses symbolic constraint systems• Reduces problem to linear programs• More powerful than iterative approaches

• Analysis uses:• Parallelization, data race detection• Detecting array bounds violations• Array bounds check elimination• Bitwidth analysis