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

3117 commits

Author SHA1 Message Date
Andy Wingo
4cbe4d72aa Fix rtl tests
* module/system/vm/assembler.scm (write-arities): Add a diagnostic.

* test-suite/tests/rtl.test: Fix tests to emit "definition"
  instructions.
2014-04-15 22:00:30 +02:00
Andy Wingo
c271065e54 Fix frame-call-representation for primitive applications
* module/system/vm/frame.scm (frame-call-representation): Fix to work
  for primitives.

* test-suite/tests/eval.test ("stacks"): Update expected result for
  substring.
2014-04-15 21:47:46 +02:00
Andy Wingo
67ddb7e264 Assembler residualizes local variable definition locations
* module/system/vm/assembler.scm (write-arities): Serialize definition
  locations after names.
  (definition): Store definition as a byte offset.
2014-04-15 20:25:16 +02:00
Andy Wingo
1a82c2012b Bump minor objcode version for recent changes
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2014-04-15 20:20:01 +02:00
Andy Wingo
c3651bd55b Write all local variable names into the arities section
* module/system/vm/assembler.scm (put-uleb128, put-sleb128)
  (port-position): Lift out these helpers.
  (arity-header-len, write-arities, link-arities): Add "nlocals" to the
  arity headers.  Write names of all locals into the arities section,
  not just the arguments.  Write them as uleb128's instead of uint32's,
  to save space.

* module/system/vm/debug.scm (arity-header-len, arity-nlocals*)
  (arity-nlocals, arity-locals, arity-arguments-alist): Adapt to new
  encoding for arities.
2014-04-15 18:24:25 +02:00
Andy Wingo
cade4c8fe1 Tweak arities debugging representation
* module/system/vm/assembler.scm (meta-arities-size, write-arity-links):
* module/system/vm/debug.scm (arity-keyword-args)
  (arity-arguments-alist): Rewrite to put they keyword literals link
  first.  Unfortunately requires a recompile :/
2014-04-15 15:27:19 +02:00
Andy Wingo
78351d1065 Beginnings of local variable information
* module/system/vm/assembler.scm (<arity>, begin-kw-arity, end-arity):
  (definition): Add definition macro-instruction.  Arrange to record
  variable definitions.

* module/language/cps/compile-bytecode.scm (compile-fun): Emit
  definition macro-instructions as appropriate.
2014-04-15 14:14:15 +02:00
Andy Wingo
863034a8ac Remove needless label remapping in slot-allocation
* module/language/cps/slot-allocation.scm (dead-after-def?):
  (dead-after-use?, allocate-slots): Remove some needless remapping
  between label indexes in the CFA, the DFA, and their names.
