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

173 commits

Author SHA1 Message Date
Andy Wingo
5675e46410 -O1 disables call precoloring
* module/language/cps/compile-bytecode.scm (compile-function)
  (emit-bytecode):
* module/language/cps/slot-allocation.scm (allocate-slots):
* module/language/cps/optimize.scm (cps-default-optimization-options):
  Allow the "lazy vars" optimization, a form of slot precoloring, to be
  disabled.  It will be disabled at -O0 or -O1, to speed compilation
  times.
2017-11-30 16:58:58 +01:00
Andy Wingo
3600dbf0cc Refactor to finish the primcalls-take-parameters work
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  helper to look up constants now that primcalls can take parameters.
* module/language/cps/devirtualize-integers.scm (peel-trace): Remove
  extra argument to expression-effects.
* module/language/cps/effects-analysis.scm (constant?, indexed-field):
  Remove unused definitions.
  (expression-effects): Remove "constants" argument; constants come from
  primcall params.
  (compute-effects): Don't compute a constants table.
* module/language/cps/slot-allocation.scm ($allocation): Remove
  "constant-values" field.
  (lookup-constant-value, lookup-maybe-constant-value): Remove; unused.
  (allocate-slots): Don't create a constants table.
* module/language/cps/specialize-primcalls.scm
  (compute-defining-expressions, compute-constant-values): Move these
  definitions here, which were previously in utils.scm
* module/language/cps/utils.scm: Remove moved definitions.
2017-11-24 11:03:46 +01:00
Andy Wingo
6866cbd676 Add support for bignum? CPS primitive.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*heap-type-predicates*): Add
  support for bignum? CPS primitive.
2017-11-24 10:37:46 +01:00
Andy Wingo
5fbd4b8f9e Better support for unboxed signed arithmetic
* module/language/cps/primitives.scm (*macro-instruction-arities*):
  Declare new u64->s64, s64->u64, sadd, ssub, smul, sadd/immediate,
  ssub/immediate, smul/immediate, slsh, and slsh/immediate primcalls
  that don't have corresponding VM instructions.
* module/language/cps/effects-analysis.scm: The new instructions are
  effect-free.
* module/language/cps/reify-primitives.scm (wrap-unary, wrap-binary):
  (wrap-binary/exp, reify-primitives): Add horrible code that turns
  e.g. sadd into a series of s64->u64, uadd, and then u64->s64.  This
  way we keep our ability to do range inference on unboxed signed
  arithmetic, but we still bottom out to the same instructions for both
  unboxed signed and unboxed unsigned arithmetic.
* module/language/cps/types.scm: Add type inferrers for new
  instructions.  Remove type checkers for some effect-free primitives.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  pseudo-emitter for u64->s64 and s64->u64 no-ops.
2017-11-20 18:36:00 +01:00
Andy Wingo
0951551fb4 Compiler specializes comparisons to immediate integers
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (load-const/unlikely):
* module/language/cps/types.scm (load-const/unlikely):
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
  new primcall, load-const/unlikely.
* module/language/cps/specialize-numbers.scm: Rework comparison
  specialization.  Add support for specializing comparisons against
  integer immediates.
2017-11-15 14:19:09 +01:00
Andy Wingo
294dbaad35 Add support for comparisons against integer immediates
* libguile/vm-engine.c (s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?)
  (imm-s64<?): New instructions.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add new
  X8_S12_Z12 word type used by the new S64/immediate instructions.  A
  Z12 is a 12-bit signed integer immediate.
* module/system/vm/assembler.scm: Export new instructions, and add
  X8_S12_Z12 support.  Also, add missing shufflers for X8_S12_C12.
* module/language/bytecode.scm (compute-instruction-arity):
* module/system/vm/disassembler.scm (unpack-s12, disassembler): Add
  support for X8_S12_Z12.
* module/language/cps/types.scm (define-predicate-inferrer/param): New
  helper.
  (u64-=, u64-<, s64-<): Remove type checkers; this procedure does not
  cause &type-check.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New type inferrers.
