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

2879 commits

Author SHA1 Message Date
Andy Wingo
a0329d0109 Root higher-order CPS term is always $kfun $cont
* module/language/cps/arities.scm:
* 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/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/tree-il/compile-cps.scm: Adapt to produce and consume
  raw $kfun $cont instances.

* .dir-locals.el: Update $letrec indentation.
2014-04-11 14:01:27 +02:00
Andy Wingo
b85f5f851f Closure conversion, reify-primitives use $kfun $cont
* module/language/cps/closure-conversion.scm: Produce a $kfun $cont.
* module/language/cps/reify-primitives.scm: Produce and consume $kfun
  $cont.
* module/language/cps/compile-bytecode.scm: Adapt.
2014-04-11 11:51:34 +02:00
Andy Wingo
6bc36ca55e Preparation for compile-bytecode to work on $kfun $conts
* module/language/cps/compile-bytecode.scm (compile-fun): Change to take
  a $kfun $cont instead of a $fun.
  (visit-funs): Change likewise, and call the proc on $kfun $cont's, not
  $fun's.
  (compile-bytecode): Adapt.

* module/language/cps/dfg.scm (analyze-reverse-control-flow): Adapt to
  expect a $kfun $cont.
2014-04-11 11:34:50 +02:00
Andy Wingo
a16af11320 compute-dfg takes a $kfun $cont, not a $fun
* module/language/cps/dfg.scm (compute-dfg): Take a $kfun $cont instead
  of a $fun.

* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm: Adapt callers.
2014-04-11 11:22:06 +02:00
Andy Wingo
d3dbf75ab3 with-fresh-name-state takes a cont, not a $fun
* module/language/cps.scm (with-fresh-name-state): Take a cont instead
  of a fun.

* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/reify-primitives.scm: Adapt.
2014-04-11 10:21:04 +02:00
Andy Wingo
686a6490f4 Function defined by make-cont-folder takes a cont, not a $fun
* module/language/cps.scm (make-cont-folder): Take a cont instead of a
  $fun.
  (with-fresh-name-state): Adapt.

* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/dfg.scm (compute-dfg):
* module/language/cps/elide-values.scm (elide-values):
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/renumber.scm (compute-new-labels-and-vars):
  (renumber): Adapt.
2014-04-11 10:12:37 +02:00
Andy Wingo
8320f50431 Rename $kentry to $kfun
* module/language/cps.scm ($kfun): Rename from $kentry.

* module/language/cps/arities.scm:
* 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/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.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/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt users.
2014-04-10 12:11:35 +02:00
Andy Wingo
24b611e81c src and meta are fields of $kentry, not $fun
* module/language/cps.scm ($kentry, $fun): Attach "src" and "meta" on
  the $kentry, not the $fun.  This prepares us for $callk to $kentry
  continuations that have no corresponding $fun.

* module/language/cps/arities.scm:
* 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/dfg.scm:
* module/language/cps/elide-values.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/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt.
2014-04-10 10:50:17 +02:00
Andy Wingo
c0c93581c4 Remove obsolete comment in compile-bytecode.scm
* module/language/cps/compile-bytecode.scm (optimize): Remove an
  obsolete comment.
2014-04-09 09:05:43 +02:00
Andy Wingo
c4a209b96f New pass to avoid free variable creation for self-recursion
* module/language/cps/self-references.scm: New pass, avoids the need for
  self-recursion to allocate free variables.

* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.
2014-04-08 21:41:42 +02:00
Andy Wingo
85270a8c89 Remove old Tree-IL CSE pass
* module/language/tree-il/cse.scm: Delete.

* module/language/tree-il/optimize.scm: Remove use of Tree-IL CSE.

* module/Makefile.am: Remove language/tree-il/cse.scm.

* module/language/cps/compile-bytecode.scm: Rename CSE keyword to
  #:cse?.
2014-04-06 11:12:29 +02:00
Andy Wingo
d03c3c7795 Flow-sensitive analysis of truth values
* module/language/cps/cse.scm (compute-truthy-expressions):
  (compute-equivalent-subexpressions, apply-cse): Arrange to infer
  truthiness of expressions, and use that information to elide redundant
  tests.
