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

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 -- )
    [

        node insn>> uses-vregs [ definers at [ node +data+ precedes ] when* ] each
    ] each ;

UNION: stack-read-write ##peek ##replace ;

PREDICATE: ds-read-write < stack-read-write
    loc>> ds-loc? ;
UNION: data-stack-insn
    ##inc-d ds-read-write ;

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
