3838
3939block_for_inst (cfg:: CFG , inst:: Int ) = block_for_inst (cfg. index, inst)
4040
41- function basic_blocks_starts (stmts:: Vector{Any} )
41+ @inline function basic_blocks_starts (stmts:: Vector{Any} )
4242 jump_dests = BitSet ()
4343 push! (jump_dests, 1 ) # function entry point
4444 # First go through and compute jump destinations
@@ -85,15 +85,14 @@ function basic_blocks_starts(stmts::Vector{Any})
8585end
8686
8787function compute_basic_blocks (stmts:: Vector{Any} )
88- bb_starts = basic_blocks_starts (stmts)
8988 # Compute ranges
89+ bb_starts = basic_blocks_starts (stmts) # ::BitSet and already sorted
9090 pop! (bb_starts, 1 )
91- basic_block_index = sort! (collect (bb_starts); alg= QuickSort)
92- blocks = BasicBlock[]
93- sizehint! (blocks, length (basic_block_index))
91+ basic_block_index = Int[bb for bb in bb_starts]
92+ blocks = Vector {BasicBlock} (undef, length (basic_block_index))
9493 let first = 1
95- for last in basic_block_index
96- push! ( blocks, BasicBlock (StmtRange (first, last - 1 ) ))
94+ for (i, last) in enumerate ( basic_block_index)
95+ blocks[i] = BasicBlock (StmtRange (first, last - 1 ))
9796 first = last
9897 end
9998 end
@@ -120,16 +119,14 @@ function compute_basic_blocks(stmts::Vector{Any})
120119 push! (blocks[block′]. preds, num)
121120 push! (b. succs, block′)
122121 end
123- elseif isa (terminator, Expr)
124- if terminator. head === :enter
125- # :enter gets a virtual edge to the exception handler and
126- # the exception handler gets a virtual edge from outside
127- # the function.
128- block′ = block_for_inst (basic_block_index, terminator. args[1 ]:: Int )
129- push! (blocks[block′]. preds, num)
130- push! (blocks[block′]. preds, 0 )
131- push! (b. succs, block′)
132- end
122+ elseif isexpr (terminator, :enter )
123+ # :enter gets a virtual edge to the exception handler and
124+ # the exception handler gets a virtual edge from outside
125+ # the function.
126+ block′ = block_for_inst (basic_block_index, terminator. args[1 ]:: Int )
127+ push! (blocks[block′]. preds, num)
128+ push! (blocks[block′]. preds, 0 )
129+ push! (b. succs, block′)
133130 end
134131 # statement fall-through
135132 if num + 1 <= length (blocks)
0 commit comments