mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 05:50:26 +02:00
Minor CSE run-time optimization
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Minor optimization to reduce the size of equivalent expression keys, and to avoid some work if an expression has no key.
This commit is contained in:
parent
bfe70b129c
commit
1575c863fe
1 changed files with 56 additions and 55 deletions
|
@ -250,9 +250,9 @@ false. It could be that both true and false proofs are available."
|
||||||
(($ $call proc args) #f)
|
(($ $call proc args) #f)
|
||||||
(($ $callk k proc args) #f)
|
(($ $callk k proc args) #f)
|
||||||
(($ $primcall name param args)
|
(($ $primcall name param args)
|
||||||
(cons* 'primcall name param (subst-vars var-substs args)))
|
(cons* name param (subst-vars var-substs args)))
|
||||||
(($ $branch _ ($ $primcall name param args))
|
(($ $branch _ ($ $primcall name param args))
|
||||||
(cons* 'primcall name param (subst-vars var-substs args)))
|
(cons* name param (subst-vars var-substs args)))
|
||||||
(($ $values args) #f)
|
(($ $values args) #f)
|
||||||
(($ $prompt escape? tag handler) #f)))
|
(($ $prompt escape? tag handler) #f)))
|
||||||
|
|
||||||
|
@ -271,16 +271,16 @@ false. It could be that both true and false proofs are available."
|
||||||
((def <- op arg ...) (aux <- op* arg* ...) ...)
|
((def <- op arg ...) (aux <- op* arg* ...) ...)
|
||||||
. clauses)
|
. clauses)
|
||||||
(match exp-key
|
(match exp-key
|
||||||
(('primcall 'op arg ...)
|
(('op arg ...)
|
||||||
(match defs
|
(match defs
|
||||||
((def) (add-def! (list 'primcall 'op* arg* ...) aux) ...)))
|
((def) (add-def! (list 'op* arg* ...) aux) ...)))
|
||||||
(_ (add-definitions . clauses))))
|
(_ (add-definitions . clauses))))
|
||||||
((add-definitions
|
((add-definitions
|
||||||
((op arg ...) (aux <- op* arg* ...) ...)
|
((op arg ...) (aux <- op* arg* ...) ...)
|
||||||
. clauses)
|
. clauses)
|
||||||
(match exp-key
|
(match exp-key
|
||||||
(('primcall 'op arg ...)
|
(('op arg ...)
|
||||||
(add-def! (list 'primcall 'op* arg* ...) aux) ...)
|
(add-def! (list 'op* arg* ...) aux) ...)
|
||||||
(_ (add-definitions . clauses))))))
|
(_ (add-definitions . clauses))))))
|
||||||
(add-definitions
|
(add-definitions
|
||||||
((b <- box #f o) (o <- box-ref #f b))
|
((b <- box #f o) (o <- box-ref #f b))
|
||||||
|
@ -319,8 +319,10 @@ false. It could be that both true and false proofs are available."
|
||||||
(define (visit-label label equiv-labels var-substs)
|
(define (visit-label label equiv-labels var-substs)
|
||||||
(match (intmap-ref conts label)
|
(match (intmap-ref conts label)
|
||||||
(($ $kargs names vars ($ $continue k src exp))
|
(($ $kargs names vars ($ $continue k src exp))
|
||||||
(let* ((exp-key (compute-exp-key var-substs exp))
|
(match (compute-exp-key var-substs exp)
|
||||||
(equiv (hash-ref equiv-set exp-key '()))
|
(#f (values equiv-labels var-substs))
|
||||||
|
(exp-key
|
||||||
|
(let* ((equiv (hash-ref equiv-set exp-key '()))
|
||||||
(fx (intmap-ref effects label))
|
(fx (intmap-ref effects label))
|
||||||
(avail (intmap-ref avail label)))
|
(avail (intmap-ref avail label)))
|
||||||
(define (finish equiv-labels var-substs)
|
(define (finish equiv-labels var-substs)
|
||||||
|
@ -341,8 +343,7 @@ false. It could be that both true and false proofs are available."
|
||||||
;; be eliminated by CSE (though DCE might do it
|
;; be eliminated by CSE (though DCE might do it
|
||||||
;; if the value proves to be unused, in the
|
;; if the value proves to be unused, in the
|
||||||
;; allocation case).
|
;; allocation case).
|
||||||
(when (and exp-key
|
(when (and (not (causes-effect? fx &allocation))
|
||||||
(not (causes-effect? fx &allocation))
|
|
||||||
(not (effect-clobbers? fx (&read-object &fluid))))
|
(not (effect-clobbers? fx (&read-object &fluid))))
|
||||||
(let ((defs (and (intset-ref singly-referenced k)
|
(let ((defs (and (intset-ref singly-referenced k)
|
||||||
(intmap-ref defs label))))
|
(intmap-ref defs label))))
|
||||||
|
@ -367,7 +368,7 @@ false. It could be that both true and false proofs are available."
|
||||||
(fold (lambda (def var var-substs)
|
(fold (lambda (def var var-substs)
|
||||||
(intmap-add var-substs def var))
|
(intmap-add var-substs def var))
|
||||||
var-substs defs vars)
|
var-substs defs vars)
|
||||||
var-substs))))))))))
|
var-substs))))))))))))
|
||||||
(_ (values equiv-labels var-substs))))
|
(_ (values equiv-labels var-substs))))
|
||||||
|
|
||||||
;; Traverse the labels in fun in reverse post-order, which will
|
;; Traverse the labels in fun in reverse post-order, which will
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue