@@ -634,52 +634,47 @@ end
634634# =====================
635635
636636# TODO add `result::InferenceResult` and put the irinterp result into the inference cache?
637- struct IRInterpretationState
638- method_info:: MethodInfo
639- ir:: IRCode
640- mi:: MethodInstance
641- world:: UInt
642- curridx:: RefValue{Int}
643- argtypes_refined:: Vector{Bool}
644- sptypes:: Vector{VarState}
645- tpdum:: TwoPhaseDefUseMap
646- ssa_refined:: BitSet
647- lazydomtree:: LazyDomtree
648- valid_worlds:: RefValue{WorldRange}
649- edges:: Vector{Any}
650- parent # ::AbsIntState
651- end
652-
653- # AbsIntState
654- # ===========
655-
656- const AbsIntState = Union{InferenceState,IRInterpretationState}
637+ mutable struct IRInterpretationState
638+ const method_info:: MethodInfo
639+ const ir:: IRCode
640+ const mi:: MethodInstance
641+ const world:: UInt
642+ curridx:: Int
643+ const argtypes_refined:: Vector{Bool}
644+ const sptypes:: Vector{VarState}
645+ const tpdum:: TwoPhaseDefUseMap
646+ const ssa_refined:: BitSet
647+ const lazydomtree:: LazyDomtree
648+ valid_worlds:: WorldRange
649+ const edges:: Vector{Any}
650+ parent # ::Union{Nothing,AbsIntState}
657651
658- function IRInterpretationState (interp:: AbstractInterpreter ,
659- method_info:: MethodInfo , ir:: IRCode , mi:: MethodInstance , argtypes:: Vector{Any} ,
660- world:: UInt , min_world:: UInt , max_world:: UInt , parent:: AbsIntState )
661- curridx = RefValue (1 )
662- given_argtypes = Vector {Any} (undef, length (argtypes))
663- for i = 1 : length (given_argtypes)
664- given_argtypes[i] = widenslotwrapper (argtypes[i])
652+ function IRInterpretationState (interp:: AbstractInterpreter ,
653+ method_info:: MethodInfo , ir:: IRCode , mi:: MethodInstance , argtypes:: Vector{Any} ,
654+ world:: UInt , min_world:: UInt , max_world:: UInt )
655+ curridx = 1
656+ given_argtypes = Vector {Any} (undef, length (argtypes))
657+ for i = 1 : length (given_argtypes)
658+ given_argtypes[i] = widenslotwrapper (argtypes[i])
659+ end
660+ given_argtypes = va_process_argtypes (optimizer_lattice (interp), given_argtypes, mi)
661+ argtypes_refined = Bool[! ⊑ (optimizer_lattice (interp), ir. argtypes[i], given_argtypes[i])
662+ for i = 1 : length (given_argtypes)]
663+ empty! (ir. argtypes)
664+ append! (ir. argtypes, given_argtypes)
665+ tpdum = TwoPhaseDefUseMap (length (ir. stmts))
666+ ssa_refined = BitSet ()
667+ lazydomtree = LazyDomtree (ir)
668+ valid_worlds = WorldRange (min_world, max_world == typemax (UInt) ? get_world_counter () : max_world)
669+ edges = Any[]
670+ parent = nothing
671+ return new (method_info, ir, mi, world, curridx, argtypes_refined, ir. sptypes, tpdum,
672+ ssa_refined, lazydomtree, valid_worlds, edges, parent)
665673 end
666- given_argtypes = va_process_argtypes (optimizer_lattice (interp), given_argtypes, mi)
667- argtypes_refined = Bool[! ⊑ (optimizer_lattice (interp), ir. argtypes[i], given_argtypes[i])
668- for i = 1 : length (given_argtypes)]
669- empty! (ir. argtypes)
670- append! (ir. argtypes, given_argtypes)
671- tpdum = TwoPhaseDefUseMap (length (ir. stmts))
672- ssa_refined = BitSet ()
673- lazydomtree = LazyDomtree (ir)
674- valid_worlds = RefValue (WorldRange (min_world, max_world == typemax (UInt) ? get_world_counter () : max_world))
675- edges = Any[]
676- return IRInterpretationState (method_info, ir, mi, world, curridx, argtypes_refined,
677- ir. sptypes, tpdum, ssa_refined, lazydomtree,
678- valid_worlds, edges, parent)
679674end
680675
681676function IRInterpretationState (interp:: AbstractInterpreter ,
682- code:: CodeInstance , mi:: MethodInstance , argtypes:: Vector{Any} , world:: UInt , parent :: AbsIntState )
677+ code:: CodeInstance , mi:: MethodInstance , argtypes:: Vector{Any} , world:: UInt )
683678 @assert code. def === mi
684679 src = @atomic :monotonic code. inferred
685680 if isa (src, Vector{UInt8})
@@ -690,9 +685,14 @@ function IRInterpretationState(interp::AbstractInterpreter,
690685 method_info = MethodInfo (src)
691686 ir = inflate_ir (src, mi)
692687 return IRInterpretationState (interp, method_info, ir, mi, argtypes, world,
693- src. min_world, src. max_world, parent )
688+ src. min_world, src. max_world)
694689end
695690
691+ # AbsIntState
692+ # ===========
693+
694+ const AbsIntState = Union{InferenceState,IRInterpretationState}
695+
696696frame_instance (sv:: InferenceState ) = sv. linfo
697697frame_instance (sv:: IRInterpretationState ) = sv. mi
698698
@@ -736,16 +736,11 @@ has_conditional(𝕃::AbstractLattice, ::InferenceState) = has_conditional(𝕃)
736736has_conditional (:: AbstractLattice , :: IRInterpretationState ) = false
737737
738738# work towards converging the valid age range for sv
739- function update_valid_age! (sv:: InferenceState , valid_worlds:: WorldRange )
739+ function update_valid_age! (sv:: AbsIntState , valid_worlds:: WorldRange )
740740 valid_worlds = sv. valid_worlds = intersect (valid_worlds, sv. valid_worlds)
741741 @assert sv. world in valid_worlds " invalid age range update"
742742 return valid_worlds
743743end
744- function update_valid_age! (irsv:: IRInterpretationState , valid_worlds:: WorldRange )
745- valid_worlds = irsv. valid_worlds[] = intersect (valid_worlds, irsv. valid_worlds[])
746- @assert irsv. world in valid_worlds " invalid age range update"
747- return valid_worlds
748- end
749744
750745"""
751746 AbsIntStackUnwind(sv::AbsIntState)
@@ -799,13 +794,13 @@ function add_mt_backedge!(irsv::IRInterpretationState, mt::MethodTable, @nospeci
799794end
800795
801796get_curr_ssaflag (sv:: InferenceState ) = sv. src. ssaflags[sv. currpc]
802- get_curr_ssaflag (sv:: IRInterpretationState ) = sv. ir. stmts[sv. curridx[] ][:flag ]
797+ get_curr_ssaflag (sv:: IRInterpretationState ) = sv. ir. stmts[sv. curridx][:flag ]
803798
804799add_curr_ssaflag! (sv:: InferenceState , flag:: UInt8 ) = sv. src. ssaflags[sv. currpc] |= flag
805- add_curr_ssaflag! (sv:: IRInterpretationState , flag:: UInt8 ) = sv. ir. stmts[sv. curridx[] ][:flag ] |= flag
800+ add_curr_ssaflag! (sv:: IRInterpretationState , flag:: UInt8 ) = sv. ir. stmts[sv. curridx][:flag ] |= flag
806801
807802sub_curr_ssaflag! (sv:: InferenceState , flag:: UInt8 ) = sv. src. ssaflags[sv. currpc] &= ~ flag
808- sub_curr_ssaflag! (sv:: IRInterpretationState , flag:: UInt8 ) = sv. ir. stmts[sv. curridx[] ][:flag ] &= ~ flag
803+ sub_curr_ssaflag! (sv:: IRInterpretationState , flag:: UInt8 ) = sv. ir. stmts[sv. curridx][:flag ] &= ~ flag
809804
810805merge_effects! (:: AbstractInterpreter , caller:: InferenceState , effects:: Effects ) =
811806 caller. ipo_effects = merge_effects (caller. ipo_effects, effects)
0 commit comments