* module/language/cps/compile-bytecode.scm (compile-function)
(emit-bytecode):
* module/language/cps/slot-allocation.scm (allocate-slots):
* module/language/cps/optimize.scm (cps-default-optimization-options):
Allow the "lazy vars" optimization, a form of slot precoloring, to be
disabled. It will be disabled at -O0 or -O1, to speed compilation
times.
* module/language/cps/cse.scm (compute-available-expressions):
(compute-equivalent-subexpressions): Improve algorithmic complexity of
CSE by pre-computing the labels whose reads are clobbered by a label's
writes.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Minor
optimization to reduce the size of equivalent expression keys, and to
avoid some work if an expression has no key.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* module/language/cps/types.scm (&exact-number): New union type.
(rational?, exact?):
* module/language/cps/type-fold.scm (mul/immediate): Use the new
definition.
* 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.
* 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).
* 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.
* 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.
* 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.
* 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".
* 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.
* 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.
* 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.
* 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=?.
* module/language/cps/type-fold.scm (compare-integer-ranges): Rename
from compare-ranges, as we can't compare ranges that might include a
NaN.
(<, =): Update uses.
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for tag-fixnum/unlikely.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Add
equivalent subexpressions for tag-fixnum.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
tag-fixnum/unlikely.
* module/language/cps/specialize-numbers.scm (specialize-u64-unop)
(specialize-u64-binop, specialize-u64-shift)
(specialize-u64-comparison): Make the arg unboxers and result boxers
into keyword arguments.
(specialize-s64-unop): New helper.
(specialize-fixnum-comparison, specialize-fixnum-scm-comparison)
(specialize-scm-fixnum-comparison): Rename from
specialize-s64-comparison et al. Perhaps this should be expanded
again to include the whole s64 range, once we start to expand scm->s64
et al.
(specialize-operations): Specialize arithmetic, etc on signed
operands and results. Use less powerful unboxing/boxing ops if
possible -- e.g. tag-fixnum instead of u64->scm. Prefer fixnum
comparisons over u64 comparisons.
(compute-specializable-fixnum-vars): New helper.
(compute-specializable-phis): Specialize fixnum phis as well.
(specialize-primcalls): Specialize untag-fixnum of a constant to
load-s64.
* module/language/cps/type-fold.scm (u64->scm, s64->scm):
(scm->s64, scm->u64): Reduce to fixnum ops where possible.
* module/language/cps/types.scm: Remove type checkers for ops that don't
throw type errors. Alias tag-fixnum/unlikely to tag-fixnum.
* module/language/cps/types.scm (&fx32-min, &fx32-max, &fx64-min)
(&fx64-max): New internal definitions.
* module/language/cps/types.scm (type-entry-saturating-union): Add more
stops as we saturate ranges towards infinity.
* module/language/cps/slot-allocation.scm (compute-var-representations):
If an optimization pass decided to e.g. use untag-fixnum for one
definition of a variable and e.g. vector-length for the other, assume
that their values are compatible. We don't know at this point whether
the values are meant to be s64 (e.g. because vector-length is a subset
of the s64 range) or u64 (e.g. because although we're calling
untag-fixnum on the value, actually we now that the value is
non-negative, or actually we just want the unsigned bits). Anyway we
default to u64. In the future we can perhasps be more precise.
* libguile/vm-engine.c (srsh, srsh/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (srsh, srsh/immediate):
* module/system/vm/assembler.scm: Add support for new instructions.
* module/language/cps/types.scm (ulsh, ursh): Remove type checkers, as
these are effect-free. Limit range of ursh count.
* module/language/cps/type-fold.scm (*primcall-macro-reducers*):
(define-primcall-macro-reducer, define-unary-primcall-macro-reducer):
(define-binary-primcall-macro-reducer): New facility, for reductions
on which reductions should run. Define macro reducers for mul, lsh,
and rsh. Move mul reducer to be a mul/immediate reducer.
(logbit?): Use target fixnum range.
(local-type-fold): Adapt to call macro reducers first.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
mul/immediate back to mul.