Skip to content

Commit cf74102

Browse files
committed
early take fix
1 parent c4e58b0 commit cf74102

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl

+22-18
Original file line numberDiff line numberDiff line change
@@ -809,11 +809,6 @@ end
809809
yroot = find_root!(estate.aliasset, yidx)
810810
if xroot yroot
811811
union!(estate.aliasset, xroot, yroot)
812-
xinfo = estate.escapes[xidx]
813-
yinfo = estate.escapes[yidx]
814-
xyinfo = xinfo ₑ yinfo
815-
estate.escapes[xidx] = xyinfo
816-
estate.escapes[yidx] = xyinfo
817812
return true
818813
end
819814
return false
@@ -851,6 +846,10 @@ function add_alias_change!(astate::AnalysisState, @nospecialize(x), @nospecializ
851846
yidx = iridx(y, estate)
852847
if xidx !== nothing && yidx !== nothing && !isaliased(xidx, yidx, astate.estate)
853848
pushfirst!(astate.changes, AliasChange(xidx, yidx))
849+
# add new escape change here so that it's shared among the expanded `aliasset`
850+
xinfo = estate.escapes[xidx]
851+
yinfo = estate.escapes[yidx]
852+
add_escape_change!(astate, x, xinfo ₑ yinfo)
854853
end
855854
return nothing
856855
end
@@ -937,6 +936,8 @@ function compute_frameinfo(ir::IRCode)
937936
end
938937
arrayinfo[idx] = dims
939938
elseif arrayinfo !== nothing
939+
# TODO this super limited alias analysis is able to handle only very simple cases
940+
# this should be replaced with a proper forward dimension analysis
940941
if isa(stmt, PhiNode)
941942
values = stmt.values
942943
local dims = nothing
@@ -946,12 +947,13 @@ function compute_frameinfo(ir::IRCode)
946947
if isa(val, SSAValue) && haskey(arrayinfo, val.id)
947948
if dims === nothing
948949
dims = arrayinfo[val.id]
949-
elseif dims arrayinfo[val.id]
950-
dims = nothing
951-
break
950+
continue
951+
elseif dims == arrayinfo[val.id]
952+
continue
952953
end
953954
end
954955
end
956+
@goto next_stmt
955957
end
956958
if dims !== nothing
957959
arrayinfo[idx] = dims
@@ -1107,28 +1109,30 @@ function escape_new!(astate::AnalysisState, pc::Int, args::Vector{Any})
11071109
# fields are known precisely: propagate escape information imposed on recorded possibilities to the exact field values
11081110
infos = AliasInfo.infos
11091111
nf = length(infos)
1110-
objinfo = ignore_aliasinfo(objinfo)
1112+
objinfo = ignore_aliasinfo(objinfo)
11111113
for i in 2:nargs
11121114
i-1 > nf && break # may happen when e.g. ϕ-node merges values with different types
11131115
arg = args[i]
11141116
add_alias_escapes!(astate, arg, infos[i-1])
11151117
push!(infos[i-1], -pc) # record def
11161118
# propagate the escape information of this object ignoring field information
1117-
add_escape_change!(astate, arg, objinfo)
1119+
add_escape_change!(astate, arg, objinfo)
11181120
add_liveness_change!(astate, arg, pc)
11191121
end
1122+
add_escape_change!(astate, obj, EscapeInfo(objinfo, AliasInfo)) # update with new AliasInfo
11201123
elseif isa(AliasInfo, Unindexable) && !AliasInfo.array
11211124
# fields are known partially: propagate escape information imposed on recorded possibilities to all fields values
11221125
info = AliasInfo.info
1123-
objinfo = ignore_aliasinfo(objinfo)
1126+
objinfo = ignore_aliasinfo(objinfo)
11241127
for i in 2:nargs
11251128
arg = args[i]
11261129
add_alias_escapes!(astate, arg, info)
11271130
push!(info, -pc) # record def
11281131
# propagate the escape information of this object ignoring field information
1129-
add_escape_change!(astate, arg, objinfo)
1132+
add_escape_change!(astate, arg, objinfo)
11301133
add_liveness_change!(astate, arg, pc)
11311134
end
1135+
add_escape_change!(astate, obj, EscapeInfo(objinfo, AliasInfo)) # update with new AliasInfo
11321136
else
11331137
# this object has been used as array, but it is allocated as struct here (i.e. should throw)
11341138
# update obj's field information and just handle this case conservatively
@@ -1405,13 +1409,11 @@ function escape_builtin!(::typeof(getfield), astate::AnalysisState, pc::Int, arg
14051409
isa(AliasInfo, Unindexable) && @goto record_unindexable_use
14061410
@label record_indexable_use
14071411
push!(AliasInfo.infos[fidx], pc) # record use
1408-
objinfo = EscapeInfo(objinfo, AliasInfo)
1409-
add_escape_change!(astate, obj, objinfo)
1412+
add_escape_change!(astate, obj, EscapeInfo(objinfo, AliasInfo)) # update with new AliasInfo
14101413
elseif isa(AliasInfo, Unindexable) && !AliasInfo.array
14111414
@label record_unindexable_use
14121415
push!(AliasInfo.info, pc) # record use
1413-
objinfo = EscapeInfo(objinfo, AliasInfo)
1414-
add_escape_change!(astate, obj, objinfo)
1416+
add_escape_change!(astate, obj, EscapeInfo(objinfo, AliasInfo)) # update with new AliasInfo
14151417
else
14161418
# this object has been used as array, but it is used as struct here (i.e. should throw)
14171419
# update obj's field information and just handle this case conservatively
@@ -1422,6 +1424,7 @@ function escape_builtin!(::typeof(getfield), astate::AnalysisState, pc::Int, arg
14221424
# as the most conservative propagation
14231425
ssainfo = estate[SSAValue(pc)]
14241426
add_escape_change!(astate, obj, ssainfo)
1427+
add_alias_change!(astate, obj, SSAValue(pc))
14251428
end
14261429
return false
14271430
end
@@ -1457,7 +1460,7 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar
14571460
add_alias_escapes!(astate, val, AliasInfo.infos[fidx])
14581461
push!(AliasInfo.infos[fidx], -pc) # record def
14591462
objinfo = EscapeInfo(objinfo, AliasInfo)
1460-
add_escape_change!(astate, obj, objinfo)
1463+
add_escape_change!(astate, obj, objinfo) # update with new AliasInfo
14611464
# propagate the escape information of this object ignoring field information
14621465
add_escape_change!(astate, val, ignore_aliasinfo(objinfo))
14631466
elseif isa(AliasInfo, Unindexable) && !AliasInfo.array
@@ -1466,7 +1469,7 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar
14661469
add_alias_escapes!(astate, val, AliasInfo.info)
14671470
push!(AliasInfo.info, -pc) # record def
14681471
objinfo = EscapeInfo(objinfo, AliasInfo)
1469-
add_escape_change!(astate, obj, objinfo)
1472+
add_escape_change!(astate, obj, objinfo) # update with new AliasInfo
14701473
# propagate the escape information of this object ignoring field information
14711474
add_escape_change!(astate, val, ignore_aliasinfo(objinfo))
14721475
else
@@ -1546,6 +1549,7 @@ function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, arg
15461549
@label conservative_propagation
15471550
ssainfo = estate[SSAValue(pc)]
15481551
add_escape_change!(astate, ary, ssainfo)
1552+
add_alias_change!(astate, ary, SSAValue(pc))
15491553
end
15501554
return true
15511555
end

0 commit comments

Comments
 (0)