summaryrefslogtreecommitdiff
path: root/module/language/tree-il/compile-bytecode.scm
AgeCommit message (Collapse)AuthorFilesLines
2021-09-20Baseline compiler no longer swaps rsh/lsh when transforming ash calls.Ludovic Courtès1-2/+2
Reported by Marius Bakke <marius@gnu.org> at <https://issues.guix.gnu.org/50696>. Previously, the baseline compiler would incorrectly emit a right shift when for, say, (ash x 2), and a left shift for (ash x -2). * module/language/tree-il/compile-bytecode.scm (canonicalize): When Y is negative, emit 'rsh', not 'lsh'. * test-suite/tests/numbers.test ("ash at -O1"): New test.
2021-09-20Fix 'ash' primcall match clause in baseline compiler.Ludovic Courtès1-3/+3
Previously the pattern would only match when the two 'src' values were the same, which is not the case for example when running on the interpreter. * module/language/tree-il/compile-bytecode.scm (canonicalize): In 'ash primcall pattern, rename second 'src' to 'src*'.
2021-04-26Simplify module variable lookup slow-pathAndy Wingo1-7/+12
* 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.
2020-08-03CPS compiler reduces eq? on constant to eq-constant?Andy Wingo1-4/+7
* 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-08-03Baseline compiler emits eq-immediate? as appropriateAndy Wingo1-19/+30
* module/language/tree-il/compile-bytecode.scm (eq?): Define eq-immediate? as immediate emitter. (canonicalize): Don't fuss so much about eq?; only if commutation is needed. (Perhaps a more generic commutation pass is needed.) (compile-closure): Add support for emit/immediate for branches.
2020-07-30Improve code generation for eq? on immediatesAndy Wingo1-0/+14
* module/language/tree-il/compile-bytecode.scm (canonicalize): * module/language/tree-il/compile-cps.scm (canonicalize): Specialize eq-false? and similar predicates.
2020-05-13Add with-lexicals helper; fix bug in (equal? #t (foo) #t)Andy Wingo1-6/+4
* module/language/tree-il.scm (with-lexicals): New public helper. * .dir-locals.el (with-lexicals): Add indentation rule. * module/language/tree-il/compile-bytecode.scm (canonicalize): Use with-lexicals. * module/language/tree-il/compile-cps.scm (canonicalize): Use with-lexicals from tree-il. * module/language/tree-il/primitives.scm (chained-comparison-expander): Remove duplicate expander definitions for <, <=, and so on. * module/language/tree-il/primitives.scm (maybe-simplify-to-eq): Avoid inadvertent code duplication by using with-lexicals. (expand-chained-comparisons): Likewise. (call-with-prompt): Simplify to use with-lexicals.
2020-05-13Slight optimization to baseline compilerAndy Wingo1-34/+34
* module/language/tree-il/compile-bytecode.scm (compile-closure): for-value-at and for-values-at take indexes instead of environments to denote destination.
2020-05-11Baseline FIXME's are done :)Andy Wingo1-10/+0
* module/language/tree-il/compile-bytecode.scm: Remove FIXME comments.
2020-05-11Baseline compiler emits source locationsAndy Wingo1-6/+42
* module/language/tree-il/compile-bytecode.scm (compile-closure): Emit source annotations where we have them.
2020-05-11Baseline O(1) access to frame-base envAndy Wingo1-15/+10
* module/language/tree-il/compile-bytecode.scm (compile-closure): No need to search for frame-base.
2020-05-11Emit handle-interrupts in baseline compilerAndy Wingo1-2/+6
* module/language/tree-il/compile-bytecode.scm (compile-closure): Handle interrupts before calls, returns, and tail calls.
2020-05-11Improve tail recursion in compilerAndy Wingo1-12/+6
* module/language/tree-il/compile-bytecode.scm (compile-closure): Make it so that for-tail is actually tail-recursive. Likewise improve tail recursion for the other helpers.
2020-05-11Fix module capture for closures in <fix>Andy Wingo1-0/+2
* module/language/tree-il/compile-bytecode.scm (compile-closure): Capture closures for <fix> if needed.
2020-05-11Fix "cons" compilation in baseline compiler in some casesAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (emit-cons): Fix for case where car is dst but cdr isn't.
2020-05-11Baseline compiler: add pop-fluid primitive.Andy Wingo1-0/+1
* module/language/tree-il/compile-bytecode.scm (pop-fluid): New primitive.
2020-05-11Fix baseline compilation error for make-struct/simpleAndy Wingo1-6/+8
* module/language/tree-il/compile-bytecode.scm (compile-closure): $allocate-struct takes an SCM.
2020-05-11Fix baseline miscompilation of <Andy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm: Fix < miscompilation.
2020-05-11Fix free var computation in baseline compiler for lexical set!Andy Wingo1-2/+3
* module/language/tree-il/compile-bytecode.scm (split-closures): Adjoin lexical being set to free vars.
2020-05-11Fix baseline canonicalization of reifying promptsAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (canonicalize): Fix arg order to make-prompt.
2020-05-11Fix compilation of prompt in tail contextAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): Compile body of prompt in values-at context at the frame base, not the current env.
2020-05-11Fix kw initializer bug in baseline compilerAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): The first sym has index 1, not 0, because of the closure.
2020-05-11Use lookup, lookup-bound in baseline compilerAndy Wingo1-22/+30
* module/language/tree-il/compile-bytecode.scm (emit-box-set!): Fix to reference by SCM, not word. (emit-box-ref): New helper. (emit-cached-module-box, emit-cached-toplevel-box, emit-toplevel-box): Add bound? arg. Before these could produce #f instead of a variable, and unbound variable errors weren't any good as they didn't have the variable name. (compile-closure): Use more box-ref and box-set!. Pass bound? arg to the helpers.
2020-05-11Rename "lookup" intrinsic to "module-variable"Andy Wingo1-3/+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-09Fix baseline compiler bugsAndy Wingo1-3/+3
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix FP-relative computation for "receive" target. Fix value-at syntax in conditional.
2020-05-08Define new "lowering" phase in compilerAndy Wingo1-2/+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.
2020-05-08Add language-specific analysis pass to compiler infrastructureAndy Wingo1-37/+13
* module/system/base/compile.scm (compute-analyzer): Compute analyzer to run on expressions before the compiler runs. (add-default-optimizations): Flesh out; still a stub.a (read-and-compile, compile, compile-and-load, compile-file): Default warning and optimization levels. (default-warning-level): New parameter, defaulting to 1. (default-optimization-level): New parameter, defaulting to 2. Currently unused. * module/system/base/language.scm (<language>): Add optimizations-for-level and analyzer fields. * module/language/tree-il/compile-bytecode.scm (compile-bytecode): * module/language/tree-il/compile-cps.scm (optimize-tree-il): No need to run warnings passes here; compilers infrastructure will run them. * module/language/tree-il/spec.scm (tree-il): Define make-analyzer as analyzer. * module/language/tree-il/analyze.scm (make-analyzer): New exported procedure. (%warning-passes): New private variable. * .dir-locals.el: Add with-test-prefix/c&e indent mode. * test-suite/tests/cross-compilation.test: * test-suite/tests/optargs.test: * test-suite/tests/tree-il.test: Adjust to disable default warnings.
2020-05-04Fix prompt compilationAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix emit-prompt invocation.
2020-05-04Fix baseline compilation of let-values and promptAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix fold invocation for visit-values-handler.
2020-05-04Fix baseline compilation of conditionalsAndy Wingo1-2/+5
* module/language/tree-il/compile-bytecode.scm (canonicalize): Don't add an extra false? around predicates. (compile-closure): Fix predicate comparison instructions.
2020-05-04Avoid shuffle-down for tail callsAndy Wingo1-4/+7
* module/language/tree-il/compile-bytecode.scm (compile-closure): We can emit the precise move sequence and just do a reset-frame once, so go ahead and do that.
2020-05-04Debugging names in baseline compiler; emit/immediate? fixesAndy Wingo1-33/+34
* module/language/tree-il/compile-bytecode.scm (compile-closure): Provide names for locals, including the closure. Fix emission of primitives with immediate args.
2020-05-04Add baseline compilerAndy Wingo1-0/+1357
* module/language/tree-il/compile-bytecode.scm: New file. * module/Makefile.am (SOURCES): * am/bootstrap.am (SOURCES): Add new file.