1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00
Commit graph

2530 commits

Author SHA1 Message Date
Andy Wingo
8695854a7d Fix assembler for keyword args
* module/system/vm/assembler.scm (begin-kw-arity, kw-prelude): Fix
  functions with keywords.
2013-10-22 22:31:26 +02:00
Andy Wingo
be0a8bb4f0 CPS conversion doesn't automatically produce $values
* module/language/tree-il/compile-cps.scm (convert): Don't convert
  values primcalls to $values, because we don't know that the
  continuation can accept that number of values.
2013-10-22 22:30:54 +02:00
Andy Wingo
8b2a96d044 Contify returns via calls to "values"
* module/language/cps/contification.scm: Returns from contified
  functions should primcall to 'values, as in general the return
  continuation is a multiple value context ($ktrunc or $ktail).  A later
  pass can elide the primcall if appropriate.
2013-10-22 22:29:56 +02:00
Andy Wingo
5db3e6bce4 CPS->RTL compiler: add push-fluid and pop-fluid
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add cases for
  push-fluid and pop-fluid.
2013-10-21 22:25:27 +02:00
Andy Wingo
1e6aee3bf9 DFG: Remove lift-definition!
* module/language/cps/dfg.scm: Remove lift-definition!.
2013-10-21 22:24:54 +02:00
Andy Wingo
0620d6b4d2 Fix contification bugs
* module/language/cps/contification.scm (compute-contification): Rewrite
  to avoid mutating the DFG and the function while we are rewriting.
  Instead we compute a contification, and if it is not empty, we apply
  it and loop.
2013-10-21 22:24:18 +02:00
Andy Wingo
e92e0bbe9c More robust contification
* module/language/cps/contification.scm (contify): It could be that
  visiting pending contifications could enqueue more contifications, so
  iterate to a fixed point.  Signal an error if there are any pending
  contifications at the end of an iteration.
2013-10-21 16:59:42 +02:00
Andy Wingo
c8ad7426e2 add lookup-block-scope
* module/language/cps/dfg.scm (lookup-block-scope): New interface.
  (visit-fun): Give a bit more info if link-blocks! fails.
2013-10-21 16:32:36 +02:00
Andy Wingo
bc01d8f7e0 DFG fixup.
* module/language/cps/dfg.scm: Remove dead-after-def? and
  dead-after-use? export.
2013-10-21 16:31:49 +02:00
Andy Wingo
e636f424b9 RTL slot allocator uses more precise, correct liveness information
* module/language/cps/dfg.scm (control-point?): New interface, replaces
  branch?.
  (dead-after-def?, dead-after-use?, dead-after-branch?): Remove these.
  The first one was fine; dead-after-use? was conservative but OK; but
  dead-after-branch? was totally bogus.  Instead we use precise liveness
  information in the allocator.

* module/language/cps/slot-allocation.scm ($allocation): Remove "def"
  and "dead" slots.  We'll communicate liveness information in some
  other way to the compiler.
  (allocate-slots): Rework to use precise liveness information.
2013-10-21 15:45:19 +02:00
Andy Wingo
db11440d38 DFG: Add code to compute live variable sets.
* module/language/cps/dfg.scm (compute-live-variables)
  (compute-maximum-fixed-point, print-dfa): New code to compute live
  variable sets.
2013-10-21 13:50:48 +02:00
Andy Wingo
fc95a944d3 DFG: Use maps have variable names
* module/language/cps/dfg.scm ($use-map): Add variable names to the use
  maps.
  (visit-fun, lookup-def, lookup-uses, constant-needs-allocation?)
  (variable-free-in?, dead-after-def?, dead-after-use?)
  (dead-after-branch?): Adapt to use-map change.
2013-10-21 11:51:11 +02:00
Andy Wingo
8bd261baaa (language tree-il analyze) works better with RTL programs
* module/system/vm/program.scm (program-arguments-alists): Export this
  interface.  Fall back to grovelling through procedure-minimum-arity if
  the program has no arities, as might be the case for continuations.

* module/language/tree-il/analyze.scm (validate-arity): Use
  program-arguments-alists instead of the program-arities interface, to
  cover both stack VM and RTL programs.
2013-10-18 18:41:59 +02:00
Andy Wingo
d724a36562 Fix statprof-proc-call-data for recent changes
* module/statprof.scm (statprof-proc-call-data): Fix statprof for recent
  fixes.