* module/language/cps/type-fold.scm (define-unary-branch-folder*): New
  helper.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New branch folders.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
  constants for new immediate branching primcalls if values out of
  range.
* module/language/cps/effects-analysis.scm: Add support for new
  primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for new primcalls and instructions.  Compile u64-imm-= to
  s64-imm=?.
2017-11-15 14:18:39 +01:00
Andy Wingo
7e79a3291e Better untagging of fixnums
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for tag-fixnum/unlikely.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Add
  equivalent subexpressions for tag-fixnum.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
  tag-fixnum/unlikely.
* module/language/cps/specialize-numbers.scm (specialize-u64-unop)
  (specialize-u64-binop, specialize-u64-shift)
  (specialize-u64-comparison): Make the arg unboxers and result boxers
  into keyword arguments.
  (specialize-s64-unop): New helper.
  (specialize-fixnum-comparison, specialize-fixnum-scm-comparison)
  (specialize-scm-fixnum-comparison): Rename from
  specialize-s64-comparison et al.  Perhaps this should be expanded
  again to include the whole s64 range, once we start to expand scm->s64
  et al.
  (specialize-operations): Specialize arithmetic, etc on signed
  operands and results.  Use less powerful unboxing/boxing ops if
  possible -- e.g. tag-fixnum instead of u64->scm.  Prefer fixnum
  comparisons over u64 comparisons.
  (compute-specializable-fixnum-vars): New helper.
  (compute-specializable-phis): Specialize fixnum phis as well.
  (specialize-primcalls): Specialize untag-fixnum of a constant to
  load-s64.
* module/language/cps/type-fold.scm (u64->scm, s64->scm):
  (scm->s64, scm->u64): Reduce to fixnum ops where possible.
* module/language/cps/types.scm: Remove type checkers for ops that don't
  throw type errors.  Alias tag-fixnum/unlikely to tag-fixnum.
2017-11-13 14:39:30 +01:00
Andy Wingo
b97321dbfd Add srsh, srsh/immediate instructions
* libguile/vm-engine.c (srsh, srsh/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (srsh, srsh/immediate):
* module/system/vm/assembler.scm: Add support for new instructions.

* module/language/cps/types.scm (ulsh, ursh): Remove type checkers, as
  these are effect-free.  Limit range of ursh count.
2017-11-13 10:25:20 +01:00
Andy Wingo
8b5f9648ff Add tag-fixnum instruction
* libguile/vm-engine.c (tag-fixnum): New instruction.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm (&min/fixnum, &max/fixnum, tag-fixnum):
* module/system/vm/assembler.scm: Add support for the new instruction.
2017-11-11 22:08:14 +01:00
Andy Wingo
7a7f71de5c Canonicalize <=, >=, and > primcalls to <
* module/language/tree-il/compile-cps.scm (canonicalize): Convert <=,
  >=, and > primcalls to <.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/effects-analysis.scm: Remove superfluous
  primcalls.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): Only emit < primcalls for ordered
  comparisons.
  (specialize-scm-u64-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Remove support for >=, <=, and the like.
* module/language/cps/type-fold.scm: Remove folders for <= and so on.
* module/language/cps/types.scm (define-=-inferrer, define-<-inferrer):
  New helpers; use them for all = and < variants.  Remove checkers and
  inferrers for <= and the like.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  unnecessary cases.
2017-11-11 22:08:14 +01:00
Andy Wingo
8b3258716c Refactor numeric comparison bytecode emission
* module/language/cps/compile-bytecode.scm (compile-function): Refactor.
2017-11-11 22:08:14 +01:00
Andy Wingo
f96a670332 Add new "throw" VM ops
* libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN.
* libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): New
  instructions.
* libguile/vm.c (vm_throw, vm_throw_with_value)
  (vm_throw_with_value_and_data): New helpers.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for new instructions.
* module/language/cps/prune-bailouts.scm (prune-bailouts): More simple,
  now that there are no $kreceives in play.
