1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

935 commits

Author SHA1 Message Date
Andy Wingo
02c624fc09 More precise stack marking via .guile.frame-maps section
* 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.
2014-01-26 20:55:04 +01:00
Andy Wingo
3652769585 Rename $ktrunc to $kreceive
* module/language/cps.scm ($kreceive): Rename from ktrunc.

* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
2014-01-12 12:37:05 +01:00
Andy Wingo
97cfb467f9 Returning too many values to call-with-values raises a runtime error
* 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.
2014-01-12 12:28:12 +01:00
Andy Wingo
310866418b Insert explicit $ktrunc nodes everywhere that truncates multiple values
* module/language/tree-il/compile-cps.scm (init-default-value, convert):
  Explicitly insert $ktrunc nodes on all places that can truncate to
  single values.
2014-01-11 16:01:18 +01:00
Andy Wingo
22a79b55b8 Add simplification pass
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/simplify.scm: New pass.
2014-01-11 16:01:18 +01:00
Andy Wingo
305cccb43c Add DCE pass.
* module/language/cps/dce.scm: New pass.
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.
2014-01-11 16:01:11 +01:00
Andy Wingo
ad4f6be137 Shuffle the first return value from truncating calls
* 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).
2014-01-11 16:01:11 +01:00
Andy Wingo
8a2d420f74 All $values expressions go through allocate-values
* module/language/cps/slot-allocation.scm (allocate-slots): Make all
  $values expressions go through allocate-values, and refactor
  allocate-values.
2014-01-11 16:01:11 +01:00
Andy Wingo
c79f873eb1 Fix allocate-slots bug
* 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.
2014-01-11 16:01:11 +01:00
Andy Wingo
f409295892 More robust compute-hints
* module/language/cps/slot-allocation.scm (allocate-slots): Allow the
  compute-hints pass to traverse through $values with 0 or 1 value.
2014-01-11 16:01:11 +01:00
Andy Wingo
e4fa7d403a Prefer "receive" over "receive-values"+"reset-frame"
* module/language/cps/compile-bytecode.scm (compile-fun): Attempt to
  emit "receive" instead of "receive-values"+"reset-frame" where
  possible.
2014-01-11 16:01:11 +01:00
Andy Wingo
4dfcb36006 Only emit receive-values if it is needed
* module/language/cps/compile-bytecode.scm (compile-fun): Don't emit
  receive-values unless there is a minimum or maximum number of values.
2014-01-11 16:01:11 +01:00
Andy Wingo
7ab76a830b Remove "pop" from $prompt
* 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.
2014-01-11 16:01:11 +01:00
Andy Wingo
146ce52d21 Enable prompt analysis
* 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.
2014-01-11 16:01:11 +01:00
Andy Wingo
9002277d0f Add prompt analysis to the DFG's analyze-control-flow
* 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.
2014-01-11 16:01:11 +01:00
Andy Wingo
f235f926d1 compute-live-variables uses CFA analysis
* 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.
2014-01-11 16:01:10 +01:00
Andy Wingo
6eb0296027 Internal analyze-control-flow refactor
* 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.
2014-01-11 16:01:10 +01:00
Andy Wingo
58ef5f0712 Fix constant-needs-allocation? for $values uses
* 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!
2014-01-11 16:01:10 +01:00
Andy Wingo
d20b4a1cd2 Add effects analysis pass on CPS
* module/Makefile.am:
* module/language/cps/effects-analysis.scm: New helper module.
2014-01-11 16:01:10 +01:00
Andy Wingo
d59060ce99 Fix prim -> VM op mapping for u8/s8 bytevector ops
* module/language/cps/primitives.scm (*instruction-aliases*): Fix
  aliases for bytevector u8 / s8 operations.

* module/language/cps/compile-bytecode.scm (compile-fun): Fix s8
  operations.
2014-01-11 16:01:10 +01:00
Mark H Weaver
1df515a077 Merge branch 'stable-2.0'
Conflicts:
	module/system/vm/traps.scm
	test-suite/tests/peval.test
