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

2705 commits

Author SHA1 Message Date
Andy Wingo
334bd8e3c1 DFG: $block no longer stores control-flow analysis
* module/language/cps/dfg.scm ($block): Remove dominator-related things
  from $block.
  (reverse-post-order, convert-predecessors): Be more abstract, taking
  arbitrary identifiers for nodes instead of assuming the nodes are
  continuation names.
  (make-block-mapping): New helper.
  ($cfa): New data type, for dominator and loop analysis.  Not yet
  public.
  (analyze-control-flow): Rewrite to only compute the dominator tree in
  one direction, but take that direction as an argument.  To be public
  once there is some code that uses it.
  ($dfa): Refactor function fields to be hash tables.
  (dfa-k-idx, dfa-var-idx): Adapt to refactor.
  (compute-live-variables): Adapt to refactor.
2013-10-31 11:02:27 +01:00
Andy Wingo
2ab2a10d50 static-patch! replaces link-procedure!
* libguile/vm-engine.c (static-patch!): Replace link-procedure! with
  this more versatile primitive.
* module/system/vm/assembler.scm (intern-constant): Emit static-patch!
  for static procedures and for strings.
* module/system/vm/disassembler.scm (code-annotation): Remove annotation
  for link-procedure!.  There can be no annotation for static-patch!, as
  neither operand is guaranteed to be a SCM value.
2013-10-31 09:47:48 +01:00
Andy Wingo
11eff82685 Fix primitive reification for class-of, bytevector-u8-ref, etc
* module/language/cps/reify-primitives.scm (primitive-module): Not all
  primitives are bound in (guile).
2013-10-31 09:47:48 +01:00
Andy Wingo
4a39546bc4 DFG: Disable control-flow analysis.
* module/language/cps/dfg.scm (visit-fun): Disable control-flow analysis
  for now, as it is not used.
2013-10-31 09:47:48 +01:00
Andy Wingo
96af4a18b8 Add "pop" field to $prompt
* module/language/cps.scm ($prompt): Add a "pop" field, indicating the
  continuation at which this prompt is popped.  The body of the prompt
  is dominated by the prompt, and post-dominated by the pop.  Adapt all
  builders and users.

* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt.

* module/language/cps/dfg.scm (visit-fun): Add an arc from the pop to
  the handler, to keep handler variables alive through the prompt body.
2013-10-31 09:47:48 +01:00
Andy Wingo
2700f19833 DWARF return arity fixen
* module/system/vm/dwarf.scm (read-die-abbrev): Fix return arity.
  (read-compilation-unit): Fix return arity of read-die.
2013-10-29 22:53:46 +01:00
Andy Wingo
73ba69a633 Dynamic-wind doesn't call thunk? on the out-guard.
* module/ice-9/boot-9.scm (dynamic-wind): Remove the thunk? check of the
  out-guard.
2013-10-27 20:09:09 +01:00
Andy Wingo
486013d67c VM has "builtins": primitives addressable by emitted RTL code
* libguile/Makefile.am:
* libguile/vm-builtins.h: New header, declaring stubs needed by the
  compiler like values, apply, and abort-to-prompt.

* libguile/vm.c: Adapt the apply and values stubs to conform to a
  standard interface.  Add an abort-to-prompt stub.  Add call/cc and
  call-with-values stubs.
  (scm_vm_builtin_ref): New helper, for the builtin-ref opcode.
  (scm_vm_builtin_name_to_index)
  (scm_vm_builtin_index_to_name): New helpers, for the compiler and
  disassembler, respectively.
  (scm_init_vm_builtins, scm_bootstrap_vm): Allow the compiler helpers
  to be loaded later into a module.
* module/language/rtl.scm: Export builtin-index->name and
  builtin-name->index.

* libguile/vm-engine.c (RETURN_VALUE_LIST): Update to use new names of
  "apply" and "values".
  (tail-call/shuffle): New opcode.
  (abort): Update to be a tail VM op, and reorder and renumber other
  ops.
  (builtin-ref): New opcode.

