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

1586 commits

Author SHA1 Message Date
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
Andy Wingo
7c4977e699 DFA uses DFG var numbering
* module/language/cps/dfg.scm ($dfa): Instead of a var-map table an a
  syms vector, use the DFG's var numbering.
  (dfa-var-idx, dfa-var-sym, compute-live-variables): Adapt.
2014-04-01 15:42:12 +02:00
Andy Wingo
7dbf40ea8b Allocate-slots avoids building CFA
* module/language/cps/slot-allocation.scm (allocate-slots): Rework to
  avoid computing a CFA, and just relying on the incoming term to have
  sorted labels.
2014-04-01 15:21:28 +02:00
Andy Wingo
a8430ab1d7 Compile-fun takes advantage of sorted output of "renumber", avoids CFA
* module/language/cps/dfg.scm ($dfg): Rename nvars and nlabels fields to
  var-count and label-count.  Export dfg-min-var, dfg-min-label,
  dfg-label-count, dfg-var-count.

* module/language/cps/compile-bytecode.scm (compile-fun): No need to
  build a CFA given the renumbering pass.  Adapt to treat labels as
  ordered small integer in a contiguous vector.
2014-04-01 14:51:05 +02:00
Andy Wingo
09220d215f CPS renumbering pass sorts conts in topological order
* module/language/cps/renumber.scm (sort-conts)
  (compute-new-labels-and-vars): Rework to sort the labels in
  topological order, and to prune any unreachable labels.
2014-04-01 14:51:01 +02:00
Andy Wingo
2c3c086ef3 Add visit-cont-successors helper
* module/language/cps/dfg.scm (lookup-successors, control-point?): Use
  the new helper.

* module/language/cps.scm (visit-cont-successors): New helper.
2014-04-01 11:59:03 +02:00
Andy Wingo
6e5e9ffb75 Fix analyze-control-flow to preserve order among unordered labels
* module/language/cps/dfg.scm (analyze-control-flow): Sort blocks to
  preserve order among unordered successors.
  (lookup-successors): Choose a more natural order, now that it doesn't
  matter.
2014-03-31 18:54:19 +02:00
Andy Wingo
90dce16db4 Use Tree-IL-like case-lambda clause chaining in CPS
* module/language/cps.scm ($kclause, $kentry): Instead of having an
  entry continuation contain a list of clauses, have the clauses contain
  clauses (as in Tree-IL).  In some ways it's not as convenient but it
  does reflect the continuation tree correctly.

* 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/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.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 aaaaaaall users.
2014-03-31 18:54:12 +02:00
Andy Wingo
a3a45279c0 Rewrite control-point? to avoid consing
* module/language/cps/dfg.scm (control-point?): Rewrite to avoid consing
  a successors list.
2014-03-31 18:21:04 +02:00
Andy Wingo
4bf757b810 Remove succs from DFG
* module/language/cps/dfg.scm ($dfg): Remove "succs" from DFG.  Instead
  we can compute the successors set on-demand.
  (lookup-successors): Adapt.
2014-03-31 18:21:04 +02:00
Andy Wingo
de3cbadcc0 Avoid consing in compute-label-and-var-ranges.
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Avoid
  consing.
2014-03-31 18:21:04 +02:00
Andy Wingo
5fc403911e Scope and scope-level in DFG vector
* module/language/cps/dfg.scm ($dfg): Hoist scopes and scope levels out
  of $block and into $dfg.  Adapt all callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
21d6d183a9 Predecessors and successors in DFG vectors
* module/language/cps/dfg.scm ($dfg, $block): Record predecessors and
  successors in vectors instead of in $block data structures.  Adapt
  users.
2014-03-31 18:21:04 +02:00
Andy Wingo
f49e994b52 DFG refactor
* module/language/cps/dfg.scm (lookup-cont, lookup-block):
  (lookup-def, constant-needs-allocation?): Rework these accessors to
  avoid completely destructuring the $dfg.
2014-03-31 18:21:04 +02:00
Andy Wingo
62b7180bfd Renumber functions before emitting code
* module/language/cps/compile-bytecode.scm (compile-bytecode): Renumber
  a function before going to compile it, so that the vars and labels are
  contiguous within each function.
2014-03-31 18:21:04 +02:00
Andy Wingo
f05517b24e Add renumber module
* module/language/cps/renumber.scm: New module.
* module/Makefile.am: Add to build.

fix renumber
2014-03-31 18:21:04 +02:00
Andy Wingo
98c5b69fa0 Replace use-map in DFG with separate def / use vectors
* module/language/cps/dfg.scm ($dfg, $use-map): Replace use-map vector
  with "defs" and "uses" vectors.  Adapt callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
b99553301c Remove "sym" from $use-map
* module/language/cps/dfg.scm ($use-map): Remove "sym" from use-map;
  it's redundant.  Adapt callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
cec43eb8f6 $use-map no longer has name member
* module/language/cps/dfg.scm ($use-map): Remove name member.  Adapt
  users.
