         node insn>> uses-vregs [ definers at [ node +data+ precedes ] when* ] each
     ] each ;
 
-: make-chain ( nodes -- )
-    [ dup rest-slice [ +control+ precedes ] 2each ] unless-empty ;
+UNION: stack-read-write ##peek ##replace ;
 
-: instruction-chain ( nodes quot -- )
-    '[ insn>> @ ] filter make-chain ; inline
+PREDICATE: ds-read-write < stack-read-write
+    loc>> ds-loc? ;
+UNION: data-stack-insn
+    ##inc-d ds-read-write ;
 
-UNION: stack-read-write ##peek ##replace ;
-UNION: stack-change-height ##inc-d ##inc-r ;
-UNION: stack-insn stack-read-write stack-change-height ;
-
-GENERIC: data-stack-insn? ( insn -- ? )
-M: object data-stack-insn? drop f ;
-M: ##inc-d data-stack-insn? drop t ;
-M: stack-read-write data-stack-insn? loc>> ds-loc? ;
-
-: retain-stack-insn? ( insn -- ? )
-    dup stack-insn? [ data-stack-insn? not ] [ drop f ] if ;
+PREDICATE: rs-read-write < stack-read-write
+    loc>> rs-loc? ;
+UNION: retain-stack-insn
+    ##inc-r rs-read-write ;
 
 UNION: ##alien-read
     ##alien-double ##alien-float ##alien-cell ##alien-vector

UNION: alien-call-insn
    ##save-context ##alien-invoke ##alien-indirect ##alien-callback ;

: add-control-edges ( nodes -- )
    {
        [ [ data-stack-insn? ] instruction-chain ]
        [ [ retain-stack-insn? ] instruction-chain ]
        [ [ alien-memory-insn? ] instruction-chain ]
        [ [ slot-memory-insn? ] instruction-chain ]
        [ [ string-memory-insn? ] instruction-chain ]
        [ [ alien-call-insn? ] instruction-chain ]
    } cleave ;

: set-follows ( nodes -- )
    [


: build-dependence-graph ( instructions -- )
    [ <node> ] map {
        [ add-control-edges ]
        [ add-data-edges ]
        [ set-follows ]
        [ set-roots ]
        [ nodes set ]
    } cleave ;

! Sethi-Ulmann numbering
