Skip to content

Commit

Permalink
porting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 13, 2022
1 parent 5daf11e commit 184afaa
Show file tree
Hide file tree
Showing 5 changed files with 1,912 additions and 1,891 deletions.
36 changes: 21 additions & 15 deletions src/utils.jl → src/EAUtils.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const EA_AS_PKG = Symbol(@__MODULE__) !== :Base # develop EA as an external package

module EAUtils

import ..EscapeAnalysis: EscapeAnalysis
import ..EA_AS_PKG
if EA_AS_PKG
import ..EscapeAnalysis
else
import Core.Compiler.EscapeAnalysis: EscapeAnalysis
Base.getindex(estate::EscapeAnalysis.EscapeState, @nospecialize(x)) =
Core.Compiler.getindex(estate, x)
end
const EA = EscapeAnalysis
const CC = Core.Compiler

let
README = normpath(dirname(@__DIR__), "README.md")
include_dependency(README)
@doc read(README, String) EA
end

# entries
# -------

using InteractiveUtils
@static if EA_AS_PKG
import InteractiveUtils: gen_call_with_extracted_types_and_kwargs

"""
@code_escapes [options...] f(args...)
Expand All @@ -24,8 +28,9 @@ As with `@code_typed` and its family, any of `code_escapes` keyword arguments ca
as the optional arguments like `@code_escpase interp=myinterp myfunc(myargs...)`.
"""
macro code_escapes(ex0...)
return InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :code_escapes, ex0)
return gen_call_with_extracted_types_and_kwargs(__module__, :code_escapes, ex0)
end
end # @static if EA_AS_PKG

"""
code_escapes(f, argtypes=Tuple{}; [world], [interp]) -> result::EscapeResult
Expand Down Expand Up @@ -402,9 +407,10 @@ end

end # module EAUtils

using .EAUtils:
code_escapes,
@code_escapes
export
code_escapes,
@code_escapes
if EA_AS_PKG
using .EAUtils: code_escapes, @code_escapes
export code_escapes, @code_escapes
else
using .EAUtils: code_escapes
export code_escapes
end
17 changes: 11 additions & 6 deletions src/EscapeAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Core.Compiler: # Core.Compiler specific definitions
if _TOP_MOD !== Core.Compiler
include(@__MODULE__, "disjoint_set.jl")
else
include(@__MODULE__, "compiler/EscapeAnalysis/disjoint_set.jl")
include(@__MODULE__, "compiler/ssair/EscapeAnalysis/disjoint_set.jl")
end

# XXX better to be IdSet{Int}?
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 @@ -981,10 +981,15 @@ function escape_call!(astate::AnalysisState, pc::Int, args::Vector{Any})
ft = argextype(first(args), ir, ir.sptypes, ir.argtypes)
f = singleton_type(ft)
if isa(f, Core.IntrinsicFunction)
# COMBAK we may break soundness and need to account for some aliasing here, e.g. `pointerref`
argtypes = Any[argextype(args[i], astate.ir) for i = 2:length(args)]
# XXX somehow `:call` expression can creep in here, ideally we should be able to do:
# argtypes = Any[argextype(args[i], astate.ir) for i = 2:length(args)]
argtypes = Any[]
for i = 2:length(args)
arg = args[i]
push!(argtypes, isexpr(arg, :call) ? Any : argextype(arg, ir))
end
intrinsic_nothrow(f, argtypes) || add_thrown_escapes!(astate, pc, args, 2)
return
return # TODO accounts for pointer operations
end
result = escape_builtin!(f, astate, pc, args)
if result === missing
Expand Down Expand Up @@ -1481,7 +1486,7 @@ end # if isdefined(Core, :arrayfreeze) && isdefined(Core, :arraythaw) && isdefi

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

end # baremodule EscapeAnalysis
Loading

0 comments on commit 184afaa

Please sign in to comment.