34
Ernst Slicing 5/97 Page 1 Practical fine-grained static slicing of optimized code Michael Ernst University of Washington (work done at Microsoft Research)

Static slicing talk - homes.cs.washington.edu

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 1

Practical fine-grained static slicingof optimized code

Michael Ernst

University of Washington

(work done at Microsoft Research)

Page 2: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 2

Simple example

Page 3: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 3

Example: function calls and pointers

Page 4: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 4

Applications of slicing

Closure slicing: visualize dependences

program understanding

maintenance

test coverage

debugging

Executable slicing: produce binary

specialization

parallelization

testing

integration of program versions

Dynamic slicing: execution tracing

Page 5: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 5

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 6: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 6

Simple slicing algorithm

For graph-based program representation:

Just graph reachability!

Page 7: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 7

The value dependence graph (VDG)

Sparse, functional, parallel representationfor imperative programs

Insights:

Only values matter

Original names and control flow are incidental

Consequences:

All values are explicit

Select values, not control paths

Control flow represented by function calls

Page 8: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 8

Components of thevalue dependence graph

+

Call

5

+

xUpdate

Store

x

operation nodes

selectors

closures (functions)

function calls

memory lookups (load instructions)memory assignments (store instructions)

Page 9: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 9

Example VDGn I/O

*<

+

Call

Call

+

1

sumi

sum product

product

0

Call

I/O

"Sum..."

printfvoid sum_product(int n)

{

int sum = 0;

int product = 0;

int i = 0;

while (i++ < n)

{ sum = sum + i;

product = product * i;

}

printf("Sum %d, product %d",

sum, product);

}

Page 10: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 10

Example VDG, sliced

n I/O

*<

+

Call

Call

+

1

sumi

sum product

product

0

Call

"Sum..."

I/O

printf

Page 11: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 11

The VDG is good for slicing

Simple, fast algorithm

Fine granularity

One graph directly links producers and consumers

All values are explicit

Page 12: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 12

Slicing criteria

Expression results, not whole computations

Any expression

Any result, including unnameable ones

Unreferenced variables

Page 13: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 13

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 14: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 14

Interprocedural slicing

Goals:

sensitive to calling context

do not include entire procedure or all calls

efficient

omit irrelevant procedures

Obvious solution: graph reachability

call results procedure returns

formal parameters actual parameters

This does not satisfy our goals.

Page 15: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 15

Interprocedural slicing (solution)

Summarize dependences of returns on formals

Separately include appropriate portions of body

When slicing criterion is within a procedure, include all calls

This meets our goals.

Page 16: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 16

Procedure summary dependences

Optimistic forward dataflow problem

operation result depends on what the operands depend on

for calls, use current approximation as transfer function

reprocess calls when new approximation becomes available

iterate until fixpoint is reached

Complexity

Page 17: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 17

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 18: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 18

Pointers

Support arbitrary pointer manipulations

Points-to analysis gives possibly referenced locations

For lookup, slice on location and (part of) store

x

store

= Lookup

store

xLookup

storex

Lookup

...*x......x...

Page 19: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 19

Treat store as a collection

Slice on every possibly referenced location.

Slice continues at

killing def: location, value (use pointer equality)

preserving def: location, value, store

other: store

Lookup

store

x

Update

a

store

22

store

Page 20: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 20

Aggregate values

Just like the store.

Complexity

Page 21: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 21

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 22: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 22

Slicing optimized code

Improve:

dependences

liveness

computations

overhead

The hardware runs optimized code

Slice reflects intermediate representation’s semantics

Page 23: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 23

Correspondence with source code

Need many-to-many mappings

VDG node source text

source text VDG node

Maintain a separate source graph

initially isomorphic to VDG

transformations modify VDG and source correspondences

slicing traverses both graphs in tandem

slice display defaultly highlights only appropriate sources

Page 24: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 24

History mechanism

Source graphs are never side-effected or removed

Transformations add to source graph

Mappings no longer necessarily inverses

This enables

undoing transformations

explaining changes

slice according to naive interpretation

slice dead code

statement-oriented display

Page 25: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 25

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 26: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 26

Executable slicing

Goal: executable binary

Applications:

specialization

parallelization

testing

integration of program versions

Page 27: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 27

Compilable slicing

Traditional technique for executable slicing:

subset the original program

compile using a standard compiler

Page 28: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 28

Compilable slicing tradeoffs

Retains context, comments, formatting, names

Include undemanded portions of the program to satisfy syntactic constraints

multi-valued computation

function call parameters

variable assignments

control flow: goto, continue, break

Limits optimization

Hard to undo

Page 29: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 29

Our executable slicing solution

Generate code directly from slice

For debugging, use original program

10110

Page 30: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 30

Outline

Motivation

Basic slicing algorithm

Interprocedural

Pointers and aggregate values

Optimized code

Executable slicing

Conclusion

Page 31: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 31

Status

Part of a programming environment

Handles C (except longjmp)

Written in Scheme

Integrated with Emacs

Page 32: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 32

Future work

Quasi-static slicing

Dynamic slicing

History mechanism

User interface alternatives

Tests on real users

Debugging optimized code

Page 33: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 33

Ambiguity in program points

+

c

Update

a

b

store

+

y

Update

z

x

store

+

y

Update

z

x

+

c

Update

a

b

store (a,b,c)

store (a,b,c)

store (x,y,z)

store (x,y,z)

z = ...;

a = b + c;

z = x * y;

Page 34: Static slicing talk - homes.cs.washington.edu

Ernst Slicing 5/97 Page 34

Comparing the VDG and PDG

Which PDG?

VDG:

no implicit quantities

better integration with programming environment

easier analysis, transformation

cleaner interprocedural representation

single graph

finer granularity