* module/language/cps2/utils.scm (compute-successors): kfun is
optional.
(compute-sorted-strongly-connected-components): New function, moved
from split-rec.scm. Doesn't assume that 0 is a free node identifier.
* module/language/cps2/split-rec.scm
(compute-sorted-strongly-connected-components): Remove, use utils.scm
version instead.
* module/language/cps2/closure-conversion.scm (intset-select): Remove
unused function.
* module/language/cps/intset.scm (intset-prev): New function.
(make-intset-folder): Add forward? argument like make-intmap-folder.
(intset-fold-right): New function.
* module/language/cps2/optimize.scm: Move comments here from
cps/compile-bytecode.scm.
* module/language/cps/compile-bytecode.scm: Remove optimization and
closure conversion calls, since CPS2 does this for us.
* module/language/cps2/compile-cps.scm (compile-cps): Use set! to save
memory at bootstrap-time. Optimize first-order CPS, to get rid of
strangeness introduced in closure conversion.
* module/language/cps2/dce.scm (compute-live-code): Use the live-labels
set to indicate function liveness. $closure and $callk mark their
associated functions as live.
(process-eliminations): Handle $closure.
* module/language/cps2/effects-analysis.scm (expression-effects): Handle
$closure.
* module/language/cps2/utils.scm (compute-reachable-functions): New
function.
* module/language/cps2/verify.scm (check-label-partition)
(compute-reachable-labels): Use the new function.
* module/language/cps2/simplify.scm (compute-singly-referenced-vars):
Allow $closure.
(compute-eta-reductions, compute-beta-reductions): Use
compute-reachable-functions, which besides being a simplification also
allows simplification to work on first-order CPS.
* module/language/cps2/closure-conversion.scm
(rewrite-shared-closure-calls): Fix to make shared closures call the
right label.
(closure-label): New helper.
(prune-free-vars): If a shared closure is not well-known, don't use
the alias optimization.
(convert-one): Fix for shared closures with one not-well-known
closure.
* module/language/cps/compile-bytecode.scm (compile-bytecode): Only
convert closures if the #:cps2-convert? option is not passed.
* module/language/cps2/compile-cps.scm (conts->fun*, compile-cps): Add
support for CPS2 closure conversion, disabled by default.
* module/language/cps2/verify.scm: New diagnostic pass.
* module/Makefile.am: Add verify.scm.
* module/language/cps2/optimize.scm: Wire up verification pass.
Always run the pass at the end, and if a variable is set run it
between passes too.
* module/language/cps2/self-references.scm: New pass, ported from CPS.
* module/language/cps2/optimize.scm: Wire up the self references pass.
* module/Makefile.am: Add new file.
* module/language/cps2/simplify.scm (compute-singly-referenced-vars):
New helper.
(compute-eta-reductions): Turns out, eta conversion on a graph
doesn't work the same way that it works on nested terms -- since
uses and defs are computed using the flow graph and not nested
terms, we need to check additionally that the vars are singly-used.
* module/language/cps/slot-allocation.scm (allocate-slots): Even if an
expression does not define a live value, it might need a place to
put its value. In that case we should stop scanning for hints,
otherwise e.g. an (current-module) primcall whose value isn't used
could clobber a hinted variable.
* module/language/cps2/cse.scm: New file, ported from CPS.
* module/language/cps2/optimize.scm: Wire up CSE.
* module/Makefile.am: Add language/cps2/cse.scm.
* module/language/cps/compile-bytecode.scm (optimize): Disable
prune-top-level-scopes on old CPS. It seems to not work if CSE has
run beforehand.
* module/language/cps2/utils.scm (compute-function-body): $callk does
not add to a local function graph.
(compute-successors): Fix extraction of "handler" continuation for
$prompt.
* module/language/cps2/utils.scm (compute-successors): New helper.
(compute-reverse-post-order): Move here from contification.scm and
rename from "sort-nodes".
(invert-graph): New helper.
(compute-strongly-connected-components): Move here from
contification.scm and rename from "compute-sccs".
* module/language/cps2/contification.scm (sort-nodes, compute-sccs): Remove.
* module/language/cps2/elide-values.scm: New file.
* module/language/cps2/optimize.scm (optimize): Wire up elide-values.
* module/Makefile.am: Add new file.
* module/language/cps2/prune-top-level-scopes.scm
(prune-top-level-scopes): Given that cache-current-module! is an
instruction, it will always continue to a nullary $kargs, so $values
is actually the correct replacement and not a values primcall.
* module/language/cps2/specialize-primcalls.scm: New file.
* module/language/cps2/optimize.scm: Wire up specialize-primcalls.
* module/Makefile.am: Add new file.