1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00

dfg: variable-free-in?, add variable-bound-in?

* module/language/cps/dfg.scm (variable-free-in?): Rename from
  variable-used-in?, to match CWCC language.
  (variable-bound-in?): New interface.

* module/language/cps/contification.scm (contify): Adapt caller.  Add
  more comments.
This commit is contained in:
Andy Wingo 2013-10-04 10:47:55 +02:00
parent b43e81dc60
commit d51fb1e67b
2 changed files with 18 additions and 4 deletions

View file

@ -80,6 +80,12 @@
(list sym) (list self) (list tail) (list sym) (list self) (list tail)
(list arities) (list bodies))) (list arities) (list bodies)))
;; Given a set of mutually recursive functions bound to local
;; variables SYMS, with self symbols SELFS, tail continuations
;; TAILS, arities ARITIES, and bodies BODIES, all bound in TERM-K,
;; contify them if we can prove that they all return to the same
;; continuation. If successful, return that common continuation.
;; Otherwise return #f.
(define (contify-funs term-k syms selfs tails arities bodies) (define (contify-funs term-k syms selfs tails arities bodies)
;; Are the given args compatible with any of the arities? ;; Are the given args compatible with any of the arities?
(define (applicable? proc args) (define (applicable? proc args)
@ -162,7 +168,7 @@
;; components, and lump everything else in the remaining ;; components, and lump everything else in the remaining
;; component. ;; component.
(define (recursive? k) (define (recursive? k)
(or-map (cut variable-used-in? <> k dfg) syms)) (or-map (cut variable-free-in? <> k dfg) syms))
(let lp ((nsf nsf) (rec '())) (let lp ((nsf nsf) (rec '()))
(match nsf (match nsf
(() (()

View file

@ -54,7 +54,8 @@
find-defining-expression find-defining-expression
find-constant-value find-constant-value
lift-definition! lift-definition!
variable-used-in? variable-bound-in?
variable-free-in?
constant-needs-allocation? constant-needs-allocation?
dead-after-def? dead-after-def?
dead-after-use? dead-after-use?
@ -341,11 +342,18 @@
(lp body)) (lp body))
(_ #t)))))))) (_ #t))))))))
(define (variable-used-in? var parent-k dfg) (define (variable-bound-in? var k dfg)
(match dfg
(($ $dfg conts use-maps uplinks)
(match (lookup-use-map k use-maps)
(($ $use-map sym def uses)
(continuation-scope-contains? def k uplinks))))))
(define (variable-free-in? var k dfg)
(match dfg (match dfg
(($ $dfg conts use-maps uplinks) (($ $dfg conts use-maps uplinks)
(or-map (lambda (use) (or-map (lambda (use)
(continuation-scope-contains? parent-k use uplinks)) (continuation-scope-contains? k use uplinks))
(match (lookup-use-map var use-maps) (match (lookup-use-map var use-maps)
(($ $use-map sym def uses) (($ $use-map sym def uses)
uses)))))) uses))))))