@@ -126,10 +126,11 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
126
126
block = block_for_inst (ir, idx)
127
127
inline_into_block! (state, block)
128
128
129
- if ! isempty (inlinee_cfg. blocks[1 ]. preds)
129
+ if length (inlinee_cfg. blocks[1 ]. preds) > 1
130
130
need_split_before = true
131
+ else
132
+ @assert inlinee_cfg. blocks[1 ]. preds[1 ] == 0
131
133
end
132
-
133
134
last_block_idx = last (state. cfg. blocks[block]. stmts)
134
135
if false # TODO : ((idx+1) == last_block_idx && isa(ir[SSAValue(last_block_idx)], GotoNode))
135
136
need_split = false
@@ -166,12 +167,18 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
166
167
end
167
168
new_block_range = (length (state. new_cfg_blocks)- length (inlinee_cfg. blocks)+ 1 ): length (state. new_cfg_blocks)
168
169
169
- # Fixup the edges of the newely added blocks
170
+ # Fixup the edges of the newly added blocks
170
171
for (old_block, new_block) in enumerate (bb_rename_range)
171
172
if old_block != 1 || need_split_before
172
173
p = state. new_cfg_blocks[new_block]. preds
173
174
let bb_rename_range = bb_rename_range
174
175
map! (p, p) do old_pred_block
176
+ # the meaning of predecessor 0 depends on the block we encounter it:
177
+ # - in the first block, it represents the function entry and so needs to be re-mapped
178
+ if old_block == 1 && old_pred_block == 0
179
+ return first (bb_rename_range) - 1
180
+ end
181
+ # - elsewhere, it represents external control-flow from a caught exception which is un-affected by inlining
175
182
return old_pred_block == 0 ? 0 : bb_rename_range[old_pred_block]
176
183
end
177
184
end
@@ -186,10 +193,6 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
186
193
end
187
194
end
188
195
189
- if need_split_before
190
- push! (state. new_cfg_blocks[first (bb_rename_range)]. preds, first (bb_rename_range)- 1 )
191
- end
192
-
193
196
any_edges = false
194
197
for (old_block, new_block) in enumerate (bb_rename_range)
195
198
if (length (state. new_cfg_blocks[new_block]. succs) == 0 )
@@ -399,7 +402,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
399
402
else
400
403
bb_offset, post_bb_id = popfirst! (todo_bbs)
401
404
# This implements the need_split_before flag above
402
- need_split_before = ! isempty (item. ir. cfg. blocks[1 ]. preds)
405
+ need_split_before = length (item. ir. cfg. blocks[1 ]. preds) > 1
403
406
if need_split_before
404
407
finish_current_bb! (compact, 0 )
405
408
end
0 commit comments