* module/language/cps/reify-primitives.scm (reify-clause): Update
  reification of no-clause functions to use new throw op.
* module/language/tree-il/compile-cps.scm (convert): Convert invocations
  of the variable-arity 'throw primitive from Tree-IL to the new
  fixed-arity CPS instructions.
* module/system/vm/assembler.scm (emit-throw/value*)
  (emit-throw/value+data*, emit-throw): Export new instructions.
* module/system/vm/disassembler.scm (code-annotation): Add annotation.
2017-11-05 15:00:16 +01:00
Andy Wingo
17bd5a8938 Add lsh, rsh instructions
* libguile/vm-engine.c (lsh, rsh, lsh/immediate, rsh/immediate): New
  instructions taking unboxed bit counts.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/specialize-numbers.scm (specialize-f64-unop):
  (specialize-u64-unop): Add ability to specialize add/immediate, etc,
  and add lsh/immediate as well.
  (specialize-u64-binop, specialize-u64-shift): Move rsh/lsh
  specialization to its own procedure, given that the bit count is
  already unboxed.
  (specialize-operations): Adapt to support more /immediate
  instructions.
* module/language/cps/type-fold.scm (mul): Reify an lsh/immediate
  instead of an ash.
* module/language/cps/types.scm (compute-ash-range): Add type inferrers
  for lsh, rsh, and their immediate variants.
* module/system/vm/assembler.scm: Export emit-lsh and so on.
* module/language/tree-il/compile-cps.scm (convert): Convert "ash" on
  immediates to rsh/immediate or lsh/immediate.
2017-11-05 15:00:16 +01:00
Andy Wingo
cc1b23ffe8 Remaining /immediate instructions take primcall imm param
* module/language/cps/compile-bytecode.scm (compile-function): Update
  add/immediate, etc.
* module/language/cps/slot-allocation.scm (compute-needs-slot):
  Simplify.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Rework for add/immediate, etc.
* module/language/cps/types.scm (define-unary-result!)
  (define-binary-result!): Take types as params instead of variables, so
  we can share this code with /imm variants.
  (add/immediate, sub/immediate, uadd/immediate, usub/immediate)
  (umul/immediate, ulsh/immediate, ursh/immediate): Update type
  inferrers.
2017-11-05 15:00:16 +01:00
Andy Wingo
56d639bfe5 builtin-ref takes immediate parameter
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/reify-primitives.scm (builtin-ref):
* module/language/cps/slot-allocation.scm (compute-needs-slot):
  Builtin-ref uses immediate parameter.
2017-11-05 15:00:16 +01:00
Andy Wingo
d7ecf35d70 Immediate parameter for struct-ref et al
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (allocate-struct/immediate)
  (struct-ref/immediate, struct-set!/immediate): Immediate struct
  constructor and accessor use immediate primcall parameters.
2017-11-05 15:00:16 +01:00
Andy Wingo
f9b8763921 Immediate variants of vector-ref, etc use immediate param
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (make-vector/immediate):
  (vector-ref/immediate, vector-set!/immediate): Use immediate primcall
  param.
2017-11-05 15:00:16 +01:00
Andy Wingo
2f45cfcb9c free-ref, free-set take immediate parameters
* module/language/cps/closure-conversion.scm (convert-one):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (define-primitive-effects*)
  (expression-effects, primitive-effects): Only fall back to passing
  constant table if the immediate parameter is false.  Adapt closure
  effects analysis.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
  special cases for free-ref/free-set!.
2017-11-05 15:00:16 +01:00
Andy Wingo
6be04684e6 load-f64, etc take immediate parameters
* module/language/cps/compile-bytecode.scm (compile-function): Make
  load-f64, load-s64, and load-u64 take an immediate parameter instead
  of a CPS value.
* module/language/cps/effects-analysis.scm: Remove CPS argument from
  immediate load instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
  special case for load-64 etc.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): Adapt.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Adapt.
