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

4452 commits

Author SHA1 Message Date
Andy Wingo
bfe70b129c Merge until 8e2314c46d from stable-2.2 2017-11-29 21:13:40 +01:00
Andy Wingo
b6762f5f7e Merge until 83d4c4d622 from stable-2.2 2017-11-29 21:12:28 +01:00
Andy Wingo
e10999be2e Merge until 2fe9a852fb from stable-2.2 2017-11-29 21:12:01 +01:00
Andy Wingo
82b57d113c Merge until 81d2e35266 from stable-2.2 2017-11-29 21:10:25 +01:00
Andy Wingo
f85d3c0bd8 Merge until e0bcda4ad9 from stable-2.2 2017-11-29 21:04:59 +01:00
Andy Wingo
8e2314c46d 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 20:23:10 +01:00
Andy Wingo
76d4608d7a 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 20:23:10 +01:00
Andy Wingo
5f59e2812d Fix logand type inference
* module/language/cps/types.scm (logand): We were computing the wrong
  ranges when either argument was negative; a terrible bug!
  (logsub): Also fix range when A is negative and B is non-negative.
  (ulogand): Tighten up range.
2017-11-29 20:23:10 +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
7d71d9b945 Optimize check-urange in assembler.scm
* module/system/vm/assembler.scm (check-urange): Hoist exact-integer?
  check so that the side effect is entirely in this function and not in
  `logand'.  Allows devirtualize-integers to peel off a nice straight
  trace.
2017-11-24 11:03:46 +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
Andy Wingo
980de88902 Add exact-integer? as interesting Tree-IL effect-free primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*, *effect+exception-free-primitives*): Detect
  use of exact-integer?.
* module/language/tree-il/compile-cps.scm (canonicalize): Compile
  exact-integer? to a fixnum?-or-bignum? check.
2017-11-24 10:37:50 +01:00
Andy Wingo
72c3107539 Remove thunk?, integer? simple predicate inferrers
* module/language/cps/types.scm (thunk?, integer?): Remove predicates;
  they were inferring incorrectly.  I don't think they were being used
  though (these primcalls don't reach here).
2017-11-24 10:37:48 +01:00
Andy Wingo
6866cbd676 Add support for bignum? CPS primitive.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*heap-type-predicates*): Add
  support for bignum? CPS primitive.
2017-11-24 10:37:46 +01:00
Andy Wingo
bd2c690901 intmap-remove returns empty-intmap if appropriate
* module/language/cps/intmap.scm (intmap-remove): Return empty-intmap if
  the result is indeed empty.
2017-11-24 10:37:44 +01:00
Andy Wingo
a3173d1758 DCE eliminates effect-free branches to the same continuation
* module/language/cps/dce.scm (compute-live-code): Eliminate some
  branches.
2017-11-24 10:37:04 +01:00
Andy Wingo
b2dc53a3e2 Fix type check elision for branches
* module/language/cps/type-checks.scm (elide-type-checks): Fix bug where
  we were matching against a list instead of a record.  Doh!
2017-11-24 10:36:14 +01:00
Andy Wingo
700ec791e7 Minor compile-cps refactor
* module/language/tree-il/compile-cps.scm (canonicalize): Refactor to
  make with-lexicals helper available to the whole function.
2017-11-24 10:30:28 +01:00
Andy Wingo
2f2e31e73e Remove effects-analysis exports that were undefined
* module/language/cps/effects-analysis.scm (exclude-effects)
  (effect-free?, constant?): Remove undefined exports.
2017-11-24 10:28:57 +01:00
Andy Wingo
73a636e08c Specialize fixnum and s64 phis
* module/language/cps/specialize-numbers.scm
  (compute-specializable-fixnum-vars, compute-specializable-s64-vars):
* module/language/cps/specialize-numbers.scm (compute-specializable-phis):
  (apply-specialization): Re-enable specialization of fixnum phis and
  also s64 phis.
2017-11-24 10:28:27 +01:00
Andy Wingo
aa22f1f677 Fix unboxed immediate range comparison type inference
* module/language/cps/types.scm (imm-u64-<, imm-s64-<): Fix minimum
  computations.
2017-11-24 10:25:13 +01:00
Andy Wingo
908d5ea169 Fix logand type inference
* module/language/cps/types.scm (logand): We were computing the wrong
  ranges when either argument was negative; a terrible bug!
  (logsub): Also fix range when A is negative and B is non-negative.
  (ulogand): Tighten up range.
2017-11-24 10:18:49 +01:00
Matt Wette
bb5d316b16 foreign: Add 'uintptr_t' and 'intptr_t'.
* libguile/foreign.c (scm_uintptr_t, scm_intptr_t): New variables.
(scm_init_foreign): Define them.
* module/system/foreign.scm: Export 'intptr_t' and 'uintptr_t'.
* doc/ref/api-foreign.texi (Foreign Types): Document them.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:33:57 +01:00
Maxim Cournoyer
3e7c80a62f scripts: help: Fix reference to the "Using Guile Tools" node.
Fixes <https://bugs.gnu.org/28835>.

* module/scripts/help.scm (list-commands): Fix reference to the "Using
Guile Tools" node.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:21:59 +01:00
Ludovic Courtès
83d4c4d622 Honor '%fresh-auto-compile'.
Fixes <https://bugs.gnu.org/29226>.

* libguile/load.c (scm_primitive_load_path): Set 'compiled_thunk' to
SCM_BOOL_F when *scm_loc_fresh_auto_compile is true.
* module/ice-9/boot-9.scm (load-in-vicinity)[load-absolute]: Call
'pre-compiled' only when %FRESH-AUTO-COMPILE is false.
2017-11-22 16:04:24 +01:00
Andy Wingo
5c38643fc6 Revert "Slot allocation allows s64/u64 representations of same var"
This reverts commit a88614fb17.
2017-11-20 20:03:07 +01:00
Andy Wingo
c22e61a7ff Fix u64/s64 typesafety around fixnum (un)tagging
* module/language/cps/type-fold.scm (u64->scm, scm->u64): Fix
  type-safety by adding casts.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
  Simplify rsh and lsh compilation by not trying to avoid scm->u64 in
  the early stages of the compiler.
2017-11-20 20:03:07 +01:00
Andy Wingo
072188618a Separate u64 and s64 type inferrers now that ops are monomorphic
* module/language/cps/types.scm: Remove some more needless type checker
  definitions.
  (u64-imm-=, u64-imm-<, imm-u64-<): Separate from the s64 definitions.
  (s64-imm-=, s64-imm-<, imm-s64-<): New definitions.
2017-11-20 18:36:00 +01:00
Andy Wingo
a48735f56c Fix s64->scm reducer
* module/language/cps/type-fold.scm (s64->scm): Fix reducer.
2017-11-20 18:36:00 +01:00
Andy Wingo
b0081accb6 Specialize-numbers reifies instructions that type-check
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Before, this pass would reify e.g. uadd for an addition of s64 values
  if it could prove that the result would be within the s64 range.  But
  this is really confusing if later we want to do range analysis over
  the result.  Additionally it would sometimes reify diamond control
  patterns that weren't really amenable to CSE.  So instead we now reify
  instructions that can pass type checks, like "sadd" instead of
  "uadd".
2017-11-20 18:36:00 +01:00
Andy Wingo
5fbd4b8f9e Better support for unboxed signed arithmetic
* module/language/cps/primitives.scm (*macro-instruction-arities*):
  Declare new u64->s64, s64->u64, sadd, ssub, smul, sadd/immediate,
  ssub/immediate, smul/immediate, slsh, and slsh/immediate primcalls
  that don't have corresponding VM instructions.
* module/language/cps/effects-analysis.scm: The new instructions are
  effect-free.
* module/language/cps/reify-primitives.scm (wrap-unary, wrap-binary):
  (wrap-binary/exp, reify-primitives): Add horrible code that turns
  e.g. sadd into a series of s64->u64, uadd, and then u64->s64.  This
  way we keep our ability to do range inference on unboxed signed
  arithmetic, but we still bottom out to the same instructions for both
  unboxed signed and unboxed unsigned arithmetic.
* module/language/cps/types.scm: Add type inferrers for new
  instructions.  Remove type checkers for some effect-free primitives.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  pseudo-emitter for u64->s64 and s64->u64 no-ops.
2017-11-20 18:36:00 +01:00
Andy Wingo
83c04003a2 Revert specialization of fixnum phi variables
* module/language/cps/specialize-numbers.scm
  (compute-specializable-fixnum-vars, compute-specializable-phis)
  (apply-specialization): Don't specialize phis as fixnums.  Need to try
  again with some proper range analysis, as a variable defined with
  tag-fixnum can indicate either a u64 or a s64.
2017-11-20 18:35:56 +01:00
Andy Wingo
8ce6f359bb ursh, ursh/immediate, etc only residualized if count < 64
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  cases for ursh/immediate etc, as these should all be within range, by
  construction.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Only reify ursh/immediate, etc if the shift count is less than 64.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Remove specialization cases for ursh/immediate etc; this is the domain
  of specialize-numbers.
* module/language/cps/types.scm (ursh, srsh, ulsh): Limit arguments to
  be less than 63.
  (ulsh/immediate): Assume parameter is in range.
2017-11-15 19:57:36 +01:00
Andy Wingo
0951551fb4 Compiler specializes comparisons to immediate integers
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (load-const/unlikely):
* module/language/cps/types.scm (load-const/unlikely):
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
  new primcall, load-const/unlikely.
* module/language/cps/specialize-numbers.scm: Rework comparison
  specialization.  Add support for specializing comparisons against
  integer immediates.
2017-11-15 14:19:09 +01:00
Andy Wingo
294dbaad35 Add support for comparisons against integer immediates
* libguile/vm-engine.c (s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?)
  (imm-s64<?): New instructions.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add new
  X8_S12_Z12 word type used by the new S64/immediate instructions.  A
  Z12 is a 12-bit signed integer immediate.
* module/system/vm/assembler.scm: Export new instructions, and add
  X8_S12_Z12 support.  Also, add missing shufflers for X8_S12_C12.
* module/language/bytecode.scm (compute-instruction-arity):
* module/system/vm/disassembler.scm (unpack-s12, disassembler): Add
  support for X8_S12_Z12.
* module/language/cps/types.scm (define-predicate-inferrer/param): New
  helper.
  (u64-=, u64-<, s64-<): Remove type checkers; this procedure does not
  cause &type-check.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New type inferrers.
* module/language/cps/type-fold.scm (define-unary-branch-folder*): New
  helper.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New branch folders.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
  constants for new immediate branching primcalls if values out of
  range.
* module/language/cps/effects-analysis.scm: Add support for new
  primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for new primcalls and instructions.  Compile u64-imm-= to
  s64-imm=?.
2017-11-15 14:18:39 +01:00