809
809
yroot = find_root! (estate. aliasset, yidx)
810
810
if xroot ≠ yroot
811
811
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
817
812
return true
818
813
end
819
814
return false
@@ -851,6 +846,10 @@ function add_alias_change!(astate::AnalysisState, @nospecialize(x), @nospecializ
851
846
yidx = iridx (y, estate)
852
847
if xidx != = nothing && yidx != = nothing && ! isaliased (xidx, yidx, astate. estate)
853
848
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)
854
853
end
855
854
return nothing
856
855
end
@@ -937,6 +936,8 @@ function compute_frameinfo(ir::IRCode)
937
936
end
938
937
arrayinfo[idx] = dims
939
938
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
940
941
if isa (stmt, PhiNode)
941
942
values = stmt. values
942
943
local dims = nothing
@@ -946,12 +947,13 @@ function compute_frameinfo(ir::IRCode)
946
947
if isa (val, SSAValue) && haskey (arrayinfo, val. id)
947
948
if dims === nothing
948
949
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
952
953
end
953
954
end
954
955
end
956
+ @goto next_stmt
955
957
end
956
958
if dims != = nothing
957
959
arrayinfo[idx] = dims
@@ -1107,28 +1109,30 @@ function escape_new!(astate::AnalysisState, pc::Int, args::Vector{Any})
1107
1109
# fields are known precisely: propagate escape information imposed on recorded possibilities to the exact field values
1108
1110
infos = AliasInfo. infos
1109
1111
nf = length (infos)
1110
- objinfo = ignore_aliasinfo (objinfo)
1112
+ objinfo′ = ignore_aliasinfo (objinfo)
1111
1113
for i in 2 : nargs
1112
1114
i- 1 > nf && break # may happen when e.g. ϕ-node merges values with different types
1113
1115
arg = args[i]
1114
1116
add_alias_escapes! (astate, arg, infos[i- 1 ])
1115
1117
push! (infos[i- 1 ], - pc) # record def
1116
1118
# propagate the escape information of this object ignoring field information
1117
- add_escape_change! (astate, arg, objinfo)
1119
+ add_escape_change! (astate, arg, objinfo′ )
1118
1120
add_liveness_change! (astate, arg, pc)
1119
1121
end
1122
+ add_escape_change! (astate, obj, EscapeInfo (objinfo, AliasInfo)) # update with new AliasInfo
1120
1123
elseif isa (AliasInfo, Unindexable) && ! AliasInfo. array
1121
1124
# fields are known partially: propagate escape information imposed on recorded possibilities to all fields values
1122
1125
info = AliasInfo. info
1123
- objinfo = ignore_aliasinfo (objinfo)
1126
+ objinfo′ = ignore_aliasinfo (objinfo)
1124
1127
for i in 2 : nargs
1125
1128
arg = args[i]
1126
1129
add_alias_escapes! (astate, arg, info)
1127
1130
push! (info, - pc) # record def
1128
1131
# propagate the escape information of this object ignoring field information
1129
- add_escape_change! (astate, arg, objinfo)
1132
+ add_escape_change! (astate, arg, objinfo′ )
1130
1133
add_liveness_change! (astate, arg, pc)
1131
1134
end
1135
+ add_escape_change! (astate, obj, EscapeInfo (objinfo, AliasInfo)) # update with new AliasInfo
1132
1136
else
1133
1137
# this object has been used as array, but it is allocated as struct here (i.e. should throw)
1134
1138
# 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
1405
1409
isa (AliasInfo, Unindexable) && @goto record_unindexable_use
1406
1410
@label record_indexable_use
1407
1411
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
1410
1413
elseif isa (AliasInfo, Unindexable) && ! AliasInfo. array
1411
1414
@label record_unindexable_use
1412
1415
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
1415
1417
else
1416
1418
# this object has been used as array, but it is used as struct here (i.e. should throw)
1417
1419
# 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
1422
1424
# as the most conservative propagation
1423
1425
ssainfo = estate[SSAValue (pc)]
1424
1426
add_escape_change! (astate, obj, ssainfo)
1427
+ add_alias_change! (astate, obj, SSAValue (pc))
1425
1428
end
1426
1429
return false
1427
1430
end
@@ -1457,7 +1460,7 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar
1457
1460
add_alias_escapes! (astate, val, AliasInfo. infos[fidx])
1458
1461
push! (AliasInfo. infos[fidx], - pc) # record def
1459
1462
objinfo = EscapeInfo (objinfo, AliasInfo)
1460
- add_escape_change! (astate, obj, objinfo)
1463
+ add_escape_change! (astate, obj, objinfo) # update with new AliasInfo
1461
1464
# propagate the escape information of this object ignoring field information
1462
1465
add_escape_change! (astate, val, ignore_aliasinfo (objinfo))
1463
1466
elseif isa (AliasInfo, Unindexable) && ! AliasInfo. array
@@ -1466,7 +1469,7 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar
1466
1469
add_alias_escapes! (astate, val, AliasInfo. info)
1467
1470
push! (AliasInfo. info, - pc) # record def
1468
1471
objinfo = EscapeInfo (objinfo, AliasInfo)
1469
- add_escape_change! (astate, obj, objinfo)
1472
+ add_escape_change! (astate, obj, objinfo) # update with new AliasInfo
1470
1473
# propagate the escape information of this object ignoring field information
1471
1474
add_escape_change! (astate, val, ignore_aliasinfo (objinfo))
1472
1475
else
@@ -1546,6 +1549,7 @@ function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, arg
1546
1549
@label conservative_propagation
1547
1550
ssainfo = estate[SSAValue (pc)]
1548
1551
add_escape_change! (astate, ary, ssainfo)
1552
+ add_alias_change! (astate, ary, SSAValue (pc))
1549
1553
end
1550
1554
return true
1551
1555
end
0 commit comments