Skip to content

Commit 9d839f9

Browse files
authored
Refactor irinterp refinement logic (#50155)
This continues the refactoring begun by #49340 to have irinterp consume the IR_FLAG_REFINED flag. This essentially has the same effect as the extra_reprocess bitset that irinterp takes, so we can remove that. However, there is a related issue where we would like to inform irinterp that we have *already* refined the type of a particular statement (likely using information not available to the irinterp) and would like it to just propagate that if possible. So bring back that extra bitset with a new name and these new semantics to make that possible. While I was working on this, I also noticed that the control hook I added in #48199 wasn't quite working as advertised. I don't currently need it, so rather than trying to work through an API without a concrete consumer, just nuke that hook for now. I do still think it'll be required at some point, but we can always add it back.
1 parent 320e00d commit 9d839f9

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

base/compiler/ssair/irinterp.jl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ function abstract_eval_phi_stmt(interp::AbstractInterpreter, phi::PhiNode, ::Int
4343
return abstract_eval_phi(interp, phi, nothing, irsv)
4444
end
4545

46-
function propagate_control_effects!(interp::AbstractInterpreter, idx::Int, stmt::GotoIfNot,
47-
irsv::IRInterpretationState, extra_reprocess::Union{Nothing,BitSet,BitSetBoundedMinPrioritySet})
48-
# Nothing to do for most abstract interpreters, but if the abstract
49-
# interpreter has control-dependent lattice effects, it can override
50-
# this method.
51-
return false
52-
end
53-
5446
function abstract_call(interp::AbstractInterpreter, arginfo::ArgInfo, irsv::IRInterpretationState)
5547
si = StmtInfo(true) # TODO better job here?
5648
(; rt, effects, info) = abstract_call(interp, arginfo, si, irsv)
@@ -102,8 +94,7 @@ function kill_terminator_edges!(irsv::IRInterpretationState, term_idx::Int, bb::
10294
end
10395

10496
function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union{Int,Nothing},
105-
@nospecialize(inst), @nospecialize(typ), irsv::IRInterpretationState,
106-
extra_reprocess::Union{Nothing,BitSet,BitSetBoundedMinPrioritySet})
97+
@nospecialize(inst), @nospecialize(typ), irsv::IRInterpretationState)
10798
ir = irsv.ir
10899
if isa(inst, GotoIfNot)
109100
cond = inst.cond
@@ -126,7 +117,7 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
126117
end
127118
return true
128119
end
129-
return propagate_control_effects!(interp, idx, inst, irsv, extra_reprocess)
120+
return false
130121
end
131122
rt = nothing
132123
if isa(inst, Expr)
@@ -204,9 +195,8 @@ function process_terminator!(ir::IRCode, @nospecialize(inst), idx::Int, bb::Int,
204195
end
205196
end
206197

207-
default_reprocess(::AbstractInterpreter, ::IRInterpretationState) = nothing
208198
function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState;
209-
extra_reprocess::Union{Nothing,BitSet} = default_reprocess(interp, irsv))
199+
externally_refined::Union{Nothing,BitSet} = nothing)
210200
interp = switch_to_irinterp(interp)
211201

212202
(; ir, tpdum, ssa_refined) = irsv
@@ -227,12 +217,11 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
227217
irsv.curridx = idx
228218
inst = ir.stmts[idx][:inst]
229219
typ = ir.stmts[idx][:type]
220+
flag = ir.stmts[idx][:flag]
230221
any_refined = false
231-
if extra_reprocess !== nothing
232-
if idx in extra_reprocess
233-
pop!(extra_reprocess, idx)
234-
any_refined = true
235-
end
222+
if (flag & IR_FLAG_REFINED) != 0
223+
any_refined = true
224+
ir.stmts[idx][:flag] &= ~IR_FLAG_REFINED
236225
end
237226
for ur in userefs(inst)
238227
val = ur[]
@@ -251,8 +240,9 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
251240
if typ === Bottom && (idx != lstmt || !is_terminator_or_phi)
252241
continue
253242
end
254-
if any_refined && reprocess_instruction!(interp,
255-
idx, bb, inst, typ, irsv, extra_reprocess)
243+
if (any_refined && reprocess_instruction!(interp,
244+
idx, bb, inst, typ, irsv)) ||
245+
(externally_refined !== nothing && idx in externally_refined)
256246
push!(ssa_refined, idx)
257247
inst = ir.stmts[idx][:inst]
258248
typ = ir.stmts[idx][:type]
@@ -277,9 +267,6 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
277267
# Slow path
278268
begin @label residual_scan
279269
stmt_ip = BitSetBoundedMinPrioritySet(length(ir.stmts))
280-
if extra_reprocess !== nothing
281-
append!(stmt_ip, extra_reprocess)
282-
end
283270

284271
# Slow Path Phase 1.A: Complete use scanning
285272
while !isempty(bb_ip)
@@ -289,6 +276,11 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
289276
for idx = stmts
290277
irsv.curridx = idx
291278
inst = ir.stmts[idx][:inst]
279+
flag = ir.stmts[idx][:flag]
280+
if (flag & IR_FLAG_REFINED) != 0
281+
ir.stmts[idx][:flag] &= ~IR_FLAG_REFINED
282+
push!(stmt_ip, idx)
283+
end
292284
for ur in userefs(inst)
293285
val = ur[]
294286
if isa(val, Argument)
@@ -335,7 +327,7 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
335327
inst = ir.stmts[idx][:inst]
336328
typ = ir.stmts[idx][:type]
337329
if reprocess_instruction!(interp,
338-
idx, nothing, inst, typ, irsv, stmt_ip)
330+
idx, nothing, inst, typ, irsv)
339331
append!(stmt_ip, tpdum[idx])
340332
end
341333
end

0 commit comments

Comments
 (0)