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

1586 commits

Author SHA1 Message Date
Andy Wingo
f488bc53e7 Instruction explosion for /immediate variants of vector prims
* module/language/tree-il/compile-cps.scm
  (prepare-vector-access/immediate): New helper.
* module/language/tree-il/compile-cps.scm (vector-ref/immediate):
  (vector-set!/immediate, make-vector/immediate): New expanders.
2018-01-07 15:42:39 +01:00
Andy Wingo
c766a883d3 Instruction explosion for make-vector
* module/language/tree-il/compile-cps.scm (untag-fixnum-in-imm-range):
  New helper.
  (make-vector): New custom expander.  Gnarly; to refactor.
2018-01-07 15:42:39 +01:00
Andy Wingo
7ef48c4069 Fix primitive reification for scm-set! / word-set!.
* module/language/cps/reify-primitives.scm (reify-primitives): Fix for
  scm-set! and word-set!.
2018-01-07 15:42:39 +01:00
Andy Wingo
1bb44a1ad6 Minor optimization in loop peeling
* module/language/cps/peel-loops.scm (compute-out-vars): Fold over the
  body of the loop, not the body of the function.  A small
  optimization.
2018-01-07 13:04:20 +01:00
Andy Wingo
ef23e512b5 Make integer devirtualization less eager
* module/language/cps/devirtualize-integers.scm (bailout?): Factor out.
  (peel-trace): Adapt to call external bailout? predicate.
  (peel-traces-in-function): Don't peel traces whose alternate is a
  bailout.
2018-01-07 13:04:20 +01:00
Andy Wingo
d4addf3792 Bug-fix to devirtualize-integers pass
* module/language/cps/devirtualize-integers.scm (peel-trace): Only
  terminate a trace at a branch if the set of live vars is empty.
2018-01-07 13:04:20 +01:00
Andy Wingo
7162c758b3 Fix specialization of the allocate-words family of instructions
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Fix specialization of allocate-words and friends.
2018-01-05 19:51:17 +01:00
Andy Wingo
d4502dba07 Fix verify.scm for call-thunk/no-inline
* module/language/cps/verify.scm (check-arities): Allow
  call-thunk/no-inline to continue to $kreceive.
2018-01-05 19:50:12 +01:00
Andy Wingo
7486806ba3 Improve compilation of make-vector without init
* module/language/tree-il/primitives.scm (*primitive-expand-table*): Add
  expansion for one-argument make-vector.
2018-01-05 15:18:16 +01:00
Andy Wingo
a821042480 Allow peval to gnaw on string->symbol, symbol->string
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*): Add string->symbol and symbol->string.
2018-01-05 15:17:46 +01:00
Andy Wingo
6fdbd3b17b Instruction explosion for vector-{length,ref,set!}
* module/language/tree-il/compile-cps.scm (ensure-vector)
  (untag-fixnum-index-in-range, compute-vector-access-pos)
  (prepare-vector-access): New helpers.
  (vector-length, vector-ref, vector-set!): New expanders.
2018-01-05 14:42:40 +01:00
Andy Wingo
3e271f1922 Allow peeling loops with bailouts
* module/language/cps/peel-loops.scm (compute-bailouts)
  (add-renamed-bailout, peel-loop, peel-loops-in-function): Allow
  peeling of loops with bailouts.
2018-01-05 14:23:29 +01:00
Andy Wingo
e4e02d8489 Prevent LICM of memory accesses guarded by effect-free predicates
* module/language/cps/licm.scm (loop-invariant?): Read or write effects
  can be guarded by effect-free branches; prevent hoisting of these
  expressions if the term isn't always reachable.
2018-01-05 11:48:06 +01:00
Andy Wingo
51fd5952cb Disable resolve-primitives pass below -O2
* module/language/tree-il/optimize.scm (optimize): Disable
  resolve-primitives below -O2.  This is because compile-cps is going to
  start expanding all primcalls it sees.
2018-01-05 10:40:03 +01:00
Andy Wingo
16db934bbc Add (system base optimize) module
* module/system/base/optimize.scm: New module.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new module.
* module/language/tree-il/optimize.scm (tree-il-optimizations): Rename
  from tree-il-default-optimization-options.  Directly specify the
  optimization level at which a pass should be enabled.
* module/language/cps/optimize.scm (cps-optimizations): Likewise, rename
  from cps-default-optimization-options.
* module/scripts/compile.scm (%options, show-optimization-help): Adapt
  to use new module.
2018-01-05 10:19:54 +01:00
Andy Wingo
118f516a8b $primcall always continues to $kargs
* module/language/cps/devirtualize-integers.scm (peel-trace): Update
  comment.
* module/language/cps/contification.scm (apply-contification): Update to
  never contify a return of $primcall to $kreceive.
* module/language/cps/verify.scm (check-arities): Require that primcalls
  continue to $kargs.
2018-01-03 21:26:00 +01:00
Andy Wingo
8248649966 Simplify prompt slot allocation now that bailouts can't continue
* module/language/cps/slot-allocation.scm (add-prompt-control-flow-edges):
  Simplify now that bailouts don't continue.
2018-01-03 21:26:00 +01:00
Andy Wingo
ad55ee83c3 $throw is a new kind of CPS term
* module/language/cps.scm ($throw): New term type that doesn't have a
  continuation.  Adapt all callers.  Remove now-unneeded
  "prune-bailouts" pass.
2018-01-03 21:25:55 +01:00
Andy Wingo
de5c81b1d1 Fix add-prompt-control-flow-edges for terms with no continuation
* module/language/cps/slot-allocation.scm (add-prompt-control-flow-edges):
  Allow for terms that don't continue, and add them to the minimal
  prompt control flow edges set.
2018-01-03 18:55:59 +01:00
Andy Wingo
ee15ca1455 $prompt is now its own kind of CPS term.
* module/language/cps.scm ($prompt): Rework to be its own term kind.
  Now $continue always continues to a single continuation.  Adapt
  callers.
2018-01-03 17:32:43 +01:00
Andy Wingo
29fee39c2a Variable renaming in type-fold.scm
* module/language/cps/type-fold.scm: Rename "name" variables that
  indicate primcalls to "op".
2018-01-03 16:32:33 +01:00
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