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/system/vm/disassembler.scm (define-stack-effect-parser)
(define-clobber-parser):
* module/system/vm/frame.scm (compute-frame-sizes, compute-killv):
Fix bug introduced in dd8bf6a98c whereby
a call would clobber all locals, leaving the backtrace much less
useful than it should be.
* 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.
* module/language/cps/compile-bytecode.scm (compile-function)
(emit-bytecode):
* module/language/cps/slot-allocation.scm (allocate-slots):
* module/language/cps/optimize.scm (cps-default-optimization-options):
Allow the "lazy vars" optimization, a form of slot precoloring, to be
disabled. It will be disabled at -O0 or -O1, to speed compilation
times.
* module/language/cps/cse.scm (compute-available-expressions):
(compute-equivalent-subexpressions): Improve algorithmic complexity of
CSE by pre-computing the labels whose reads are clobbered by a label's
writes.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Minor
optimization to reduce the size of equivalent expression keys, and to
avoid some work if an expression has no key.
* module/language/cps/slot-allocation.scm
(compute-reverse-control-flow-order): For graphs without back-edges,
use a simplified computation of reverse control flow order.
* module/language/cps/types.scm (logand): We were computing the wrong
ranges when either argument was negative; a terrible bug!
(logsub): Also fix range when A is negative and B is non-negative.
(ulogand): Tighten up range.
* module/language/cps/slot-allocation.scm
(compute-reverse-control-flow-order): For graphs without back-edges,
use a simplified computation of reverse control flow order.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Fix typo in match syntax preventing us from optimizing the immediate
variants of lsh and rsh, and typo also in specialize-unop argument
order.
* module/system/vm/assembler.scm (check-urange): Hoist exact-integer?
check so that the side effect is entirely in this function and not in
`logand'. Allows devirtualize-integers to peel off a nice straight
trace.
* module/language/cps/dce.scm (compute-live-code): DCE removes
effect-free branches where both continuations are the same. This
change makes it so that we compare the next *live* continuations.
This allows DCE to remove chains of dead branches, not just the last
one, improving compilation e.g. of
(unless (and (exact-integer? x) (<= 10 x 20)) (error "foo" x))
so that the bignum trace goes away entirely.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
helper to look up constants now that primcalls can take parameters.
* module/language/cps/devirtualize-integers.scm (peel-trace): Remove
extra argument to expression-effects.
* module/language/cps/effects-analysis.scm (constant?, indexed-field):
Remove unused definitions.
(expression-effects): Remove "constants" argument; constants come from
primcall params.
(compute-effects): Don't compute a constants table.
* module/language/cps/slot-allocation.scm ($allocation): Remove
"constant-values" field.
(lookup-constant-value, lookup-maybe-constant-value): Remove; unused.
(allocate-slots): Don't create a constants table.
* module/language/cps/specialize-primcalls.scm
(compute-defining-expressions, compute-constant-values): Move these
definitions here, which were previously in utils.scm
* module/language/cps/utils.scm: Remove moved definitions.
* module/language/cps/specialize-numbers.scm (specialize-operations): Do
a better job unboxing logand if we know the result is a u64, even if
arguments are s64.
* module/language/cps/types.scm (bignum?): New predicate inferrer.
(infer-integer-<, <, u64-<, s64-<): Factor out how integer comparisons
are done. Improve inference over bignums.
(define-<-inferrer): Remove unused definition.
(s64-=): Define inferrer; omitted before because of a typo.
(define-binary-result!, abs): Fix up fixnum/bignum bits; before, we
would lose some cases where fixnums could become bignums and vice
versa.
(define-unary-result!): Remove unused helper.
* module/language/cps/types.scm (bignum?): New folder.
* module/language/cps/types.scm (&exact-number): New union type.
(rational?, exact?):
* module/language/cps/type-fold.scm (mul/immediate): Use the new
definition.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*, *effect+exception-free-primitives*): Detect
use of exact-integer?.
* module/language/tree-il/compile-cps.scm (canonicalize): Compile
exact-integer? to a fixnum?-or-bignum? check.