2014-04-15 12:25:26 +02:00
Andy Wingo
21a528fd82 DFA datums don't rename their labels
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Don't
  compute and return an order vector; it's not needed.
  ($dfa): Remove label renaming.  We can just rename labels before
  returning the DFA.
  (dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
  (compute-live-variables): Adapt, and rename labels before returning.
2014-04-15 12:16:41 +02:00
Andy Wingo
bec786c1fe Better backtraces for optimized closures
* module/system/vm/debug.scm (arity-keyword-args, find-program-arity):
  New exports.

* module/system/vm/frame.scm (frame-call-representation): Prefer to use
  the frame IP to get the procedure.
2014-04-15 11:18:50 +02:00
Andy Wingo
da169db26a statprof avoids mucking with VM trace levels when not counting calls
* module/statprof.scm (statprof-start, statprof-stop): Don't futz the vm
  trace level when we aren't counting calls.  With this change, statprof
  now imposes no overhead on the measured program.
2014-04-14 17:06:05 +02:00
Andy Wingo
a234ab929c Better state handling in statprof
* module/statprof.scm (statprof-fold-call-data)
  (statprof-proc-call-data): Add optional state arg.
  (gcprof): Add optional port arg, and pass state arg explicitly.
  (statprof-display-anomalies, statprof-display)
  (statprof-call-data->stats): Pass state explicitly.
2014-04-14 16:54:51 +02:00
Andy Wingo
2ad91e6b34 Optimize make-global-cont-folder
* module/language/cps.scm (make-global-cont-folder): Inline the
  fold-values, as peval doesn't do so.  Allows closure conversion to
  avoid any closure creation.
2014-04-14 13:53:35 +02:00
Andy Wingo
560bfa9241 Improve disassembly for optimized closures
* module/system/vm/disassembler.scm (code-annotation): Add call-label
  and tail-call-label cases.
  (disassemble-addr): With call-label we can see sets of mutually
  recursive functions, so keep a global "visited?" set.
2014-04-13 14:40:22 +02:00
Andy Wingo
c4aa51bae8 Remove debugging code in closure-conversion
* module/language/cps/closure-conversion.scm (prune-free-vars): Remove
  pk.
2014-04-13 14:26:03 +02:00
Andy Wingo
d0d8a552b4 Eval has no more free variables
* module/ice-9/eval.scm (primitive-eval): Expand out the call to
  make-general-closure, so that make-general-closure becomes
  well-known.  Now eval has no more free variables!
2014-04-13 14:22:22 +02:00
Andy Wingo
fcb31f2953 Closure conversion eliminates self-references introduced by fixpoint
* module/language/cps/closure-conversion.scm (analyze-closures): Build a
  bound-vars set as well, to resolve introduced self-references.
  (prune-free-vars, convert-one): Arrange to eliminate self-references.
2014-04-13 14:21:25 +02:00
Andy Wingo
2920554a1e Refactor to closure-conversion
* module/language/cps/closure-conversion.scm (convert-one): Refactor to
  pull in helpers locally, as they will need more state.
2014-04-13 13:54:17 +02:00
Andy Wingo
1487367e21 Avoid consing an unbound-arg marker in the evaluator
* module/ice-9/eval.scm (primitive-eval): Turns out we don't need to
  cons to make the unbound-arg marker.
2014-04-13 12:21:36 +02:00
Andy Wingo
32e62c2dae Optimize closures with one free variable
* module/language/cps/closure-conversion.scm (convert-free-var)
  (allocate-closure, init-closure, prune-free-vars, convert-one)
  (convert-closures): Optimize closures with one free variable.
2014-04-13 11:47:17 +02:00
Andy Wingo
cd130361b8 Well-known closures represented using pairs or vectors
* module/language/cps/closure-conversion.scm (convert-free-var):
  (convert-free-vars): Take self-known? param, to do the right thing for
  well-known closures.
  (allocate-closure): New helper.  Well-known closures are represented
  using pairs or vectors.
  (init-closure): Adapt tpo DTRT for well-known closures.
  (prune-free-vars): Move up.
  (convert-one): Adapt to new well-known closure representation.
2014-04-12 23:31:08 +02:00
Andy Wingo
a2acec7c7f Update verify-cps
* module/language/cps/verify.scm (verify-cps): Update for recent CPS
  changes.
2014-04-12 22:42:23 +02:00
Andy Wingo
6dc886faf1 Avoid creating closures with no free variables
* module/language/cps/closure-conversion.scm (init-closure): Return just
  one value.
  (analyze-closures): Rewrite the well-known set to key off the label
  instead of the closure identifiers before returning.
  (convert-one): Avoid creating closure objects at runtime or load-time
  when "instantiating" or calling well-known closures with no free
  variables.
  (prune-free-vars): New pass.
  (convert-closures): Adapt.
2014-04-12 19:46:23 +02:00
Andy Wingo
983413a1d9 Hard-wire calls to known procedures
* module/language/cps/closure-conversion.scm (analyze-closures):
  (convert-one, convert-closures): Hard-wire calls to known procedures
  by transforming $call to $callk.
2014-04-12 16:12:33 +02:00
Andy Wingo
8b1a4b23fd closure conversion computes well-known functions
* module/language/cps/closure-conversion.scm (analyze-closures)
  (convert-closures, convert-one): Adapt to compute well-known
  functions.  We don't yet produce $callk though.
2014-04-12 15:53:58 +02:00
Andy Wingo
cf8bb03772 First-order CPS has $program and $closure forms
* module/language/cps.scm ($closure, $program): New CPS types, part of
  low-level (first-order) CPS.
  (build-cps-exp, build-cps-term, parse-cps, unparse-cps)
  (compute-max-label-and-var): Update for new CPS types.

* module/language/cps/closure-conversion.scm: Rewrite to produce a
  $program with $closures, and no $funs.

* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm (compile-fun):
  (compile-bytecode): Adapt to new first-order format.

* module/language/cps/dfg.scm (compute-dfg): Add $closure case.

* module/language/cps/renumber.scm (renumber): Allow this pass to work
  on either format.

* module/language/cps/slot-allocation.scm (allocate-slots): Add $closure
  case.
2014-04-12 14:59:31 +02:00
Andy Wingo
405805fbc3 Separate make-cont-folder into global and local variants
* module/language/cps.scm (make-global-cont-folder)
  (make-local-cont-folder): Separate this macro in two.  It's hot and
  the difference can be important for perf.

* module/language/cps/dfg.scm (compute-label-and-var-ranges):
* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code): Adapt.
2014-04-11 18:32:54 +02:00
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