Skip to content

Commit

Permalink
update with JuliaLang/julia#42465
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 13, 2022
1 parent 5daf11e commit 370fa6f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/EscapeAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ._TOP_MOD: ==, getindex, setindex!
import Core:
MethodInstance, Const, Argument, SSAValue, PiNode, PhiNode, UpsilonNode, PhiCNode,
ReturnNode, GotoNode, GotoIfNot, SimpleVector, sizeof, ifelse, arrayset, arrayref,
arraysize
arraysize, ImmutableArray, arrayfreeze, mutating_arrayfreeze, arraythaw
import ._TOP_MOD: # Base definitions
@__MODULE__, @eval, @assert, @nospecialize, @inbounds, @inline, @noinline, @label, @goto,
!, !==, !=, , +, -, , <, , >, &, |, include, error, missing, copy,
Expand Down Expand Up @@ -481,7 +481,7 @@ end
"""
cache_escapes!(linfo::MethodInstance, estate::EscapeState, _::IRCode)
Transforms escape information of `estate` for interprocedural propagation,
Transforms escape information of `estate` for interprocedural propagation,
and caches it in a global cache that can then be looked up later when
`linfo` callsite is seen again.
"""
Expand Down Expand Up @@ -1214,6 +1214,8 @@ function escape_builtin!(::typeof(setfield!), astate::AnalysisState, pc::Int, ar
return true
end

const Arrayish = Union{Array,Core.ImmutableArray}

function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, args::Vector{Any})
length(args) 4 || return false
# check potential escapes from this arrayref call
Expand All @@ -1222,7 +1224,7 @@ function escape_builtin!(::typeof(arrayref), astate::AnalysisState, pc::Int, arg
argtypes = Any[argextype(args[i], astate.ir) for i in 2:length(args)]
boundcheckt = argtypes[1]
aryt = argtypes[2]
if !array_builtin_common_typecheck(boundcheckt, aryt, argtypes, 3)
if !array_builtin_common_typecheck(Arrayish, boundcheckt, aryt, argtypes, 3)
add_thrown_escapes!(astate, pc, args, 2)
end
# we don't track precise index information about this array and thus don't know what values
Expand Down Expand Up @@ -1283,7 +1285,7 @@ function escape_builtin!(::typeof(arrayset), astate::AnalysisState, pc::Int, arg
boundcheckt = argtypes[1]
aryt = argtypes[2]
valt = argtypes[3]
if !(array_builtin_common_typecheck(boundcheckt, aryt, argtypes, 4) &&
if !(array_builtin_common_typecheck(Array, boundcheckt, aryt, argtypes, 4) &&
arrayset_typecheck(aryt, valt))
add_thrown_escapes!(astate, pc, args, 2)
end
Expand Down Expand Up @@ -1463,22 +1465,18 @@ end
# return true
# end

if isdefined(Core, :arrayfreeze) && isdefined(Core, :arraythaw) && isdefined(Core, :mutating_arrayfreeze)

escape_builtin!(::typeof(Core.arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(Array, astate, args)
escape_builtin!(::typeof(Core.mutating_arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(Array, astate, args)
escape_builtin!(::typeof(Core.arraythaw), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(Core.ImmutableArray, astate, args)
function is_safe_immutable_array_op(@nospecialize(arytype), astate::AnalysisState, args::Vector{Any})
escape_builtin!(::typeof(arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(Array, astate, pc, args)
escape_builtin!(::typeof(mutating_arrayfreeze), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(Array, astate, pc, args)
escape_builtin!(::typeof(arraythaw), astate::AnalysisState, pc::Int, args::Vector{Any}) =
is_safe_immutable_array_op(ImmutableArray, astate, pc, args)
function is_safe_immutable_array_op(@nospecialize(arytype), astate::AnalysisState, pc::Int, args::Vector{Any})
length(args) == 2 || return false
argextype(args[2], astate.ir) ₜ arytype || return false
return true
end

end # if isdefined(Core, :arrayfreeze) && isdefined(Core, :arraythaw) && isdefined(Core, :mutating_arrayfreeze)

# NOTE define fancy package utilities when developing EA as an external package
if _TOP_MOD !== Core.Compiler
include(@__MODULE__, "utils.jl")
Expand Down

0 comments on commit 370fa6f

Please sign in to comment.