* module/language/cps/types.scm (define-type-inferrer*): Also take param
  argument.
  (define-type-inferrer, define-predicate-inferrer): Adapt.
  (define-type-inferrer/param): New helper.
  (load-f64, load-s64, load-u64): Adapt inferrers to pass on value from
  param.
* module/language/cps/utils.scm (compute-constant-values): Adapt.
2017-11-05 15:00:16 +01:00
Andy Wingo
4fb538e90e cache-current-module, etc use immediate primcall parameters
* module/language/bytecode.scm (*macro-instruction-arities*):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/primitives.scm (*macro-instruction-arities*):
* module/language/cps/prune-top-level-scopes.scm (compute-used-scopes):
  (prune-top-level-scopes):
* module/language/cps/reify-primitives.scm (module-box):
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/tree-il/compile-cps.scm (toplevel-box):
  (module-box, capture-toplevel-scope): Move the primcalls that deal
  with top-level references to use immediate parameters.
2017-11-05 15:00:16 +01:00
Andy Wingo
c54c151eb6 $primcall has a "param" member
* module/language/cps.scm ($primcall): Add "param" member, which will be
  a constant parameter to the primcall.  The idea is that constants used
  by primcalls as immediates don't need to participate in optimizations
  in any way -- they should not participate in CSE, have the same
  lifetime as the primcall so not part of DCE either, and don't need
  slot allocation.  Indirecting them through a named $const binding is
  complication for no benefit.  This change should eventually improve
  compilation time and memory usage, once we fully take advantage of it,
  as the number of labels and variables will go down.
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/handle-interrupts.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-checks.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
2017-11-05 15:00:16 +01:00
Andy Wingo
0d42f5467f Lower logtest branches to instead be 'zero? logand'
* module/language/cps/compile-bytecode.scm (compile-function): Rename
  the binary* helper back to binary, update uses, and remove logtest
  branch as we no longer put logtest in test context.
* module/language/cps/primitives.scm (*comparisons*): Remove logtest.
* module/language/cps/type-fold.scm: Remove logtest folder.
  (logbit?): Fold to logand.
* module/language/cps/types.scm (logtest): Update to be a type inferrer
  and not a predicate inferrer.
* module/language/tree-il/peval.scm (peval): Transform logtest and
  logbit? to (zero? (logand _ _)).
2017-10-30 11:50:45 +01:00
Andy Wingo
d1c69b5c95 Remove compiler support for u64-scm comparisons
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm: Remove compiler support for u64-scm
  comparisons, as this is now inlined.
2017-10-29 21:02:56 +01:00
Andy Wingo
f34abbc396 Add hacks around lack of allocation sinking
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*):
* module/language/cps/specialize-numbers.scm (compute-specializable-vars):
* module/language/cps/types.scm: Add new variants of u64->scm and
  s64->scm that can't be replaced by CSE's auxiliary definitions, so we
  can sink unlikely allocations to side branches.  This is a hack until
  we can get allocation sinking working
2017-10-29 20:33:35 +01:00
Andy Wingo
c9ec866ef9 Add untag-fixnum instruction
* libguile/vm-engine.c (untag-fixnum): New instruction.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm (untag-fixnum):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm (untag-fixnum): Add compiler support for
  untag-fixnum.
2017-10-29 19:56:51 +01:00
Andy Wingo
31e7f44340 Add compiler support for fixnum? primcall predicate
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/type-fold.scm (fixnum?):
* module/language/cps/types.scm (fixnum?):
* module/system/vm/assembler.scm (system): Add cases for fixnum?
  primcall predicate.
2017-10-29 19:42:50 +01:00
Andy Wingo
79a2748f83 Add compiler support for s64 comparisons.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  emitters for s64 comparisons.
* module/language/cps/effects-analysis.scm: Add entries.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm (s64-<, s64-<=, s64-=, s64->=)
  (s64->): Add folders.
