Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96...

14
Fast Effective Dynamic Fast Effective Dynamic Compilation Compilation Joel Auslander, Mathai Philipose, Craig Chambers, Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 etc. PLDI’96 Department of Computer Science and Engineering Univ. of Washington Presented by Zhelong Pan April 12 th , 2002
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96...

Page 1: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Fast Effective Dynamic CompilationFast Effective Dynamic Compilation

Joel Auslander, Mathai Philipose, Craig Chambers, etc. Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96PLDI’96

Department of Computer Science and Engineering Univ. of Washington

Presented by Zhelong Pan April 12th, 2002

Page 2: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

IntroductionIntroduction

• Enable optimizations based on the invariant Enable optimizations based on the invariant data computed at run-time:data computed at run-time:– Eliminate memory loadsEliminate memory loads– Perform constant propagation and foldingPerform constant propagation and folding– Remove branchesRemove branches– Fully unroll loopsFully unroll loops

• Overhead: the run-time cost of dynamic Overhead: the run-time cost of dynamic compilation.compilation.

• Goal: Fast compilation and high-quality Goal: Fast compilation and high-quality code.code.

Page 3: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Basic IdeasBasic IdeasStep 1: The programmer

annotates the dynamic regions.

Step 3: Compute and patch the run-time constants to the

template.

Step 2: Generate pre-optimized templates.

Step 4: Use the new code during the execution.

Templates: pre-compiled optimized machine-code containing holes to be filled by the run-time data.

Set-up code: calculating the values of derived run-time constants.

Directives: instructing the dynamic compiler to produce executable code.

Page 4: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

AnnotationAnnotationDynamicRegion delineates the section of code to be dynamically compiled. Its arguments indicate the variables are constant at the entry of the dynamic region and remain unchanged.

The contents of arrays and pointer-based data are assumed to be run-time constants. Otherwise, the dereference operators should be used, e.g. x:=dynamic* p, x:=p dynamic->f, and x:=a dynamic[i]

Unroll directs to completely unroll a loop.

To produce several compiled versions, each optimized for a different set of run-time constants, key Variables are defined, e.g. dynamicRegion key(cache)

Page 5: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Static CompilerStatic Compiler

• Identify the constant variables and Identify the constant variables and expressions based on the annotated expressions based on the annotated constants.constants.

• Split into set-up and template code Split into set-up and template code subgraphs.subgraphs.

• Apply the standard optimizations with few Apply the standard optimizations with few restrictions.restrictions.

• Generate machine code and stitcher Generate machine code and stitcher directives.directives.

Page 6: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Computing Derived Run-Time Computing Derived Run-Time ConstantsConstants

Start with the initial set of constants through the Start with the initial set of constants through the control flow graph, updating the set after each control flow graph, updating the set after each instruction as follows:instruction as follows:+ x:=y iff y is a constant.+ x:=y iff y is a constant.+ x:=y op z iff y and z are constants, op is an + x:=y op z iff y and z are constants, op is an

idempotent, side- idempotent, side-effect-free, non-trapping effect-free, non-trapping operator. operator.+ x:=f(y1,…,yn) iff y’s are constants, f is an + x:=f(y1,…,yn) iff y’s are constants, f is an

idempotent, side- idempotent, side-effect-free, non-trapping effect-free, non-trapping function. function. + x:=*p iff p is a constant.+ x:=*p iff p is a constant.– x:=dynamic* p: x is not a constant.– x:=dynamic* p: x is not a constant.– *p:=x– *p:=x

Page 7: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

A forward dataflow analysis on A forward dataflow analysis on control flow graphcontrol flow graph

test is not a constant test is a constant

After a control flow merge, if a variable has the same run-time constant reaching definition along all predecessors, it is considered a constant after the merge.

Page 8: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Reachability Analysis(1)Reachability Analysis(1)

A forward dataflow analysis to compute the branch conditions at each program point.

Page 9: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Reachability Analysis (2)Reachability Analysis (2)

If the reachability conditions for each merge predecessor are mutually exclusive, the merge is labeled as a constant merge.

For a constant merge, the union is taken.

For a non-constant merge, the intersection is taken.

(The paper implies it, although it is not given explicitly.)

Page 10: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Reachability Analysis (3)Reachability Analysis (3)

The reachability conditions of the loop entry arc and loop back edge arc are not normally mutually-exclusive, the loop head is treated as a non-constant merge.

For an unrolled loop, only one predecessor arc exists. So, its loop head is a constant merge.

Page 11: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Setup codes, templates, Setup codes, templates, directivesdirectives

Static compiler divides each dynamic region into setup code and template code.

Setup code computes the runtime constants.

Templates contain all the remaining code with “holes” embedded for runtime constants.

Stitcher directives are generated to inform the stitcher to patch the holes and unroll the loops.

Page 12: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

OptimizationsOptimizations

• Optimizations (e.g. CSE) can be Optimizations (e.g. CSE) can be performed both before and after the performed both before and after the dynamic region is divided into setup dynamic region is divided into setup and template codes.and template codes.

• Optimizations performed afterwards Optimizations performed afterwards must be modified slightly to deal with must be modified slightly to deal with “holes”, marked as compile time “holes”, marked as compile time constants with unknown values.constants with unknown values.

Page 13: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

Experimental ResultsExperimental Results

Page 14: Fast Effective Dynamic Compilation Joel Auslander, Mathai Philipose, Craig Chambers, etc. PLDI’96 Department of Computer Science and Engineering Univ.

DiscussionDiscussion

+Using the run time data to do optimization.Using the run time data to do optimization.

+The idea of doing most work during static The idea of doing most work during static compilation is important for dynamic/adaptive compilation is important for dynamic/adaptive compilers.compilers.

– Run-time constant assumption limits its Run-time constant assumption limits its applicability. How much could the real application applicability. How much could the real application gain from it?gain from it?

– Annotation is not added automatically by the Annotation is not added automatically by the compiler, which may require inter-procedural compiler, which may require inter-procedural analysis and pointer analysis.analysis and pointer analysis.