* module/language/cps/slot-allocation.scm (lookup-dead-slot-map)
(allocate-slots): For each non-tail call in a function, compute the
set of slots that are dead after the function has begun the call.
* module/language/cps/compile-bytecode.scm (compile-fun): Emit the
`dead-slot-map' macro instruction for non-tail calls.
* module/system/vm/assembler.scm (<asm>): Add `dead-slot-maps' member.
(dead-slot-map): New macro-instruction.
(link-frame-maps, link-dynamic-section, link-objects): Write dead
slots information into .guile.frame-maps sections of ELF files.
* module/system/vm/elf.scm (DT_GUILE_FRAME_MAPS): New definition.
* libguile/loader.h:
* libguile/loader.c (DT_GUILE_FRAME_MAPS, process_dynamic_segment):
(load_thunk_from_memory, register_elf): Arrange to parse
DT_GUILE_FRAME_MAPS out of the dynamic section.
(find_mapped_elf_image_unlocked, find_mapped_elf_image): New helpers.
(scm_find_mapped_elf_image): Refactor.
(scm_find_dead_slot_map_unlocked): New interface.
* libguile/vm.c (scm_i_vm_mark_stack): Mark the hottest frame
conservatively, as before. Otherwise use the dead slots map, if
available, to avoid marking data that isn't live.
* module/language/cps/compile-bytecode.scm (compile-fun): Now that all
$call expressions continue to $ktail or $ktrunc, remove the $kargs
case, and make receive-values bail if too many values are returned.
* module/language/tree-il/compile-cps.scm (init-default-value, convert):
Explicitly insert $ktrunc nodes on all places that can truncate to
single values.
* module/language/cps/slot-allocation.scm (allocate-slots): For
truncating calls, shuffle the first return value (if any). Avoids
frame size growth due to sparse locals, pegged where they were left by
procedure call returns. With this patch, eval with $ktrunc nodes goes
from 31 locals to 18 (similar to the size before adding $ktrunc
nodes).
* module/language/cps/slot-allocation.scm (allocate-slots): Fix bug in
allocate!, whereby a previously hinted allocation would not be added
to the live set if a hint was not given later.
* module/language/cps.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dfg.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Remove "pop" member from
$prompt data type, as it is no longer used.
* module/language/cps/dfg.scm (compute-live-variables, visit-fun):
Use the new prompt analysis pass in analyze-control-flow instead of
always adding a link in the DFG. Avoids problems if there are
parts of the prompt body that have no path to the pop.
* module/language/cps/dfg.scm (compute-reachable, find-prompts)
(compute-interval, find-prompt-bodies, visit-prompt-control-flow): New
helpers.
(analyze-control-flow): Add a mode that adds on CFA edges
corresponding to non-local control flow in a prompt.
* module/language/cps/dfg.scm ($dfa): Store a CFA instead of a separate
k-map and order.
(dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
(compute-live-variables): Use analyze-control-flow instead of rolling
out own RPO numbering. Will allow us to fix some prompt-related
things in a central place.
* module/language/cps/dfg.scm (reverse-post-order): Fold-all-conts is
now a required arg.
(analyze-control-flow): Reverse CFA adds forward-reachable
continuations to the numbering.
* module/language/cps/dfg.scm (constant-needs-allocation?): Use of a
constant in a $values expression of any arity does not cause slot
allocation.
* module/language/cps/compile-bytecode.scm (compile-fun): Allow $values
with a constant value to be compiled in test context. Really we
should fold these in a previous pass!
Fixes <http://bugs.gnu.org/15533>.
* module/language/tree-il/peval.scm (peval): Final list argument to
`apply' should not be inlined if it is mutable.
* test-suite/tests/peval.test ("partial evaluation"): Add test.
* module/language/cps/slot-allocation.scm (allocate-slots): Don't
allocate slots to unused results of function calls. This can allow us
to avoid consing a rest list for call-with-values with an ignored rest
parameter, and can improve the parallel move code.
* module/language/cps/compile-bytecode.scm (compile-fun): Adapt to avoid
emitting bind-rest in values context if the rest arg is unused.
* module/oop/goops.scm: Remove definitions of @slot-ref and @slot-set!.
They are equivalent to struct-ref and struct-set!.
(define-standard-accessor-method): Reimplement using syntax-case.
(bound-check-get, standard-get, standard-set): Replace @slot-ref and
@slot-set! uses with struct-ref and struct-set!.
* module/language/cps/reify-primitives.scm (primitive-module): Remove
@slot-set! and @slot-ref references.
* module/language/cps/contification.scm (compute-contification):
Converge more quickly by using the information we compute within a
compute-contification pass.
* module/language/cps/contification.scm (compute-contification): If we
decide to contify, don't forget to visit the body. Should make
contification converge faster.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump for frame layout
change.
* libguile/frames.c: Update some static checks.
(scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x):
Update to not skip over uninitialized frames, as that's not a thing
any more.
* libguile/frames.h: Update to remove MVRA. Woo!
* libguile/vm-engine.c (ALLOC_FRAME, RETURN_ONE_VALUE):
(rtl_vm_engine): Update for 3 words per frame instead of 4.
* libguile/vm.c (vm_return_to_continuation): Likewise.
* module/language/cps/slot-allocation.scm (allocate-slots): 3 words per
frame, not 4.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump. Also
remove a couple of tc7's that aren't around any more.
* module/language/cps/slot-allocation.scm (allocate-slots): Convert
cont-table to a vector, for ease of access. Run a pass before
allocation that determines the set of variables whose slot allocation
can and should be delayed, so that they can ideally be allocated
directly in an argument slot.
* module/language/cps/slot-allocation.scm ($allocation): Refactor
internal format of allocations. Instead of an allocation being a hash
table of small $allocation objects, it is an $allocation object that
contains packed vectors.
(find-first-trailing-zero): Rework to not need a maximum.
(lookup-maybe-slot): New interface.
(lookup-slot): Raise an error if a var has no slot.
(lookup-call-allocation): New helper.
(lookup-constant-value, lookup-maybe-constant-value):
(lookup-call-proc-slot, lookup-parallel-moves): Adapt to $allocation
change
(allocate-slots): Rewrite so that instead of being recursive, it
traverses the blocks in CFA order. Also, procedure call frames are
now allocated with respect to the live set after using arguments (and
killing any dead-after-use vars); this should make call frames more
compact but it does necessitate a parallel move solution. Therefore
parallel moves are recorded for all calls, for arguments; also if the
continuation is a $ktrunc, the continuation gets parallel moves for
the results.
This rewrite is in preparation to allocating call args directly in the
appropriate slots, where possible.
* module/language/cps/compile-rtl.scm (compile-fun): Adapt to slot
allocation changes, using lookup-maybe-slot where appropriate,
performing parallel moves when calling functions, and expecting return
moves to be associated with $ktrunc continuations.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/objcodes.c (process_dynamic_segment): Expect the minor
version to be present and, while we are still banging on the VM,
exactly equal to SCM_OBJCODE_MINOR_VERSION.
* libguile/vm-engine.c: Renumber ops. Remove the general make-vector.
Rename constant-FOO to FOO/immediate. Remove struct-ref and
struct-set!, replace with struct-ref/immediate and
struct-set!/immediate.
* module/Makefile.am:
* module/language/cps/specialize-primcalls.scm: New pass, inlines FOO to
FOO/immediate -- e.g. vector-ref to vector-ref/immediate.
* module/language/cps/arities.scm: Remove struct-set! case, now that
there is no struct-set! opcode.
* module/language/cps/compile-rtl.scm (compile-fun): Remove dispatch to
constant-FOO versus FOO here -- that decision is made by
specialize-primcalls.
(optimize): Add specialize-primcalls pass.
* module/language/cps/dfg.scm (constant-needs-allocation?): Adapt to
name changes.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*primitive-constructors*): Add allocate-struct.
* module/system/vm/assembler.scm (*bytecode-major-version*):
(*bytecode-minor-version*, link-dynamic-section): Write minor version
into resulting image.
* module/language/tree-il/effects.scm (compile-time-cond):
(define-effects): Make the effects analysis more precise,
distinguishing between different kinds of mutable data. On 64-bit
systems we take advantage of the additional bits to be even more
precise.
(make-effects-analyzer): Inline handlers for all "accessor" primitives
and their corresponding mutators.
* module/language/tree-il/peval.scm (peval): Reflow to remove use of the
"accessor-primitive?" predicate.
* module/language/tree-il/primitives.scm (accessor-primitive?): Remove.
* module/language/tree-il/effects.scm (make-effects-analyzer): Allow
module-ref calls to be treated as bailouts, if the procedure has the
"definite-bailout?" property. Perhaps this should be renamed.
* module/ice-9/match.upstream.scm (match-error):
* module/srfi/srfi-9.scm (throw-bad-struct): Give these procedures the
definite-bailout? property.
* libguile/Makefile.am:
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Remove the old VM files, and the rules to
build the .i files.
* libguile/vm-engine.c:
* libguile/vm.c: Remove the old VM. Woot!
* libguile/_scm.h (SCM_OBJCODE_COOKIE, SCM_OBJCODE_ENDIANNESS_OFFSET)
(SCM_OBJCODE_WORD_SIZE_OFFSET): Remove.
* libguile/evalext.c (scm_self_evaluating_p): Remove objcode and program
cases.
* libguile/frames.c (scm_frame_num_locals, scm_frame_previous): Remove
program cases.
* libguile/gc.c (scm_i_tag_name): Remove objcode case.
* libguile/goops.c (scm_class_of, create_standard_classes): Remove
objcode and program cases.
* libguile/instructions.h:
* libguile/instructions.c (scm_instruction_list, scm_instruction_p)
(scm_instruction_length, scm_instruction_pops, scm_instruction_pushes)
(scm_instruction_to_opcode, scm_opcode_to_instruction): Remove old VM
code.
* libguile/objcodes.h:
* libguile/objcodes.c: Remove the objcode data type, and handling for
objcode files.
* libguile/print.c: Remove objcode and program printers.
* libguile/procprop.c: Remove program cases.
* libguile/procs.c:
* libguile/programs.h:
* libguile/programs.c: Remove old program code.
* libguile/smob.c: Remove objcodes include.
* libguile/snarf.h: Remove static program defines.
* libguile/stacks.c: Remove program case.
* libguile/tags.h: Remove program and objcode tc7s.
* module/ice-9/session.scm (procedure-arguments)
* module/language/tree-il/analyze.scm (validate-arity)
* module/statprof.scm (get-call-data, procedure=?)
* module/system/vm/frame.scm (frame-bindings)
(frame-call-representation): Remove old program cases.
* module/system/repl/debug.scm (frame->module): Add a FIXME.
* module/system/vm/instruction.scm: Remove old exports.
* module/system/vm/program.scm: Remove old program code.