2014-01-09 02:52:34 -05:00
Ian Price
265e7bd92a Fix inlining of tail list to apply.
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.
2014-01-07 03:37:21 +00:00
Andy Wingo
7bbfc02959 Arities-fixing pass handles incoming $ktrunc with rest args
* module/language/cps/arities.scm (fix-clause-arities): Allow $ktrunc
  arities with rest arguments.
2013-12-06 12:04:10 +01:00
Andy Wingo
67b5d06c1a Elide values primcalls with continuations with rest arguments
* module/language/cps/elide-values.scm (elide-values): Elide values
  primcalls when continuation has rest arguments.
2013-12-06 11:39:04 +01:00
Andy Wingo
fa48a2f79a (call-with-values foo (lambda (a . b) a)) avoids consing rest list
* 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.
2013-12-06 11:08:45 +01:00
Andy Wingo
691697de09 Rename "RTL" to "bytecode"
"RTL" didn't make any sense, and now that there's no other bytecode to
disambiguate against, just call it bytecode.

* module/Makefile.am:
* module/ice-9/eval-string.scm:
* module/language/bytecode.scm:
* module/language/bytecode/spec.scm:
* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/contification.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/primitives.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/spec.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/rtl.scm:
* module/language/rtl/spec.scm:
* module/scripts/compile.scm:
* module/system/base/compile.scm:
* module/system/repl/common.scm:
* module/system/vm/assembler.scm:
* module/system/vm/debug.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/dwarf.scm:
* test-suite/tests/cross-compilation.test:
* test-suite/tests/dwarf.test:
* test-suite/tests/rtl-compilation.test:
* test-suite/tests/rtl.test:
* test-suite/vm/run-vm-tests.scm: Fixups.
2013-12-02 21:31:47 +01:00
Andy Wingo
e54c7dd67c Fix brainfuck comment
* module/language/brainfuck/parse.scm: Fix outdated comment.
2013-12-02 19:03:50 +01:00
Andy Wingo
60ce72b9b9 Fix brainfuck->scheme compiler.
* module/language/brainfuck/compile-scheme.scm (compile-scheme): Fix
  brainfuck compiler.
2013-12-02 19:03:48 +01:00
Andy Wingo
7f71030837 Fix brainfuck comment
* module/language/brainfuck/parse.scm: Fix outdated comment.
2013-12-02 19:02:38 +01:00
Andy Wingo
cdc75fd001 Fix brainfuck->scheme compiler.
* module/language/brainfuck/compile-scheme.scm (compile-scheme): Fix
  brainfuck compiler.
2013-12-02 19:02:38 +01:00
Andy Wingo
4d6a7ac6ad Remove GOOPS-internal @slot-ref and @slot-set!
* 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.
2013-11-30 18:46:14 +01:00
Andy Wingo
310da5e1ef Contification converges more quickly
* module/language/cps/contification.scm (compute-contification):
  Converge more quickly by using the information we compute within a
  compute-contification pass.
2013-11-26 08:52:56 +01:00
Andy Wingo
7338a49fa1 Compute-contification also visits body
* module/language/cps/contification.scm (compute-contification): If we
  decide to contify, don't forget to visit the body.  Should make
  contification converge faster.
2013-11-25 20:07:53 +01:00
Andy Wingo
4cbc95f150 Rename objcodes?.{scm,c,h} to loader.{scm,c,h}
* libguile/loader.c:
* libguile/loader.h: Rename from objcodes.[ch].
* module/system/vm/loader.scm: Rename from objcode.scm.

* libguile/Makefile.am:
* libguile/gsubr.c:
* libguile/init.c:
* libguile/procs.c:
* libguile/vm.c:
* module/Makefile.am:
* module/ice-9/eval-string.scm:
* module/language/rtl/spec.scm:
* module/system/base/target.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/vm/debug.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/objcode.scm:
* test-suite/tests/compiler.test:
* test-suite/tests/dwarf.test:
* test-suite/tests/rtl-compilation.test:
* test-suite/tests/rtl.test: Adapt.
2013-11-19 21:45:07 +01:00
Andy Wingo
1b780c134b (system vm instruction) rtl-instruction-list -> (language rtl) instruction-list
* libguile/instructions.c (struct scm_instruction, fetch_instruction_table)
  (scm_instruction_list): Remove rtl_ infix.
