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

1799 commits

Author SHA1 Message Date
Andy Wingo
afb0a92d50 $branch is now a distinct CPS term type
* module/language/cps.scm ($branch): Refactor to be its own CPS term
  type, not relying on $continue to specify a continuation (which before
  was only for the false case) or a source location.  Update allllllll
  callers.
2018-01-03 16:16:39 +01:00
Andy Wingo
108ade6b0e Re-add support for logbit?
* module/language/cps/type-fold.scm (logbit?): Adapt for logbit?
  continuing to $kargs.
* module/language/tree-il/cps-primitives.scm (logbit?): Declare this CPS
  primitive.
2017-12-27 15:46:31 +01:00
Andy Wingo
bc5a599cad Unknown primcalls convert as calls
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  case where $prim could continue to $kreceive; this isn't possible.
  However when reifying an unknown primcall, always add a $kreceive, as
  the continuation has to be $kargs.
* module/language/tree-il/compile-cps.scm (convert): Unknown primcalls
  convert as calls.  With this change, all primcalls should continue to
  $kargs, with the exception of 'throw.
2017-12-27 15:46:31 +01:00
Andy Wingo
0b4c1e2c29 Remove inline-constructors pass
* module/language/cps/constructors.scm: Remove pass, as "list" and
  "vector" are now inlined by CPS conversion, and nothing in the
  optimizer reifies "list" or "vector" primcalls.
* module/language/cps/optimize.scm (optimize-higher-order-cps)
  (cps-default-optimization-options):
* am/bootstrap.am:
* module/Makefile.am: Remove references to inline-constructors pass.
2017-12-27 15:46:31 +01:00
Andy Wingo
cf1611ef38 Contification also inlines "elide-values" pass
* module/language/cps/contification.scm (apply-contification): Inline
  returns to the corresponding $kargs.
* module/language/cps/licm.scm (loop-invariant?): Remove handling of
  "values" primcall, as this doesn't exist any more.
2017-12-27 15:46:31 +01:00
Andy Wingo
c9efff30de CPS conversion avoids residualizing unknown primcalls
* module/language/tree-il/compile-cps.scm: Avoid residualizing "apply"
  or "abort-to-prompt" primcalls; instead, these are just calls to
  $prim.
2017-12-27 15:46:31 +01:00
Andy Wingo
7f7cbe8b65 Inline "elide-values" optimization into CPS conversion
* module/language/tree-il/compile-cps.scm (adapt-arity, convert): Avoid
  reifying "values" primcalls unless necessary.  Effectively inlines the
  "elide-values" optimization into CPS conversion.
* module/language/cps/elide-values.scm: Remove, as it's now unneeded.
* module/language/cps/optimize.scm (optimize-higher-order-cps):
* module/Makefile.am:
* am/bootstrap.am: Remove elide-values references.
2017-12-27 15:46:31 +01:00
Andy Wingo
9111f8cdcd CPS conversion expands "list"
* module/language/tree-il/compile-cps.scm (build-list): New helper.
  (convert, canonicalize): Canonicalize "list" earlier.  Allow sinking
  of any initializer that can't capture the continuation, not just in
  cases where all initializers have this property.  Reify a cons chain
  internally as appropriate.
2017-12-27 15:46:31 +01:00
Andy Wingo
36e6a3daca Refactor lowering of Tree-IL primcalls to CPS
* module/language/tree-il/cps-primitives.scm: New file,
  replacing (language cps primitives).  Lists known primitives and their
  relation to Tree-IL explicitly, instead of assuming that any Tree-IL
  primcall that shares a name with a bytecode instruction is a CPS
  primcall.
* module/language/cps/verify.scm: Remove use of (language cps
  primitives) and primcall arity checking.  Would be nice to add this
  back at some point.
* module/language/tree-il/compile-cps.scm (convert): Refactor to use new
  tree-il-primitive->cps-primitive+nargs+nvalues helper.
* module/Makefile.am:
* am/bootstrap.am: Adapt.
2017-12-27 15:46:31 +01:00
Andy Wingo
549ad3ce8c Flesh out compile-bytecode for all heap objects
* module/language/cps/compile-bytecode.scm (compile-function): Organize
  emitters and flesh out with more heap type tag predicates.  Remove
  now-needless (language cps primitives) import.
