Skip to content

Commit 146ae3d

Browse files
oxinaboxaviatesk
andauthored
Update to changes to construct_ssa (#234)
* =Update to changes to construct_ssa * adjust to the latest JuliaLang/julia#master Particularily the update for `CC.finish!` is essential. --------- Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
1 parent 5c980a0 commit 146ae3d

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/stage1/recurse.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,16 @@ function optic_transform!(ci, mi, nargs, N)
273273
# SSA conversion
274274
meth = mi.def::Method
275275
domtree = construct_domtree(ir.cfg.blocks)
276-
stmts = VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt
276+
stmts = @static VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt
277277
defuse_insts = scan_slot_def_use(Int(meth.nargs), ci, stmts)
278278
ci.ssavaluetypes = Any[Any for i = 1:ci.ssavaluetypes]
279-
ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance)
279+
@static if VERSION > v"1.11.0-DEV.337"
280+
interp = NativeInterpreter() # dummy interpreter (not used by `construct_ssa!`)
281+
opt_state=OptimizationState(mi, ci, interp)
282+
ir = construct_ssa!(ci, ir, opt_state, domtree, defuse_insts, SimpleInferenceLattice.instance)
283+
else
284+
ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance)
285+
end
280286
ir = compact!(ir)
281287

282288
nfixedargs = Int(meth.nargs)

src/stage2/abstractinterpret.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import Core.Compiler: abstract_call_gf_by_type, abstract_call
2-
using Core.Compiler: Const, isconstType, argtypes_to_type, tuple_tfunc, Const,
3-
getfield_tfunc, _methods_by_ftype, VarTable, cache_lookup, nfields_tfunc,
1+
import .CC: abstract_call_gf_by_type, abstract_call_opaque_closure
2+
using .CC: Const, isconstType, argtypes_to_type, tuple_tfunc, Const,
3+
getfield_tfunc, _methods_by_ftype, VarTable, nfields_tfunc,
44
ArgInfo, singleton_type, CallMeta, MethodMatchInfo, specialize_method,
55
PartialOpaque, UnionSplitApplyCallInfo, typeof_tfunc, apply_type_tfunc, instanceof_tfunc,
66
StmtInfo
77
using Core: PartialStruct
88
using Base.Meta
99

10-
function Core.Compiler.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f),
10+
function CC.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f),
1111
arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype), sv::InferenceState, max_methods::Int)
1212
(;argtypes) = arginfo
1313
if interp.backward
@@ -25,7 +25,7 @@ function Core.Compiler.abstract_call_gf_by_type(interp::ADInterpreter, @nospecia
2525
mi = specialize_method(call.info.results.matches[1], preexisting=true)
2626
ci = get(rinterp.unopt[rinterp.current_level], mi, nothing)
2727
clos = AbstractCompClosure(rinterp.current_level, 1, call.info, ci.stmt_info)
28-
clos = Core.PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos)
28+
clos = PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos)
2929
elseif isa(call.info, RRuleInfo)
3030
if rinterp.current_level == 1
3131
clos = getfield_tfunc(call.info.rrule_rt, Const(2))
@@ -550,7 +550,7 @@ function infer_prim_closure(interp::ADInterpreter, pc::PrimClosure, @nospecializ
550550
error()
551551
end
552552

553-
function Core.Compiler.abstract_call_opaque_closure(interp::ADInterpreter,
553+
function CC.abstract_call_opaque_closure(interp::ADInterpreter,
554554
closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool=true)
555555

556556
if isa(closure.source, AbstractCompClosure)
@@ -565,8 +565,6 @@ function Core.Compiler.abstract_call_opaque_closure(interp::ADInterpreter,
565565
return infer_prim_closure(interp, closure.source, argtypes[2], sv)
566566
end
567567

568-
rt = invoke(Core.Compiler.abstract_call_opaque_closure, Tuple{AbstractInterpreter, PartialOpaque, ArgInfo, InferenceState, Bool},
569-
interp, closure, arginfo, sv, check)
570-
571-
return rt
568+
return @invoke CC.abstract_call_opaque_closure(interp::AbstractInterpreter,
569+
closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool)
572570
end

src/stage2/interpreter.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,6 @@ CC.get_inference_cache(ei::ADInterpreter) = get_inference_cache(ei.native_interp
260260
CC.lock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing
261261
CC.unlock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing
262262

263-
struct CodeInfoView
264-
d::Dict{MethodInstance, Any}
265-
end
266-
267263
function CC.code_cache(ei::ADInterpreter)
268264
while ei.current_level > lastindex(ei.opt)
269265
push!(ei.opt, Dict{MethodInstance, Any}())
@@ -273,16 +269,6 @@ end
273269
CC.may_optimize(ei::ADInterpreter) = true
274270
CC.may_compress(ei::ADInterpreter) = false
275271
CC.may_discard_trees(ei::ADInterpreter) = false
276-
function CC.get(view::CodeInfoView, mi::MethodInstance, default)
277-
r = get(view.d, mi, nothing)
278-
if r === nothing
279-
return default
280-
end
281-
if isa(r, OptimizationState)
282-
r = r.src
283-
end
284-
return r::CodeInfo
285-
end
286272

287273
function CC.add_remark!(interp::ADInterpreter, sv::InferenceState, msg)
288274
key = CC.any(sv.result.overridden_by_const) ? sv.result : sv.linfo
@@ -365,11 +351,17 @@ function CC.optimize(interp::ADInterpreter, opt::OptimizationState,
365351
end
366352
=#
367353

368-
function CC.finish!(interp::ADInterpreter, caller::InferenceResult)
354+
function _finish!(caller::InferenceResult)
369355
effects = caller.ipo_effects
370356
caller.src = Cthulhu.create_cthulhu_source(caller.src, effects)
371357
end
372358

359+
@static if VERSION v"1.11.0-DEV.737"
360+
CC.finish!(::ADInterpreter, caller::InferenceState) = _finish!(caller.result)
361+
else
362+
CC.finish!(::ADInterpreter, caller::InferenceResult) = _finish!(caller)
363+
end
364+
373365
function ir2codeinst(ir::IRCode, inst::CodeInstance, ci::CodeInfo)
374366
CodeInstance(inst.def, inst.rettype, isdefined(inst, :rettype_const) ? inst.rettype_const : nothing,
375367
Cthulhu.OptimizedSource(CC.copy(ir), ci, inst.inferred.isinlineable, CC.decode_effects(inst.purity_bits)),

0 commit comments

Comments
 (0)