A Probabilistic Pointer Analysis A Probabilistic Pointer Analysis - - PowerPoint PPT Presentation

a probabilistic pointer analysis a probabilistic pointer
SMART_READER_LITE
LIVE PREVIEW

A Probabilistic Pointer Analysis A Probabilistic Pointer Analysis - - PowerPoint PPT Presentation

A Probabilistic Pointer Analysis A Probabilistic Pointer Analysis for Speculative Optimization for Speculative Optimization Jeff DaSilva Jeff DaSilva Greg Steffan Greg Steffan Electrical and Computer Engineering Electrical and Computer


slide-1
SLIDE 1

A Probabilistic Pointer Analysis for Speculative Optimization A Probabilistic Pointer Analysis for Speculative Optimization

Jeff DaSilva Greg Steffan Jeff DaSilva Greg Steffan

Electrical and Computer Engineering University of Toronto

Toronto, ON, Canada

Oct 17th, 2005

Electrical and Computer Engineering University of Toronto

Toronto, ON, Canada

Oct 17th, 2005

slide-2
SLIDE 2

2 University Of Toronto

Pointers Impede Optimization Pointers Impede Optimization

Many optimizations come to a halt when

they encounter an ambiguous pointer

foo(int *a) { … while(…)

{

x = *a; …

} }

Loop Invariant Code Motion Parallelize

Pointer Analysis is Important

slide-3
SLIDE 3

3 University Of Toronto

Pointer Analysis Pointer Analysis

Do pointers a and b point to the same location?

Do this for every pair of pointers at every program point

*a = ~ ~ = *b *a = ~ ~ = *b

Definitely Not Definitely Maybe

Pointer Analysis

  • ptimize
slide-4
SLIDE 4

4 University Of Toronto

  • Pointer analysis

Pointer analysis is a difficult problem

  • scalable

scalable and overly conservative

  • verly conservative
  • fails

fails-

  • to

to-

  • scale

scale and accurate accurate

Ambiguous pointers will persist

even when using the most accurate

accurate of algorithms

  • utput is often unavoidable

What can be done with ?

Pointer Analysis is Difficult Pointer Analysis is Difficult

Maybe Maybe

  • r
  • r
slide-5
SLIDE 5

5 University Of Toronto

Lets Speculate Lets Speculate

Compilers make conservative

conservative assumptions

They must always

always preserve program correctness

“It's easier to apologize than ask for permission.”

Author: Anonymous

Implement a potentially unsafe unsafe optimization

Verify Verify and Recover Recover if necessary

slide-6
SLIDE 6

6 University Of Toronto

Speculation applied to Pointers Speculation applied to Pointers

int *a, x; … while(…)

{

x = *a; …

}

a is probably

loop invariant

int *a, x, tmp; … tmp = *a; while(…)

{

x = tmp; …

}

<verify, recover?> <verify, recover?>

slide-7
SLIDE 7

7 University Of Toronto

Data Speculative Optimizations Data Speculative Optimizations

The EPIC Instruction set

Explicit support for speculative load/store instructions (eg. Itanium)

Speculative compiler transformations

Dead store elimination, redundancy elimination, copy propagation,

strength reduction, register promotion

Thread-level speculation (TLS)

Hardware support for tracking speculative parallel threads

Transactional programming

Rollback support for aborted transactions

When to speculate? Techniques rely on profiling

slide-8
SLIDE 8

8 University Of Toronto

Quantitative Output Required Quantitative Output Required

Estimate the potential benefit for speculating:

SPECULATE? Expected Expected speedup speedup

(if successful) (if successful)

Recovery Recovery penalty penalty

(if unsuccessful) (if unsuccessful)

Overhead Overhead for verify for verify

Probabilistic output needed

Maybe

Maybe

Maybe

Probability Probability

  • f success
  • f success
slide-9
SLIDE 9

9 University Of Toronto

Conventional Pointer Analysis Conventional Pointer Analysis

Do pointers a and b point to the same location?

Do this for every pair of pointers at every program point

*a = ~ ~ = *b *a = ~ ~ = *b

Definitely Not Definitely Maybe