2017-12-27 15:46:31 +01:00
Andy Wingo
140b69dfc6 Refactor list->seq to make return arity apparent
* module/language/tree-il.scm (list->seq): Change to let tail of seq
  indicate number of values.
2017-12-27 15:46:31 +01:00
Andy Wingo
7dbc571db1 Refactor reify-primitives pass
* module/language/cps/reify-primitives.scm (*ephemeral-reifiers*)
  (define-ephemeral, define-binary-signed-ephemeral)
  (define-binary-signed-ephemeral/imm, compute-known-primitives):
  (*known-primitives*, known-primitive?): New definitions.
  (reify-primitives): Extract reification of "ephemeral primitives".
2017-12-27 15:46:31 +01:00
Andy Wingo
b918784412 Remove compile-bytecode cases for ephemeral primitives
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  cases for tag-fixnum/unlikely, etc.
2017-12-27 15:46:31 +01:00
Andy Wingo
1f460cb054 Reify-primitives removes "/unlikely" ephemeral instructions
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  tag-fixnum/unlikely, etc.
2017-12-27 15:46:31 +01:00
Andy Wingo
8e7170a67a Refactor boxing/unboxing primcall args/results
This will allow individual primcall converters to define ad-hoc
conversion routines.

* module/language/tree-il/compile-cps.scm (convert-primcall/default)
  (convert-indexed-getter, convert-indexed-setter)
  (convert-indexed-getter/tag, convert-indexed-setter/untag)
  (convert-scm-u64->scm-primcall, convert-scm-u64-scm-primcall)
  (convert-scm-u64->f64-primcall, convert-scm-u64-f64-primcall)
  (convert-scm-u64->u64-primcall, convert-scm-u64-u64-primcall)
  (convert-scm-u64->s64-primcall, convert-scm-u64-s64-primcall)
  (convert-*->u64-primcall, convert-scm->u64-primcall)
  (convert-u64->scm-primcall): Define some primcall converter helpers.
  (*primcall-converters*, define-primcall-converter)
  (define-primcall-converters): Define converters for a number of
  primcalls.
  (convert-primcall*, convert-primcall): Interface to primcall
  converters.
  (convert): Pass most primcalls through convert-primcall, unless we
  know already that they don't need instruction explosion or
  boxing/unboxing.
2017-12-27 15:46:31 +01:00
Andy Wingo
f75d0adc3f Fix mismatch between CPS and Scheme "complex?" predicate
* module/system/base/types/internal.scm (heap-tags): Rename complex and
  fraction predicates to "compnum?" and "fracnum?", as they aren't the
  same as the Scheme predicates "complex?" and "fraction?".
2017-12-27 15:46:31 +01:00
Andy Wingo
da7144d93c Use unchecked scm-ref/set in closure conversion
* module/language/cps/closure-conversion.scm (convert-one): Use
  unchecked initializers and accessors.
2017-12-06 13:46:14 +01:00
Andy Wingo
4dca2c5cfb Support closure annotations to scm-ref et al
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
* module/language/cps/types.scm (annotation->type): Add pairs and
  closures.
2017-12-06 13:45:24 +01:00
Andy Wingo
52e28fd19e Fix DCE over primcall setters with params
* module/language/cps/dce.scm (compute-live-code): The primcall-param
  refactor made it so that a vector-set! to a dead vector would
  needlessly mark the vector as live.  This commit fixes it and adds
  scm-set!, etc.
2017-12-06 13:44:17 +01:00
Andy Wingo
eed4e09723 Assignment conversion uses unchecked memory accessors
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Add box type annotation.
* module/language/cps/reify-primitives.scm (primitive-ref): Reify
  scm-ref/immediate instead of box-ref.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Remove needless and unbound -> literal.
* module/language/cps/types.scm (annotation->type): Add box type.
* module/language/tree-il/compile-cps.scm (convert): Reify
  scm-ref/immediate / scm-set!/immediate instead of box-ref / box-set!.
2017-12-06 11:26:03 +01:00
Andy Wingo
f84474ef39 CPS conversion residualizes undefined? predicate
* module/language/tree-il/compile-cps.scm (init-default-value): Use
  undefined? predicate instead of reifying an unbound value in the CPS
  term.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for the special immediate predicates.  Evidently we aren't emitting
  these yet!