2013-10-18 11:47:05 +02:00
Andy Wingo
27337b6373 Subrs are RTL programs
* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
  (SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
  pointer instead of a SCM value.
  (create_subr): Create RTL procedures instead of stack VM procedures.
  For RTL procedures, the function pointer, name, and generic address
  pointer go inline to the procedure, as free variables.
  (scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
  (scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
  (scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
  to create_subr.

  Remove gsubr test code.

* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
  programs can be primitives now.
  (SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
  the RTL free variables, not the object table.

* libguile/programs.c (scm_i_rtl_program_name):
  (scm_i_rtl_program_documentation):
  (scm_i_rtl_program_properties):
  (scm_i_rtl_program_minimum_arity): Implement these appropriately for
  primitives, which lack debugging information.
  (scm_primitive_p, scm_primitive_call_ip): New helpers.

* libguile/snarf.h: Remove static allocation for subrs.  Since there is
  nothing to allocate besides the program itself, which needs runtime
  relocation, static allocation is not a win.

* system/vm/program.scm: Fix up various arity-related things for
  primitives, which don't use ELF arity info.

* test-suite/tests/eval.test ("stack involving a primitive"): Add an
  XFAIL until we get just one VM.
2013-10-18 11:39:35 +02:00
Andy Wingo
9dff1df97f (system vm debug): implement arity-low-pc, arity-high-pc
* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Implement
  these exports.
2013-10-18 11:39:35 +02:00
Andy Wingo
ac37196321 Procedure traps work with RTL programs.
* module/system/vm/traps.scm (frame-matcher): Work with RTL programs.
2013-10-17 23:20:32 +02:00
Andy Wingo
342370bd56 minimal RTL program support in (system xref)
* module/system/xref.scm (procedure-sources*): Work with RTL programs.
2013-10-17 23:20:32 +02:00
Andy Wingo
1d94a35d69 (system vm coverage) works with RTL programs
* module/system/vm/coverage.scm (hashq-proc, assq-proc)
  (program-sources*, closed-over-procedures, coverage-data->lcov): Work
  with RTl procedures.
2013-10-17 23:20:32 +02:00
Andy Wingo
0bd6b1cae1 Statprof works better with RTL programs
* module/statprof.scm (get-call-data, procedure=?): Work with RTL
  programs.
2013-10-17 23:20:32 +02:00
Andy Wingo
5bd4b6585b Reify call-thunk/no-inline.
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  call-thunk/no-inline in this late phase.
2013-10-14 16:43:42 +02:00
Andy Wingo
8d59d55e86 RTL: Compile prompts
* libguile/vm-engine.c (prompt): Adapt to explicitly set the saved SP so
  we know how many incoming values the handler will receive, and to make
  escape-only? a flag.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): $prompt
  should only be found in a "seq" context, as it just pushes on a prompt
  and doesn't bind any values.  On the other hand it should emit
  appropriate code for the handler to bind its values, so do that.

* module/language/cps/slot-allocation.scm ($cont-allocation): Add a note
  that proc-slot is used by prompts as well.
  (allocate-slots): Compute the allocation of a prompt handler's args.

* module/language/tree-il/compile-cps.scm (convert): Use "unwind"
  instead of the nonexistent "pop-prompt".

* module/system/vm/disassembler.scm (code-annotation): Adapt to change
  in prompt VM op.
2013-10-14 16:13:57 +02:00
Andy Wingo
82f4bac420 RTL VM: receive-values has allow-extra? flag
* libguile/vm-engine.c (receive-values): Add an ALLOW-EXTRA? flag in
  unused bits of the third word.  Without it, receive-values will check
  for the exact number of incoming values.

* libguile/vm.c (vm_error_wrong_number_of_values): New error case.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Adapt to add
  the ALLOW-EXTRA? flag.
2013-10-14 16:09:43 +02:00
Andy Wingo
b7f10defe6 call-with-prompt always compiles to CPS $prompt
* module/language/tree-il/compile-cps.scm (convert): For prompts without
  inline handlers, eta-convert the handler.
2013-10-14 12:20:58 +02:00
Andy Wingo
649f6043de More precise dead-after-use? for loop variables
* module/language/cps/dfg.scm (dead-after-use?):
  (dead-after-branch?): A symbol defined in the header block of a loop
  is still within the same loop.
2013-10-12 16:36:28 +02:00
Andy Wingo
b8da548fba RTL slot allocation: Don't kill variables that flow into loops
* module/language/cps/dfg.scm (dead-after-use?): Don't kill a variable
  if it was defined outside the current loop.
  (dead-after-branch?): Likewise, but I don't think this helper is
  correct yet :/
2013-10-12 16:22:45 +02:00
Andy Wingo
0e2446d4db Compute post-dominators
* module/language/cps/dfg.scm ($block): Add pdom and pdom-level fields,
  for post-dominators.
  (reverse-post-order, convert-predecessors): Arrange to work either
  way: for dominators or for post-dominators.
  (analyze-control-flow!): Compute post-dominators.
  (dominates?): Refactor.
  (post-dominates?): New helper.
2013-10-12 16:11:36 +02:00
Andy Wingo
96b8027cc4 Identify loops
* module/language/cps/dfg.scm (compute-dom-edges)
  (compute-join-edges, compute-reducible-back-edges)
  (compute-irreducible-dom-levels, compute-nodes-by-level)
  (mark-loop-body, mark-irreducible-loops, identify-loops): Identify
  loops.  Irreducible loops are TODO.

* test-suite/tests/rtl-compilation.test ("contification"): Add an
  irreducible loop test.
2013-10-12 15:19:20 +02:00
Andy Wingo
366eb4d764 DFG refactorings
* module/language/cps/dfg.scm ($block): Add "irreducible" field, format
  TBD.
  (reverse-post-order): Return a vector directly.
  (convert-predecessors, compute-dom-levels, compute-idoms):
  (analyze-control-flow!): Factor out control flow analsysis a bit
  better.
  (identify-loops): New helper.  Currently a NOP.
  (visit-fun): Adapt to compute-dominator-tree rename to
  analyze-control-flow!.
2013-10-12 15:19:16 +02:00
Andy Wingo
238ef4cf44 Replace conservatively-dominates? with a precise dominator lookup
* module/language/cps/dfg.scm (dominates?): Use the dominator tree
  instead of the scope tree.
2013-10-11 14:10:19 +02:00
Andy Wingo
3aee6cfdd7 Compute a dominator tree
* module/language/cps/dfg.scm (reverse-post-order, for-each/enumerate)
  (convert-predecessors, finish-idoms, compute-dominator-tree): Compute
  a dominator tree.  We don't use it yet.
2013-10-11 13:35:43 +02:00
Andy Wingo
f22979db66 DFG refactor to allow dominator tree construction
* module/language/cps/dfg.scm: Refactor so that we can think about
  building a dominator tree.  Split continuations out of use maps and
  put them in a separate table, which will have more flow information.
  (visit-fun): Mark clauses as using their bodies.
  (lookup-predecessors, lookup-successors): New exports.
  (find-defining-expression): Add an exception for clauses, now that
  clauses are in the flow graph.
  (continuation-bound-in?): Rename from variable-bound-in?, as it can
  currently only be used for continuations.

* module/language/cps/contification.scm (contify): Adapt to use
  lookup-predecessors and continuation-bound-in?.
2013-10-10 12:42:50 +02:00
Andy Wingo
6b71a76713 A couple of fixes when no source info is available
* module/system/vm/assembler.scm (link-debug): If there was no debugging
  info, reset the file register to 0 from its default value of 1 before
  adding the final row.

* module/system/vm/dwarf.scm (line-prog-scan-to-pc): If we rescanned
  from the beginning and still found no source info for this pc, return
  #f instead of the default value of the file register (1).
2013-10-10 12:22:20 +02:00
Andy Wingo
4a6d351979 Fix peval bug with inlining and optional argument initializers
* module/language/tree-il/peval.scm (peval): Fix a bug whereby inlined
  function applications with default argument initializers were putting
  the initializers in the wrong scope.

* test-suite/tests/peval.test ("partial evaluation"): Add a test.
2013-10-10 11:19:19 +02:00
Andy Wingo
61c7264fcc Fix slot allocation bug
* module/language/cps/slot-allocation.scm (allocate-slots): Fix
  dead-after-use computation to use the expression's label and not its
  continuation.
2013-10-05 15:57:54 +02:00
Andy Wingo
f8fb13ef8c better RTL debugging
* libguile/frames.c (scm_frame_source, scm_frame_instruction_pointer):
  Fix to work with RTL programs.

* module/system/vm/debug.scm (find-debug-context): Allow for the
  possibility of there being no ELF image.
  (find-program-debug-info, find-program-arities)
  (program-minimum-arity, find-program-docstring)
  (find-program-properties, find-source-for-addr)
  (find-program-die, find-program-sources): Don't bail if we couldn't
  get the debug context.

* module/system/vm/frame.scm (frame-next-source)
  (frame-call-representation): Allow RTL programs.

* module/system/vm/program.scm (program-arguments-alist): Placeholder
  implementation for RTL programs.
  (program-arguments-alists): Don't bail if we couldn't get the
  arities.
2013-10-04 19:55:12 +02:00
Andy Wingo
fea115c33f Fix nested contification bugs
* module/language/cps/contification.scm (contify): Exhaustively replace
  contified tail continuations, to fix a bug in nested tail-recursive
  contifications.  Likewise, call lookup-return-cont when searching for
  common return continuations.
2013-10-04 18:03:29 +02:00
Andy Wingo
c648869346 Fix variable-bound-in?
* module/language/cps/dfg.scm (variable-bound-in?): Fix to look up
  correct variable.
2013-10-04 17:30:59 +02:00
Andy Wingo
25833e807d Fix verify-cps
* module/language/cps/verify.scm (verify-cps): Fix visiting functions.
2013-10-04 16:36:17 +02:00
Andy Wingo
e9588e7032 Disassembling RTL prints source information.
* module/system/vm/disassembler.scm (disassemble-buffer): Print source
  information.
2013-10-04 15:28:40 +02:00
Andy Wingo
7ea00e230a Contify functions in the scope of their continuation.
* module/language/cps/contification.scm (contify): Fix to contify
  functions in the scope of their continuation.
2013-10-04 14:08:52 +02:00
Andy Wingo
d51fb1e67b dfg: variable-free-in?, add variable-bound-in?
* module/language/cps/dfg.scm (variable-free-in?): Rename from
  variable-used-in?, to match CWCC language.
  (variable-bound-in?): New interface.

* module/language/cps/contification.scm (contify): Adapt caller.  Add
  more comments.
2013-10-04 14:07:36 +02:00
Andy Wingo
b43e81dc60 anonymous RTl functions print with source info
* module/system/vm/debug.scm (find-program-sources): If there is no
  source location before the low-pc of the procedure we're grovelling
  for, we were skipping the source loc info.  Fix that.

* module/system/vm/program.scm (write-program): Get source info for
  anonymous RTL functions.
  (program-sources, program-sources-pre-retire): Provide program
  counters relative to the beginning of the procedure.
2013-10-03 22:48:17 +02:00
Andy Wingo
7c54029740 program-source / program-sources works with RTL programs
* libguile/programs.c (scm_program_sources): Define as %program-sources,
  and let Scheme export the program-sources proper.
  (scm_program_source): Call out to Scheme.

* module/system/vm/program.scm: Convert to use match instead of pmatch.
  Adapt existing callers.
  (program-sources, program-source): New Scheme implementations of these
  functions.
  (program-sources-pre-retire): Add RTL program case.
2013-10-03 22:31:37 +02:00
Andy Wingo
c0ada5a766 Add (system vm debug) interface to source location information
* module/system/vm/debug.scm (<source>, source-pre-pc)
  (source-post-pc, source-file, source-line, source-column)
  (source-line-for-user): New data type for source location
  information.
  (find-source-for-addr, find-program-sources): New procedures to get
  source location information for a particular address.
2013-10-03 16:14:29 +02:00
Andy Wingo
1ed81e0229 Add interface to read .debug_line data
* module/system/vm/dwarf.scm (die-line-prog):
  (line-prog-advance, line-prog-scan-to-pc): New public interfaces,
  allowing clients to interpret the "statement programs" from
  .debug_line DWARF sections.
  (<meta>, elf->dwarf-context): Record the bounds of the .debug_line
  section.
2013-10-03 16:14:25 +02:00
Andy Wingo
d56ab5a913 Serialize source positions into .debug_line
* module/system/vm/assembler.scm (link-debug): Generate a correct DWARF2
  line program.  Tests come next.
2013-10-03 16:14:20 +02:00
Andy Wingo
0a7340ac98 Emit a placeholder .debug_line section.
* module/system/vm/assembler.scm (link-debug): Emit a .debug_line
  section also.
  (link-objects): Expect .debug_line.
2013-09-30 21:49:12 +02:00
Andy Wingo
e675e9bd39 Add new "source" macro instruction; compile-rtl emits it.
* module/system/vm/assembler.scm (<asm>): Add "sources" field.
  (make-assembler): Adapt to make-asm change.
  (source): New macro assembler.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence):
  (compile-fun): Emit source instructions as appropriate.
2013-09-30 21:48:07 +02:00
Andy Wingo
6371e368e6 DWARF linker: encode strings using the correct form
* module/system/vm/assembler.scm (link-debug): Encode strings using the
  strp form.
2013-09-28 18:15:50 +02:00