Skip to content

Commit b677df8

Browse files
committed
Move BasicBlock to separate source file
This is so we can add type declarations to fields in ir.jl that are domtrees, by breaking the dependency loop between domtree.jl (uses basic blocks but defines domtrees) and ir.jl (uses domtrees but defined basic blocks).
1 parent 893f8dd commit b677df8

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

base/compiler/ssair/basicblock.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
"""
4+
Like UnitRange{Int}, but can handle the `last` field, being temporarily
5+
< first (this can happen during compacting)
6+
"""
7+
struct StmtRange <: AbstractUnitRange{Int}
8+
start::Int
9+
stop::Int
10+
end
11+
12+
first(r::StmtRange) = r.start
13+
last(r::StmtRange) = r.stop
14+
iterate(r::StmtRange, state=0) = (last(r) - first(r) < state) ? nothing : (first(r) + state, state + 1)
15+
16+
StmtRange(range::UnitRange{Int}) = StmtRange(first(range), last(range))
17+
18+
struct BasicBlock
19+
stmts::StmtRange
20+
preds::Vector{Int}
21+
succs::Vector{Int}
22+
end
23+
24+
function BasicBlock(stmts::StmtRange)
25+
return BasicBlock(stmts, Int[], Int[])
26+
end
27+
28+
function BasicBlock(old_bb, stmts)
29+
return BasicBlock(stmts, old_bb.preds, old_bb.succs)
30+
end
31+
32+
copy(bb::BasicBlock) = BasicBlock(bb.stmts, copy(bb.preds), copy(bb.succs))

base/compiler/ssair/driver.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ else
1010
end
1111
end
1212

13-
include("compiler/ssair/ir.jl")
13+
include("compiler/ssair/basicblock.jl")
1414
include("compiler/ssair/domtree.jl")
15+
include("compiler/ssair/ir.jl")
1516
include("compiler/ssair/slot2ssa.jl")
1617
include("compiler/ssair/queries.jl")
1718
include("compiler/ssair/passes.jl")

base/compiler/ssair/ir.jl

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,11 @@ struct ReturnNode
2323
ReturnNode() = new()
2424
end
2525

26-
"""
27-
Like UnitRange{Int}, but can handle the `last` field, being temporarily
28-
< first (this can happen during compacting)
29-
"""
30-
struct StmtRange <: AbstractUnitRange{Int}
31-
start::Int
32-
stop::Int
33-
end
34-
first(r::StmtRange) = r.start
35-
last(r::StmtRange) = r.stop
36-
iterate(r::StmtRange, state=0) = (last(r) - first(r) < state) ? nothing : (first(r) + state, state + 1)
37-
38-
StmtRange(range::UnitRange{Int}) = StmtRange(first(range), last(range))
39-
40-
struct BasicBlock
41-
stmts::StmtRange
42-
preds::Vector{Int}
43-
succs::Vector{Int}
44-
end
45-
function BasicBlock(stmts::StmtRange)
46-
return BasicBlock(stmts, Int[], Int[])
47-
end
48-
function BasicBlock(old_bb, stmts)
49-
return BasicBlock(stmts, old_bb.preds, old_bb.succs)
50-
end
51-
copy(bb::BasicBlock) = BasicBlock(bb.stmts, copy(bb.preds), copy(bb.succs))
52-
5326
struct CFG
5427
blocks::Vector{BasicBlock}
5528
index::Vector{Int} # map from instruction => basic-block number
5629
# TODO: make this O(1) instead of O(log(n_blocks))?
57-
domtree # TODO type
30+
domtree::DomTree
5831
end
5932

6033
function CFG(blocks::Vector{BasicBlock}, index::Vector{Int})
@@ -491,7 +464,7 @@ mutable struct IncrementalCompact
491464
result_lines::Vector{Int32}
492465
result_flags::Vector{UInt8}
493466
result_bbs::Vector{BasicBlock}
494-
result_domtree # TODO type
467+
result_domtree::DomTree
495468

496469
ssa_rename::Vector{Any}
497470
# `bb_rename_pred` is for renaming predecessors to the blocks they have

0 commit comments

Comments
 (0)