2017-12-06 11:13:31 +01:00
Andy Wingo
315dd366ee Add scm-ref, etc instructions for generic heap object field access
* libguile/vm-engine.c (allocate-words, allocate-words/immediate)
  (scm-ref, scm-set!, scm-ref/tag, scm-set!/tag, scm-ref/immediate)
  (scm-set!/immediate): New instructions for generic access to fields in
  heap objects.
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (allocate-words)
  (allocate-words/immediate, scm-ref, scm-ref/immediate, scm-ref/tag)
  (scm-set!/tag, scm-set!, scm-set!/immediate, word-ref)
  (word-ref/immediate, word-set!, word-set!/immediate):
* module/system/vm/assembler.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for the new instructions.
2017-12-06 11:13:29 +01:00
Andy Wingo
9db628ee29 Bailouts can continue directly to tail
* module/language/cps/compile-bytecode.scm (compile-function): Allow a
  'throw primcall in tail position.
* module/language/cps/prune-bailouts.scm (prune-bailouts): Continue
  directly to the nearest tail continuation, so we don't cause
  unreachable handle-interrupts / return 0 instructions to be emitted.
* module/language/cps/reify-primitives.scm (reify-clause): Residualized
  'throw primcall continues directly to tail.
* module/language/cps/verify.scm (check-arities): Relax check for
  'throw.
2017-12-05 14:27:01 +01:00
Andy Wingo
64acf24b40 Fix NaN handling in <= and >=
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for emitting <= via < and jge / jnge.
* module/language/cps/effects-analysis.scm: Declare effects for <= and
  f64-<=.
* module/language/cps/primitives.scm (*comparisons*): Add <=, f64-<=.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Specialize <= to < for integer comparisons.  Specialize to f64-<= for
  f64 ops.
* module/language/cps/type-fold.scm (<=): Add folder.
* module/language/cps/types.scm (infer-<=): Add inferrer.
* module/language/tree-il/compile-cps.scm (canonicalize): Canonicalize
  <= and >= to <=, so that nans are handled correctly.
2017-12-02 21:07:48 +01:00
Andy Wingo
40dac99d42 Integer comparison folding refactors
* module/language/cps/type-fold.scm (compare-exact-ranges): Rename from
  compare-integer-ranges.
  (<, u64-<, s64-<, =, u64-=, s64-=): Separate the generic and unboxed
  implementations.
2017-12-02 20:50:13 +01:00
Andy Wingo
8c37cf083f Refactor number specialization to reduce duplication
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Factor out specialize-primcall and specialize-branch operations.
2017-12-02 20:40:26 +01:00
Andy Wingo
0cbba8efe0 Avoid generating arity-adapting zero-value conts where possible
* module/language/tree-il/compile-cps.scm (adapt-arity, convert): Avoid
  generating arity-adapting continuations for nullary continuations.
2017-12-02 10:14:45 +01:00
Andy Wingo
4002849393 Avoid generating arity-adapting continuations if not needed
* module/language/tree-il/compile-cps.scm (adapt-arity): Allow k to be
  $kargs for the 1-valued case.
  (convert): For single-valued continuations where the definition is
  clearly single-valued, avoid making a needless $kreceive and extra
  "rest" binding that will just be filled with () and have to be
  eliminated later.
2017-12-02 10:14:25 +01:00
Andy Wingo
67901cde76 Allow integer devirtualization to be disabled
* module/language/cps/optimize.scm (optimize-higher-order-cps)
  (cps-default-optimization-options): Add #:devirtualize-integers?.
2017-11-30 17:00:37 +01:00
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
2ab89102e7 Improve CSE complexity
* module/language/cps/cse.scm (compute-available-expressions):
  (compute-equivalent-subexpressions): Improve algorithmic complexity of
  CSE by pre-computing the labels whose reads are clobbered by a label's
  writes.
2017-11-30 12:51:45 +01:00
Andy Wingo
eb85b4190f Add compute-clobber-map to effect analysis
* module/language/cps/effects-analysis.scm (compute-clobber-map): New
  public function.
2017-11-30 12:25:43 +01:00
Andy Wingo
1575c863fe Minor CSE run-time optimization
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Minor
  optimization to reduce the size of equivalent expression keys, and to
  avoid some work if an expression has no key.
2017-11-30 10:41:45 +01:00
Andy Wingo
39520f879a Simplify live variable computation for graphs without loops
* module/language/cps/slot-allocation.scm
  (compute-reverse-control-flow-order): For graphs without back-edges,
  use a simplified computation of reverse control flow order.