2014-04-06 10:38:48 +02:00
Andy Wingo
e84cdfb6d4 Add effects for specialized primitives
* module/language/cps/effects-analysis.scm (make-vector)
  (make-vector/immediate, vector-ref/immediate, vector-set!/immediate)
  (struct-ref/immediate, struct-set!/immediate): Add effects.
2014-04-05 21:06:35 +02:00
Andy Wingo
df1bdc1ea7 Minor cleanup/optimization in CSE
* module/language/cps/cse.scm (compute-available-expressions): Remove
  needless for-each definition.
  (compute-equivalent-subexpressions): Optimize for-each/2.
2014-04-05 14:38:37 +02:00
Andy Wingo
9e94cd9bf5 Prune bailouts after contification
* module/language/cps/compile-bytecode.scm (optimize): Prune bailouts
  after contifying, so that we return to the tail of the contified
  function.
2014-04-05 12:16:39 +02:00
Andy Wingo
3625351955 Match and srfi-9 expose their bailouts to the CSE pass
* module/ice-9/match.upstream.scm (match-next): Inline a call to
  "error", so the new CSE pass will see this case as a bailout.

* module/srfi/srfi-9.scm (throw-bad-struct): Reimplement as a syntax
  rule, so that the CSE pass sees the "throw" call.
2014-04-05 11:56:44 +02:00
Andy Wingo
4fef637362 Remove &bailout; replace uses of &unknown-effects with &all-effects
* module/language/cps/effects-analysis.scm (&bailout): Remove effect.
  (&unknown-effects): Remove.  Replace uses with &all-effects.
* module/language/cps/cse.scm:
2014-04-05 11:40:22 +02:00
Andy Wingo
9382794ab6 Remove parts of CSE that deal with bailout
* module/language/cps/cse.scm (compute-available-expressions, cse):
  (compute-idoms, compute-equivalent-subexpressions, apply-cse): Remove
  attempts to deal with bailout, as the bailout pass handles that
  already.
2014-04-05 11:40:21 +02:00
Andy Wingo
634638801c Add prune-bailouts pass
* module/language/cps/prune-bailouts.scm: New pass.
* module/language/cps/compile-bytecode.scm: Wire it up.
* module/Makefile.am: Add new file.
2014-04-05 11:40:21 +02:00
Andy Wingo
84d3ce20cd Disable Tree-IL CSE
* module/language/tree-il/optimize.scm (optimize): Disable Tree-IL CSE
  by default.
2014-04-05 11:40:21 +02:00
Andy Wingo
a79f4f67e2 Fix effects analysis for cached-module-box
* module/language/cps/effects-analysis.scm (cached-module-box): Fix
  expected arity.
2014-04-05 11:40:21 +02:00
Andy Wingo
8c6a0b7e13 More bailout preparation work
* module/language/cps/cse.scm (compute-available-expressions): Compute a
  bailout set -- or at least, set things up so that we can do so.
  (compute-idoms): Don't add predecessors that bail out.
  (apply-cse, cse, compute-equivalent-subexpressions): Thread the
  bailout set through the computations.
2014-04-04 14:29:11 +02:00
Andy Wingo
780ad383bb Prepare for CSE bailout propagation
* module/language/cps/cse.scm (compute-available-expressions): Prepare
  for being able to prune joins from bailouts.  Always loop after the
  first iteration.

* module/language/cps/effects-analysis.scm: Remove &possible-bailout.
  Rename &definite-bailout to &bailout, and rename
  &all-effects-but-bailout to &unknown-effects.
2014-04-04 14:22:51 +02:00
Andy Wingo
7a08e47967 Add common subexpression elimination pass on CPS
* module/language/cps/cse.scm: New file.
* module/language/cps/compile-bytecode.scm: Wire up CSE, on by default.
  Currently using the #:cps-cse? keyword.

* module/Makefile.am: Add new file.
2014-04-04 12:15:10 +02:00
Andy Wingo
a11778dd8e Effects analysis tweaks
* module/language/cps/effects-analysis.scm: Add &fluid-environment
  effect, a dependency of fluid-ref and fluid-set!, and an effect of
  push-fluid/pop-fluid.
  (list): Depend on &cdr.
  (resolve, cached-toplevel-box, cached-module-box): Don't depend on
  &box.
