* module/language/cps/verify.scm (check-arities): If a callk continues
to kargs, the caller knows the number of return values that the callee
provides and no number-of-values check is needed.
* module/language/cps/contification.scm (apply-contification): Allow
contification of known-return-values calls.
* module/language/cps/reify-primitives.scm (uniquify-receive)
(reify-primitives): No need for uniquify-receive any more as receive
shuffles are attached to the call, not the continuation.
* module/language/cps/compile-bytecode.scm (compile-function): Add kargs
case.
* module/language/cps/utils.scm (compute-var-representations): Use
'arg-representations from metadata for arg representations.
* module/language/tree-il/compile-cps.scm (sanitize-meta):
(convert): Make sure incoming terms have no arg representations.
* module/language/cps/graphs.scm (rename-keys, rename-intset)
(rename-graph, compute-reverse-control-flow-order)
(compute-live-variables): Move here from slot-allocation.
* module/language/cps/utils.scm: Remove duplicate compute-idoms
definition.
(compute-defs-and-uses, compute-var-representations): Move here from
slot-allocation.
* module/language/cps/slot-allocation.scm: Move routines out to utils
and graphs.
* module/language/cps/closure-conversion.scm (compute-elidable-closures):
New function.
(convert-one, convert-closures): Add ability to set "self" variable of
$kfun to $f, hopefully avoiding passing that argument in some cases.
* module/language/cps/compile-bytecode.scm (compile-function): Pass the
has-closure? bit on through to the assembler.
* module/system/vm/assembler.scm (begin-standard-arity)
(begin-opt-arity, begin-kw-arity): Only reserve space for the closure
as appropriate.
* module/language/cps/slot-allocation.scm (allocate-args)
(compute-defs-and-uses, compute-needs-slot)
(compute-var-representations): Allow for closure slot allocation
differences.
* module/language/cps/cse.scm (compute-defs):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/renumber.scm (renumber, compute-renaming):
(allocate-args):
* module/language/cps/specialize-numbers.scm (compute-significant-bits):
(compute-defs):
* module/language/cps/split-rec.scm (compute-free-vars):
* module/language/cps/types.scm (infer-types):
* module/language/cps/utils.scm (compute-max-label-and-var):
* module/language/cps/verify.scm (check-distinct-vars):
(compute-available-definitions): Allow closure to be #f.
* 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/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/compile-bytecode.scm (compile-function): Make
load-f64, load-s64, and load-u64 take an immediate parameter instead
of a CPS value.
* module/language/cps/effects-analysis.scm: Remove CPS argument from
immediate load instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
special case for load-64 etc.
* module/language/cps/specialize-numbers.scm
(specialize-u64-scm-comparison): Adapt.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Adapt.
* module/language/cps/types.scm (define-type-inferrer*): Also take param
argument.
(define-type-inferrer, define-predicate-inferrer): Adapt.
(define-type-inferrer/param): New helper.
(load-f64, load-s64, load-u64): Adapt inferrers to pass on value from
param.
* module/language/cps/utils.scm (compute-constant-values): Adapt.
* module/language/cps.scm ($primcall): Add "param" member, which will be
a constant parameter to the primcall. The idea is that constants used
by primcalls as immediates don't need to participate in optimizations
in any way -- they should not participate in CSE, have the same
lifetime as the primcall so not part of DCE either, and don't need
slot allocation. Indirecting them through a named $const binding is
complication for no benefit. This change should eventually improve
compilation time and memory usage, once we fully take advantage of it,
as the number of labels and variables will go down.
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/handle-interrupts.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-checks.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
* module/language/cps/utils.scm (intmap-map): Use transient intmap-add!
on an empty intmap to build the result instead of intmap-replace! on
the argument. Avoids spooky action-at-a-distance mutation of the
argument if it happens to be a transient -- although the intmap-fold
will correctly traverse a snapshot of the argument and the result will
be correct, the argument value would be modified in place, causing
strange results to calling code that passes in a transient.
* libguile/vm-engine.c (bv-s8-ref, bv-s16-ref, bv-s32-ref, bv-s64-ref):
Unbox index and return unboxed S32 value.
(bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Unbox index and
take unboxed S32 value.
(bv-u8-ref, bv-u16-ref, bv-u32-ref, bv-u64-ref)
(bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Likewise, but
with unsigned values.
(bv-f32-ref, bv-f32-set!, bv-f64-ref, bv-f64-set!): Use memcpy to
access the value so we don't have to think about alignment. GCC will
inline this to a single instruction on architectures that support
unaligned access.
* libguile/vm.c (vm_error_out_of_range_uint64)
(vm_error_out_of_range_int64): New helpers.
* module/language/cps/slot-allocation.scm (compute-var-representations):
All bytevector ref operations produce untagged values.
* module/language/cps/types.scm (define-bytevector-accessors): Update
for bytevector untagged indices and values.
* module/language/cps/utils.scm (compute-constant-values): Fix s64
case.
* module/language/tree-il/compile-cps.scm (convert): Box results of all
bytevector accesses, and unbox incoming indices and values.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add word
types for immediate f64 and u64 values.
(TYPE_WIDTH): Bump up by a bit, now that we have 32 word types.
(NOP, parse_instruction): Use 64-bit meta type.
* libguile/vm-engine.c (load-f64, load-u64): New instructions.
* module/language/bytecode.scm (compute-instruction-arity): Add parser
for new instruction word types.
* module/language/cps/compile-bytecode.scm (compile-function): Add
special-cased assemblers for new instructions, and also for scm->u64
and u64->scm which I missed before.
* module/language/cps/effects-analysis.scm (load-f64, load-u64): New
instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): load-f64
and load-u64 don't need slots.
(compute-var-representations): Update for new instructions.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Specialize scm->f64 and scm->u64 to make-f64 and make-u64.
* module/language/cps/types.scm (load-f64, load-u64): Wire up to type
inference, though currently type inference only runs before
specialization.
* module/language/cps/utils.scm (compute-defining-expressions): For some
reason I don't understand, it's possible to see two definitions that
are equal but not equal? here. Allow for now.
(compute-constant-values): Punch through type conversions to get
constant u64/f64 values.
* module/system/vm/assembler.scm (assembler): Support for new word
types. Export the new assemblers.
* module/language/cps/utils.scm (solve-flow-equations): Revert to take
separate in and out maps. Take an optional initial worklist.
* module/language/cps/slot-allocation.scm: Adapt to solve-flow-equations
change.
* module/language/cps/slot-allocation.scm (compute-lazy-vars):
(compute-live-variables): Adapt to solve-flow-equations interface
change.
* module/language/cps/utils.scm (solve-flow-equations): Move here. Use
an init value instead of an init map.