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

Update to changes to construct_ssa #234

Merged
merged 2 commits into from
Nov 23, 2023
Merged
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
10 changes: 8 additions & 2 deletions src/stage1/recurse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@
# SSA conversion
meth = mi.def::Method
domtree = construct_domtree(ir.cfg.blocks)
stmts = VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt
stmts = @static VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt
defuse_insts = scan_slot_def_use(Int(meth.nargs), ci, stmts)
ci.ssavaluetypes = Any[Any for i = 1:ci.ssavaluetypes]
ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance)
@static if VERSION > v"1.11.0-DEV.337"

Check warning on line 279 in src/stage1/recurse.jl

View check run for this annotation

Codecov / codecov/patch

src/stage1/recurse.jl#L279

Added line #L279 was not covered by tests
interp = NativeInterpreter() # dummy interpreter (not used by `construct_ssa!`)
opt_state=OptimizationState(mi, ci, interp)
ir = construct_ssa!(ci, ir, opt_state, domtree, defuse_insts, SimpleInferenceLattice.instance)
else
ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance)
end
ir = compact!(ir)

nfixedargs = Int(meth.nargs)
Expand Down
18 changes: 8 additions & 10 deletions src/stage2/abstractinterpret.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Core.Compiler: abstract_call_gf_by_type, abstract_call
using Core.Compiler: Const, isconstType, argtypes_to_type, tuple_tfunc, Const,
getfield_tfunc, _methods_by_ftype, VarTable, cache_lookup, nfields_tfunc,
import .CC: abstract_call_gf_by_type, abstract_call_opaque_closure
using .CC: Const, isconstType, argtypes_to_type, tuple_tfunc, Const,
getfield_tfunc, _methods_by_ftype, VarTable, nfields_tfunc,
ArgInfo, singleton_type, CallMeta, MethodMatchInfo, specialize_method,
PartialOpaque, UnionSplitApplyCallInfo, typeof_tfunc, apply_type_tfunc, instanceof_tfunc,
StmtInfo
using Core: PartialStruct
using Base.Meta

function Core.Compiler.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f),
function CC.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f),
arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype), sv::InferenceState, max_methods::Int)
(;argtypes) = arginfo
if interp.backward
Expand All @@ -25,7 +25,7 @@
mi = specialize_method(call.info.results.matches[1], preexisting=true)
ci = get(rinterp.unopt[rinterp.current_level], mi, nothing)
clos = AbstractCompClosure(rinterp.current_level, 1, call.info, ci.stmt_info)
clos = Core.PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos)
clos = PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos)

Check warning on line 28 in src/stage2/abstractinterpret.jl

View check run for this annotation

Codecov / codecov/patch

src/stage2/abstractinterpret.jl#L28

Added line #L28 was not covered by tests
elseif isa(call.info, RRuleInfo)
if rinterp.current_level == 1
clos = getfield_tfunc(call.info.rrule_rt, Const(2))
Expand Down Expand Up @@ -550,7 +550,7 @@
error()
end

function Core.Compiler.abstract_call_opaque_closure(interp::ADInterpreter,
function CC.abstract_call_opaque_closure(interp::ADInterpreter,

Check warning on line 553 in src/stage2/abstractinterpret.jl

View check run for this annotation

Codecov / codecov/patch

src/stage2/abstractinterpret.jl#L553

Added line #L553 was not covered by tests
closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool=true)

if isa(closure.source, AbstractCompClosure)
Expand All @@ -565,8 +565,6 @@
return infer_prim_closure(interp, closure.source, argtypes[2], sv)
end

rt = invoke(Core.Compiler.abstract_call_opaque_closure, Tuple{AbstractInterpreter, PartialOpaque, ArgInfo, InferenceState, Bool},
interp, closure, arginfo, sv, check)

return rt
return @invoke CC.abstract_call_opaque_closure(interp::AbstractInterpreter,

Check warning on line 568 in src/stage2/abstractinterpret.jl

View check run for this annotation

Codecov / codecov/patch

src/stage2/abstractinterpret.jl#L568

Added line #L568 was not covered by tests
closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool)
end
22 changes: 7 additions & 15 deletions src/stage2/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@
CC.lock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing
CC.unlock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing

struct CodeInfoView
d::Dict{MethodInstance, Any}
end

function CC.code_cache(ei::ADInterpreter)
while ei.current_level > lastindex(ei.opt)
push!(ei.opt, Dict{MethodInstance, Any}())
Expand All @@ -273,16 +269,6 @@
CC.may_optimize(ei::ADInterpreter) = true
CC.may_compress(ei::ADInterpreter) = false
CC.may_discard_trees(ei::ADInterpreter) = false
function CC.get(view::CodeInfoView, mi::MethodInstance, default)
r = get(view.d, mi, nothing)
if r === nothing
return default
end
if isa(r, OptimizationState)
r = r.src
end
return r::CodeInfo
end

function CC.add_remark!(interp::ADInterpreter, sv::InferenceState, msg)
key = CC.any(sv.result.overridden_by_const) ? sv.result : sv.linfo
Expand Down Expand Up @@ -365,11 +351,17 @@
end
=#

function CC.finish!(interp::ADInterpreter, caller::InferenceResult)
function _finish!(caller::InferenceResult)
effects = caller.ipo_effects
caller.src = Cthulhu.create_cthulhu_source(caller.src, effects)
end

@static if VERSION ≥ v"1.11.0-DEV.737"
CC.finish!(::ADInterpreter, caller::InferenceState) = _finish!(caller.result)

Check warning on line 360 in src/stage2/interpreter.jl

View check run for this annotation

Codecov / codecov/patch

src/stage2/interpreter.jl#L360

Added line #L360 was not covered by tests
else
CC.finish!(::ADInterpreter, caller::InferenceResult) = _finish!(caller)
end

function ir2codeinst(ir::IRCode, inst::CodeInstance, ci::CodeInfo)
CodeInstance(inst.def, inst.rettype, isdefined(inst, :rettype_const) ? inst.rettype_const : nothing,
Cthulhu.OptimizedSource(CC.copy(ir), ci, inst.inferred.isinlineable, CC.decode_effects(inst.purity_bits)),
Expand Down
Loading