* module/language/cps/types.scm (s64-<, s64-<=, s64-=, s64->=, s64->):
  Add type checkers and inferrers.
2017-10-29 19:42:14 +01:00
Andy Wingo
73d1502630 Lower eqv? and equal? to new instructions.
* libguile/numbers.h:
* libguile/eq.c (scm_i_heap_numbers_equal_p): New helper, factored out
  of scm_eqv_p.
  (scm_eqv_p): Use new helper.
* libguile/vm-engine.c (heap-numbers-equal?): New op.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for heap-number? and heap-numbers-equal?.  Remove case for
  eqv?.
* module/language/cps/effects-analysis.scm: Add heap-numbers-equal?.
* module/language/cps/primitives.scm (*comparisons*): Add
  heap-numbers-equal?.
* module/language/cps/type-fold.scm (heap-numbers-equal?): Update.
* module/language/cps/types.scm (heap-numbers-equal?): Update.
* module/language/tree-il/compile-cps.scm (canonicalize): Completely
  inline eqv?, and partially inline equal?.
* module/system/vm/assembler.scm (system): Export emit-heap-numbers-equal?.
2017-10-29 15:47:25 +01:00
Andy Wingo
9d1235af96 Use new instructions for f64 comparisons
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for f64 comparisons.
2017-10-29 10:05:24 +01:00
Andy Wingo
8a96b5d085 Use new instructions for u64 comparisons.
* module/language/cps/compile-bytecode.scm (compile-function): Compile
  new instructions for u64 comparisons.
2017-10-29 10:05:24 +01:00
Andy Wingo
f8ac680965 Use new instructions for less-than, etc
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for generic numeric comparisons (< <= = >= >).
2017-10-29 10:05:24 +01:00
Andy Wingo
056914b555 Emit new eq? instruction
* module/language/cps/compile-bytecode.scm (compile-function): Emit
  new-style eq? instruction.
2017-10-29 10:05:24 +01:00
Andy Wingo
c119623e45 Simplify $branch to always take a $primcall
* module/language/tree-il/compile-cps.scm (convert): Lower (if foo A B)
  to (if (false? foo) B A).
* module/language/cps/specialize-numbers.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/verify.scm: Adapt.
* module/language/cps/compile-bytecode.scm: Add support for new-style
  false? instruction for false? primcall.
2017-10-29 10:05:24 +01:00
Andy Wingo
c74b2257c7 Use new instructions for null?, nil?
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for branches on null? and nil?.
2017-10-29 10:05:24 +01:00
Andy Wingo
e3c062dce6 Emit char? instead of br-if-char
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for char? test.
2017-10-29 10:05:24 +01:00
Andy Wingo
29b8e32ffe Emit new instructions for heap object type tests
* module/language/cps/compile-bytecode.scm (compile-function): Compile
  heap object tests to use the new instructions.
2017-10-29 10:05:24 +01:00
Andy Wingo
1139c10e09 Heap type predicates preceded by heap-object?
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for heap-object? in test context.
* module/language/cps/primitives.scm (*immediate-predicates*):
  (*heap-type-predicates*, *comparisons*): New sets of predicates for
  which the VM has branching operations.
  (heap-type-predicate?): New predicate.
  (*branching-primcall-arities*): Make a hash table.
  (branching-primitive?, prim-arity): Adapt
  to *branching-primcall-arities* being a hash table.
* module/language/cps/type-fold.scm (heap-object?): Add folder.
* module/language/tree-il/compile-cps.scm (convert): Precede heap type
  checks with a heap-object? guard.
2017-10-29 10:05:24 +01:00
Andy Wingo
3d848f22f8 First step towards emitting new instructions: "j" instead of "br"
* module/language/cps/compile-bytecode.scm (compile-function): Emit "j"
  instructions instead of "br".
2017-10-25 16:53:18 +02:00
Andy Wingo
c525aa6d95 VM support for string-set!; slimmer read-string
* doc/ref/vm.texi (Inlined Scheme Instructions): Add string-set!.
* libguile/vm-engine.c (string-set!): New opcode.
* module/ice-9/rdelim.scm (read-string): Reimplement in terms of a
  geometrically growing list of strings, to reduce total heap usage when
  reading big files.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  string-set! support.
