mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
Marginal bootstrap memory improvements
* module/language/cps/compile-bytecode.scm (optimize, compile-bytecode): Marginally improve bootstrap memory usage by not retaining stale copies of already-rewritten terms.
This commit is contained in:
parent
a9ec16f9c5
commit
af082f9b1c
1 changed files with 49 additions and 34 deletions
|
@ -56,39 +56,53 @@
|
||||||
(_ default)))
|
(_ default)))
|
||||||
|
|
||||||
(define (optimize exp opts)
|
(define (optimize exp opts)
|
||||||
(define (run-pass exp pass kw default)
|
(define (run-pass! pass kw default)
|
||||||
(if (kw-arg-ref opts kw default)
|
(set! exp
|
||||||
(pass exp)
|
(if (kw-arg-ref opts kw default)
|
||||||
exp))
|
(pass exp)
|
||||||
|
exp)))
|
||||||
|
|
||||||
;; The first DCE pass is mainly to eliminate functions that aren't
|
;; The first DCE pass is mainly to eliminate functions that aren't
|
||||||
;; called. The last is mainly to eliminate rest parameters that
|
;; called. The last is mainly to eliminate rest parameters that
|
||||||
;; aren't used, and thus shouldn't be consed.
|
;; aren't used, and thus shouldn't be consed.
|
||||||
|
|
||||||
(let* ((exp (run-pass exp eliminate-dead-code #:eliminate-dead-code? #t))
|
;; This series of assignments to `env' used to be a series of let*
|
||||||
(exp (run-pass exp prune-top-level-scopes #:prune-top-level-scopes? #t))
|
;; bindings of `env', as you would imagine. In compiled code this is
|
||||||
(exp (run-pass exp simplify #:simplify? #t))
|
;; fine because the compiler is able to allocate all let*-bound
|
||||||
(exp (run-pass exp contify #:contify? #t))
|
;; variable to the same slot, which also means that the garbage
|
||||||
(exp (run-pass exp inline-constructors #:inline-constructors? #t))
|
;; collector doesn't have to retain so many copies of the term being
|
||||||
(exp (run-pass exp specialize-primcalls #:specialize-primcalls? #t))
|
;; optimized. However during bootstrap, the interpreter doesn't do
|
||||||
(exp (run-pass exp elide-values #:elide-values? #t))
|
;; this optimization, leading to excessive data retention as the terms
|
||||||
(exp (run-pass exp prune-bailouts #:prune-bailouts? #t))
|
;; are rewritten. To marginally improve bootstrap memory usage, here
|
||||||
(exp (run-pass exp eliminate-common-subexpressions #:cse? #t))
|
;; we use set! instead. The compiler should produce the same code in
|
||||||
(exp (run-pass exp type-fold #:type-fold? #t))
|
;; any case, though currently it does not because it doesn't do escape
|
||||||
(exp (run-pass exp resolve-self-references #:resolve-self-references? #t))
|
;; analysis on the box created for the set!.
|
||||||
(exp (run-pass exp eliminate-dead-code #:eliminate-dead-code? #t))
|
|
||||||
(exp (run-pass exp simplify #:simplify? #t)))
|
|
||||||
;; Passes that are needed:
|
|
||||||
;;
|
|
||||||
;; * Abort contification: turning abort primcalls into continuation
|
|
||||||
;; calls, and eliding prompts if possible.
|
|
||||||
;;
|
|
||||||
;; * Loop peeling. Unrolls the first round through a loop if the
|
|
||||||
;; loop has effects that CSE can work on. Requires effects
|
|
||||||
;; analysis. When run before CSE, loop peeling is the equivalent
|
|
||||||
;; of loop-invariant code motion (LICM).
|
|
||||||
|
|
||||||
exp))
|
(run-pass! eliminate-dead-code #:eliminate-dead-code? #t)
|
||||||
|
(run-pass! prune-top-level-scopes #:prune-top-level-scopes? #t)
|
||||||
|
(run-pass! simplify #:simplify? #t)
|
||||||
|
(run-pass! contify #:contify? #t)
|
||||||
|
(run-pass! inline-constructors #:inline-constructors? #t)
|
||||||
|
(run-pass! specialize-primcalls #:specialize-primcalls? #t)
|
||||||
|
(run-pass! elide-values #:elide-values? #t)
|
||||||
|
(run-pass! prune-bailouts #:prune-bailouts? #t)
|
||||||
|
(run-pass! eliminate-common-subexpressions #:cse? #t)
|
||||||
|
(run-pass! type-fold #:type-fold? #t)
|
||||||
|
(run-pass! resolve-self-references #:resolve-self-references? #t)
|
||||||
|
(run-pass! eliminate-dead-code #:eliminate-dead-code? #t)
|
||||||
|
(run-pass! simplify #:simplify? #t)
|
||||||
|
|
||||||
|
;; Passes that are needed:
|
||||||
|
;;
|
||||||
|
;; * Abort contification: turning abort primcalls into continuation
|
||||||
|
;; calls, and eliding prompts if possible.
|
||||||
|
;;
|
||||||
|
;; * Loop peeling. Unrolls the first round through a loop if the
|
||||||
|
;; loop has effects that CSE can work on. Requires effects
|
||||||
|
;; analysis. When run before CSE, loop peeling is the equivalent
|
||||||
|
;; of loop-invariant code motion (LICM).
|
||||||
|
|
||||||
|
exp)
|
||||||
|
|
||||||
(define (compile-fun f asm)
|
(define (compile-fun f asm)
|
||||||
(let* ((dfg (compute-dfg f #:global? #f))
|
(let* ((dfg (compute-dfg f #:global? #f))
|
||||||
|
@ -493,13 +507,14 @@
|
||||||
(compile-entry)))))
|
(compile-entry)))))
|
||||||
|
|
||||||
(define (compile-bytecode exp env opts)
|
(define (compile-bytecode exp env opts)
|
||||||
(let* ((exp (fix-arities exp))
|
;; See comment in `optimize' about the use of set!.
|
||||||
(exp (optimize exp opts))
|
(set! exp (fix-arities exp))
|
||||||
(exp (convert-closures exp))
|
(set! exp (optimize exp opts))
|
||||||
;; first-order optimization should go here
|
(set! exp (convert-closures exp))
|
||||||
(exp (reify-primitives exp))
|
;; first-order optimization should go here
|
||||||
(exp (renumber exp))
|
(set! exp (reify-primitives exp))
|
||||||
(asm (make-assembler)))
|
(set! exp (renumber exp))
|
||||||
|
(let* ((asm (make-assembler)))
|
||||||
(match exp
|
(match exp
|
||||||
(($ $program funs)
|
(($ $program funs)
|
||||||
(for-each (lambda (fun) (compile-fun fun asm))
|
(for-each (lambda (fun) (compile-fun fun asm))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue