summaryrefslogtreecommitdiff
path: root/module/language/cps/compile-bytecode.scm
AgeCommit message (Collapse)AuthorFilesLines
2023-11-20Add logand/immediate, ulogand/immediate primcallsAndy Wingo1-0/+2
* libguile/jit.c (compile_ulogand_immediate, compile_ulogand_immediate_slow) * libguile/vm-engine.c (ulogand_immediate): New JIT and interpreter support for ulogand/immediate. * module/language/cps/guile-vm/lower-primcalls.scm (string-ref): (vtable-vtable?): (vtable-field-boxed?): Emit ulogand/immediate. * module/language/cps/guile-vm/reify-primitives.scm (reify-primitives): Remove logand/immediate. Only emit ulogand/immediate if the immediate is a u8. Refactor mul/immediate. * module/language/cps/specialize-numbers.scm (specialize-operations): Produce ulogand/immediate if the result is a u64. * module/language/cps/effects-analysis.scm: * module/language/cps/types.scm (logand/immediate): Add effect and type inference for logand/immediate, ulogand/immediate, * module/language/cps/utils.scm (primcall-raw-representations): ulogand/immediate makes a u64. * module/language/tree-il/compile-cps.scm (convert): Generate logand/immediate if possible. * module/language/cps/compile-bytecode.scm (compile-function): * module/system/vm/assembler.scm (system): Add ulogand/immediate emitter. * libguile/loader.h (SCM_OBJCODE_MINOR_VERSION): Bump.
2023-08-28Better compilation of calls to `raise-exception`Andy Wingo1-1/+3
Recognize `raise-exception` in the same way we recognize `throw`, though it is a bit less optimized and the boot story is not as complicated. * doc/ref/vm.texi (Non-Local Control Flow Instructions): * libguile/jit.c (compile_unreachable): (compile_unreachable_slow): * libguile/vm-engine.c (VM_NAME): * module/language/cps/compile-bytecode.scm (compile-function): * module/system/vm/assembler.scm (emit-unreachable): Add new "unreachable" instruction, inserted after a call to non-continuable `raise-exception`. * module/language/tree-il/compile-cps.scm (raise-exception): * module/language/tree-il/primitives.scm (*interesting-primitive-names*): Recognize raise-exception, and if it is called with just one argument, prune that branch of the control-flow graph.
2023-08-17Add new $calli expression type.Andy Wingo1-1/+3
* module/language/cps.scm ($calli): New expression type which calls a function entry as originally captured via $code. Adapt all callers.
2023-06-19Fix bug in compilation of rsh/lshAndy Wingo1-2/+2
* module/language/cps/compile-bytecode.scm (compile-function): The rsh/lsh patterns would never match. I think these would end up dispatching through emit-text though.
2021-11-15Allow callk to continue to kargsAndy Wingo1-0/+2
* module/language/cps/verify.scm (check-arities): If a callk continues to kargs, the caller knows the number of return values that the callee provides and no number-of-values check is needed. * module/language/cps/contification.scm (apply-contification): Allow contification of known-return-values calls. * module/language/cps/reify-primitives.scm (uniquify-receive) (reify-primitives): No need for uniquify-receive any more as receive shuffles are attached to the call, not the continuation. * module/language/cps/compile-bytecode.scm (compile-function): Add kargs case.
2021-11-15Refactor send and receive shuffles in slot allocationAndy Wingo1-7/+7
* module/language/cps/slot-allocation.scm (lookup-send-parallel-moves): Rename from `lookup-parallel-moves'. (lookup-receive-parallel-moves): New function. Now we attach "receive moves" to call and prompt conts instead of to their continuations. (compute-shuffles): Refactor to allow a continuation to have both send and receive shuffles. (compute-frame-size): Refactor for new shuffles mechanism (allocate-slots): Allow calls to proceed directly to kargs.
2021-11-15Refactor compile-bytecodeAndy Wingo1-142/+115
* module/language/cps/compile-bytecode.scm (compile-function): Treat $kreceive as a forwarding cont, and refactor the treatment of calls and $values.
2021-04-26Simplify module variable lookup slow-pathAndy Wingo1-0/+6
* libguile/intrinsics.h: * libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two new intrinsics. (scm_bootstrap_intrinsics): Wire them up. * libguile/jit.c (compile_call_scm_from_scmn_scmn): (compile_call_scm_from_scmn_scmn_slow): (COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction kind. * libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes arguments as non-immediate offsets, to avoid needless loads and register pressure. * module/language/cps/effects-analysis.scm: Add cases for new primcalls. * module/language/cps/compile-bytecode.scm (compile-function): Add new primcalls. * module/language/cps/reify-primitives.scm (cached-module-box): If the variable is bound, call lookup-bound-public / lookup-bound-private as appropriate instead of separately resolving the module, name, and doing the bound check. * module/language/tree-il/compile-bytecode.scm (emit-cached-module-box): Use new instructions. * module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic): (lookup-bound-public, lookup-bound-private): Add assembler support.
2021-04-23Fix comments in cps/compile-bytecodeAndy Wingo1-2/+5
* module/language/cps/compile-bytecode.scm (compile-function): Fix unfinished comments.
2021-04-21Allow $kargs as entry of $kfunAndy Wingo1-3/+10
* module/language/cps.scm: * module/language/cps/contification.scm: * module/language/cps/cse.scm: * module/language/cps/dce.scm: * module/language/cps/simplify.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/types.scm: Allow $kargs to follow $kfun. In that case, the function must be well-known and callers are responsible for calling with the appropriate arity. * module/language/cps/compile-bytecode.scm: Emit "unchecked-arity" for $kargs following $kfun. * module/system/vm/assembler.scm: Adapt.
2020-08-12Add $switch CPS term kindAndy Wingo1-0/+6
* module/language/cps.scm ($switch): New term. * doc/ref/compiler.texi (CPS in Guile): Add documentation. * module/language/cps.scm (build-term, parse-cps, unparse-cps) * module/language/cps/closure-conversion.scm (compute-non-operator-uses) (compute-singly-referenced-labels, rewrite-shared-closure-calls) (compute-free-vars, convert-one) * module/language/cps/compile-bytecode.scm (compile-function) * module/language/cps/contification.scm (compute-singly-referenced-labels) (compute-contification-candidates, apply-contification) * module/language/cps/cse.scm (compute-truthy-expressions) (forward-cont, term-successors, eliminate-common-subexpressions-in-fun) * module/language/cps/dce.scm (compute-known-allocations) (compute-live-code, process-eliminations) * module/language/cps/devirtualize-integers.scm (compute-use-counts) (peel-trace) * module/language/cps/effects-analysis.scm (compute-effects) * module/language/cps/licm.scm (hoist-one, hoist-in-loop) * module/language/cps/loop-instrumentation.scm (compute-loop-headers) * module/language/cps/peel-loops.scm (rename-cont) * module/language/cps/renumber.scm (sort-labels-locally, renumber) * module/language/cps/rotate-loops.scm (rotate-loop) (rotate-loops-in-function) * module/language/cps/self-references.scm (resolve-self-references) * module/language/cps/simplify.scm (compute-singly-referenced-vars) (eta-reduce, compute-singly-referenced-labels, beta-reduce) * module/language/cps/slot-allocation.scm (compute-defs-and-uses) (add-prompt-control-flow-edges, compute-var-representations) * module/language/cps/specialize-numbers.scm (compute-significant-bits) * module/language/cps/split-rec.scm (compute-free-vars) * module/language/cps/type-fold.scm (local-type-fold) * module/language/cps/types.scm (successor-count, infer-types) * module/language/cps/utils.scm (compute-function-body) (compute-successors, compute-predecessors) * module/language/cps/verify.scm (compute-available-definitions) (check-valid-var-uses, check-arities): Add support for new term.
2020-08-03CPS compiler reduces eq? on constant to eq-constant?Andy Wingo1-7/+2
* module/language/cps/compile-bytecode.scm (compile-function): Expect eq-constant? instead of eq-null?, etc. * module/language/cps/effects-analysis.scm: Likewise. * module/language/cps/reify-primitives.scm (reify-primitives): For eq-constant?, reify a $const unless the constant is an immediate whose encoding fits in 16 bits. * module/language/cps/type-fold.scm (materialize-constant): Helper to make a constant from a type, min, and max. (fold-eq-constant?): New helper. (eq-constant?): New folder. (undefined?): Define specifically. (define-nullish-predicate-folder): Renamd from define-special-immediate-predicate-folder. Use only for null?, false, and nil?. (*branch-reducers*): New mechanism. Reduce eq? to eq-constant? if possible. (local-type-fold): Refactor to use materialize-constant, and to allow reducing branches. * module/language/cps/types.scm (constant-type): Return three values instead of a type entry. (constant-type-entry): New function that returns a type entry. Adapt callers. (infer-constant-comparison): New helper. (eq-constant?): New inferrer. (undefined?): New inferrer. * module/language/tree-il/compile-bytecode.scm (eq-constant?): Fix truncate-bits signed arg. (define-immediate-type-predicate): Adapt to visit-immediate-tags change. * module/language/tree-il/compile-cps.scm (convert): Convert eq? to constant to eq-constant?. Advantaged is that it gets fixnums and chars in addition to special immediates. * module/language/tree-il/cps-primitives.scm (define-immediate-type-predicate): Adapt to allow #f as pred. * module/system/base/types/internal.scm (immediate-tags): Use #f as pred for false, nil, etc. (immediate-bits->scm): Adapt. * module/system/vm/assembler.scm (emit-eq-null?, emit-eq-nil?) (emit-eq-false?, emit-eq-true?, emit-unspecified?, emit-eof-object?): Remove specialized emitters. * module/system/vm/assembler.scm (define-immediate-tag=?-macro-assembler): Allow for pred to be #f. * module/system/vm/disassembler.scm (define-immediate-tag-annotation): Adapt to pred being #f.
2020-05-11Add new lookup, lookup-bound intrinsicsAndy Wingo1-0/+6
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (lookup, lookup_bound): * libguile/intrinsics.c (scm_bootstrap_intrinsics): New intrinsics. * module/language/cps/reify-primitives.scm (reify-primitives): * module/language/cps/effects-analysis.scm (current-module): * module/language/cps/compile-bytecode.scm (compile-function): * module/system/vm/assembler.scm: Add compiler support.
2020-05-11Rename "lookup" intrinsic to "module-variable"Andy Wingo1-2/+3
It can return #f, unlike scm_(module_)?lookup. * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (module_variable, scm_bootstrap_intrinsics): Rename. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm (current-module): * module/language/cps/reify-primitives.scm (reify-lookup) (compute-known-primitives): * module/language/tree-il/compile-bytecode.scm (emit-cached-module-box) (emit-cached-toplevel-box, emit-toplevel-box): * module/language/tree-il/compile-cps.scm (toplevel-box): * module/system/vm/assembler.scm (module-variable): Adapt users.
2020-05-08Define new "lowering" phase in compilerAndy Wingo1-24/+1
* module/language/cps/compile-bytecode.scm (compile-bytecode): * module/language/tree-il/compile-bytecode.scm (compile-bytecode): * module/language/tree-il/compile-cps.scm (compile-cps): Rely on compiler to lower incoming term already. * module/language/tree-il/optimize.scm (make-lowerer): New procedure. * module/system/base/compile.scm (compute-lowerer): New procedure, replaceing add-default-optimizations. (compute-compiler): Lower before running compiler. * module/system/base/language.scm (<language>): Change optimizations-for-level field to "lowerer". * module/scripts/compile.scm (%options, compile): Parse -O0, -O1 and so on to #:optimization-level instead of expanding to all the optimization flags. * module/language/cps/optimize.scm (lower-cps): Move here from compile-bytecode.scm. (make-cps-lowerer): New function. * module/language/cps/spec.scm (cps): Declare lowerer.
2019-08-26Compiler allocates boxed flonums in unmarked spaceAndy Wingo1-0/+6
This fixes a bug whereby the compiler would sometimes allocate floats in marked space. * libguile/gc-inline.h (scm_inline_gc_malloc_pointerless_words): New internal helper. * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (allocate_pointerless_words): (allocate_pointerless_words_with_freelist): New intrinsics. * libguile/jit.c (compile_allocate_pointerless_words): (compile_allocate_pointerless_words_immediate): New compilers. * libguile/vm-engine.c (allocate_pointerless_words) (allocate_pointerless_words_immediate): New opcodes. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm (param): * module/language/cps/reify-primitives.scm (reify-primitives): * module/language/cps/specialize-primcalls.scm (specialize-primcalls): * module/language/cps/types.scm (allocate-words): (allocate-words/immediate): * module/system/vm/assembler.scm (system): Add support for the new opcodes.
2019-08-18Fix bug in which codegen accessed data beyond end of stackAndy Wingo1-8/+20
* module/language/cps/compile-bytecode.scm (compile-function): When shuffling return values, we need to reset the frame after any "extra" values are read and before any "extra" values may be set.
2019-06-07Add support no closure in $callkAndy Wingo1-2/+4
* module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/contification.scm (compute-contification-candidates): * module/language/cps/cse.scm (apply-cse): * module/language/cps/dce.scm (compute-live-code): * module/language/cps/devirtualize-integers.scm (compute-use-counts): * module/language/cps/peel-loops.scm (rename-cont): * module/language/cps/renumber.scm (renumber): * module/language/cps/rotate-loops.scm (rotate-loop): * module/language/cps/simplify.scm (compute-singly-referenced-vars): (beta-reduce): * module/language/cps/slot-allocation.scm (compute-defs-and-uses): (compute-lazy-vars): (compute-shuffles): (compute-frame-size): (allocate-lazy-vars): (allocate-slots): * module/language/cps/specialize-numbers.scm (compute-significant-bits): * module/language/cps/verify.scm (check-valid-var-uses): Allow for the $callk proc to be #f. * module/language/cps/compile-bytecode.scm (compile-function): Reset frame to appropriate size.
2019-06-07Add compiler support for eliding closure bindingsAndy Wingo1-5/+8
* module/language/cps/closure-conversion.scm (compute-elidable-closures): New function. (convert-one, convert-closures): Add ability to set "self" variable of $kfun to $f, hopefully avoiding passing that argument in some cases. * module/language/cps/compile-bytecode.scm (compile-function): Pass the has-closure? bit on through to the assembler. * module/system/vm/assembler.scm (begin-standard-arity) (begin-opt-arity, begin-kw-arity): Only reserve space for the closure as appropriate. * module/language/cps/slot-allocation.scm (allocate-args) (compute-defs-and-uses, compute-needs-slot) (compute-var-representations): Allow for closure slot allocation differences. * module/language/cps/cse.scm (compute-defs): * module/language/cps/dce.scm (compute-live-code): * module/language/cps/renumber.scm (renumber, compute-renaming): (allocate-args): * module/language/cps/specialize-numbers.scm (compute-significant-bits): (compute-defs): * module/language/cps/split-rec.scm (compute-free-vars): * module/language/cps/types.scm (infer-types): * module/language/cps/utils.scm (compute-max-label-and-var): * module/language/cps/verify.scm (check-distinct-vars): (compute-available-definitions): Allow closure to be #f.
2018-10-03Rename $closure to $const-funAndy Wingo1-1/+1
* module/language/cps.scm ($const-fun): Rename from $closure, as we always use this now with nfree == 0. * module/language/cps/closure-conversion.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/devirtualize-integers.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/licm.scm: * module/language/cps/peel-loops.scm: * module/language/cps/renumber.scm: * module/language/cps/rotate-loops.scm: * module/language/cps/simplify.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/specialize-numbers.scm: * module/language/cps/types.scm: * module/language/cps/utils.scm: * module/language/cps/verify.scm: Adapt users.
2018-07-29Emit instrument-loop in loops.Andy Wingo1-3/+8
* am/bootstrap.am (SOURCES): * module/Makefile.am (SOURCES): Handle renamve of handle-interrupts.scm to loop-instrumentation.scm. * libguile/jit.h (SCM_JIT_COUNTER_ENTRY_INCREMENT): Rename from SCM_JIT_COUNTER_CALL_INCREMENT. * libguile/vm-engine.c (instrument-entry): Rename from instrument-call. * module/language/cps/compile-bytecode.scm (compile-function): Add handle-interrupts code before calls and returns. Compile the "instrument-loop" primcall to an "instrument-loop" instruction and a "handle-interrupts" instruction. (lower-cps): Adapt to add-loop-instrumentation name change. * module/language/cps/loop-instrumentation.scm: Rename from handle-interrupts.scm and just add "instrument-loop" primcalls in loops. The compiler will add handle-interrupts primcalls as appropriate. * module/system/vm/assembler.scm (<jit-data>): New data type, for emitting embedded JIT data. (<meta>): Add field for current JIT data. (make-meta): Initialize current JIT data. (emit-instrument-entry*, emit-instrument-loop*): New instruction emitters that reference the current JIT data. (end-program): Now that all labels are known, arrange to serialize the JIT data. (link-data): Reserve space for JIT data, and add relocs to initialize the "start" / "end" fields.
2018-07-20Multiple-value returns now start from slot 0, not slot 1Andy Wingo1-4/+4
This should reduce frame sizes. * libguile/vm-engine.c (halt): Adapt to multiple-values change. Also adapt to not having the boot closure on the stack. (receive, receive-values, subr-call, foreign-call): Adapt to expect values one slot down. (prompt): Capture one less word for the values return. * libguile/vm.c (vm_dispatch_pop_continuation_hook): (vm_dispatch_abort_hook): Adapt for where to expect values. (vm_builtin_values_code): Add a call to shuffle-down before returning. This is more overhead than what existed before, but the hope is that the savings elsewhere pay off. (vm_builtin_values_code): Adapt to different values location. (reinstate_continuation_x, compose_continuation): Adapt to place resume args at right position. (capture_delimited_continuation): Remove unused sp and ip arguments. (abort_to_prompt): Adapt to capture_delimited_continuation change. (scm_call_n): Adapt to not reserve space for the boot closure. * module/language/cps/compile-bytecode.scm (compile-function): When returning values, adapt reset-frame call for return calling convention change. Adapt truncating or rest returns to expect values in the right place. * module/language/cps/slot-allocation.scm (compute-shuffles): (allocate-lazy-vars, allocate-slots): Allocate values from the "proc slot", not proc-slot + 1. * module/system/vm/assembler.scm (emit-init-constants): Reset the frame before returning so that the return value is in the right place. * test-suite/tests/rtl.test: Update for return convention change. * libguile/foreign.c (get_foreign_stub_code): Update for return calling convention change.
2018-07-20Rework VM approach to shuffling unknown numbers of argsAndy Wingo1-3/+9
* libguile/vm-engine.c (shuffle-down, expand-apply-argument): New instructions. (tail-call, tail-call-label, return-values): Don't reset the frame. The compiler should reset the frame appropriately. (tail-call/shuffle, tail-apply): Remove unused instructions. * libguile/vm.c (vm_builtin_apply_code): Use new shuffle-down and expand-apply-argument opcodes. (vm_builtin_call_with_values_code): Replace tail-call/shuffle with shuffle-down then tail-call. * libguile/jit.c (compile_shuffle_down, compile_expand_apply_argument): Add compiler stubs (COMPILE_X8_F12_F12): New definition. (compile_tail_call_shuffle, compile_tail_apply): Remove unused compilers. * module/language/cps/compile-bytecode.scm (compile-function): Emit reset-frame before tail calls and returns. * module/system/vm/assembler.scm (system): Remove unbound "emit-return" export. * module/system/vm/disassembler.scm (code-annotation) (instruction-has-fallthrough?, define-stack-effect-parser): Adapt for opcode changes.
2018-05-14Compile "define!" via intrinsicAndy Wingo1-2/+3
* libguile/intrinsics.c (scm_bootstrap_intrinsics): * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new define! intrinsic. * module/language/cps/compile-bytecode.scm (compile-function): Adapt compilation for define! to take two arguments. * module/language/cps/effects-analysis.scm (current-module): Update define! for two arguments. * module/language/tree-il/compile-cps.scm (convert): When reifying "define", grab the current module. * module/system/vm/assembler.scm (define!): Define assembler as intrinsic.
2018-05-14Remove backend support for cached-module-box et al.Andy Wingo1-6/+0
* module/language/cps/compile-bytecode.scm (compile-function): Remove unused assemblers for cached-module-box, cached-toplevel-box, and cache-current-module!. * module/language/cps/effects-analysis.scm (&cache): New memory kind. (cache-current-module!): Set &cache memory, not &box. (resolve-module, lookup-module, cache-ref, cache-set!): Add effect annotations. * module/system/vm/assembler.scm (emit-cache-current-module!) (emit-cached-toplevel-box, emit-cached-module-box): Remove assemblers. * module/system/vm/disassembler.scm (code-annotation, fold-code-range): Remove special cases for toplevel-box and module-box. * module/system/xref.scm (program-callee-rev-vars): Add a FIXME for the future.
2018-05-14Add cache-ref, cache-set! macro-instructionsAndy Wingo1-0/+4
* module/system/vm/assembler.scm (<cache-cell>): Remove "scope" member. Just be an opaque key comparable with equal?. (intern-cache-cell): Remove scope arg. (intern-module-cache-cell): Remove; callers use intern-cache-cell now. (cache-current-module!, cached-toplevel-box, cached-module-box): Create cache keys that by construction won't collide between types. (cache-ref, cache-set!): Add new macro assemblers. * module/language/cps/reify-primitives.scm: * module/language/cps/compile-bytecode.scm: Add cases for new macro instructions.
2018-05-14Add intrinsics for module operationsAndy Wingo1-0/+4
* libguile/intrinsics.c (scm_bootstrap_intrinsics): * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * module/system/vm/assembler.scm (resolve-module, lookup): New intrinsics. * module/language/cps/compile-bytecode: Add cases for primcalls corresponding to new intrinsics.
2018-04-13Explode atomic box ops to new atomic instructionsAndy Wingo1-13/+15
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add C8_S24 word type. * libguile/vm-engine.c (UNPACK_8_24): New helper. (atomic-scm-ref/immediate, atomic-scm-set!/immediate) (atomic-swap-scm!/immediate, atomic-scm-compare-and-swap!/immediate): New instructions. (make-atomic-box, atomic-box-ref, atomic-box-set!, atomic-box-swap!) (atomic-box-compare-and-swap!): Disable these ops. * module/language/bytecode.scm (compute-instruction-arity): Add C8_S24 support. * module/system/vm/assembler.scm: Add C8_S24 support. Export assemblers for new opcodes. * module/system/vm/disassembler.scm (disassembler): Support C8_S24. * module/language/cps/compile-bytecode.scm (compile-function): Replace old atomic-box assemblers with the new instructions. * module/language/cps/effects-analysis.scm (annotation->memory-kind): * module/language/cps/types.scm (annotation->type): Add cases for atomic boxes. Mark as all memory kinds because atomic ops serialize memory accesses. * module/language/tree-il/compile-cps.scm (make-atomic-box): (ensure-atomic-box, atomic-box-ref, atomic-box-set!): (atomic-box-swap!, atomic-box-compare-and-swap!): Explode these ops to more basic instructions. * module/system/base/types/internal.scm (%tc7-atomic-box): Add forgotten export.
2018-04-10Disable f64->scm instructionAndy Wingo1-2/+0
* libguile/vm-engine.c (f64->scm): Disable instruction. * module/language/cps/compile-bytecode.scm (compile-function): Remove f64->scm case. * module/system/vm/assembler.scm: Remove emit-f64->scm export.
2018-04-10Add $code CPS expression typeAndy Wingo1-2/+2
* module/language/cps.scm ($code): New CPS type, for labels as values. Add cases to all CPS type dispatches. $closure now indicates only statically allocated closures. * module/language/cps/closure-conversion.scm (convert-one): Only reify $closure for statically allocated procedures. Otherwise allocate an object using low-level primitives. * module/language/cps/compile-bytecode.scm (compile-function): Remove make-closure case. * module/language/cps/slot-allocation.scm (compute-var-representations): $code produces a u64 value. * module/system/vm/assembler.scm: Remove make-closure export. * module/language/cps/contification.scm: * module/language/cps/cse.scm: * module/language/cps/dce.scm: * module/language/cps/devirtualize-integers.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/licm.scm: * module/language/cps/peel-loops.scm: * module/language/cps/renumber.scm: * module/language/cps/rotate-loops.scm: * module/language/cps/simplify.scm: * module/language/cps/specialize-numbers.scm: * module/language/cps/types.scm: * module/language/cps/utils.scm: * module/language/cps/verify.scm: Add cases for $code.
2018-04-10Instruction explosion for char->integerAndy Wingo1-2/+0
* module/language/cps/effects-analysis.scm: * module/language/cps/slot-allocation.scm (compute-var-representations): * module/language/cps/types.scm: * module/language/cps/compile-bytecode.scm (compile-function): Remove char->integer cases. * module/system/vm/assembler.scm: Remove emit-char->integer export. * module/language/tree-il/compile-cps.scm (char->integer): Define instruction exploder.
2018-04-10Remove integer->char opAndy Wingo1-2/+0
* libguile/vm-engine.c (integer->char): Remove unused op. * module/language/cps/types.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/compile-bytecode.scm (compile-function): Remove integer->char cases. * module/system/vm/assembler.scm: Remove emit-integer->char.
2018-04-08Add VM ops needed for string-refAndy Wingo1-0/+7
* libguile/vm-engine.c (tail-pointer-ref/immediate, tag-char) (untag-char): New instructions. * module/language/cps/compile-bytecode.scm (compile-function): Add support for new instructions. * module/language/cps/cse.scm (compute-equivalent-subexpressions): CSE cases for tag-char / untag-char. * module/language/cps/effects-analysis.scm: * module/language/cps/types.scm: Add cases for new primcalls. * module/language/cps/reify-primitives.scm (reify-primitives): Update comment. * module/language/cps/slot-allocation.scm (compute-var-representations): Add cases for untag-char, tail-pointer-ref/immediate. * module/language/cps/specialize-primcalls.scm (specialize-primcalls): Add untag-char case, and add FIXME comment for tag-char. * module/system/vm/assembler.scm: Export new assemblers.
2018-01-22Remove free-ref, free-set!Andy Wingo1-5/+0
* libguile/vm-engine.c (free-ref, free-set!): Remove ops. * module/language/cps/effects-analysis.scm: * module/system/vm/assembler.scm: * module/system/vm/disassembler.scm (code-annotation): * module/language/cps/compile-bytecode.scm (compile-function): Remove support for free-ref / free-set!.
2018-01-22Remove optimizer and backend support for struct opsAndy Wingo1-22/+0
* module/language/cps/compile-bytecode.scm: * module/language/cps/cse.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/reify-primitives.scm: * module/language/cps/specialize-primcalls.scm: * module/language/cps/types.scm: * module/language/tree-il/cps-primitives.scm: * module/system/vm/assembler.scm: Remove support for struct-ref, struct-set!, allocate-struct, struct-vtable CPS primcalls and bytecode instructions.
2018-01-16Remove optimizer and backend support for bv-u8-ref et alAndy Wingo1-63/+0
* module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm: * module/language/cps/slot-allocation.scm (compute-var-representations): * module/language/cps/types.scm: * module/system/vm/assembler.scm: Remove optimizer and backend support for bv- ops.
2018-01-16Instruction explosion for bytevector settersAndy Wingo1-7/+7
* module/language/cps/compile-bytecode.scm (compile-function): Fix emitters for u64-set! et al. * module/language/tree-il/compile-cps.scm (bytevector-set-converter): New helper. Lower bytevector setters to pointer ops.
2018-01-15Instruction explosion for integer bytevector ref proceduresAndy Wingo1-6/+6
* module/language/cps/compile-bytecode.scm (compile-function): Fix emitters for u16-ref et al. * module/language/tree-il/compile-cps.scm (bytevector-ref-converter): (define-bytevector-ref-converter, define-bytevector-ref-converters): New helpers. Use to define lowerers for bv-s32-ref et al.
2018-01-14Rename gc-pointer-ref to pointer-refAndy Wingo1-5/+5
The pointer dereferencing instructions will keep the pointer alive by referencing a containing object. * module/language/cps/compile-bytecode.scm: * libguile/vm-engine.c: * module/language/cps/cse.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/reify-primitives.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/specialize-primcalls.scm: * module/language/cps/types.scm: * module/system/vm/assembler.scm: * module/system/vm/debug.scm: Rename instructions.
2018-01-14Add raw u8-ref, etc instructionsAndy Wingo1-0/+65
* libguile/vm-engine.c (PTR_REF, PTR_SET): New helper macros. (u8-ref, u16-ref, u32-ref, u64-ref, s8-ref, s16-ref, s32-ref, s64-ref) (u8-set!, u16-set!, u32-set!, u64-set!, s8-set!, s16-set!, s32-set!, s64-set!) (f32-ref, f64-ref, f32-set!, f64-set!): New instructions. * module/system/vm/assembler.scm: * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/slot-allocation.scm (compute-var-representations): * module/language/cps/types.scm: Add optimizer and backend support for the new instructions.
2018-01-10Add optimizer and backend support for gc-pointer-refAndy Wingo1-0/+5
* 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/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 (gc-pointer-ref/immediate): (gc-pointer-set!/immediate): * module/system/vm/assembler.scm: Add support for pointer-ref.
2018-01-10Lower box, box-ref, box-set! primcallsAndy Wingo1-2/+0
* module/language/tree-il/compile-cps.scm (box, ensure-box): (box-ref, box-set!): Lower box primcalls. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/cse.scm (compute-equivalent-subexpressions): * module/language/cps/dce.scm (compute-live-code): * module/language/cps/effects-analysis.scm: * module/language/cps/types.scm: Remove special support for boxes. What a pleasure!
2018-01-07Remove special optimizer and backend support for pairsAndy Wingo1-4/+0
* module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/cse.scm (compute-equivalent-subexpressions): * module/language/cps/dce.scm (compute-live-code): * module/language/cps/effects-analysis.scm: * module/language/cps/types.scm: Remove support for cons, car, etc primcalls. * module/language/cps/effects-analysis.scm (&car, &cdr): Remove undefined exports. * module/system/vm/assembler.scm: Remove emit-cons, etc exports.
2018-01-07Re-add compiler backend support for immutable vectorsAndy Wingo1-0/+2
* module/language/cps/compile-bytecode.scm (compile-function): Add cases for mutable-vector? and immutable-vector?. * module/system/vm/assembler.scm: Export emit-mutable-vector? and emit-immutable-vector?.
2018-01-07CPS pass now expects exploded vector primitivesAndy Wingo1-18/+0
* module/language/cps/closure-conversion.scm (convert-one): Reify make-vector inline, without field initialization. * module/language/cps/cse.scm (compute-equivalent-subexpressions): * module/language/cps/dce.scm (compute-live-code): * 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: * module/language/cps/compile-bytecode.scm (compile-function): Remove cases for make-vector, vector-ref, etc. * module/system/vm/assembler.scm: Remove make-vector, vector-ref etc exports.
2018-01-03$throw is a new kind of CPS termAndy Wingo1-8/+13
* module/language/cps.scm ($throw): New term type that doesn't have a continuation. Adapt all callers. Remove now-unneeded "prune-bailouts" pass.
2018-01-03$prompt is now its own kind of CPS term.Andy Wingo1-23/+28
* module/language/cps.scm ($prompt): Rework to be its own term kind. Now $continue always continues to a single continuation. Adapt callers.
2018-01-03$branch is now a distinct CPS term typeAndy Wingo1-75/+81
* module/language/cps.scm ($branch): Refactor to be its own CPS term type, not relying on $continue to specify a continuation (which before was only for the false case) or a source location. Update allllllll callers.
2017-12-27Flesh out compile-bytecode for all heap objectsAndy Wingo1-11/+28
* module/language/cps/compile-bytecode.scm (compile-function): Organize emitters and flesh out with more heap type tag predicates. Remove now-needless (language cps primitives) import.
2017-12-27Remove compile-bytecode cases for ephemeral primitivesAndy Wingo1-8/+5
* module/language/cps/compile-bytecode.scm (compile-function): Remove cases for tag-fixnum/unlikely, etc.