1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

Assignment conversion uses unchecked memory accessors

* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Add box type annotation.
* module/language/cps/reify-primitives.scm (primitive-ref): Reify
  scm-ref/immediate instead of box-ref.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Remove needless and unbound -> literal.
* module/language/cps/types.scm (annotation->type): Add box type.
* module/language/tree-il/compile-cps.scm (convert): Reify
  scm-ref/immediate / scm-set!/immediate instead of box-ref / box-set!.
This commit is contained in:
Andy Wingo 2017-12-06 11:26:03 +01:00
parent dd8bf6a98c
commit eed4e09723
5 changed files with 32 additions and 20 deletions

View file

@ -341,7 +341,8 @@ the LABELS that are clobbered by the effects of LABEL."
;; FIXME: Flesh this out. ;; FIXME: Flesh this out.
(match annotation (match annotation
('pair &pair) ('pair &pair)
('vector &vector))) ('vector &vector)
('box &box)))
(define-primitive-effects* param (define-primitive-effects* param
((allocate-words size) (&allocate (annotation->memory-kind param))) ((allocate-words size) (&allocate (annotation->memory-kind param)))

View file

@ -91,7 +91,8 @@
(lambda (cps box) (lambda (cps box)
(with-cps cps (with-cps cps
(build-term (build-term
($continue k src ($primcall 'box-ref #f (box)))))))) ($continue k src
($primcall 'scm-ref/immediate '(box . 1) (box))))))))
(define (builtin-ref cps idx k src) (define (builtin-ref cps idx k src)
(with-cps cps (with-cps cps
@ -257,7 +258,7 @@
(letv n*) (letv n*)
(letk kop ($kargs ('n) (n*) (letk kop ($kargs ('n) (n*)
($continue k src ($continue k src
($primcall 'allocate-words ann (n))))) ($primcall 'allocate-words ann (n*)))))
(setk label ($kargs names vars (setk label ($kargs names vars
($continue kop src ($continue kop src
($primcall 'load-u64 n ()))))))))) ($primcall 'load-u64 n ())))))))))

View file

@ -108,10 +108,10 @@
(define (rename name) (define (rename name)
(build-exp ($primcall name param args))) (build-exp ($primcall name param args)))
(define-syntax compute-constant (define-syntax compute-constant
(syntax-rules (->) (syntax-rules ()
((_ (c -> exp) body) ((_ (c exp) body)
(let* ((c (intmap-ref constants c)) (c exp)) body)) (let* ((c (intmap-ref constants c)) (c exp)) body))
((_ c body) (compute-constant (c -> c) body)))) ((_ c body) (compute-constant (c c) body))))
(define-syntax-rule (specialize-case (pat (op c (arg ...))) ...) (define-syntax-rule (specialize-case (pat (op c (arg ...))) ...)
(match (cons name args) (match (cons name args)
(pat (pat
@ -125,11 +125,11 @@
(('allocate-struct v (? uint? n)) (allocate-struct/immediate n (v))) (('allocate-struct v (? uint? n)) (allocate-struct/immediate n (v)))
(('struct-ref s (? uint? n)) (struct-ref/immediate n (s))) (('struct-ref s (? uint? n)) (struct-ref/immediate n (s)))
(('struct-set! s (? uint? n) x) (struct-set!/immediate n (s x))) (('struct-set! s (? uint? n) x) (struct-set!/immediate n (s x)))
(('allocate-words (? uint? n)) (allocate-words/immediate (n -> (cons param n)) ())) (('allocate-words (? uint? n)) (allocate-words/immediate (n (cons param n)) ()))
(('scm-ref o (? uint? i)) (scm-ref/immediate (i -> (cons param i)) (o))) (('scm-ref o (? uint? i)) (scm-ref/immediate (i (cons param i)) (o)))
(('scm-set! o (? uint? i) x) (scm-set!/immediate (i -> (cons param i)) (o x))) (('scm-set! o (? uint? i) x) (scm-set!/immediate (i (cons param i)) (o x)))
(('word-ref o (? uint? i)) (word-ref/immediate (i -> (cons param i)) (o))) (('word-ref o (? uint? i)) (word-ref/immediate (i (cons param i)) (o)))
(('word-set! o (? uint? i) x) (word-set!/immediate (i -> (cons param i)) (o x))) (('word-set! o (? uint? i) x) (word-set!/immediate (i (cons param i)) (o x)))
(('add x (? num? y)) (add/immediate y (x))) (('add x (? num? y)) (add/immediate y (x)))
(('add (? num? y) x) (add/immediate y (x))) (('add (? num? y) x) (add/immediate y (x)))
(('sub x (? num? y)) (sub/immediate y (x))) (('sub x (? num? y)) (sub/immediate y (x)))

View file

@ -712,7 +712,8 @@ minimum, and maximum."
(define (annotation->type ann) (define (annotation->type ann)
;; Expand me! ;; Expand me!
(match ann (match ann
('vector &vector))) ('vector &vector)
('box &box)))
(define-type-inferrer/param (allocate-words param size result) (define-type-inferrer/param (allocate-words param size result)
(define! result (annotation->type param) (&min/0 size) (&max/scm-size size))) (define! result (annotation->type param) (&min/0 size) (&max/scm-size size)))

View file

@ -360,7 +360,8 @@
(letv unboxed) (letv unboxed)
(let$ body (k unboxed)) (let$ body (k unboxed))
(letk kunboxed ($kargs ('unboxed) (unboxed) ,body)) (letk kunboxed ($kargs ('unboxed) (unboxed) ,body))
(build-term ($continue kunboxed src ($primcall 'box-ref #f (box)))))) (build-term ($continue kunboxed src
($primcall 'scm-ref/immediate '(box . 1) (box))))))
((orig-var subst-var #f) (k cps subst-var)) ((orig-var subst-var #f) (k cps subst-var))
(var (k cps var)))) (var (k cps var))))
((? single-valued?) ((? single-valued?)
@ -411,7 +412,8 @@
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 1)) (let$ k (adapt-arity k src 1))
(rewrite-term (hashq-ref subst sym) (rewrite-term (hashq-ref subst sym)
((orig-var box #t) ($continue k src ($primcall 'box-ref #f (box)))) ((orig-var box #t) ($continue k src
($primcall 'scm-ref/immediate '(box . 1) (box))))
((orig-var subst-var #f) ($continue k src ($values (subst-var)))) ((orig-var subst-var #f) ($continue k src ($values (subst-var))))
(var ($continue k src ($values (var))))))) (var ($continue k src ($values (var)))))))
@ -491,7 +493,8 @@
(lambda (cps box) (lambda (cps box)
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 1)) (let$ k (adapt-arity k src 1))
(build-term ($continue k src ($primcall 'box-ref #f (box)))))))) (build-term ($continue k src
($primcall 'scm-ref/immediate '(box . 1) (box))))))))
(($ <module-set> src mod name public? exp) (($ <module-set> src mod name public? exp)
(convert-arg cps exp (convert-arg cps exp
@ -502,7 +505,8 @@
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 0)) (let$ k (adapt-arity k src 0))
(build-term (build-term
($continue k src ($primcall 'box-set! #f (box val)))))))))) ($continue k src
($primcall 'scm-set!/immediate '(box . 1) (box val))))))))))
(($ <toplevel-ref> src name) (($ <toplevel-ref> src name)
(toplevel-box (toplevel-box
@ -510,7 +514,9 @@
(lambda (cps box) (lambda (cps box)
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 1)) (let$ k (adapt-arity k src 1))
(build-term ($continue k src ($primcall 'box-ref #f (box)))))))) (build-term
($continue k src
($primcall 'scm-ref/immediate '(box . 1) (box))))))))
(($ <toplevel-set> src name exp) (($ <toplevel-set> src name exp)
(convert-arg cps exp (convert-arg cps exp
@ -521,7 +527,8 @@
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 0)) (let$ k (adapt-arity k src 0))
(build-term (build-term
($continue k src ($primcall 'box-set! #f (box val)))))))))) ($continue k src
($primcall 'scm-set!/immediate '(box . 1) (box val))))))))))
(($ <toplevel-define> src name exp) (($ <toplevel-define> src name exp)
(convert-arg cps exp (convert-arg cps exp
@ -530,7 +537,8 @@
(let$ k (adapt-arity k src 0)) (let$ k (adapt-arity k src 0))
(letv box) (letv box)
(letk kset ($kargs ('box) (box) (letk kset ($kargs ('box) (box)
($continue k src ($primcall 'box-set! #f (box val))))) ($continue k src
($primcall 'scm-set!/immediate '(box . 1) (box val)))))
($ (with-cps-constants ((name name)) ($ (with-cps-constants ((name name))
(build-term (build-term
($continue kset src ($primcall 'define! #f (name)))))))))) ($continue kset src ($primcall 'define! #f (name))))))))))
@ -921,7 +929,8 @@
(with-cps cps (with-cps cps
(let$ k (adapt-arity k src 0)) (let$ k (adapt-arity k src 0))
(build-term (build-term
($continue k src ($primcall 'box-set! #f (box exp)))))))))) ($continue k src
($primcall 'scm-set!/immediate '(box . 1) (box exp))))))))))
(($ <seq> src head tail) (($ <seq> src head tail)
(if (zero-valued? head) (if (zero-valued? head)