* libguile/continuations.h:
* libguile/continuations.c (scm_i_call_with_current_continuation):
  Move this to vm.[ch], implemented as a builtin.

* module/language/tree-il/compile-cps.scm (convert): Convert to
  'abort-to-prompt calls, possibly with 'apply, effectively undoing the
  tree-il transformation.

* module/language/cps/reify-primitives.scm (builtin-ref): New helper.
  (reify-primitives): Convert builtin primitives to builtin-ref.

* module/language/cps/dfg.scm (constant-needs-allocation?):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling builtin-ref.

* module/system/vm/disassembler.scm (code-annotation): Add annotation
  for builtin-ref.
2013-10-27 20:09:01 +01:00
Andy Wingo
0720f70ed7 Memoized expressions are pairs, not SMOBs
* libguile/memoize.c (MAKMEMO): Memoized objects are pairs now, not
  SMOBs.  This lets eval.scm destructure them more efficiently.
  (scm_print_memoized, scm_memoized_p, scm_memoized_expression_typecode)
  (scm_memoized_expression_data): Remove these interfaces.
  (unmemoize, scm_memoize_variable_access_x): Remove SMOB type checks.
  (scm_init_memoize): Remove SMOB type definition.

* libguile/memoize.h (scm_tc16_memoized, SCM_MEMOIZED_P)
  (scm_memoized_expression_typecode, scm_memoized_expression_data)
  (scm_memoized_p): Remove declarations.

* libguile/validate.h (SCM_VALIDATE_MEMOIZED): Remove declaration.

* libguile/eval.c (eval): Remove memoized type check, and inline the
  inum unpacking.

* module/ice-9/eval.scm (memoized-expression-case): Use car and cdr to
  destructure memoized expressions.  A big win!
2013-10-27 09:52:39 +01:00
Andy Wingo
c450b47723 Tree-IL->GLIL: Fix primitive-ref reification bug
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Fix a
  bug whereby a primitive that is present in the compilation module but
  not at runtime was getting compiled as a toplevel-ref.  This was
  causing current-module to fail to resolve in R6RS modules.
2013-10-27 09:14:04 +01:00
Andy Wingo
d422f3167e Mark current-module as an interesting primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  Add current-module, to allow RTL compilation.
2013-10-26 22:54:29 +02:00
Andy Wingo
7e273b7a75 New pass: elide-values
* module/Makefile.am:
* module/language/cps/elide-values.scm (elide-values): New pass.

* module/language/cps/compile-rtl.scm (optimize): Call the new pass.
2013-10-26 22:30:54 +02:00
Andy Wingo
607fe5a604 Add make-vector, constant-make-vector instructions
* libguile/vm-engine.c (rtl_vm_engine): Add make-vector and
  constant-make-vector instructions and renumber.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
  constant-make-vector and make-vector as appropriate.

* module/language/cps/dfg.scm (constant-needs-allocation?): In some
  cases, make-vector doesn't need to allocate its index.

*  module/language/tree-il/primitives.scm
   (*interesting-primitive-names*, *primitive-constructors*): Add
   make-vector.
2013-10-26 22:06:01 +02:00
Andy Wingo
8ba3f20c47 Emit constant-vector-ref, constant-vector-set! for known small indices
* libguile/vm-engine.c (rtl_vm_engine): Add constant-vector-set!
  instruction and renumber.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
  constant-vector-ref and constant-vector-set! as appropriate.

* module/language/cps/dfg.scm (constant-needs-allocation?): In some
  cases, vector-ref and vector-set! don't need to allocate their index.
2013-10-26 21:30:37 +02:00
Andy Wingo
fa3b6e57c2 New pass: inline-constructors
* module/Makefile.am:
* module/language/cps/constructors.scm (inline-constructors): New pass.

* module/language/cps/compile-rtl.scm (optimize): Call the new pass.

