Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: overhaul EscapeAnalysis.jl #56849

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Compiler/src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ function ((; code_cache)::GetNativeEscapeCache)(codeinst::Union{CodeInstance,Met
codeinst isa CodeInstance || return false
end
argescapes = traverse_analysis_results(codeinst) do @nospecialize result
return result isa EscapeAnalysis.ArgEscapeCache ? result : nothing
return result isa EscapeAnalysis.EscapeCache ? result : nothing
end
if argescapes !== nothing
return argescapes
Expand All @@ -673,10 +673,10 @@ function refine_effects!(interp::AbstractInterpreter, opt::OptimizationState, sv
if !is_effect_free(sv.result.ipo_effects) && sv.all_effect_free && !isempty(sv.ea_analysis_pending)
ir = sv.ir
nargs = Int(opt.src.nargs)
estate = EscapeAnalysis.analyze_escapes(ir, nargs, optimizer_lattice(interp), get_escape_cache(interp))
argescapes = EscapeAnalysis.ArgEscapeCache(estate)
eresult = EscapeAnalysis.analyze_escapes(ir, nargs, get_escape_cache(interp))
argescapes = EscapeAnalysis.EscapeCache(eresult)
stack_analysis_result!(sv.result, argescapes)
validate_mutable_arg_escapes!(estate, sv)
validate_mutable_arg_escapes!(eresult, sv)
end

any_refinable(sv) || return false
Expand Down Expand Up @@ -718,7 +718,7 @@ function iscall_with_boundscheck(@nospecialize(stmt), sv::PostOptAnalysisState)
end

function check_all_args_noescape!(sv::PostOptAnalysisState, ir::IRCode, @nospecialize(stmt),
estate::EscapeAnalysis.EscapeState)
eresult::EscapeAnalysis.EscapeResult)
stmt isa Expr || return false
if isexpr(stmt, :invoke)
startidx = 2
Expand All @@ -737,7 +737,7 @@ function check_all_args_noescape!(sv::PostOptAnalysisState, ir::IRCode, @nospeci
end
# See if we can find the allocation
if isa(arg, Argument)
if has_no_escape(estate[arg])
if has_no_escape(eresult[arg])
# Even if we prove everything else effect_free, the best we can
# say is :effect_free_if_argmem_only
if sv.effect_free_if_argmem_only === nothing
Expand All @@ -748,23 +748,23 @@ function check_all_args_noescape!(sv::PostOptAnalysisState, ir::IRCode, @nospeci
end
return false
elseif isa(arg, SSAValue)
has_no_escape(estate[arg]) || return false
check_all_args_noescape!(sv, ir, ir[arg][:stmt], estate) || return false
has_no_escape(eresult[arg]) || return false
check_all_args_noescape!(sv, ir, ir[arg][:stmt], eresult) || return false
else
return false
end
end
return true
end

function validate_mutable_arg_escapes!(estate::EscapeAnalysis.EscapeState, sv::PostOptAnalysisState)
function validate_mutable_arg_escapes!(eresult::EscapeAnalysis.EscapeResult, sv::PostOptAnalysisState)
ir = sv.ir
for idx in sv.ea_analysis_pending
# See if any mutable memory was allocated in this function and determined
# not to escape.
inst = ir[SSAValue(idx)]
stmt = inst[:stmt]
if !check_all_args_noescape!(sv, ir, stmt, estate)
if !check_all_args_noescape!(sv, ir, stmt, eresult)
return sv.all_effect_free = false
end
end
Expand Down
Loading
Loading