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

3279 commits

Author SHA1 Message Date
Andy Wingo
e5d7c0f13b All arities serialize a "closure" binding
* module/language/cps/compile-bytecode.scm (compile-function): Always
  define a 'closure binding in slot 0.
* module/system/vm/frame.scm (available-bindings): No need to futz
  around not having a closure binding.
* module/system/vm/debug.scm (arity-arguments-alist): Expect a closure
  binding.
* test-suite/tests/rtl.test: Emit definitions for the closure.
2015-12-01 10:57:20 +01:00
Andy Wingo
3e5d4131d2 Don't compile equal? to br-if-equal
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/type-fold.scm (equal?):
* module/language/cps/types.scm (equal?):
* module/language/tree-il/compile-cps.scm (convert): `equal?' is no
  longer a branching primcall, because it isn't inline.  The
  implementation could lead to bad backtraces also, as it didn't save
  the IP, and actually could lead to segfaults as it didn't reload the
  SP after the return.  There is an eqv? fast-path, though.
* module/system/vm/assembler.scm (br-if-equal): Remove interface.
* module/system/vm/disassembler.scm (code-annotation):
  (compute-labels): No need to handle br-if-equal.
2015-11-12 21:22:19 +01:00
Andy Wingo
92ed7f6989 Fix miscompilation of closures allocated as vectors
* module/language/cps/closure-conversion.scm (convert-one): Fix
  miscompilation of vector closure initialization.
2015-11-11 16:30:59 +01:00
Andy Wingo
25738ec35d Eval speedup for lexical-ref
* module/ice-9/eval.scm (primitive-eval): Specialize lexical-ref for
  depths 0, 1, and 2.  Speeds up this test by around 13%:

    (primitive-eval '(let lp ((n 0)) (when (< n #e1e7) (lp (1+ n)))))
2015-11-11 14:51:19 +01:00
Andy Wingo
ac5a05d02e Bump bytecode version
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump
  bytecode version to prevent 2.1.1 users from thinking that they don't
  need to make clean after pulling.
2015-11-11 10:25:23 +01:00
Andy Wingo
7dc3e4ba23 Remove debug printout in specialize-numbers
* module/language/cps/specialize-numbers.scm (apply-f64-specialization):
  Remove printout.  I didn't see any when compiling Guile, which means
  that probably this optimization doesn't hit for any code in Guile
  itself, sadly :P
2015-11-11 10:21:43 +01:00
Andy Wingo
80f2726310 Better f64 unboxing for loop vars that might flow to $ktail
* module/language/cps/specialize-numbers.scm (compute-specializable-f64-vars):
  Tweak to allow f64 values to flow directly to return sites.
2015-11-11 10:21:43 +01:00
Andy Wingo
5b9835e1f8 The compiler can unbox float64 loop variables
* module/language/cps/specialize-numbers.scm: Specialize phi variables
  as well.
2015-11-11 10:21:43 +01:00
Andy Wingo
f0594be035 Fix slot representation computation for fadd, fmul, etc
* module/language/cps/slot-allocation.scm (compute-var-representations):
  fadd, fmul and so on also define f64 values.
2015-11-11 10:21:43 +01:00
Andy Wingo
12e9e2148e Add new pass to specialize "add" into "fadd" where possible
* module/language/cps/specialize-numbers.scm: New pass, to turn "add"
  into "fadd", and similarly for sub, mul, and div.

* module/language/cps/optimize.scm:
* module/Makefile.am:
* bootstrap/Makefile.am: Wire up the new pass.
2015-11-11 10:21:43 +01:00
Andy Wingo
3b4941f3a9 Add fadd, fsub, fmul, fdiv instructions
* libguile/vm-engine.c (fadd, fsub, fmul, fdiv): New instructions.

* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Wire up support for new instructions.

* module/system/vm/assembler.scm: Export emit-fadd and friends.
2015-11-11 10:21:28 +01:00
Andy Wingo
c438998e48 Scalar replacement for f64->scm
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
  Scalar replacement for float boxes.
2015-11-11 10:21:16 +01:00
Andy Wingo
b1ac8d68b5 bv-{f32,f64}-{ref,set!} operate on raw f64 values
* module/language/tree-il/compile-cps.scm (convert): Box results of
  bv-f32-ref and bv-f64-ref.  Unbox the argument to bv-f32-set! and
  bv-f64-set!.

* libguile/vm-engine.c (bv-f32-ref, bv-f64-ref): Results are raw.
  (bv-f32-set!, bv-f64-set!): Take unboxed arguments.

* module/system/vm/assembler.scm (emit-scm->f64, emit-f64->scm):
  Export.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm: Add support for scm->f64 and
  f64->scm.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  Add cases for primops returning raw values.

* module/language/cps/types.scm (bv-f32-ref, bv-f32-set!)
  (bv-f64-ref, bv-f64-set!): Deal in &f64 values instead of reals.
2015-11-11 10:20:12 +01:00
Andy Wingo
608753982f Type inference distinguishes between untagged and tagged flonums
* module/language/cps/types.scm (&f64): New type, for untagged f64
  values.  Having a distinct type prevents type folding from replacing
  an untagged 3.0 with a tagged 3.0.
  (scm->f64, f64->scm): Support these new primcalls.
2015-11-11 10:14:51 +01:00
Andy Wingo
e3cc0eeb3a Reflection support for unboxed f64 slots
* module/system/vm/assembler.scm (emit-definition): Add representation
  field.
  (write-arities): Emit representations into the arities section.

* module/system/vm/debug.scm (arity-definitions): Read representations.

* module/system/vm/frame.scm (<binding>): Add representation field and
  binding-representation getter.
  (available-bindings): Pass representation to make-binding.
  (frame-binding-set!, frame-binding-ref, frame-call-representation):
  Pass representation to frame-local-ref / frame-local-set!.

* test-suite/tests/rtl.test: Update definition instructions.

* module/language/cps/slot-allocation.scm ($allocation): Add
  representations field.
  (lookup-representation): New public function.
  (allocate-slots): Pass representations to make-$allocation.

* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  emit-definition change.

* libguile/frames.h:
* libguile/frames.c (scm_frame_local_ref, scm_frame_local_set_x): Take
  representation argument.
  (scm_to_stack_item_representation): New internal helper.
2015-10-28 17:43:55 +00:00
Andy Wingo
e7660a607c VM support for raw slots
* libguile/loader.c (scm_find_slot_map_unlocked): Rename from
  scm_find_dead_slot_map_unlocked.

* libguile/vm.c (struct slot_map_cache_entry, struct slot_map_cache)
  (find_slot_map): Rename, changing "dead_slot" to "slot".
  (enum slot_desc): New type.
  (scm_i_vm_mark_stack): Interpret slot maps as having two bits per
  slot, allowing us to indicate that a slot is live but not a pointer.

* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  emit-slot-map name change.

* module/system/vm/assembler.scm (<asm>): Rename dead-slot-maps field to
  slot-maps.
  (emit-slot-map): Rename from emit-dead-slot-map.
  (link-frame-maps): 2 bits per slot.

* module/language/cps/slot-allocation.scm (lookup-slot-map): Rename from
  lookup-dead-slot-map.
  (compute-var-representations): New function.
  (allocate-slots): Adapt to encode two-bit slot representations.
2015-10-28 16:40:53 +00:00
Andy Wingo
dd77a818ba Treat tail $values as generating lazy allocations
* module/language/cps/slot-allocation.scm (compute-lazy-vars): Returning
  values in tail position also generates lazy vars.
2015-10-28 13:33:37 +00:00
Andy Wingo
c984432f60 Remove use of return in disassembler.scm
* module/system/vm/disassembler.scm (instruction-has-fallthrough?):
  Remove return from static opcode set.
2015-10-28 13:11:20 +00:00
Andy Wingo
696339a603 Always emit return-values
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  special cases for nullary and unary returns; instead always use
  return-values and rely on hinting to try to place values in the right
  slot already.

* module/system/vm/assembler.scm (emit-init-constants): Use
  return-values.

* module/system/vm/disassembler.scm (code-annotation): Add annotation
  for return-values.
2015-10-28 11:32:15 +00:00
Andy Wingo
2f08838cd6 Replace return primcalls with $values
* module/language/cps/compile-bytecode.scm:
* module/language/cps/contification.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Never generate a return
  primcall.  Instead use $values.
2015-10-28 11:11:23 +00:00
Andy Wingo
7c9e477b82 Don't emit redundant reset-frame before return
* module/language/cps/compile-bytecode.scm (compile-function): Don't
  emit reset-frame before return-values.
2015-10-28 11:00:05 +00:00
Andy Wingo
7aee3c74f5 return-values opcode resets the frame
* libguile/vm-engine.c (return-values): Change to also reset the frame,
  if nlocals is nonzero.

* doc/ref/vm.texi (Procedure Call and Return Instructions): Updated
  docs.

* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  call emit-return-values with the right number of arguments.
2015-10-28 10:47:18 +00:00
Andy Wingo
34f3fb78e0 Fix slot-allocation to make 'return' not need to alloc-frame
* module/language/cps/slot-allocation.scm (compute-frame-sizes): Ensure
  that frames with `return' have space to shuffle the arg into return
  position.
