 ! These need to be numbered so that the same instruction
 ! will get distinct nodes if it occurs multiple times
 TUPLE: node
+    precedes-data precedes-control
     number insn precedes follows
     children parent
     registers parent-index ;

: precedes ( first second -- )
    swap precedes>> conjoin ;

:: add-data-edges ( nodes -- )
    ! This builds up def-use information on the fly, since
    ! we only care about local def-use
    H{ } clone :> definers
    nodes [| node |
        node insn>> defs-vreg [ node swap definers set-at ] when*
        node insn>> uses-vregs [ definers at [ node precedes ] when* ] each
    ] each ;

: make-chain ( nodes -- )
    [ dup rest-slice [ precedes ] 2each ] unless-empty ;

: instruction-chain ( nodes quot -- )
    '[ insn>> @ ] filter make-chain ; inline

USING: accessors assocs combinators compiler.cfg.def-use
compiler.cfg.instructions compiler.cfg.registers fry kernel
locals namespaces sequences sets sorting math.vectors
make math combinators.short-circuit vectors ;
IN: compiler.cfg.dependence

! Dependence graph construction