Pointer Analysis

  • ptimize
  • ptimize
slide-10
SLIDE 10

10 University Of Toronto

*a = ~ ~ = *b *a = ~ ~ = *b

  • ptimize

Probabilistic Pointer Analysis Probabilistic Pointer Analysis (PPA)

(PPA)

PPA

p p = 0.0 p p = 1.0 0.0 < p p < 1.0

With what probability p

p, do pointers a and b point

to the same location?

Do this for every pair of pointers at every program point

  • ptimize
slide-11
SLIDE 11

11 University Of Toronto

PPA Research Objectives PPA Research Objectives

Accurate points-to probability information

at every static pointer dereference

Scalable analysis

Goal: The entire SPEC integer benchmark suite

Understand scalability

scalability/accuracy accuracy tradeoff

through flexible static memory model

Improve our understanding of programs

slide-12
SLIDE 12

12 University Of Toronto

Algorithm Design Choices Algorithm Design Choices

  • Fixed

Fixed

Bottom Up / Top Down Approach Linear

Linear transfer functions (for scalability)

One-level context

context and flow flow sensitive

  • Flexible

Flexible

Edge profiling (or static prediction) Safe (or unsafe) Field sensitive (or field insensitive)

slide-13
SLIDE 13

13 University Of Toronto

Traditional Points Traditional Points-

  • To Graph

To Graph

int x, y, z, *b = &x;

void foo(int *a) {

if(…) b = &y; if(…) a = &z; else(…) a = b; while(…) { x = *a; …

} }

y

UND

a z b x = pointer = pointed at

Definitely Maybe

= =

Results are inconclusive

slide-14
SLIDE 14

14 University Of Toronto

Probabilistic Points Probabilistic Points-

  • To Graph

To Graph

int x, y, z, *b = &x;

void foo(int *a) {

if(…) b = &y; if(…) a = &z; else(…) a = b; while(…) { x = *a; …

} }

y

UND

a z b x

  • 0.1

0.1 taken

taken(

(edge edge profile profile) )

  • 0.2

0.2 taken

taken(

(edge edge profile profile) )

= pointer = pointed at

p = 1.0 0.0<p< 1.0

= =

p

0.1 0.9 0.72 0.08 0.2

Results provide more information

slide-15
SLIDE 15

15 University Of Toronto

LOL LOLL

LIP

IPO

OP

P

Our PPA Algorithm Our PPA Algorithm

L Linear

inear

O One

ne -

  • L

Level

evel

I Interprocedural

nterprocedural

P Probabilistic

robabilistic

P Pointer Analysis

  • inter Analysis
slide-16
SLIDE 16

16 University Of Toronto

Points Points-

  • To Matrix

To Matrix

Location Sets Area Of Interest

I

1 2 … N-1 N … M-1 M

All matrix rows sum to 1.0

Location Sets Pointer Sets

slide-17
SLIDE 17

17 University Of Toronto

Points Points-

  • To Matrix Example

To Matrix Example

y

UND

z x y

UND

z x a b

0.72 0.08 0.20 0.90 0.10 1.0 1.0

1.0 1.0

I

y

UND

a z b x

0.1 0.9 0.72 0.08 0.2

slide-18
SLIDE 18

18 University Of Toronto

Solving for a Points Solving for a Points-

  • To Matrix

To Matrix

I

Any I nstruction Any I nstruction

I

Points-To Matrix In Points-To Matrix Out

slide-19
SLIDE 19

19 University Of Toronto

The Fundamental PPA Equation The Fundamental PPA Equation Points-To Matrix Out Points-To Matrix In

Transformation

Matrix

=

This can be applied to any instruction (incl. function calls)

slide-20
SLIDE 20

20 University Of Toronto

Transformation Matrix Transformation Matrix

1 2 N-1 N

ø I

1 2 3 … … N-1 N …

Area of Interest

Location Sets Pointer Sets

All matrix rows sum to 1.0

Location Sets Pointer Sets

slide-21
SLIDE 21

21 University Of Toronto

Transformation Matrix Example Transformation Matrix Example

y

UND

