449449
450450const AliasSet = IntDisjointSet{Int}
451451
452+ const ArrayInfo = IdDict{Int,Vector{Int}}
453+
452454"""
453455 estate::EscapeState
454456
@@ -459,12 +461,13 @@ struct EscapeState
459461 escapes:: Vector{EscapeInfo}
460462 aliasset:: AliasSet
461463 nargs:: Int
464+ arrayinfo:: Union{Nothing,ArrayInfo} # TODO make this aware of aliasing of nested arrays
462465end
463- function EscapeState (nargs:: Int , nstmts:: Int )
466+ function EscapeState (nargs:: Int , nstmts:: Int , arrayinfo :: Union{Nothing,ArrayInfo} )
464467 escapes = EscapeInfo[
465468 1 ≤ i ≤ nargs ? ArgEscape () : ⊥ for i in 1 : (nargs+ nstmts)]
466469 aliaset = AliasSet (nargs+ nstmts)
467- return EscapeState (escapes, aliaset, nargs)
470+ return EscapeState (escapes, aliaset, nargs, arrayinfo )
468471end
469472function getindex (estate:: EscapeState , @nospecialize (x))
470473 xidx = iridx (x, estate)
@@ -618,13 +621,10 @@ struct LivenessChange <: Change
618621end
619622const Changes = Vector{Change}
620623
621- const ArrayInfo = IdDict{Int,Vector{Int}}
622-
623624struct AnalysisState
624625 ir:: IRCode
625626 estate:: EscapeState
626627 changes:: Changes
627- arrayinfo:: Union{Nothing,ArrayInfo} # TODO make this aware of aliasing of nested arrays
628628end
629629
630630function getinst (ir:: IRCode , idx:: Int )
@@ -646,10 +646,10 @@ function analyze_escapes(ir::IRCode, nargs::Int)
646646 stmts = ir. stmts
647647 nstmts = length (stmts) + length (ir. new_nodes. stmts)
648648
649- estate = EscapeState (nargs, nstmts)
650- changes = Changes () # keeps changes that happen at current statement
651649 tryregions, arrayinfo = compute_frameinfo (ir)
652- astate = AnalysisState (ir, estate, changes, arrayinfo)
650+ estate = EscapeState (nargs, nstmts, arrayinfo)
651+ changes = Changes () # keeps changes that happen at current statement
652+ astate = AnalysisState (ir, estate, changes)
653653
654654 local debug_itr_counter = 0
655655 while true
@@ -1628,7 +1628,7 @@ end
16281628function array_nd_index (astate:: AnalysisState , @nospecialize (ary), args:: Vector{Any} , nidxs:: Int = length (args))
16291629 isa (ary, SSAValue) || return nothing
16301630 aryid = ary. id
1631- arrayinfo = astate. arrayinfo
1631+ arrayinfo = astate. estate . arrayinfo
16321632 isa (arrayinfo, ArrayInfo) || return nothing
16331633 haskey (arrayinfo, aryid) || return nothing
16341634 dims = arrayinfo[aryid]
0 commit comments