@@ -94,14 +94,17 @@ function getindex(tpdum::TwoPhaseDefUseMap, idx::Int)
9494 return TwoPhaseVectorView (tpdum. data, nelems, range)
9595end
9696
97- struct IRInterpretationState
97+ # TODO add `result::InferenceResult` & `parent::InferenceState` for this
98+ struct IRInterpretationState <: AbsIntState
9899 ir:: IRCode
99100 mi:: MethodInstance
100101 world:: UInt
101102 argtypes_refined:: Vector{Bool}
103+ sptypes:: Vector{VarState}
102104 tpdum:: TwoPhaseDefUseMap
103105 ssa_refined:: BitSet
104106 lazydomtree:: LazyDomtree
107+ callers_in_cycle:: Vector{InferenceState}
105108 function IRInterpretationState (interp:: AbstractInterpreter ,
106109 ir:: IRCode , mi:: MethodInstance , world:: UInt , argtypes:: Vector{Any} )
107110 argtypes = va_process_argtypes (optimizer_lattice (interp), argtypes, mi)
@@ -114,10 +117,40 @@ struct IRInterpretationState
114117 tpdum = TwoPhaseDefUseMap (length (ir. stmts))
115118 ssa_refined = BitSet ()
116119 lazydomtree = LazyDomtree (ir)
117- return new (ir, mi, world, argtypes_refined, tpdum, ssa_refined, lazydomtree)
120+ callers_in_cycle = Vector {InferenceState} ()
121+ return new (ir, mi, world, argtypes_refined, ir. sptypes, tpdum, ssa_refined, lazydomtree, callers_in_cycle)
118122 end
119123end
120124
125+ frame_instance (sv:: IRInterpretationState ) = sv. mi
126+ frame_parent (sv:: IRInterpretationState ) = nothing
127+ frame_cached (sv:: IRInterpretationState ) = false
128+ frame_src (sv:: IRInterpretationState ) = retrieve_code_info (sv. mi) # TODO optimize
129+ callers_in_cycle (sv:: IRInterpretationState ) = sv. callers_in_cycle
130+ # TODO
131+ merge_effects! (:: AbstractInterpreter , :: IRInterpretationState , :: Effects ) = return
132+ get_max_methods (:: IRInterpretationState , :: AbstractInterpreter ) = 3
133+ get_max_methods (@nospecialize (f), :: IRInterpretationState , :: AbstractInterpreter ) = 3
134+ ssa_def_slot (@nospecialize (arg), :: IRInterpretationState ) = nothing
135+ function bail_out_toplevel_call (:: AbstractInterpreter , :: InferenceLoopState , :: IRInterpretationState )
136+ return false
137+ end
138+ function bail_out_call (:: AbstractInterpreter , state:: InferenceLoopState , :: IRInterpretationState )
139+ return state. rt === Any && ! is_foldable (state. effects)
140+ end
141+ function bail_out_apply (:: AbstractInterpreter , @nospecialize (rt), :: IRInterpretationState )
142+ return rt === Any
143+ end
144+ should_infer_this_call (:: AbstractInterpreter , :: IRInterpretationState ) = true
145+ const_prop_enabled (:: AbstractInterpreter , :: IRInterpretationState , match:: MethodMatch ) = false
146+
147+ # TODO
148+ update_valid_age! (:: IRInterpretationState , :: WorldRange ) = return
149+ update_valid_age! (:: InferenceState , :: IRInterpretationState ) = return
150+ add_backedge! (:: IRInterpretationState , :: MethodInstance ) = return
151+ add_invoke_backedge! (:: IRInterpretationState , @nospecialize (invokesig:: Type ), :: MethodInstance ) = return
152+ add_mt_backedge! (:: IRInterpretationState , :: MethodTable , @nospecialize (typ)) = return
153+
121154function codeinst_to_ir (interp:: AbstractInterpreter , code:: CodeInstance )
122155 src = @atomic :monotonic code. inferred
123156 mi = code. def
@@ -129,13 +162,13 @@ function codeinst_to_ir(interp::AbstractInterpreter, code::CodeInstance)
129162 return inflate_ir (src, mi)
130163end
131164
132- function abstract_call_gf_by_type (interp :: AbstractInterpreter , @nospecialize (f) ,
133- arginfo :: ArgInfo , si :: StmtInfo , @nospecialize (atype),
134- sv :: IRCode , max_methods :: Int )
135- return CallMeta (Any, Effects (), NoCallInfo () )
165+ function from_interconditional ( :: AbstractLattice ,
166+ typ, :: IRInterpretationState , :: ArgInfo , maybecondinfo)
167+ @nospecialize typ maybecondinfo
168+ return widenconditional (typ )
136169end
137170
138- function collect_limitations! (@nospecialize (typ), :: IRCode )
171+ function collect_limitations! (@nospecialize (typ), :: IRInterpretationState )
139172 @assert ! isa (typ, LimitedAccuracy) " semi-concrete eval on recursive call graph"
140173 return typ
141174end
@@ -147,7 +180,7 @@ function concrete_eval_invoke(interp::AbstractInterpreter,
147180 if code === nothing
148181 return Pair {Any, Bool} (nothing , false )
149182 end
150- argtypes = collect_argtypes (interp, inst. args[2 : end ], nothing , irsv. ir )
183+ argtypes = collect_argtypes (interp, inst. args[2 : end ], nothing , irsv)
151184 argtypes === nothing && return Pair {Any, Bool} (Union{}, false )
152185 effects = decode_effects (code. ipo_purity_bits)
153186 if is_foldable (effects) && is_all_const_arg (argtypes, #= start=# 1 )
@@ -169,8 +202,10 @@ function concrete_eval_invoke(interp::AbstractInterpreter,
169202 return Pair {Any, Bool} (nothing , is_nothrow (effects))
170203end
171204
205+ abstract_eval_ssavalue (s:: SSAValue , sv:: IRInterpretationState ) = abstract_eval_ssavalue (s, sv. ir)
206+
172207function abstract_eval_phi_stmt (interp:: AbstractInterpreter , phi:: PhiNode , :: Int , irsv:: IRInterpretationState )
173- return abstract_eval_phi (interp, phi, nothing , irsv. ir )
208+ return abstract_eval_phi (interp, phi, nothing , irsv)
174209end
175210
176211function propagate_control_effects! (interp:: AbstractInterpreter , idx:: Int , stmt:: GotoIfNot ,
@@ -237,7 +272,7 @@ function reprocess_instruction!(interp::AbstractInterpreter,
237272 if isa (inst, Expr)
238273 head = inst. head
239274 if head === :call || head === :foreigncall || head === :new || head === :splatnew
240- (; rt, effects) = abstract_eval_statement_expr (interp, inst, nothing , ir, irsv. mi )
275+ (; rt, effects) = abstract_eval_statement_expr (interp, inst, nothing , irsv)
241276 # All other effects already guaranteed effect free by construction
242277 if is_nothrow (effects)
243278 ir. stmts[idx][:flag ] |= IR_FLAG_NOTHROW
@@ -261,7 +296,6 @@ function reprocess_instruction!(interp::AbstractInterpreter,
261296 head === :gc_preserve_end
262297 return false
263298 else
264- ccall (:jl_ , Cvoid, (Any,), inst)
265299 error (" reprocess_instruction!: unhandled expression found" )
266300 end
267301 elseif isa (inst, PhiNode)
@@ -276,8 +310,7 @@ function reprocess_instruction!(interp::AbstractInterpreter,
276310 elseif isa (inst, GlobalRef)
277311 # GlobalRef is not refinable
278312 else
279- ccall (:jl_ , Cvoid, (Any,), inst)
280- error ()
313+ error (" reprocess_instruction!: unhandled instruction found" )
281314 end
282315 if rt != = nothing && ! ⊑ (optimizer_lattice (interp), typ, rt)
283316 ir. stmts[idx][:type ] = rt
0 commit comments