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

2570 commits

Author SHA1 Message Date
Andy Wingo
d258fcccee RTL compilation sorts continuations topologically before visiting them
* module/language/cps/compile-rtl.scm (compile-fun): Rewrite to visit
  conts in reverse-post-order, which is a topological sort on the basic
  blocks.

* module/language/cps/slot-allocation.scm (allocate-slots): Expect a DFG
  as an argument.
2013-11-01 14:37:57 +01:00
Andy Wingo
4a565538bd Failed match errors generate less code
* module/ice-9/match.upstream.scm (match-next): Call out to an external
  procedure on error, and use a begin instead of double-parens.  This
  results in less generated code.
2013-11-01 13:37:27 +01:00
Andy Wingo
58dee5b9e4 Add compile-cps hack for vectors
* module/language/tree-il/compile-cps.scm (convert): Add a special case
  for "vector" primcalls.  Boo!
2013-11-01 08:51:52 +01:00
Andy Wingo
cb8054c7ac Better range checks in the assembler
* module/system/vm/assembler.scm (pack-u8-u24, pack-u8-s24):
  (pack-u1-u7-u24, pack-u8-u12-u12, pack-u8-u8-u16, pack-u8-u8-u8-u8):
  Prevent adjacent fields from stompling each other.
2013-10-31 22:57:06 +01:00
Andy Wingo
ef47c4229c Be smarter about capturing the environment for memoized code
* libguile/memoize.h (SCM_M_CAPTURE_MODULE)
* libguile/memoize.c (MAKMEMO_CAPTURE_MODULE, capture_env):
  (maybe_makmemo_capture_module, memoize): Determine when to capture the
  module on the environment chain at compile-time, instead of at
  runtime.  Introduces a new memoized expression type, capture-module.
  (scm_memoized_expression): Start memoizing with #f as the
  environment.
  (unmemoize): Add unmemoizer.
  (scm_memoize_variable_access_x): Cope with #f as module, and treat as
  the root module (captured before modules were booted).

* libguile/eval.c (eval):
* module/ice-9/eval.scm (primitive-eval): Adapt.
2013-10-31 22:16:10 +01:00
Andy Wingo
3e248c70e3 define! is an interesting primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  Add define!.
2013-10-31 20:39:22 +01:00
Andy Wingo
5bff312598 fix compilation of (let lp () (lp))
* module/language/cps/dfg.scm (reverse-post-order): Add an optional
  "fold-all-conts" argument.
  (compute-live-variables): Take the function as an arg instead of the
  start continuation, and implement fold-all-conts so that nodes that
  never reach the tail also get liveness information.
2013-10-31 20:24:38 +01:00
Andy Wingo
dda5fd94de DFG: Export analyze-control-flow.
* module/language/cps/dfg.scm ($cfa, $dominator-analysis): Remove
  dominator things from $cfa, to break out to separate structure.
  (cfa-k-idx, cfa-k-count, cfa-k-sym, cfa-predecessors): New public
  accessors.
  (analyze-control-flow): New public function.
  (analyze-dominators): Adapt.
2013-10-31 19:49:19 +01:00
Andy Wingo
c7cb2bc200 static-patch! for pair and vector fields
* module/system/vm/assembler.scm (intern-constant): Use static-patch!
  for fields.
2013-10-31 19:21:31 +01:00
Andy Wingo
57a5cc9760 Better REPL support for disassembling RTL images
* module/system/repl/command.scm (load-image): New helper.
  (compile, disassemble): Handle bytevectors.
2013-10-31 14:18:25 +01:00
Andy Wingo
b73a2ee017 Default to compiling to RTL
* module/ice-9/eval-string.scm (eval-string)
* module/language/tree-il/spec.scm (tree-il)
* module/scripts/compile.scm (compile)
* module/system/base/compile.scm (compile-file, read-and-compile)
* module/system/repl/common.scm (repl-compile, repl-prepare-eval-thunk):
  Default to compiling to RTL.

* module/language/rtl/spec.scm (rtl->value): Add value compiler.
2013-10-31 14:17:30 +01:00
Andy Wingo
6165d8120d Better aliased primcall compilation
* libguile/vm-engine.c (define!): Rename from define.
* module/language/cps/arities.scm (fix-clause-arities): If a prim
  aliases an RTL instruction with a different name and we reify a
  primcall, reify the instruction name.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Update
  emit-define! for new name.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
  bytevector native accessors.
2013-10-31 12:55:24 +01:00
Andy Wingo
becce37b58 Better compiler support for bytevector ops
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add emitters
  for bytevector ops.  Add br-if-bytevector emitter.
* module/language/cps/primitives.scm (*branching-primcall-arities*):
  Mark bytevector? as a branching primitive.
* module/system/vm/assembler.scm (br-if-bytevector): New instruction
* module/system/vm/disassembler.scm (code-annotation): Add support for
  bytevector?.
2013-10-31 12:55:24 +01:00
Andy Wingo
7bfbc7b1c5 Support serialization of uniform vector literals
* libguile/uniform.h:
* libguile/uniform.c (scm_uniform_vector_element_type_code): New
  interface, returns a type code as an integer.

* module/system/vm/assembler.scm (<uniform-vector-backing-store>)
  (simple-vector?, uniform-array?, statically-allocatable?)
  (intern-constant, link-data, link-constants): Support uniform arrays,
  and punt on vectors aren't contiguous from 0.  Support for general
  arrays will come later.

* test-suite/tests/rtl.test ("load-constant"): Add tests.
2013-10-31 12:55:23 +01:00
Andy Wingo
6a37b7faaf Compile-time debugging
* module/language/cps/compile-rtl.scm:
* module/language/cps/contification.scm: Add some compile-time
  printouts.  Will be removed later.
2013-10-31 12:55:17 +01:00
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