z x a b y

UND

z x a b

1.0 1.0 1.0

1.0 1.0

1.0

S1: S1: a = &z;

a = &z;

=

TS1

slide-22
SLIDE 22

22 University Of Toronto

1.0 1.0

1.0 1.0

1.0 1.0

Example Example -

  • The PPA Equation

The PPA Equation

S1: S1: a = &z;

a = &z;

PTout = TS1 PTin

0.72 0.08 0.20 0.90 0.10 1.0 1.0

1.0 1.0

=

PTout

slide-23
SLIDE 23

23 University Of Toronto

Example Example -

  • The PPA Equation

The PPA Equation

y

UND

z x y

UND

z x a b

1.0 0.90 0.10 1.0 1.0

1.0 1.0 y

UND

z b x

0.1

0.9

a

S1: S1: a = &z;

a = &z;

PTout = TS1 PTin =

PTout

slide-24
SLIDE 24

24 University Of Toronto

Combining Transformation Matrices Combining Transformation Matrices

I

Basic Block

S1: S1: I nstr

I nstr

S2: S2: I nstr

I nstr

S3: S3: I nstr

I nstr

I

PTout

TS1

=

PTin TS3 PTin

PTout = TBB

TS1

slide-25
SLIDE 25

25 University Of Toronto

Control flow Control flow -

  • if/else

if/else

Y Y X X

TX TY

= + p q p q p + q = 1.0

slide-26
SLIDE 26

26 University Of Toronto

Control flow Control flow -

  • loops

loops

TX

=

X X

N N

= U L i

TY

=

1

U-L+1

i

<L,U>

Y Y

Both operations can be implemented efficiently

<L,U> <min,max>

slide-27
SLIDE 27

27 University Of Toronto

Safe vs. Unsafe Safe vs. Unsafe Pointer Assignment Instructions Pointer Assignment Instructions

Store Assignment *x = y Load Assignment x = *y Copy Assignment x = y Address-of Assignment x = &y

  • Safe?
slide-28
SLIDE 28

28 University Of Toronto

LOL LOLL

LIP

IPO

OP

P Implementation

Implementation

.spd Edge Profile Results

SUIF Infrastructure

Static Memory Model

MATLAB C Library

TF-Matrix Collector Points-To Matrix Propagator

Stats

ICFG ICFG SMM SMM BU BU TD TD

.spx

slide-29
SLIDE 29

29 University Of Toronto

Measuring Measuring

LOL LOLL

LIP

IPO

OP

P’

’s s Efficiency Efficiency and and Accuracy Accuracy

slide-30
SLIDE 30

30 University Of Toronto

SPEC2000 Benchmark Data SPEC2000 Benchmark Data

Experimental Framework: 3GHz P4 with 2GB of RAM

PPA Analysis Time

[Safe]

PPA Analysis Time

[Unsafe] Matrix Size N LOC

Benchmark 30.72 seconds 2732 11402 Parser Parser 16.59 seconds 2611 20469 Twolf Twolf 9.33 seconds 1976 17750 Vpr Vpr 5.49 seconds 1917 21297 Cr Craf afty ty 0.71 seconds 563 8616 Gzip Gzip 0.39 seconds 354 2429 Mcf Mcf 0.3 seconds 251 4686 Bzip2 Bzip2 50.04 seconds 20.64 seconds 10.34 seconds 5.51 seconds 0.77 seconds 0.61 seconds 0.3 seconds 5hour 10 min 42109 22225 Gcc Gcc 44min 15seconds 20922 85221 Perlb Perlbmk 54min 56seconds 25882 71766 Gap Gap 3min 59seconds 11018 67225 Vortex Vortex Still Running… 89min 43seconds 83min 38seconds 4min 56seconds

Scales to all of SPECint

slide-31
SLIDE 31

31 University Of Toronto

Comparison w ith Comparison w ith Das Das’ ’s s GOLF GOLF

Yes No Probabilistic Yes Yes Safe > 5 hours < 10 seconds

Analysis Time on GCC

