of optimized code Michael Ernst University of Washington (work - - PowerPoint PPT Presentation

of optimized code
SMART_READER_LITE
LIVE PREVIEW

of optimized code Michael Ernst University of Washington (work - - PowerPoint PPT Presentation

Practical fine-grained static slicing of optimized code Michael Ernst University of Washington (work done at Microsoft Research) Ernst Slicing 5/97 Page 1 Simple example Ernst Slicing 5/97 Page 2 Example: function calls and pointers Ernst


slide-1
SLIDE 1

Ernst Slicing 5/97 Page 1

Practical fine-grained static slicing

  • f optimized code

Michael Ernst University of Washington (work done at Microsoft Research)

slide-2
SLIDE 2

Ernst Slicing 5/97 Page 2

Simple example

slide-3
SLIDE 3

Ernst Slicing 5/97 Page 3

Example: function calls and pointers

slide-4
SLIDE 4

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

slide-5
SLIDE 5

Ernst Slicing 5/97 Page 5

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-6
SLIDE 6

Ernst Slicing 5/97 Page 6

Simple slicing algorithm

For graph-based program representation: Just graph reachability!

slide-7
SLIDE 7

Ernst Slicing 5/97 Page 7

The value dependence graph (VDG)

Sparse, functional, parallel representation for 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

slide-8
SLIDE 8

Ernst Slicing 5/97 Page 8

Components of the value dependence graph

+

Call 5 + x Update Store x

  • peration nodes

selectors closures (functions) function calls memory lookups (load instructions) memory assignments (store instructions)

slide-9
SLIDE 9

Ernst Slicing 5/97 Page 9

Example VDG

n I/O

* <

+ Call

Call + 1

sum i sum product product

Call

I/O

"Sum..."

printf void 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); }

slide-10
SLIDE 10

Ernst Slicing 5/97 Page 10

Example VDG, sliced

n I/O

* <

+ Call

Call + 1

sum i sum product product

Call

"Sum..."

I/O

printf

slide-11
SLIDE 11

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

slide-12
SLIDE 12

Ernst Slicing 5/97 Page 12

Slicing criteria

Expression results, not whole computations Any expression Any result, including unnameable ones Unreferenced variables

slide-13
SLIDE 13

Ernst Slicing 5/97 Page 13

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-14
SLIDE 14

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.

slide-15
SLIDE 15

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.

slide-16
SLIDE 16

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

slide-17
SLIDE 17

Ernst Slicing 5/97 Page 17

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-18
SLIDE 18

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 x Lookup store x Lookup

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

Ernst Slicing 5/97 Page 20

Aggregate values

Just like the store. Complexity

slide-21
SLIDE 21

Ernst Slicing 5/97 Page 21

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-22
SLIDE 22

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

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

Ernst Slicing 5/97 Page 25

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-26
SLIDE 26

Ernst Slicing 5/97 Page 26

Executable slicing

Goal: executable binary Applications:

specialization parallelization testing integration of program versions

slide-27
SLIDE 27

Ernst Slicing 5/97 Page 27

Compilable slicing

Traditional technique for executable slicing:

subset the original program compile using a standard compiler

slide-28
SLIDE 28

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

slide-29
SLIDE 29

Ernst Slicing 5/97 Page 29

Our executable slicing solution

Generate code directly from slice For debugging, use original program

10110

slide-30
SLIDE 30

Ernst Slicing 5/97 Page 30

Outline

Motivation Basic slicing algorithm Interprocedural Pointers and aggregate values Optimized code Executable slicing Conclusion

slide-31
SLIDE 31

Ernst Slicing 5/97 Page 31

Status

Part of a programming environment Handles C (except longjmp) Written in Scheme Integrated with Emacs

slide-32
SLIDE 32

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

slide-33
SLIDE 33

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;

slide-34
SLIDE 34

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