Added unboxed letrec bindings.

original commit: 8dc23d43eb23eac7a887ae2f3ef3633c54d3ba87
This commit is contained in:
Vincent St-Amour 2010-07-26 16:12:46 -04:00
parent c625d547ca
commit 277df87ff6
3 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,7 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(let ((x (+ 1.0+2.0i 2.0+3.0i)))
(let ((x (+ x 2.0+3.0i)))
(+ x 3.0+6.0i)))

View File

@ -0,0 +1,8 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(letrec ((#{f : (Any -> Any)} (lambda: ((x : Any)) (f x)))
(#{x : Inexact-Complex} 1.0+2.0i)
(#{y : Inexact-Complex} (+ 2.0+4.0i 3.0+6.0i)))
(+ x y))

View File

@ -15,7 +15,8 @@
(define-syntax-class unboxed-let-opt-expr
#:literal-sets (kernel-literals)
(pattern (~and exp (let-values (clause:expr ...) body:expr ...))
(pattern (~and exp ((~and op (~or (~literal let-values) (~literal letrec-values)))
(clause:expr ...) body:expr ...))
;; we look for bindings of complexes that are not mutated and only
;; used in positions where we would unbox them
;; these are candidates for unboxing
@ -40,7 +41,8 @@
(r (in-list (syntax->list #'(opt-candidates.real-binding ...))))
(i (in-list (syntax->list #'(opt-candidates.imag-binding ...)))))
(dict-set! unboxed-vars-table v (list r i)))
#`(let* (opt-candidates.bindings ... ... opt-others.res ...)
#`(#,(if (free-identifier=? #'op #'let-values) #'let* #'letrec)
(opt-candidates.bindings ... ... opt-others.res ...)
#,@(map (optimize) (syntax->list #'(body ...)))))))
;; if a variable is only used in complex arithmetic operations, it's safe