|
3 | 3 | @inline isexpr(@nospecialize(stmt), head::Symbol) = isa(stmt, Expr) && stmt.head === head |
4 | 4 | Core.PhiNode() = Core.PhiNode(Int32[], Any[]) |
5 | 5 |
|
6 | | -""" |
7 | | -Like UnitRange{Int}, but can handle the `last` field, being temporarily |
8 | | -< first (this can happen during compacting) |
9 | | -""" |
10 | | -struct StmtRange <: AbstractUnitRange{Int} |
11 | | - start::Int |
12 | | - stop::Int |
13 | | -end |
14 | | -first(r::StmtRange) = r.start |
15 | | -last(r::StmtRange) = r.stop |
16 | | -iterate(r::StmtRange, state=0) = (last(r) - first(r) < state) ? nothing : (first(r) + state, state + 1) |
17 | | - |
18 | | -StmtRange(range::UnitRange{Int}) = StmtRange(first(range), last(range)) |
19 | | - |
20 | | -struct BasicBlock |
21 | | - stmts::StmtRange |
22 | | - preds::Vector{Int} |
23 | | - succs::Vector{Int} |
24 | | -end |
25 | | -function BasicBlock(stmts::StmtRange) |
26 | | - return BasicBlock(stmts, Int[], Int[]) |
27 | | -end |
28 | | -function BasicBlock(old_bb, stmts) |
29 | | - return BasicBlock(stmts, old_bb.preds, old_bb.succs) |
30 | | -end |
31 | | -copy(bb::BasicBlock) = BasicBlock(bb.stmts, copy(bb.preds), copy(bb.succs)) |
| 6 | +isterminator(@nospecialize(stmt)) = isa(stmt, GotoNode) || isa(stmt, GotoIfNot) || isa(stmt, ReturnNode) |
32 | 7 |
|
33 | 8 | struct CFG |
34 | 9 | blocks::Vector{BasicBlock} |
35 | 10 | index::Vector{Int} # map from instruction => basic-block number |
36 | 11 | # TODO: make this O(1) instead of O(log(n_blocks))? |
37 | 12 | end |
| 13 | + |
38 | 14 | copy(c::CFG) = CFG(BasicBlock[copy(b) for b in c.blocks], copy(c.index)) |
39 | 15 |
|
40 | 16 | function cfg_insert_edge!(cfg::CFG, from::Int, to::Int) |
|
0 commit comments