Contification Using Dominators

1 / 28
About This Presentation
Title:

Contification Using Dominators

Description:

use traditional optimizations in functional-language compilers ... based on a similar analysis in Moby [Reppy 2001] fm. f. g. k. h. k. k. k. k. But... –

Number of Views:45
Avg rating:3.0/5.0
Slides: 29
Provided by: mfl2
Category:

less

Transcript and Presenter's Notes

Title: Contification Using Dominators


1
Contification Using Dominators
  • Matthew Fluet
  • Cornell University

Stephen Weeks InterTrust STAR Lab
2
Motivation
  • use traditional optimizations in
    functional-language compilers
  • traditional optimizations require intraprocedural
    control-flow information
  • in functional languages, most control-flow
    information is interprocedural
  • contification a technique for turning function
    calls into local control-flow transfers
  • interprocedural ? intraprocedural

3
An Example
4
MLton
  • a whole-program optimizing compiler for Standard
    ML

SML
defunctorize
polymorphic, higher-order IL
monomorphise
simply-typed, higher-order IL
closure convert
optimize
simply-typed, first-order IL
generate code
native x86
5
Contification
  • when a function g is contified within a function
    f
  • intraprocedural control-flow is exposed
  • g will share the same stack frame as f
  • invocations of g can be optimized
  • goal contify as many functions as possible
  • components of contification
  • analysis what functions are contified and where
  • transformation single-pass rewrite of the
    program

6
Contification Analysis I
  • represent a program by its call graph
  • functions m, f, g, h and continuations k, l
  • a distinguished main function m
  • nontail calls
  • tail calls

7
Contification Analysis II
  • an analysis maps functions to abstract return
    locations
  • Return ? ? Cont ? Func
  • A ? Analysis Func ? Return
  • A(g) f g always returns to function f g is
    contified in the body of f
  • A(g) k g always returns to continuation k g
    is contified where k is defined and g is
    transformed to transfer control to k
  • A(g) ? g is not contified in the transformed
    program

8
Safety
  • safety ensures a well-defined and correct
    transformation
  • an analysis A is safe if the following hold
  • A(m) ?
  • if then A(g) ? k, ?
  • if then A(g) ? f, A(f), ?

9
The Acall and Acont Analyses
  • Acall a simple syntactic analysis
  • Acont a least fixed-point analysis Reppy 2001

10
The Adom Analysis I
  • build a directed graph G, similar to the call
    graph
  • Node Return ? ? Cont ? Func
  • each edge (l, f) indicates that f returns to
    location l
  • if l ?, then f has no return location

11
The Adom Analysis II
  • build the dominator tree D of G
  • l dominates f if f always returns to l in any
    execution of the program
  • define Adom(f) to be the dominator of f closest
    to ?
  • if the immediate dominator of f is ?, then
    Adom(f) ?

12
The Adom Analysis III
  • Theorem Adom is safe.
  • Theorem Adom is maximal.
  • for all safe analyses B and all functions f,if
    B(f) ? ?, then Adom(f) ? ?

13
Compile-time Performance
  • three rounds of contification in the optimizing
    cycle
  • contification quiesces after two rounds
  • contification takes less than 4 of total compile
    time
  • typically less than one second, with a maximum of
    13 seconds

14
Run-time Performance
  • anomalies
  • contification may disable size-based inlining
  • MLtons optimizer evolved around Acall

15
Conclusions
  • a simple, yet general, framework for expressing
    contification analyses
  • single transformation
  • safety condition
  • maximality criterion
  • contification is efficient and improves running
    times
  • Got MLton?
  • You should.
  • http//www.sourcelight.com/MLton

16
(No Transcript)
17
Related Transformations
  • Local CPS conversion Reppy 2001
  • analyzes a module in isolation
  • operates over a higher-order IL
  • escaping functions with unknown control-flow
    cause imprecision
  • requires local CPS conversion to apply
    transformation
  • Lambda dropping Danvy and Schultz 2000
  • does not approximate the returns of a function
  • does not change calls from tail to nontail, or
    vice versa
  • Loop headers Appel 1994
  • transformation local to a particular function
  • relies on inlining to expose new control-flow

18
References
  • A. W. Appel. Loop headers in ?-calculus or CPS.
    Lisp and Symbolic Computation, 7337-343, 1994.
  • O. Danvy and U. P. Schultz. Lambda-dropping
    Transforming recursive equations into programs
    with block structure. Theoretical Computer
    Science, 248(1-2)243-287, 2000.
  • J. Reppy. Local CPS conversion in a direct-style
    compiler. In Workshop on Continuations, pages
    1-5, Jan. 2001.

19
Comparison to Inlining
  • no substitution of actual arguments for function
    parameters
  • no duplication of code

20
The Acall Analysis
  • intuition a function f has one return location
    if
  • there is exactly one call to f from outside its
    body and
  • there are only tail calls to f within its body
  • a simple syntactic analysis
  • original contification analysis used in MLton

21
But
  • f, g, and h always return to continuation k
  • but, the call analysis fails to contify any of
    the functions

22
The Acont Analysis
  • intuition a function f returns to continuation k
    if
  • all nontail calls to f use k and
  • all tail callers of f also return to k
  • a least fixed point ties the recursion
  • based on a similar analysis in Moby Reppy 2001

23
But
  • g1, g2, and h all return to function f
  • but, the call analysis fails to contify h
  • and, the continuation analysis fails to contify
    any function

24
The Adom Analysis IV
  • setting Adom(f) equal to the immediate dominator
    of f violates safety
  • Adom(h1) f ? g3, A(g3), ? g3, g2, ?

25
An Example I
26
An Example II
27
An Example III
28
An Example IV
Write a Comment
User Comments (0)
About PowerShow.com