Skip to content

Commit

Permalink
Seriously turn down the let lifting so we get correct results on mand…
Browse files Browse the repository at this point in the history
…elbrot.kfc again.

Issues #116 and #56.
  • Loading branch information
eholk committed Jan 16, 2014
1 parent 7518e18 commit d737274
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
38 changes: 22 additions & 16 deletions harlan/middle/lifting.scm
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@
,[Expr -> end end-bindings]
,[Expr -> step step-bindings])
,[body bindings])
(let-values (((liftable pinned)
((split-bindings (list x)) bindings)))
(values
`(for (,x ,start ,end ,step)
,(make-let pinned body))
(append start-bindings end-bindings step-bindings liftable))))
;; We don't lift any body bindings out of the for loop, in case
;; side effects mess with them. Again, we need a proper assigned
;; variable analysis.
(values
`(for (,x ,start ,end ,step)
,(make-let bindings body))
(append start-bindings end-bindings step-bindings)))
((while ,[Expr -> test test-bindings]
,[body bindings])
(values `(while ,test ,body)
(append test-bindings bindings)))
;; We don't lift any bindings in the body outside of the while
;; loop. This avoids problems when there are side effects. That
;; said, this is exactly the situation where we do want to lift
;; bindings, so we should probably do a proper assigned variable
;; analysis instead.
(values `(while ,test ,(make-let bindings body))
test-bindings))
((if ,[Expr -> e bindings] ,c)
(values `(if ,e ,c) bindings))
((if ,[Expr -> e bindings] ,c ,a)
Expand All @@ -128,15 +134,15 @@
`(begin ,@(map make-let bindings* stmt*) ,(make-let bindings e))
`()))
((kernel ,kt ,d (((,x* ,t) (,e ,es) ,dim) ...) ,[body bindings])
(let-values (((liftable pinned) ((split-bindings x*) bindings)))
(values `(kernel ,kt ,d (((,x* ,t) (,e ,es) ,dim) ...)
,(make-let pinned body))
liftable)))
;; Don't lift out of kernels, in case there are side
;; effects. Again, we need an assigned variable analysis.
(values `(kernel ,kt ,d (((,x* ,t) (,e ,es) ,dim) ...)
,(make-let bindings body))
'()))
((kernel ,kt ,r ,d (((,x* ,t) (,e ,es) ,dim) ...) ,[body bindings])
(let-values (((liftable pinned) ((split-bindings x*) bindings)))
(values `(kernel ,kt ,r ,d (((,x* ,t) (,e ,es) ,dim) ...)
,(make-let pinned body))
liftable)))
(values `(kernel ,kt ,r ,d (((,x* ,t) (,e ,es) ,dim) ...)
,(make-let bindings body))
'()))
(,e (values e `())))

(define-match free-vars-Expr
Expand Down
2 changes: 1 addition & 1 deletion harlanc.scm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
(let ((filename (car args)))
(print-compile-harlan filename)))))

;;(trace-pass 'typecheck)
;(trace-pass 'optimize-lift-lets)

(harlanc (command-line))
1 change: 1 addition & 0 deletions lib/harlan/graphics.kfc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
(for (i 0 rows 1)
(for (j 0 cols 1)
(let ((p (vector-ref (vector-ref data i) j)))
;;(println* i "\t" j "\t" p)
(print (cond
((< p 0) 0)
((> p 255) 255)
Expand Down
5 changes: 2 additions & 3 deletions test/mandelbrot.kfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
(set! xi xip)
(let ((m (+ (* xr xr) (* xi xi))))
(if (< m 4.0)
;; Why do the pixels all turn white
;; if I just do (set! escape idx)?
(set! escape (- idx 1)))
(set! escape idx))
(set! idx (+ idx 1)))))
escape)))))
(let ((stop (nanotime)))
(println* (length img) "x" (length (vector-ref img 0)))
(write-pgm "test.bin/mandelbrot.pgm" img)
(print "Time to generate Mandelbrot Set in milliseconds:\n")
(print (/ (- stop start) 1000000))
Expand Down

0 comments on commit d737274

Please sign in to comment.