Skip to content

Commit

Permalink
Purify all procedures, even when (declare (block)) not used
Browse files Browse the repository at this point in the history
  • Loading branch information
feeley committed Nov 13, 2023
1 parent fada59c commit 2015e0e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions gsc/_front.scm
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@
(set! live-definition-queue '())
(set! proc-queue '())
(set! known-procs '())
(set! all-procs '())

(restore-context
(make-context 0 '() (list ret-var) '() (entry-poll) #f))
Expand Down Expand Up @@ -820,6 +821,7 @@
proc
(call-pattern val))
(add-constant-var var (make-obj proc))
(set! all-procs (cons proc all-procs))
(set! const-procs (cons proc const-procs))))))))
program)

Expand All @@ -846,6 +848,7 @@
#f))) ;; standard
(add-constant-var var (make-obj proc))
(set-car! lst proc)
(set! all-procs (cons proc all-procs))
(set! const-procs (cons proc const-procs))
(loop1 (cdr lst)))))

Expand Down Expand Up @@ -927,22 +930,25 @@

(proc-obj-code-set! main-proc *bbs*)

(set! *bb* '())
(set! *bbs* '())
(set! *proc* '())
(set! *global-env* '())
(let ((procs-to-purify
(cons main-proc
(reverse
(keep proc-obj-code all-procs)))))

(set! definition-table '())
(set! live-definition-queue '())
(set! proc-queue '())
(set! known-procs '())
(set! *bb* '())
(set! *bbs* '())
(set! *proc* '())
(set! *global-env* '())

(clear-context)
(set! definition-table '())
(set! live-definition-queue '())
(set! proc-queue '())
(set! known-procs '())
(set! all-procs '())

(purify-procs
(cons main-proc
(reverse
(keep proc-obj-code const-procs)))))))
(clear-context)

(purify-procs procs-to-purify)))))

(define *bb* '())
(define *bbs* '())
Expand All @@ -954,6 +960,7 @@
(define live-definition-queue '())
(define proc-queue '())
(define known-procs '())
(define all-procs '())

(define trace-indentation '())

Expand Down Expand Up @@ -1119,6 +1126,7 @@
(proc-obj-call-pat-set!
proc
(call-pattern val))
(set! all-procs (cons proc all-procs))
proc)))
(bbs
(make-bbs)))
Expand Down

2 comments on commit 2015e0e

@gambiteer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool. I suppose it doesn't affect the runtime or compiler because (block) is always declared in them. Do you know of any cases where this change makes a significant difference?

@feeley
Copy link
Member Author

@feeley feeley commented on 2015e0e Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't observed an actual speed improvement in my code because I typically use (declare (block)). However, I was doing some experimentation and noticed rather odd generated C code when (declare (block)) was not used. The generated code was correct but had many more labels that the "purification" step helps to remove. It is possible that the optimization work (removing and reordering labels) was just transferred to the C compiler.

Please sign in to comment.