2015-10-28 10:14:30 +00:00
Andy Wingo
3f345f564f Run CSE to clean up after closure conversion
* module/language/cps/optimize.scm: Enable CSE over first-order CPS.
2015-10-28 10:07:38 +00:00
Andy Wingo
04356dabb9 CSE can run on first-order CPS
* module/language/cps/cse.scm (compute-truthy-expressions):
  (compute-equivalent-subexpressions):
  (eliminate-common-subexpressions): Refactor to be able to work on
  first-order CPS.
2015-10-28 09:13:20 +00:00
Andy Wingo
8d79dfddb6 Revert "Bootstrap build doesn't have to expand CPS optimizations"
This reverts commit ce36fb16ff.
2015-10-28 09:12:02 +00:00
Andy Wingo
ce36fb16ff Bootstrap build doesn't have to expand CPS optimizations
* module/language/cps/optimize.scm (define-optimizer)
  (optimize-higher-order-cps, optimize-first-order-cps): Obfuscate a bit
  so that the bootstrap build won't have to expand optimization passes.
  Might marginally speed up the bootstrap process.
2015-10-28 09:10:37 +00:00
Andy Wingo
5f4ac529e1 Use a bootstrapped -O0 compiler to compile the -O2 Guile
This reduces total build time to around 30 minutes or so.

