* module/language/cps/effects-analysis.scm: Remove case for "ash".
* module/language/cps/types.scm (ash): Remove.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
Convert "ash" to "lsh"/"rsh" early on.
* module/system/base/target.scm (target-fixnum?): New procedure.
* module/system/base/target.scm (target-most-negative-fixnum):
(target-most-positive-fixnum): New definitions.
* module/language/cps/types.scm (constant-type, define-exact-integer!)
(&min/fixnum, &max/fixnum): Use new definitions.
(&max/vector): Use target-max-vector-length.
* module/language/cps/specialize-numbers.scm (specialize-s64-comparison)
(specialize-s64-scm-comparison, specialize-scm-s64-comparison): New
helpers.
(specialize-scm-u64-comparison, specialize-u64-scm-comparison):
Remove. Comparing SCM as s64 is better as fixnums are a subset of
s64, not u64.
(specialize-operations): Prefer s64 comparisons when we can't
specialize both arguments; this at least inlines the fixnum case.
* module/language/tree-il/compile-cps.scm (canonicalize): Convert <=,
>=, and > primcalls to <.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/effects-analysis.scm: Remove superfluous
primcalls.
* module/language/cps/specialize-numbers.scm
(specialize-u64-scm-comparison): Only emit < primcalls for ordered
comparisons.
(specialize-scm-u64-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Remove support for >=, <=, and the like.
* module/language/cps/type-fold.scm: Remove folders for <= and so on.
* module/language/cps/types.scm (define-=-inferrer, define-<-inferrer):
New helpers; use them for all = and < variants. Remove checkers and
inferrers for <= and the like.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
unnecessary cases.
* libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN.
* libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): New
instructions.
* libguile/vm.c (vm_throw, vm_throw_with_value)
(vm_throw_with_value_and_data): New helpers.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
for new instructions.
* module/language/cps/prune-bailouts.scm (prune-bailouts): More simple,
now that there are no $kreceives in play.
* module/language/cps/reify-primitives.scm (reify-clause): Update
reification of no-clause functions to use new throw op.
* module/language/tree-il/compile-cps.scm (convert): Convert invocations
of the variable-arity 'throw primitive from Tree-IL to the new
fixed-arity CPS instructions.
* module/system/vm/assembler.scm (emit-throw/value*)
(emit-throw/value+data*, emit-throw): Export new instructions.
* module/system/vm/disassembler.scm (code-annotation): Add annotation.
* libguile/vm-engine.c (lsh, rsh, lsh/immediate, rsh/immediate): New
instructions taking unboxed bit counts.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/specialize-numbers.scm (specialize-f64-unop):
(specialize-u64-unop): Add ability to specialize add/immediate, etc,
and add lsh/immediate as well.
(specialize-u64-binop, specialize-u64-shift): Move rsh/lsh
specialization to its own procedure, given that the bit count is
already unboxed.
(specialize-operations): Adapt to support more /immediate
instructions.
* module/language/cps/type-fold.scm (mul): Reify an lsh/immediate
instead of an ash.
* module/language/cps/types.scm (compute-ash-range): Add type inferrers
for lsh, rsh, and their immediate variants.
* module/system/vm/assembler.scm: Export emit-lsh and so on.
* module/language/tree-il/compile-cps.scm (convert): Convert "ash" on
immediates to rsh/immediate or lsh/immediate.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Don't restrict /imm params to encodeable immediates; specialize any
imm. Rely on reify-primitives to undo the transformation if needed.
* module/system/base/target.scm (target-max-size-t):
(target-max-size-t/scm, target-max-vector-length): New public
functions.
* module/language/cps/types.scm (type-entry-saturating-union): Remove
restriction of polymorphic types to be within max-size-t; this could
incorrectly apply constraints on numeric values.
(&max/size, &max/scm-size): Use target-max-size-t.
(*max-size-t*): Remove; replace uses with (target-max-size-t).
* module/language/cps/optimize.scm (optimize-first-order-cps): Move up
the simplify-primcalls pass, to allow DCE to take away unneeded
constants. An incremental step
* module/language/cps/reify-primitives.scm (reify-primitives): Add pass
to re-reify constant arguments for primcalls with immediate parameters
that can't be encoded as bytecode.
* module/language/cps/compile-bytecode.scm (compile-function): Update
add/immediate, etc.
* module/language/cps/slot-allocation.scm (compute-needs-slot):
Simplify.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Rework for add/immediate, etc.
* module/language/cps/types.scm (define-unary-result!)
(define-binary-result!): Take types as params instead of variables, so
we can share this code with /imm variants.
(add/immediate, sub/immediate, uadd/immediate, usub/immediate)
(umul/immediate, ulsh/immediate, ursh/immediate): Update type
inferrers.
* module/language/cps/closure-conversion.scm (convert-one):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (define-primitive-effects*)
(expression-effects, primitive-effects): Only fall back to passing
constant table if the immediate parameter is false. Adapt closure
effects analysis.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
special cases for free-ref/free-set!.
* module/language/cps/compile-bytecode.scm (compile-function): Make
load-f64, load-s64, and load-u64 take an immediate parameter instead
of a CPS value.
* module/language/cps/effects-analysis.scm: Remove CPS argument from
immediate load instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
special case for load-64 etc.
* module/language/cps/specialize-numbers.scm
(specialize-u64-scm-comparison): Adapt.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Adapt.
* module/language/cps/types.scm (define-type-inferrer*): Also take param
argument.
(define-type-inferrer, define-predicate-inferrer): Adapt.
(define-type-inferrer/param): New helper.
(load-f64, load-s64, load-u64): Adapt inferrers to pass on value from
param.
* module/language/cps/utils.scm (compute-constant-values): Adapt.
* module/language/cps.scm ($primcall): Add "param" member, which will be
a constant parameter to the primcall. The idea is that constants used
by primcalls as immediates don't need to participate in optimizations
in any way -- they should not participate in CSE, have the same
lifetime as the primcall so not part of DCE either, and don't need
slot allocation. Indirecting them through a named $const binding is
complication for no benefit. This change should eventually improve
compilation time and memory usage, once we fully take advantage of it,
as the number of labels and variables will go down.
* 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/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/handle-interrupts.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.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/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-checks.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
* module/language/cps/compile-bytecode.scm (compile-function): Rename
the binary* helper back to binary, update uses, and remove logtest
branch as we no longer put logtest in test context.
* module/language/cps/primitives.scm (*comparisons*): Remove logtest.
* module/language/cps/type-fold.scm: Remove logtest folder.
(logbit?): Fold to logand.
* module/language/cps/types.scm (logtest): Update to be a type inferrer
and not a predicate inferrer.
* module/language/tree-il/peval.scm (peval): Transform logtest and
logbit? to (zero? (logand _ _)).
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm: Remove compiler support for u64-scm
comparisons, as this is now inlined.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*):
* module/language/cps/specialize-numbers.scm (compute-specializable-vars):
* module/language/cps/types.scm: Add new variants of u64->scm and
s64->scm that can't be replaced by CSE's auxiliary definitions, so we
can sink unlikely allocations to side branches. This is a hack until
we can get allocation sinking working
* module/language/tree-il/compile-cps.scm (canonicalize, convert):
Simplify handling of branching primcalls so that `convert' only ever
sees branching primcalls in a test context.
* module/language/tree-il/compile-cps.scm (convert): Fold test of
constants directly to their branches without reifying booleans, to
simplify "and" chains early.
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for heap-object? in test context.
* module/language/cps/primitives.scm (*immediate-predicates*):
(*heap-type-predicates*, *comparisons*): New sets of predicates for
which the VM has branching operations.
(heap-type-predicate?): New predicate.
(*branching-primcall-arities*): Make a hash table.
(branching-primitive?, prim-arity): Adapt
to *branching-primcall-arities* being a hash table.
* module/language/cps/type-fold.scm (heap-object?): Add folder.
* module/language/tree-il/compile-cps.scm (convert): Precede heap type
checks with a heap-object? guard.
* module/language/cps/types.scm (&special-immediate): Model all special
immediates (iflags) under this type bit. This makes type analysis
less precise on these values as we have to use ranges instead of sets
to represent the values, but it frees up bits for other purposes,
allowing us to totally model all types in Guile.
(&eof): New &special-immediate value.
(&other-heap-object): New type bit.
Adapt inferrers.
* module/language/cps/type-fold.scm
(define-special-immediate-predicate-folder): New helper, used for
iflag comparisons.
(local-type-fold): Adapt scalar-value for &special-immediate change.
Delegate branch on $values to a primcall to `false?'.
This will allow heap-object? / inum? predicates to do something useful.
* module/language/cps/types.scm (&fixnum, &bignum): Split &exact-integer
into these types. Keep &exact-integer as a union type.
(type<=?): New helper.
(constant-type): Return &fixnum or &bignum as appropriate.
(define-exact-integer!): New helper, tries to make exact integer
results be &fixnum if they are within range. Adapt users.
(restricted-comparison-ranges, define-binary-result!): Use type<=?
instead of = for &exact-integer.
* module/language/cps/type-fold.scm (logtest, mul, logbit?): Use
type<=?.
* module/language/cps/specialize-numbers.scm (inferred-sigbits):
(specialize-operations): Use type<=?.