* libguile/instructions.h: Adapt.

* module/system/vm/instruction.scm: Remove.

* module/language/rtl.scm: Export instruction-list from here.

* module/Makefile.am:
* module/language/cps/primitives.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/frame.scm:
* module/system/vm/program.scm:
* module/system/vm/trace.scm:
* module/system/vm/traps.scm: Adapt.
2013-11-19 20:45:57 +01:00
Andy Wingo
0bd1e9c6a0 rtl-program? -> program?
* libguile/programs.c (scm_program_p): Rename from scm_rtl_program_p.
  Changes name also from rtl-program? to program?.

* libguile/programs.h:
* module/ice-9/session.scm:
* module/language/tree-il/analyze.scm:
* module/statprof.scm:
* module/system/repl/command.scm:
* module/system/repl/debug.scm:
* module/system/vm/coverage.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/frame.scm:
* module/system/vm/program.scm:
* module/system/vm/traps.scm:
* module/system/xref.scm: Adapt.
2013-11-19 19:11:40 +01:00
Andy Wingo
f8085163d6 Remove MVRA from VM frames
* 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.
2013-11-15 17:13:27 +01:00
Andy Wingo
0c247a2fb6 Try to allocate arguments directly in call frames
* 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.
2013-11-15 15:19:04 +01:00
Andy Wingo
987c1f5ff3 Rewrite slot allocation pass
* 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.
2013-11-15 11:17:18 +01:00
Andy Wingo
13085a828f Replace ($var sym) with ($values (sym)).
* module/language/cps.scm: Remove $var.  Replaced by $values with one
  value.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/dfg.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all the world.
2013-11-13 20:55:28 +01:00
Andy Wingo
4c906ad5a5 Add specialize-primcalls pass; bump objcode version.
* 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.
2013-11-10 19:27:19 +01:00
Andy Wingo
863dd87362 Effects analysis distinguishes between struct fields
* 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.
2013-11-10 12:05:35 +01:00
Andy Wingo
a2972c195d Effects analysis sees match-error, throw-bad-structs as bailouts
* 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.
2013-11-10 10:17:44 +01:00
Andy Wingo
1c33be992e Remove stack programs, objcode, and the old VM.
* 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.
2013-11-08 18:28:24 +01:00
Andy Wingo
70974fd213 Remove (language objcode)
* module/language/objcode.scm: Remove.  Seems to have been unused.
2013-11-08 17:40:46 +01:00
Andy Wingo
0d4bcc71d2 Remove objcode language.
* module/language/objcode/elf.scm:
* module/language/objcode/spec.scm: Remove objcode language.

* module/Makefile.am: Adapt.
2013-11-08 16:51:44 +01:00
Andy Wingo
ad9b491fa7 Remove bytecode language.
* module/language/bytecode/spec.scm: Remove.

* module/Makefile.am: Adapt.
2013-11-08 16:49:04 +01:00
Andy Wingo
f3c0b53346 Remove assembly language.
* module/system/repl/command.scm: Remove disassembly cases for stack
  procedures.

* module/system/vm/inspect.scm: Adapt to disassemble RTL programs.

* module/language/assembly.scm:
* module/language/assembly/compile-bytecode.scm:
* module/language/assembly/decompile-bytecode.scm:
* module/language/assembly/disassemble.scm:
* module/language/assembly/spec.scm: Remove assembly language.

* module/Makefile.am: Adapt.
2013-11-08 16:45:10 +01:00
Andy Wingo
5af36584d8 Remove GLIL language
* module/Makefile.am:
* module/language/glil.scm:
* module/language/glil/compile-assembly.scm:
* module/language/glil/spec.scm: Remove.
2013-11-08 14:58:40 +01:00
Andy Wingo
ac023564b2 Remove tree-il->glil compiler
* module/Makefile.am:
* module/language/tree-il/compile-glil.scm: Remove.

* module/language/tree-il/spec.scm: Remove tree-il->glil link.
2013-11-08 14:57:43 +01:00