* Makefile.am (SUBDIRS): Visit bootstrap/ before module/.

* bootstrap/Makefile.am: New file.

* configure.ac: Generate bootstrap/Makefile.

* meta/uninstalled-env.in (top_builddir): Add bootstrap/ to the
  GUILE_LOAD_COMPILED_PATH.

* module/Makefile.am: Simplify to just sort files in alphabetical order;
  since bootstrap/ was already compiled, we don't need to try to
  optimize compilation order.  Although the compiler will get faster as
  more of the compiler itself is optimized, this isn't a significant
  enough effect to worry about.
2015-10-23 13:29:03 +00:00
Andy Wingo
f169be9fc8 Wire up `guild compile -O0 foo.scm'
* module/scripts/compile.scm (%options): Resurrect -O option and make it
  follow GCC, more or less.  The default is equivalent to -O2.

* module/language/cps/compile-bytecode.scm (lower-cps):
* module/language/cps/optimize.scm (optimize-higher-order-cps): Move
  split-rec to run unconditionally for now, as closure conversion fails
  without it.
  (define-optimizer): Only verify the result if we are debugging, to
  save time.
  (cps-default-optimization-options): New exported procedure.

* module/language/tree-il/optimize.scm
  (tree-il-default-optimization-options): New exported procedure.
2015-10-22 17:44:17 +00:00
Andy Wingo
467e587d68 Update VM documentation for new stack layout
* doc/ref/vm.texi: Update for new stack layout.
* module/system/vm/disassembler.scm (code-annotation): Print the frame
  sizes after alloc-frame, reset-frame, etc to make reading the
  disassembly easier.
2015-10-22 11:02:18 +00:00
Andy Wingo
f03960412e Add stack size computation to disassembler
* module/system/vm/disassembler.scm (define-stack-effect-parser)
  (stack-effect-parsers, instruction-stack-size-after): New stack size
  facility.
  (define-clobber-parser, clobber-parsers, instruction-slot-clobbers):
  Take incoming and outgoing stack sizes as arguments to interpret
  SP-relative clobbers.

* module/system/vm/frame.scm (compute-frame-sizes): New helper that
  computes frame sizes for each position in a function.
  (compute-killv): Adapt to compute the clobbered set given the computed
  frame sizes.
2015-10-21 15:02:28 +02:00
Andy Wingo
4afb46f859 Minor assembler cleanups
* module/system/vm/assembler.scm (shuffling-assembler): Minor renames.
2015-10-21 15:02:08 +02:00
Andy Wingo
70c317ab51 SP-relative local addressing
* libguile/vm-engine.c: S24/S12/S8 operands addressed relative to the
  SP, not the FP.  Cache the SP instead of a FP-relative locals
  pointer.  Further cleanups to follow.

* libguile/vm.c (vm_builtin_call_with_values_code): Adapt to mov operand
  addresing change.

* module/language/cps/compile-bytecode.scm (compile-function): Reify
  SP-relative local indexes where appropriate.

* module/system/vm/assembler.scm (emit-fmov*): New helper, exported as
  emit-fmov.
  (shuffling-assembler, define-shuffling-assembler): Rewrite to shuffle
  via push/pop/drop.
  (standard-prelude, opt-prelude, kw-prelude): No need to provide for
  shuffling args.

* test-suite/tests/rtl.test: Update.

* module/language/cps/slot-allocation.scm: Don't reserve slots 253-255.
2015-10-21 11:49:20 +02:00
Andy Wingo
0da0308b84 Prepare for SP-addressed locals
* libguile/vm-engine.c: Renumber opcodes, and take the opportunity to
  fold recent additions into more logical places.  Be more precise when
  describing the encoding of operands, to shuffle local references only
  and not constants, immediates, or other such values.
  (SP_REF, SP_SET): New helpers.
  (BR_BINARY, BR_ARITHMETIC): Take full 24-bit operands.  Our shuffle
  strategy is to emit push when needed to bring far locals near, then
  pop afterwards, shuffling away far destination values as needed; but
  that doesn't work for conditionals, unless we introduce a trampoline.
  Let's just do the simple thing for now.  Native compilation will use
  condition codes.
  (push, pop, drop): Back from the dead!  We'll only use these for
  temporary shuffling though, when an opcode can't address the full
  24-bit range.
  (long-fmov): New instruction, like long-mov but relative to the frame
  pointer.
  (load-typed-array, make-array): Don't use a compressed encoding so
  that we can avoid the shuffling case.  It would be a pain, given that
  they have so many operands already.

* module/language/bytecode.scm (compute-instruction-arity): Update for
  new instrution word encodings.

* module/system/vm/assembler.scm: Update to expose some opcodes
  directly, without the need for shuffling wrappers.  Adapt to
  instruction word encodings change.

* module/system/vm/disassembler.scm (disassembler): Adapt to instruction
  coding change.
2015-10-21 11:49:20 +02:00
Andy Wingo
d7199da8c9 Fix prompt miscompilation
* module/language/cps/compile-bytecode.scm (compile-function): Fix
  miscompilation when the handler body is forwarded.
2015-10-21 11:49:20 +02:00
Mark H Weaver
315adb6347 Fix typo in CPS conversion.
Fixes <http://bugs.gnu.org/21614>.
Reported by tantalum <sph@posteo.eu>.

* module/language/tree-il/compile-cps.scm (convert): Add missing 'cps'
  argument to the continuation passed to 'convert-arg'.
2015-10-06 10:09:12 -04:00
Andy Wingo
78fdc3e673 Remove unused (language tree-il inline) module.
* module/language/tree-il/inline.scm: Remove.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Remove inline.scm.
2015-09-17 12:45:36 +02:00
Andy Wingo
48412395c6 Add closure effects
* module/language/cps/effects-analysis.scm: Add closure effects, to
  enable hoisting/CSE of free-ref/free-set!.
2015-07-27 15:19:45 +02:00
Andy Wingo
90c11483e6 Better codegen for $values terms that don't shuffle
* module/language/cps/compile-bytecode.scm (compute-forwarding-labels):
  Analyze forwarding labels before emitting code.  This lets us elide
  conts that cause no shuffles, allowing more fallthrough.
2015-07-27 14:53:59 +02:00
Andy Wingo
3b60e79879 Loop peeling
* module/language/cps/peel-loops.scm: New pass.  Only enabled if the
  loop has one successor.

* module/language/cps/optimize.scm: Peel instead of doing LICM on
  higher-order CPS, then LICM on first-order CPS.

* module/Makefile.am: Wire up new pass.
2015-07-27 13:45:23 +02:00
Andy Wingo
4792577ab8 solve-flow-equations tweak
* module/language/cps/utils.scm (solve-flow-equations): Revert to take
  separate in and out maps.  Take an optional initial worklist.

* module/language/cps/slot-allocation.scm: Adapt to solve-flow-equations
  change.
2015-07-27 13:25:38 +02:00
Andy Wingo
ce2888701c Simplify rotate-loops.scm
* module/language/cps/rotate-loops.scm: Clean up unused code.
2015-07-27 12:59:09 +02:00
Andy Wingo
e54fbff185 Loop inversion with multiple exits
* module/language/cps/rotate-loops.scm (rotate-loop): Instead of
  restricting rotation to loops with just one exit node, restrict to
  loops with just one exit successor.
2015-07-25 11:03:59 +02:00
Andy Wingo
ee85e2969f Rotate comparisons down to loop back-edges
* module/language/cps/rotate-loops.scm: New pass.
* module/Makefile.am:
* module/language/cps/optimize.scm: Wire up the new pass.
2015-07-24 16:51:04 +02:00
Andy Wingo
bf6930b3f6 Eliminate trampoline gotos when possible in compile-bytecode
* module/language/cps/compile-bytecode.scm (compile-function): Eliminate
  trampoline jumps for conditional branches that don't shuffle.
2015-07-24 16:51:04 +02:00
Andy Wingo
bcfa9fe70e Small expression-effects tweak
* module/language/cps/effects-analysis.scm (expression-effects):
  Closures with zero free vars don't allocate.
2015-07-24 16:51:04 +02:00
Andy Wingo
ec9554d138 Loop-invariant code motion
* module/language/cps/licm.scm: New pass.
* module/language/cps/optimize.scm: Wire up new pass.
* module/Makefile.am: Add new file.
2015-07-24 16:50:58 +02:00
Andy Wingo
bebc70c8b1 Move solve-flow-equations to utils
* module/language/cps/slot-allocation.scm (compute-lazy-vars):
  (compute-live-variables):  Adapt to solve-flow-equations interface
  change.

* module/language/cps/utils.scm (solve-flow-equations): Move here.  Use
  an init value instead of an init map.
2015-07-24 11:40:00 +02:00
Andy Wingo
b40fac1e98 Factor out compute-effects/elide-type-checks from dce.scm
* module/language/cps/type-checks.scm: New module.
* module/language/cps/dce.scm: Use new module.
* module/Makefile.am: Add new module.
2015-07-24 11:39:18 +02:00
Andy Wingo
4aabc205cc Add missing files
Last commit meant to rename files, not delete them.  Whoops!
2015-07-22 18:27:37 +02:00