Profiled Solved Indirect Calls Modeled Some Modeled All Library Calls Callsite Alloc Callsite Alloc Heap Model Turned Off No Field Sensitive Yes No Flow Sensitive One-level One-level Context Sensitive

LOLLIPOP GOLF

slide-32
SLIDE 32

32 University Of Toronto

Comparison w ith Das Comparison w ith Das’ ’s GOLF s GOLF

Average Dereference Size

more accurate

LOLLIPOP is very Accurate

Accurate (even without probability information)

14.8 3.3 7.7 1.2 11.9 21.9 59.3 3.3 1.8 2.6 1.1 80.1 6.7 18.5 6.1 10 20 30 40 50 60 70 80 90 100

g

  • m

8 8 k s i m * g c c c

  • m

p r e s s l i i j p e g p e r l v

  • r

t e x GOLF LOLLIPOP

185.6

slide-33
SLIDE 33

33 University Of Toronto

Easy SPEC2000 Benchmarks Easy SPEC2000 Benchmarks

1.4 1.2 1.5 1.8 6.1 1.0 1.3

1 2 3 4 5 6 7

gzip vpr mcf crafty vortex bzip2 twolf

unsafe safe p > 0.001

Average Dereference Size

more accurate

A one-level Analysis is often adequate (i.e. safe=unsafe)

slide-34
SLIDE 34

34 University Of Toronto

Challenging SPEC 95/2000 Benchmarks Challenging SPEC 95/2000 Benchmarks

42.5 89.0 143.8 80.1 6.7 18.5

20 40 60 80 100 120 140

parser perlbmk gap li ijpeg perl

unsafe safe p > 0.001

Average Dereference Size

more accurate

Many improbable points-to relations can be pruned away

slide-35
SLIDE 35

35 University Of Toronto

Metric: Average Certainty Metric: Average Certainty

while(…)

{

x = *a; …

}

{ (0.72, ), (0.08, ), (0.2, ) }

y z x

Σ(max probability value)

(num of loads & stores)

Avg Certainty =

Max probability value = 0.72

slide-36
SLIDE 36

36 University Of Toronto

SPEC2000 Average Certainty SPEC2000 Average Certainty

0.905 0.949 0.970 0.920 0.946 0.969 0.870 0.783 0.908 1.000 0.901

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

g z i p v p r * g c c m c f c r a f t y p a r s e r p e r l b m k g a p v

  • r

t e x b z i p 2 t w

  • l

f

Probabilistic Certainty

more accurate

On average, LOLLIPOP can predict a single likely points-to relation

slide-37
SLIDE 37

37 University Of Toronto

Conclusions and Future Work Conclusions and Future Work

  • LOL

LOLL

LIP

IPO

OP

P

A novel PPA algorithm Scales to SPECint 95/2000 As accurate as the most precise algorithms

  • Future Ongoing Work

Future Ongoing Work

Measure the probabilistic accuracy Optimize LOLLIPOP’s implementation Apply PPA

Provides the key puzzle piece for a speculation compiler

slide-38
SLIDE 38

38 University Of Toronto

References References

  • Manuvir Das, Ben Liblit, Manuel Fahndrich, and Jakob Rehof. Estimating

the Impact of Scalable Pointer Analysis on Optimization. SAS 2001, 260-278.

  • Peng-Sheng Chen, Ming-Yu Hung, Yuan-Shin Hwang, Roy Dz-Ching Ju,

and Jenq Kuen Lee. Compiler support for speculative multithreading architecture with probabilistic points-to analysis. PPOPP 2003, 25-36.

  • Jin Lin, Tong Chen, Wei-Chung Hsu, Peng-Chung Yew, Roy Dz-Ching Ju,

Tin-Fook Ngai and Sun Chan, A Compiler Framework for Speculative Analysis and Optimizations. PLDI 2003, 289-299.

  • R.D. Ju, J. Collard, and K. Oukbir. Probabilistic Memory Disambiguation

and its Application to Data Speculation. SIGARCH Comput. Archit. News 27 1999, 27-30.

  • Manel Fernandez and Roger Espasa. Speculative Alias Analysis for

Executable Code. PACT 2002, 221-231.