1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel compiler.cfg.instructions compiler.cfg.rpo
4 compiler.cfg.def-use compiler.cfg.linearization compiler.cfg.utilities
5 compiler.cfg.mr combinators.short-circuit accessors math
6 sequences sets assocs ;
7 IN: compiler.cfg.checker
9 ERROR: bad-kill-block bb ;
11 : check-kill-block ( bb -- )
12 dup instructions>> first2
14 { [ ##return? ] [ ##callback-return? ] [ ##jump? ] } 1||
16 [ drop ] [ bad-kill-block ] if ;
18 ERROR: last-insn-not-a-jump bb ;
20 : check-last-instruction ( bb -- )
21 dup instructions>> last {
24 [ ##conditional-branch? ]
25 [ ##compare-imm-branch? ]
30 } 1|| [ drop ] [ last-insn-not-a-jump ] if ;
32 ERROR: bad-kill-insn bb ;
34 : check-kill-instructions ( bb -- )
35 dup instructions>> [ kill-vreg-insn? ] any?
36 [ bad-kill-insn ] [ drop ] if ;
38 : check-normal-block ( bb -- )
39 [ check-last-instruction ]
40 [ check-kill-instructions ]
43 ERROR: bad-successors ;
45 : check-successors ( bb -- )
46 dup successors>> [ predecessors>> memq? ] with all?
47 [ bad-successors ] unless ;
49 : check-basic-block ( bb -- )
50 [ dup kill-block? [ check-kill-block ] [ check-normal-block ] if ]
56 ERROR: undefined-values uses defs ;
59 ! Check that every used register has a definition
61 [ [ uses-vregs ] map concat ]
62 [ [ [ temp-vregs ] [ defs-vreg ] bi [ suffix ] when* ] map concat ] bi
63 2dup subset? [ 2drop ] [ undefined-values ] if ;
65 : check-cfg ( cfg -- )
66 [ [ check-basic-block ] each-basic-block ]