* module/language/cps/licm.scm (loop-invariant?): Read or write effects
can be guarded by effect-free branches; prevent hoisting of these
expressions if the term isn't always reachable.
* module/language/tree-il/optimize.scm (optimize): Disable
resolve-primitives below -O2. This is because compile-cps is going to
start expanding all primcalls it sees.
* module/system/base/optimize.scm: New module.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new module.
* module/language/tree-il/optimize.scm (tree-il-optimizations): Rename
from tree-il-default-optimization-options. Directly specify the
optimization level at which a pass should be enabled.
* module/language/cps/optimize.scm (cps-optimizations): Likewise, rename
from cps-default-optimization-options.
* module/scripts/compile.scm (%options, show-optimization-help): Adapt
to use new module.
* module/language/cps/devirtualize-integers.scm (peel-trace): Update
comment.
* module/language/cps/contification.scm (apply-contification): Update to
never contify a return of $primcall to $kreceive.
* module/language/cps/verify.scm (check-arities): Require that primcalls
continue to $kargs.
* module/language/cps/slot-allocation.scm (add-prompt-control-flow-edges):
Allow for terms that don't continue, and add them to the minimal
prompt control flow edges set.
* module/language/cps.scm ($branch): Refactor to be its own CPS term
type, not relying on $continue to specify a continuation (which before
was only for the false case) or a source location. Update allllllll
callers.
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
case where $prim could continue to $kreceive; this isn't possible.
However when reifying an unknown primcall, always add a $kreceive, as
the continuation has to be $kargs.
* module/language/tree-il/compile-cps.scm (convert): Unknown primcalls
convert as calls. With this change, all primcalls should continue to
$kargs, with the exception of 'throw.
* module/language/cps/constructors.scm: Remove pass, as "list" and
"vector" are now inlined by CPS conversion, and nothing in the
optimizer reifies "list" or "vector" primcalls.
* module/language/cps/optimize.scm (optimize-higher-order-cps)
(cps-default-optimization-options):
* am/bootstrap.am:
* module/Makefile.am: Remove references to inline-constructors pass.
* module/language/cps/contification.scm (apply-contification): Inline
returns to the corresponding $kargs.
* module/language/cps/licm.scm (loop-invariant?): Remove handling of
"values" primcall, as this doesn't exist any more.
* module/language/tree-il/compile-cps.scm (build-list): New helper.
(convert, canonicalize): Canonicalize "list" earlier. Allow sinking
of any initializer that can't capture the continuation, not just in
cases where all initializers have this property. Reify a cons chain
internally as appropriate.
* module/language/tree-il/cps-primitives.scm: New file,
replacing (language cps primitives). Lists known primitives and their
relation to Tree-IL explicitly, instead of assuming that any Tree-IL
primcall that shares a name with a bytecode instruction is a CPS
primcall.
* module/language/cps/verify.scm: Remove use of (language cps
primitives) and primcall arity checking. Would be nice to add this
back at some point.
* module/language/tree-il/compile-cps.scm (convert): Refactor to use new
tree-il-primitive->cps-primitive+nargs+nvalues helper.
* module/Makefile.am:
* am/bootstrap.am: Adapt.
* module/language/cps/compile-bytecode.scm (compile-function): Organize
emitters and flesh out with more heap type tag predicates. Remove
now-needless (language cps primitives) import.
This will allow individual primcall converters to define ad-hoc
conversion routines.
* module/language/tree-il/compile-cps.scm (convert-primcall/default)
(convert-indexed-getter, convert-indexed-setter)
(convert-indexed-getter/tag, convert-indexed-setter/untag)
(convert-scm-u64->scm-primcall, convert-scm-u64-scm-primcall)
(convert-scm-u64->f64-primcall, convert-scm-u64-f64-primcall)
(convert-scm-u64->u64-primcall, convert-scm-u64-u64-primcall)
(convert-scm-u64->s64-primcall, convert-scm-u64-s64-primcall)
(convert-*->u64-primcall, convert-scm->u64-primcall)
(convert-u64->scm-primcall): Define some primcall converter helpers.
(*primcall-converters*, define-primcall-converter)
(define-primcall-converters): Define converters for a number of
primcalls.
(convert-primcall*, convert-primcall): Interface to primcall
converters.
(convert): Pass most primcalls through convert-primcall, unless we
know already that they don't need instruction explosion or
boxing/unboxing.
* module/system/base/types/internal.scm (heap-tags): Rename complex and
fraction predicates to "compnum?" and "fracnum?", as they aren't the
same as the Scheme predicates "complex?" and "fraction?".
* module/language/cps/dce.scm (compute-live-code): The primcall-param
refactor made it so that a vector-set! to a dead vector would
needlessly mark the vector as live. This commit fixes it and adds
scm-set!, etc.
* module/language/tree-il/compile-cps.scm (init-default-value): Use
undefined? predicate instead of reifying an unbound value in the CPS
term.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
for the special immediate predicates. Evidently we aren't emitting
these yet!
* module/language/cps/compile-bytecode.scm (compile-function): Allow a
'throw primcall in tail position.
* module/language/cps/prune-bailouts.scm (prune-bailouts): Continue
directly to the nearest tail continuation, so we don't cause
unreachable handle-interrupts / return 0 instructions to be emitted.
* module/language/cps/reify-primitives.scm (reify-clause): Residualized
'throw primcall continues directly to tail.
* module/language/cps/verify.scm (check-arities): Relax check for
'throw.
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for emitting <= via < and jge / jnge.
* module/language/cps/effects-analysis.scm: Declare effects for <= and
f64-<=.
* module/language/cps/primitives.scm (*comparisons*): Add <=, f64-<=.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Specialize <= to < for integer comparisons. Specialize to f64-<= for
f64 ops.
* module/language/cps/type-fold.scm (<=): Add folder.
* module/language/cps/types.scm (infer-<=): Add inferrer.
* module/language/tree-il/compile-cps.scm (canonicalize): Canonicalize
<= and >= to <=, so that nans are handled correctly.
* module/language/cps/type-fold.scm (compare-exact-ranges): Rename from
compare-integer-ranges.
(<, u64-<, s64-<, =, u64-=, s64-=): Separate the generic and unboxed
implementations.
* module/language/tree-il/compile-cps.scm (adapt-arity): Allow k to be
$kargs for the 1-valued case.
(convert): For single-valued continuations where the definition is
clearly single-valued, avoid making a needless $kreceive and extra
"rest" binding that will just be filled with () and have to be
eliminated later.