* 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.
* module/Makefile.am:
* module/language/cps2/types.scm: Port to CPS2. Relative to the CPS1
module, this one uses worklists, which should result in fewer
visits, though it does use a different strategy for deciding when to
saturate. We'll see!
* module/Makefile.am (CPS2_LANG_SOURCES): Add effects-analysis.scm.
* module/language/cps2/effects-analysis.scm: New file, based on
cps/effects-analysis.scm.
* module/language/cps2/utils.scm (intmap-map):
(compute-defining-expressions, compute-constant-values): New helpers.
* module/language/cps/intmap.scm: Intmaps can now contain any value;
#f does not indicate the absence of a value. Instead we use a unique
private sentinel to mark absent values or branches.
(*absent*, absent?, present?): New helpers.
(new-branch): Initialize empty elements to *absent*.
(clone-branch-with-edit): New helper.
(clone-branch-and-set): Use clone-branch-with-edit.
(writable-branch): Use clone-branch-with-edit
(empty-intmap): Initialize value to *absent*.
(add-level): clone-branch-and-set doesn't take #f as a branch any
more; use new-branch.
(branch-empty?, make-intmap/prune, intmap-add!):
(intmap-add, intmap-remove, intmap-next, intmap-prev):
(intmap-fold, intmap-union, intmap-intersect): Use absent? to detect
absent branches / values.
(intmap-ref): Likewise. Instead of returning #f if the value is not
found, call the optional not-found procedure. By default this will
signal an error.
* module/language/cps/types.scm:
* module/language/cps2/renumber.scm:
* module/language/cps2/simplify.scm: Adapt to intmap-ref signalling an
error by default if the value is not found.
* module/language/tree-il/compile-cps2.scm: Adapt to intmap-add
signalling an error if #f was in the intmap as a value.