* module/language/tree-il/compile-cps.scm (convert): Don't handle "list"
  specially here.
2013-10-26 21:07:27 +02:00
Andy Wingo
4f406fea7e Compile variable-ref, variable-set!
* libguile/vm-engine (box-ref, box-set!): Instead of aborting if a box
  isn't a var, call out to vm_error_not_a_variable.  This makes these
  instructions equivalent to variable-ref/variable-set!.
  (vector-set!): Rename from vector-set.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add
  variable-set! case, and adapt vector-set!.

* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
  variable-ref / variable-set! aliases to box-ref / box-set!.
2013-10-26 15:40:49 +02:00
Andy Wingo
d023ae8679 Recognize tree-il variable? primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*)
  (*effect-free-primitives*, *effect+exception-free-primitives*): Add
  variable?.  Fix nil? spelling.
2013-10-26 15:25:49 +02:00
Andy Wingo
be8b62ca7f RTL compiler: Compile TC7 branches.
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling symbol?, variable?, vector?, and string? branches.
2013-10-26 15:16:09 +02:00
Andy Wingo
4fc6b4d2c5 Fix primcall return arities
* module/language/cps/arities.scm (fix-clause-arities): Primcalls of
  known arity that continue to ktrunc should, if their return arity does
  not match the ktrunc, adapt via a call to `values'.  This call may
  later get removed.
2013-10-26 14:38:11 +02:00
Andy Wingo
6fb508da2a RTL compiler: Compile `wind' primcalls
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add handler
  for `wind'.
2013-10-26 14:38:11 +02:00
Andy Wingo
0f676d8725 Peval: Fold `thunk?' in more cases.
* module/language/tree-il/peval.scm (peval): Better folding of the
  `thunk?' predicate.
2013-10-26 13:13:17 +02:00
Andy Wingo
27ecfd3649 Evaluator sets same procedure properties as compiler
* libguile/memoize.c (MAKMEMO_LAMBDA, memoize): Instead of passing the
  docstring in the memoized lambda, pass the meta as-is.  That way we
  get all procedure properties, including "name".
* module/ice-9/eval.scm (primitive-eval): Set procedure properties when
  making lambdas.  Don't set the name when defining toplevel variables
  -- before we did so only if the procedure didn't have a name
  property, but I would like to avoid calls to procedure-property in
  eval, because getting the name for an RTL function requires loading up
  other modules.
2013-10-26 13:10:43 +02:00
Andy Wingo
cfc28c808e Evaluator uses two-dimensional environment
* libguile/memoize.c (MAKMEMO_LEX_REF, MAKMEMO_LEX_SET): Change to
  address lexicals by depth and width.
  (try_lookup_rib, lookup_rib, make_pos): New helpers.
  (lookup): Adapt to return a pair.
  (memoize, unmemoize_bindings, unmemoize_lexical): Adapt.

* libguile/eval.c (eval, prepare_boot_closure_env_for_eval):
  (prepare_boot_closure_env_for_apply):
* module/ice-9/eval.scm (make-fixed-closure, make-general-closure)
  (eval): Adapt to new environment.

This is currently a slight win for C, and a slight lose for Scheme --
because the lookup loop is so poorly compiled by the stack VM.  I expect
that the RTL-compiled eval will fix this.
2013-10-25 17:15:23 +02:00
Andy Wingo
33e9a90d7b Always resolve-primitives in the root module.
* module/language/tree-il/primitives.scm (resolve-primitives): If we are
  compiling in the root module, ignore local definitions.
2013-10-23 19:28:26 +02:00
Andy Wingo
a4b64fa246 Optimize closures with only required and rest arguments in eval
* module/ice-9/eval.scm: Pregenerate closures with rest arguments, as we
  do for fixed arguments.  This is important given the amount of (lambda
  args (apply foo args)) that we are doing lately.
2013-10-23 19:28:25 +02:00
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