2014-04-04 12:08:52 +02:00
Andy Wingo
b764157a7b Fix verify-cps to work
* module/language/cps/verify.scm (verify-cps): Relax requirements for
  variable names to be symbols.
2014-04-04 12:07:24 +02:00
Andy Wingo
36aeda5b6a constant-needs-allocation? fix
* module/language/cps/dfg.scm (constant-needs-allocation?): Constants
  need allocation when they are used as a slot-needing operand, not when
  they are not used as an immediate operand.  Fixes the case where one
  var is used in both ways after CSE, in struct-set!/immediate.
2014-04-04 12:06:59 +02:00
Andy Wingo
f85ce39610 Remove variable-set! clause from compile-fun
* module/language/cps/compile-bytecode.scm (compile-fun): Remove
  vestigial `variable-set!' clause.
2014-04-04 12:05:18 +02:00
Andy Wingo
19ceadab51 Effects analysis: define causes-all-effects?
* module/language/cps/effects-analysis.scm (causes-all-effects?): New
  export.
2014-04-03 16:37:07 +02:00
Andy Wingo
f5fcd7f203 build-cps niceties
* module/language/cps.scm (build-cps-exp, build-cont-body): Respect
  unquote in list builders (kargs, call, callk, primcall, and values).
2014-04-03 16:36:23 +02:00
Andy Wingo
54c7882a75 Minor CSE optimization
* module/language/tree-il/cse.scm (cse): Use hashq instead of modulo to
  convert a full-width hash value to a vector index.
2014-04-03 09:40:18 +02:00
Andy Wingo
3e1b97c1b0 Add with-fresh-name-state-from-dfg
* module/language/cps/dfg.scm (with-fresh-name-state-from-dfg): New
  helper.
  ($dfg, compute-dfg): Store max-var and max-label in the dfg.

* module/language/cps.scm (with-fresh-name-state): Don't raise an error
  on recursive invocation; that was mostly useful when finding a bug.

* module/language/cps/arities.scm (fix-arities):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Use the new helper.

* .dir-locals.el: Update.
2014-04-03 09:29:05 +02:00
Andy Wingo
48e65b4468 Refactor toplevel scope name generation in compile-cps
* module/language/tree-il/compile-cps.scm (scope-counter, fresh-scope-id):
  (toplevel-box, capture-toplevel-scope, convert, cps-convert/thunk):
  Refactor to avoid abusing the var counter to generate scope
  identifiers.
2014-04-02 15:58:06 +02:00
Andy Wingo
408da79015 compute-max-label-and-var takes letrec vars into account.
* module/language/cps.scm (compute-max-label-and-var): Fix to take
  letrec vars into account.
2014-04-02 15:48:13 +02:00
Andy Wingo
ce1dbe8c1b Fix DCE for refactor-introduced borkage
* module/language/cps/dce.scm ($fun-data, compute-live-code)
  (process-eliminations): Fix clownshoes regarding fun-data field names
  and order.
2014-04-02 15:41:14 +02:00
Andy Wingo
b7dc00b1e7 Fix prune-top-level-scopes to allow collisions between var, scope, cont names
* module/language/cps/prune-top-level-scopes.scm (compute-referenced-scopes):
  Fix to not assume that scope names, continuation names, and var names
  are mutually unique.
  (prune-top-level-scopes): Better variable names.
2014-04-02 15:40:03 +02:00
Andy Wingo
2896942751 Update old-style REPL code for deprecation
* module/ice-9/scm-style-repl.scm:
* module/ice-9/save-stack.scm: As the deprecated bindings have been
  removed from the default environment, use #:export instead of
  #:replace.
2014-04-02 12:08:48 +02:00
Andy Wingo
a7324faf1b Remove CFA data type
* module/language/cps/dfg.scm: Remove CFA data type.
  (analyze-reverse-control-flow): Take min-label and label-count as
  args, and return multiple values instead of returning a CFA object.
  (compute-live-variables): Rework to accept multiple values from
  analyze-reverse-control-flow.
  ($dfa): Update comments.
2014-04-02 12:00:09 +02:00
Andy Wingo
a57f6e1e36 $dfa includes CFA fields
* module/language/cps/dfg.scm ($dfa): Include CFA min-label, k-map, and
  k-order inline.
  (dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
  (compute-live-variables): Extract fields of CFA for make-dfa.
  (print-dfa): Adapt (and fix positional record matching).
2014-04-02 11:45:26 +02:00
Andy Wingo
4ec3ded05d More CFA removals
* module/language/cps/dfg.scm (compute-reachable): Reword docstring.
  (visit-prompt-control-flow): Likewise.
  ($dominator-analysis): Change to store min-label instead of CFA.
  (compute-idoms, compute-join-edges, mark-loop-body, identify-loops):
  Take min-label and label-count, and use the DFG's preds list instead
  of requiring a fresh renumbered one.
  (analyze-dominators): Adapt to use a DFG with a label range instead of
  a CFA.
2014-04-02 11:39:36 +02:00
Andy Wingo
ae0388b698 Simplify analyze-reverse-control-flow
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Use the
  DFG's label count and min label analysis instead of rolling our own.
2014-04-02 11:04:04 +02:00
Andy Wingo
16af91e862 analyze-control-flow only used in reverse direction; make private
* module/language/cps/dfg.scm ($cfa): Use a vector to map labels to
  indices.  Don't export any CFA bindings.
  (cfa-k-idx): Adapt.
  (compute-reachable, find-prompts, compute-interval):
  (find-prompt-bodies, visit-prompt-control-flow): Take a DFG as an
  argument instead of a CFA.
  (analyze-reverse-control-flow): Refactor from analyze-control-flow, as
  it is only used in the reverse case.  Simplify accordingly, inlining
  the RPO sort.
  (compute-live-variables): Adapt to call analyze-reverse-control-flow
  instead.
2014-04-02 11:01:39 +02:00
Andy Wingo
0a44542fce Fix DFG compute-reachable bug
* module/language/cps/dfg.scm (compute-reachable): Fix embarassing bug
  where we wouldn't actually iterate to fixpoint.  I haven't seen it
  yet, but that's just luck...
2014-04-01 20:55:31 +02:00
Andy Wingo
f082c5f30a Optimize two-list srfi-1 map
* module/srfi/srfi-1.scm (map): Optimize the two-list variant.
2014-04-01 20:52:15 +02:00
Andy Wingo
545274a035 Speed up compute-label-and-var-ranges
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Duplicate
  the cont-folder cases in the global/not-global cases.  Lets the
  optimizer DTRT.
2014-04-01 18:20:02 +02:00
Andy Wingo
0912202a51 Fix compute-label-and-var-ranges for global DFG computation
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Fix to
  work with global DFGs -- it wasn't taking $letrec into account for var
  ranges.

* module/language/cps/dce.scm (compute-live-code): Use bitvectors to
  represent the live var set.
2014-04-01 18:16:00 +02:00
Andy Wingo
f9bceb770b Renumber doesn't visit unreachable continuations
* module/language/cps/renumber.scm (compute-new-labels-and-vars): Don't
  visit functions that are not reachable.
  (renumber): Reindent.
2014-04-01 17:51:26 +02:00
Andy Wingo
cc8eb19545 Renumber returns label/var counters for use in let-fresh
* module/language/cps/renumber.scm (renumber): Refactor to return the
  label and var counters as additional values.

* module/language/cps/dce.scm (eliminate-dead-code): Use the renumber
  label/var counters to initialize the fresh name state.
2014-04-01 16:47:11 +02:00
Andy Wingo
3269e1b647 Refactor DCE to not build a CFA
* module/language/cps/effects-analysis.scm (compute-effects): Change to
  analyze the effects for a subrange of a DFG's continuations.

* module/language/cps/dce.scm (compute-defs, $fun-data, compute-live-code):
  (process-eliminations, eliminate-dead-code): Renumber before
  eliminating dead code, to avoid computing a CFG and other data.
2014-04-01 16:43:55 +02:00
Andy Wingo
c79c02d694 Simplification renumbers instead of local prune-continuation pass
* module/language/cps/simplify.scm (simplify): Use renumbering instead
  of rolling our own prune-continuations pass.
2014-04-01 15:56:45 +02:00