* module/language/cps/types.scm (string-set!): Update for &u64 index.
* module/language/tree-il/compile-cps.scm (convert): Unbox index to
  string-set!.
* module/system/vm/assembler.scm (system): Export string-set!.
2017-03-09 17:24:06 +01:00
Andy Wingo
7cdfaaada9 Remove contification restriction in case-lambda
* module/language/cps/compile-bytecode.scm (compile-function): Check for
  fallthrough after $kclause too; possible to need to jump if clause
  tails are contified.
* module/language/cps/contification.scm (compute-contification-candidates):
  Enable inter-clause contification.
2017-03-09 14:47:42 +01:00
Andy Wingo
6d9335ad46 All clauses of function have same nlocals
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm ($allocation)
  (lookup-nlocals, compute-frame-size, allocate-slots): Adapt to
  have one frame size per function, for all clauses.
2017-03-09 14:25:37 +01:00
David Thompson
35a9059250 Add unboxed floating point comparison instructions.
* libguile/vm-engine.c (BR_F64_ARITHMETIC): New preprocessor macro.
(br_if_f64_ee, br_if_f64_lt, br_if_f64_le, br_if_f64_gt, br_if_f64_ge):
New VM instructions.
* doc/ref/vm.texi ("Unboxed Floating-Point Arithmetic"): Document them.
* module/language/cps/compile-bytecode.scm (compile-function): Emit f64
comparison instructions.
* module/language/cps/effects-analysis.scm: Define effects for f64
primcalls.
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
arities for f64 primcalls.
* module/language/cps/specialize-numbers.scm (specialize-f64-comparison):
New procedure.
(specialize-operations): Specialize f64 comparisons.
* module/system/vm/assembler.scm (emit-br-if-f64-=, emit-br-if-f64-<)
(emit-br-if-f64-<=, emit-br-if-f64->, emit-br-if-f64->=): Export.
* module/system/vm/disassembler.scm (code-annotation): Add annotations
for f64 comparison instructions.
2017-01-12 09:27:43 -05:00
Andy Wingo
7184c176b4 with-dynamic-state compiler and VM support
* libguile/dynstack.h (SCM_DYNSTACK_TYPE_DYNAMIC_STATE):
* libguile/dynstack.c (DYNAMIC_STATE_WORDS, DYNAMIC_STATE_STATE_BOX):
  (scm_dynstack_push_dynamic_state):
  (scm_dynstack_unwind_dynamic_state): New definitions.
  (scm_dynstack_unwind_1, scm_dynstack_wind_1): Add with-dynamic-state
  cases.
* libguile/memoize.c (push_dynamic_state, pop_dynamic_state)
  (do_push_dynamic_state, do_pop_dynamic_state): New definitions.
  (memoize, scm_init_memoize): Handle push-dynamic-state and
  pop-dynamic-state.
* libguile/vm-engine.c (push-dynamic-state, pop-dynamic-state): New
  opcodes.
* module/ice-9/boot-9.scm (with-dynamic-state): New definition in Scheme
  so that the push-dynamic-state and pop-dynamic-state always run in the
  VM.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm:
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
* module/system/vm/assembler.scm: Add support for with-dynamic-state to
  the compiler.
* test-suite/tests/fluids.test ("dynamic states"): Add basic tests.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
2016-12-05 22:57:29 +01:00
Andy Wingo
8bd5dae8c3 Compile fluid-set! to VM opcode
* libguile/vm-engine.c (fluid-set!): Fix name of opcode to correspond
  with name of Tree-IL primitive.  Fixes compilation of fluid-set! to
  actually use the fluid-set! opcode.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  fluid-set! case.
* module/system/vm/assembler.scm: Update export name for
  emit-fluid-set!.
