caltry/mlton — pull request #6 by MatthewFluet (2013-09-13 03:56:49+00:00)
Title: Convert ImplementProfiling to multi-entry.

No significant difficulties with the conversion.

However, one feature of the single-entry ImplementProfiling has not
been converted. The original ImplementProfiling searched for the
first Enter statement encountered in a depth-first traversal (from the
'start' label) and moved it to the beginning of the 'start' block.
This was added by commit 7c1e382 for code coverage reasons. Often,
code is added to the "beginning" of a function by introducing a new
start block (and possibly additional blocks) to preceed the old start
block; for example, limit checks and signal checks insert checks at
the beginning of a function in this manner. By moving an Enter
statement to the beginning of a function, this added code is "charged"
to the current function.

This approach does not suffice for multi-entry, since different entry
points could have different first Enter statements. (In particular, a
proposed multi-entry optimization that merges tail-callers/callees
into a single function would result in different entry points with
different first Enter statements.) The invariant of properly nested
Enter/Leave pairs could be violated if a single Enter were moved to
the beginning of each entry point's 'start' block.

Furthermre, It is not clear that this approach suffices for
single-entry, since it is not necessarily the case that the first
Enter statement encounted in a depth-first traversal (from the 'start'
label) is the the first Enter statement encountered in every path from
the 'start' label. Such a condition is not required by the SSA/SSA2
checking of profiling expressions.