2014-03-31 18:21:04 +02:00
Andy Wingo
29619661e4 $dfa no longer includes name vector (can get that from dfg)
* module/language/cps/dfg.scm ($dfa, dfa-var-name):
  (compute-live-variables, print-dfa): Remove "names" from DFAs.
2014-03-31 18:21:04 +02:00
Andy Wingo
5e89790896 DFG stores conts, blocks, and use-maps in vectors
* module/language/cps/dfg.scm ($dfg): Change to store conts, blocks, and
  use-maps as vectors.  A DFG also records the minimum label, minimum
  variable, and the number of labels and variables.  The first entry in
  one of these vectors corresponds to the minimum.  This can be
  optimum in the local case if the conts and variables have been renamed
  appropriately.

  Adapt callers.

  (compute-live-variables): Adapt.  This is currently suboptimal but it
  works, so it's a useful base for optimization.
2014-03-31 18:21:04 +02:00
Andy Wingo
fbdb69b21c lookup-cont takes a DFG as its argument
* module/language/cps/dfg.scm (lookup-cont): Change to take a DFG
  instead of a cont table.
  (build-cont-table): Change to return a vector.

* module/language/cps/arities.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm: Adapt to lookup-cont and
  build-cont-table changes.
2014-03-31 18:21:04 +02:00
Andy Wingo
a6f823bd02 Public make-cont-folder
* module/language/cps.scm (make-cont-folder): Add global? parameter, and
  make public.
  (fold-conts): Adapt.
  (fold-local-conts): Use make-cont-folder, and take a function instead
  of a continuation.

* module/language/cps/arities.scm (fix-clause-arities, fix-arities*):
* module/language/cps/compile-bytecode.scm (collect-conts):
* module/language/cps/elide-values.scm (elide-values*): Adapt to
  fold-local-conts change.
2014-03-31 18:21:04 +02:00
Andy Wingo
1eda52c8ad Vars and labels are separate namespaces
* module/language/cps.scm (fresh-var, with-fresh-name-state): Vars have
  their own namespace.
2014-03-31 18:21:04 +02:00
Andy Wingo
b9e601d20d Prepare for decoupling of var/label name uniqueness
* module/language/cps/simplify.scm (compute-beta-reductions):
  (beta-reduce): Separate state into two tables, so we can relax current
  guarantee that vars and labels are mutually unique.
2014-03-31 18:21:04 +02:00
Andy Wingo
eb60b4136b Update verify-cps
* module/language/cps/verify.scm (verify-cps): Vars should only be exact
  integers now.
2014-03-31 18:21:04 +02:00
Andy Wingo
e6cf744ab4 CPS conversion renames incoming gensyms to small integers
* module/language/tree-il/compile-cps.scm (fold-formals)
  (unbound?, init-default-value, convert): Arrange to rename incoming
  gensyms as small integers.
  (canonicalize): Convert vector and abort here too.
2014-03-31 18:20:55 +02:00
Andy Wingo
699ed8ce29 Less copying in tree-il pre-order / post-order.
* module/language/tree-il.scm (pre-post-order): If the pre handler
  doesn't modify the components of a tree-il expression, avoid copying a
  new one.
2014-03-31 18:20:55 +02:00
Andy Wingo
ef58442a05 Prompt-related refactor in compile-cps
* module/language/tree-il/compile-cps.scm (fix-prompts): New procedure.
  Eta-expand prompts before compiling to ensure that they have inline
  handlers.
2014-03-31 18:20:55 +02:00
Andy Wingo
cd72929e71 DCE uses fresh-var instead of gensym
* module/language/cps/dce.scm (eliminate-dead-code): Use fresh-var
  instead of gensym.
2014-03-31 18:20:55 +02:00
Andy Wingo
39056a81fc Adapt verify-cps to CPS changes
* module/language/cps/verify.scm (verify-cps): Update to expect integer
  labels, and to allow integer variables.
2014-03-31 18:20:55 +02:00
Andy Wingo
828ed94469 Replace all let-gensyms uses with let-fresh
* .dir-locals.el: Add with-fresh-name-state.
* module/language/cps.scm (fresh-label, fresh-var): Signal an error if
  the counters are not initialized.
  (with-fresh-name-state): New macro.
  (make-cont-folder): New macro, generates an n-ary folder.
  (compute-max-label-and-var): New function, uses make-cont-folder.
  (fold-conts): Use make-cont-folder.
  (let-gensyms): Remove.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/dce.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/specialize-primcalls.scm: Use let-fresh instead of
  let-gensyms, and wrap in a with-fresh-name-state as needed.

* module/language/tree-il/compile-cps.scm: Remove hack to avoid
  importing let-gensyms from (language tree-il).