2016-11-27 21:55:42 +01:00
Andy Wingo
ca74e3fae5 Add handle-interrupts inst and compiler pass
* libguile/vm-engine.c (vm_engine): Remove initial VM_HANDLE_INTERRUPTS
  call; surely our caller already handled interrupts.  Add
  handle-interrupts opcode.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Add handle-interrupts.scm.
* module/system/vm/assembler.scm (system):
* module/language/cps/compile-bytecode.scm (compile-function):
  (lower-cps): Add handle-interrupts support.
* module/language/cps/handle-interrupts.scm: New file.
2016-11-16 22:55:45 +01:00
Andy Wingo
32f309d5ce Compiler support for atomics
* doc/ref/vm.texi (Inlined Atomic Instructions): New section.
* libguile/vm-engine.c (VM_VALIDATE_ATOMIC_BOX, make-atomic-box)
  (atomic-box-ref, atomic-box-set!, atomic-box-swap!)
  (atomic-box-compare-and-swap!): New instructions.
* libguile/vm.c: Include atomic and atomics-internal.h.
  (vm_error_not_a_atomic_box): New function.
* module/ice-9/atomic.scm: Register primitives with the compiler.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for atomic ops.
* module/language/cps/effects-analysis.scm: Add comment about why no
  effects analysis needed.
* module/language/cps/reify-primitives.scm (primitive-module): Add case
  for (ice-9 atomic).
* module/language/tree-il/primitives.scm (*effect-free-primitives*):
  (*effect+exception-free-primitives*): Add atomic-box?.
* module/system/vm/assembler.scm: Add new instructions.

* test-suite/tests/atomic.test: Test with compilation and
  interpretation.
2016-09-06 12:18:35 +02:00
Andy Wingo
f1c0434403 `define!' instruction returns the variable
* doc/ref/vm.texi (Top-Level Environment Instructions): Update
  documentation.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump, sadly.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c (define!): Change to store variable in dst slot.
* module/language/tree-il/compile-cps.scm (convert):
* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  define! change.
* module/language/cps/effects-analysis.scm (current-module): Fix define!
  effects.  Incidentally here was the bug: in Guile 2.2 you can't have
  effects on different object kinds in one instruction, without
  reverting to &unknown-memory-kinds.
* test-suite/tests/compiler.test ("regression tests"): Add a test.
2016-06-21 22:40:31 +02:00
Andy Wingo
f5b9a53bd0 Add integer->char and char->integer opcodes
* libguile/vm-engine.c (integer_to_char, char_to_integer): New opcodes.
* libguile/vm.c (vm_error_not_a_char): New error case.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm:
* module/language/tree-il/compile-cps.scm (convert):
* doc/ref/vm.texi (Inlined Scheme Instructions):
* module/system/vm/assembler.scm: Add support for new opcodes.
2016-05-04 12:36:41 +02:00
Andy Wingo
1d4b4ec39c Add support for comparing u64 values with SCM values
* libguile/vm-engine.c (BR_U64_SCM_COMPARISON): New helper.
  (br-if-u64-<=-scm, br-if-u64-<-scm, br-if-u64-=-scm)
  (br-if-u64->-scm, br-if-u64->=-scm): New instructions, to compare an
  untagged u64 with a tagged SCM.  Avoids many u64->scm operations.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/type-fold.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation, compute-labels):
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
  support for new opcodes.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Specialize u64 comparisons.
* module/language/cps/types.scm (true-comparison-restrictions): New helper.
  (define-comparison-inferrer): Use the new helper.  Add support for
  u64-<-scm et al.
2015-12-03 09:01:24 +01:00
Andy Wingo
9514dc7b95 Add ursh/immediate and ulsh/immediate ops
* libguile/vm-engine.c (ursh/immediate, ulsh/immediate): New ops.
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations)
  (compute-needs-slot):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm:
* module/language/cps/types.scm: Add support for new ops, and specialize
  ursh and ulsh.
2015-12-02 22:11:19 +01:00