[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 13/16: Earlier conversion to /imm primcalls
From: |
Andy Wingo |
Subject: |
[Guile-commits] 13/16: Earlier conversion to /imm primcalls |
Date: |
Sun, 5 Nov 2017 09:00:42 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit dea84a46b476643ea0abf7133ff4bdf59c46a88e
Author: Andy Wingo <address@hidden>
Date: Fri Nov 3 10:36:00 2017 +0100
Earlier conversion to /imm primcalls
* module/language/tree-il/compile-cps.scm (convert): Convert to /imm
variants of primcalls early on, to decrease complexity of later
passes.
---
module/language/tree-il/compile-cps.scm | 75 ++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 19 deletions(-)
diff --git a/module/language/tree-il/compile-cps.scm
b/module/language/tree-il/compile-cps.scm
index be7fe64..6835ce0 100644
--- a/module/language/tree-il/compile-cps.scm
+++ b/module/language/tree-il/compile-cps.scm
@@ -646,27 +646,64 @@
(lambda (cps integer)
(have-args cps (list integer)))))))
(else (have-args cps args))))
+ (define (convert-primcall cps k src instruction args)
+ (define (default)
+ (convert-args cps args
+ (lambda (cps args)
+ (unbox-args
+ cps args
+ (lambda (cps args)
+ (with-cps cps
+ (build-term
+ ($continue k src
+ ($primcall instruction #f args)))))))))
+ (define-syntax-rule (specialize-case (pat (op c (arg ...))) ...
+ (_ def))
+ (match (cons instruction args)
+ (pat
+ (convert-args cps (list arg ...)
+ (lambda (cps args)
+ (with-cps cps
+ (build-term
+ ($continue k src ($primcall 'op c args)))))))
+ ...
+ (_ def)))
+ (define (uint? val) (and (exact-integer? val) (<= 0 val)))
+ ;; FIXME: Add cases for mul, rsh, lsh
+ (specialize-case
+ (('make-vector ($ <const> _ (? uint? n)) init)
+ (make-vector/immediate n (init)))
+ (('vector-ref v ($ <const> _ (? uint? n)))
+ (vector-ref/immediate n (v)))
+ (('vector-set! v ($ <const> _ (? uint? n)) x)
+ (vector-set!/immediate n (v x)))
+ (('allocate-struct v ($ <const> _ (? uint? n)))
+ (allocate-struct/immediate n (v)))
+ (('struct-ref s ($ <const> _ (? uint? n)))
+ (struct-ref/immediate n (s)))
+ (('struct-set! s ($ <const> _ (? uint? n)) x)
+ (struct-set!/immediate n (s x)))
+ (('add x ($ <const> _ (? number? y)))
+ (add/immediate y (x)))
+ (('add ($ <const> _ (? number? y)) x)
+ (add/immediate y (x)))
+ (('sub x ($ <const> _ (? number? y)))
+ (sub/immediate y (x)))
+ (_ (default))))
(when (branching-primitive? name)
(error "branching primcall in bad context" name))
- (convert-args cps args
- (lambda (cps args)
- ;; Tree-IL primcalls are sloppy, in that it could be
- ;; that they are called with too many or too few
- ;; arguments. In CPS we are more strict and only
- ;; residualize a $primcall if the argument count
- ;; matches.
- (match (prim-arity instruction)
- ((out . in)
- (if (= in (length args))
- (with-cps cps
- (let$ k (box+adapt-arity k src out))
- ($ (unbox-args
- args
- (lambda (cps args)
- (with-cps cps
- (build-term
- ($continue k src
- ($primcall instruction #f args))))))))
+ ;; Tree-IL primcalls are sloppy, in that it could be that
+ ;; they are called with too many or too few arguments. In
+ ;; CPS we are more strict and only residualize a $primcall
+ ;; if the argument count matches.
+ (match (prim-arity instruction)
+ ((out . in)
+ (if (= in (length args))
+ (with-cps cps
+ (let$ k (box+adapt-arity k src out))
+ ($ (convert-primcall k src instruction args)))
+ (convert-args cps args
+ (lambda (cps args)
(with-cps cps
(letv prim)
(letk kprim ($kargs ('prim) (prim)
- [Guile-commits] branch master updated (2d8c75f -> f96a670), Andy Wingo, 2017/11/05
- [Guile-commits] 10/16: Tweak optimization order, Andy Wingo, 2017/11/05
- [Guile-commits] 12/16: Specialize primcalls more aggressively, Andy Wingo, 2017/11/05
- [Guile-commits] 13/16: Earlier conversion to /imm primcalls,
Andy Wingo <=
- [Guile-commits] 02/16: cache-current-module, etc use immediate primcall parameters, Andy Wingo, 2017/11/05
- [Guile-commits] 05/16: Immediate variants of vector-ref, etc use immediate param, Andy Wingo, 2017/11/05
- [Guile-commits] 15/16: error, scm-error primcalls expand to `throw', Andy Wingo, 2017/11/05
- [Guile-commits] 07/16: builtin-ref takes immediate parameter, Andy Wingo, 2017/11/05
- [Guile-commits] 09/16: reify-primitives reifies constants for out-of-range imm params, Andy Wingo, 2017/11/05
- [Guile-commits] 03/16: load-f64, etc take immediate parameters, Andy Wingo, 2017/11/05
- [Guile-commits] 04/16: free-ref, free-set take immediate parameters, Andy Wingo, 2017/11/05
- [Guile-commits] 11/16: (system base types) uses target's idea of max size_t, Andy Wingo, 2017/11/05
- [Guile-commits] 16/16: Add new "throw" VM ops, Andy Wingo, 2017/11/05
- [Guile-commits] 14/16: Add lsh, rsh instructions, Andy Wingo, 2017/11/05