2014-03-31 18:20:55 +02:00
Andy Wingo
9a1dfb7d2e Continuation labels and variable identifiers may be integers
* module/language/cps.scm (label-counter, var-counter): New parameters,
  for producing fresh label and var names.
  (fresh-label, fresh-var): New procedures.
  (let-fresh): New macro, will replace let-gensyms.
  (build-cps-term): Use let-fresh.

* module/language/tree-il/compile-cps.scm: Use let-fresh to generate
  fresh names.

* module/system/vm/assembler.scm (make-meta, begin-kw-arity): Allow
  exact integers as labels.
  (link-debug): Explicitly mark low-pc as being an "addr" value.
2014-03-31 18:20:55 +02:00
Andy Wingo
48c2a5395a DFG inlines uses of for-each
* module/language/cps/dfg.scm (for-each, for-each/2): Define inline
  versions of these.  Adapt callers.
2014-03-17 10:10:36 +01:00
Andy Wingo
4b3d7a2b7c Simplification pass prunes all unreachable continuations
* module/language/cps/simplify.scm (prune-continuations): Prune
  continuations as a post-pass with a fresh DFG.  Using a
  pre-eta-conversion DFG as we were doing before missed some cases.
2014-02-25 21:32:36 +01:00
Andy Wingo
90c8094aec Avoid attempting to eta-reduce self-loops.
* module/language/cps/simplify.scm (compute-eta-reductions): Avoid
  trying to eta-reduce a jump-to-self, as in (let lp () (lp)).  This
  caused the compiler to hang.
2014-02-22 15:34:46 +01:00
Andy Wingo
82490a665c Don't peval-penalize let-bound lambdas only referenced once
* module/language/tree-il/peval.scm (peval): When going to peval a call
  whose operator isn't just a lambda but is a let-bound lambda, as one
  bound via define-inlinable, don't create a new counter if the lambda
  is only referenced once in the source.  Avoids needless failure to
  inline once-referenced procedures.

* test-suite/tests/peval.test ("partial evaluation"): Wheeeee
2014-02-17 22:23:40 +01:00
Andy Wingo
a104380d53 bytevector-length reifies to correct module
* module/language/cps/reify-primitives.scm (primitive-module): Whoops,
  bytevector-length is needs to map to the (rnrs bytevectors) module.
2014-02-14 10:49:45 +01:00
Andy Wingo
a694809e3a bytevector-length is an interesting primitive.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*):
* module/language/cps/effects-analysis.scm: bytevector-length is an
  interesting primitive.
2014-02-13 17:51:20 +01:00
Andy Wingo
9b3c4cedd4 sqrt and abs are interesting primitives
* module/language/cps/effects-analysis.scm:
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*): Add sqrt and abs.
2014-02-13 11:04:55 +01:00
Andy Wingo
dd692618b8 Add prune-top-level-scopes pass
* module/language/cps/prune-top-level-scopes.scm: New pass, to prune
  unneeded "cache-current-module!" forms.

* module/language/cps/compile-bytecode.scm:
* module/Makefile.am: Add the new pass to the build and enable by
  default.
2014-02-13 09:30:39 +01:00
Andy Wingo
9253198baf Bytevector f32 an f64 ops actually map to VM primitives
* module/language/cps/primitives.scm (*instruction-aliases*): Whoops!
  Fix mapping of f32 and f64 instructions to VM primitives.
2014-02-11 21:54:05 +01:00
Andy Wingo
04f59ec2e7 Merge commit '58147d6780' 2014-02-07 15:12:35 +01:00
Andy Wingo
ae7f13be4b Merge commit 'ca5e0414e9'
Conflicts:
	module/language/tree-il/primitives.scm
2014-02-07 15:05:55 +01:00
Andy Wingo
b3ae2b5068 Add VM and compiler support for calls to known procedures
* module/language/cps.scm ($callk): New expression type, for calls to
  known labels.  Part of "low CPS".
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm: Adapt call sites.

* libguile/vm-engine.c (call-label, tail-call-label): New instructions.
  Renumber the rest; this is an ABI change.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.

* doc/ref/compiler.texi (CPS in Guile): Document $callk.
2014-02-02 23:19:22 +01:00
Mark H Weaver
58147d6780 Compile numerical comparisons with more than 2 arguments to VM code.
* module/language/tree-il/primitives.scm (chained-comparison-expander):
  New procedure.
  (*primitive-expand-table*): Add primitive expanders for '<', '>',
  '<=', '>=', and '='.
2014-02-01 01:19:16 -05:00
Mark H Weaver
e6c1c5f6cb Revert "Primitive expand numerical comparisons with more than 2 arguments."
This reverts commit 4dc4b86e85.
2014-01-31 04:01:12 -05:00
Mark H Weaver
4dc4b86e85 Primitive expand numerical comparisons with more than 2 arguments.
* module/language/tree-il/primitives.scm (chained-comparison-expander):
  New procedure.
  (*primitive-expand-table*): Add primitive expanders for '<', '>',
  '<=', '>=', and '='.
2014-01-28 17:44:22 -05:00