cse passes a lookup procedure to the effects analyzer
authorAndy Wingo <wingo@pobox.com>
Tue, 15 May 2012 15:23:06 +0000 (17:23 +0200)
committerAndy Wingo <wingo@pobox.com>
Tue, 15 May 2012 15:23:06 +0000 (17:23 +0200)
* module/language/tree-il/cse.scm (cse): Arrange to pass a lookup
  procedure to compute-effects, for better effects analysis.

module/language/tree-il/cse.scm

index 5ba5906..ceef15f 100644 (file)
       (lambda (sym)
         (vhash-assq sym table))))
 
-  (define compute-effects
+  (define %compute-effects
     (make-effects-analyzer assigned-lexical?))
 
   (define (negate exp ctx)
        (make-application #f (make-primitive-ref #f 'not) (list exp)))))
 
   
-  (define (bailout? exp)
-    (causes-effects? (compute-effects exp) &definite-bailout))
-
   (define (hasher n)
     (lambda (x size) (modulo n size)))
 
                                 (make-lexical-ref (tree-il-src exp) name sym)
                                 (lp (1+ n) (- db-len db-len*))))))))))))
 
+  (define (lookup-lexical sym env)
+    (let ((env-len (vlist-length env)))
+      (let lp ((n 0))
+        (and (< n env-len)
+             (match (vlist-ref env n)
+               ((#(exp _ sym* _) . _)
+                (if (eq? sym sym*)
+                    exp
+                    (lp (1+ n)))))))))
+
   (define (intersection db+ db-)
     (vhash-fold-right
      (lambda (k h out)
                 (lp (cdr in) (cons x out) (concat db** db*))))
             (values (reverse out) db*))))
 
+    (define (compute-effects exp)
+      (%compute-effects exp (lambda (sym) (lookup-lexical sym env))))
+
+    (define (bailout? exp)
+      (causes-effects? (compute-effects exp) &definite-bailout))
+
     (define (return exp db*)
       (let ((effects (compute-effects exp)))
         (cond