2017-11-29 19:57:48 +01:00
Andy Wingo
b077e807c0 Add nullary intmap and intset folders
* module/language/cps/intmap.scm (intmap-fold, intmap-fold-right):
* module/language/cps/intset.scm (intset-fold, intset-fold-right): Add
  nullary folders.
2017-11-29 19:57:11 +01:00
Andy Wingo
16ed2aee88 Enable lsh/immediate, rsh/immediate specialization
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Fix typo in match syntax preventing us from optimizing the immediate
  variants of lsh and rsh, and typo also in specialize-unop argument
  order.
2017-11-28 22:35:27 +01:00
Andy Wingo
96d1cff802 Tighten up untag-fixnum range
* module/language/cps/types.scm (untag-fixnum): Tighten up range.
2017-11-28 22:35:27 +01:00
Andy Wingo
abd5d2e428 Fix arity of slsh/immediate inferrer
* module/language/cps/types.scm (slsh/immediate): Fix arity.
2017-11-28 22:35:27 +01:00
Andy Wingo
aeb7c18b99 Add fabricated expressions for u64-s64 conversion
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Add
  cases for u64->s64 and s64->u64.
2017-11-27 16:57:45 +01:00
Andy Wingo
bc1fdf73db Refactor aux definition fabrication in CSE pass
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
  Define a little language for creating aux definitions.
2017-11-27 16:54:11 +01:00
Andy Wingo
8d30643751 DCE of branches punches through dead terms
* module/language/cps/dce.scm (compute-live-code): DCE removes
  effect-free branches where both continuations are the same.  This
  change makes it so that we compare the next *live* continuations.
  This allows DCE to remove chains of dead branches, not just the last
  one, improving compilation e.g. of

    (unless (and (exact-integer? x) (<= 10 x 20)) (error "foo" x))

  so that the bignum trace goes away entirely.
2017-11-24 11:03:46 +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
5c9398099d Add integer devirtualization pass.
* module/language/cps/devirtualize-integers.scm: New pass.
* module/language/cps/optimize.scm:
* module/Makefile.am:
* am/bootstrap.am: Add new pass.
2017-11-24 11:03:46 +01:00
Andy Wingo
3ae2a88c15 Better unboxing for logand over s64 values
* module/language/cps/specialize-numbers.scm (specialize-operations): Do
  a better job unboxing logand if we know the result is a u64, even if
  arguments are s64.
2017-11-24 11:03:46 +01:00
Andy Wingo
695362a830 Better type folding for = on exact numbers
* module/language/cps/type-fold.scm (=): Fold to #f if values are exact
  but of different types.
  (s64-=): Add missing alias.
2017-11-24 11:03:46 +01:00
Andy Wingo
cdd51d0995 Declare bignum? as effect-free
* module/language/cps/effects-analysis.scm (bignum?): Mark as
  effect-free.
2017-11-24 11:03:46 +01:00
Andy Wingo
31691000b7 Minor refactoring to type inference on < and =
* module/language/cps/types.scm (infer-=): Factor out of
  `define-=-inferrer'.
  (define-<-inferrer): Remove unused definition.
  (=, u64-=, s64-=): Use infer-=.
2017-11-24 11:03:46 +01:00
Andy Wingo
e79de9d4b5 Fix inference of generic < on NaN values
* module/language/cps/types.scm (<): Don't infer anything if either
  number could be a flonum.
2017-11-24 11:03:44 +01:00
Andy Wingo
6f3ae92b37 Improve type and range inference on bignums
* module/language/cps/types.scm (bignum?): New predicate inferrer.
  (infer-integer-<, <, u64-<, s64-<): Factor out how integer comparisons
  are done.  Improve inference over bignums.
  (define-<-inferrer): Remove unused definition.
  (s64-=): Define inferrer; omitted before because of a typo.
  (define-binary-result!, abs): Fix up fixnum/bignum bits; before, we
  would lose some cases where fixnums could become bignums and vice
  versa.
  (define-unary-result!): Remove unused helper.
* module/language/cps/types.scm (bignum?): New folder.
2017-11-24 10:59:29 +01:00
Andy Wingo
6a11fb1532 Add &exact-number helper definition
* module/language/cps/types.scm (&exact-number): New union type.
  (rational?, exact?):
* module/language/cps/type-fold.scm (mul/immediate): Use the new
  definition.
2017-11-24 10:41:28 +01:00