Skip to content

Commit 4511f85

Browse files
oscardssmithmaleadt
authored andcommitted
Updates for 1.12.
1 parent 6a79a53 commit 4511f85

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

src/compiler/compilation.jl

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ end
455455
function compute_ir_rettype(ir::IRCode)
456456
rt = Union{}
457457
for i = 1:length(ir.stmts)
458-
stmt = ir.stmts[i][:inst]
458+
stmt = ir[Core.SSAValue(i)][:stmt]
459459
if isa(stmt, Core.Compiler.ReturnNode) && isdefined(stmt, :val)
460460
rt = Core.Compiler.tmerge(Core.Compiler.argextype(stmt.val, ir), rt)
461461
end
@@ -479,31 +479,34 @@ function compute_oc_signature(ir::IRCode, nargs::Int, isva::Bool)
479479
return Tuple{argtypes...}
480480
end
481481

482-
function OpaqueClosure(ir::IRCode, @nospecialize env...; isva::Bool = false)
482+
function OpaqueClosure(ir::IRCode, @nospecialize env...;
483+
isva::Bool = false,
484+
slotnames::Union{Nothing,Vector{Symbol}}=nothing)
483485
# NOTE: we need ir.argtypes[1] == typeof(env)
484486
ir = Core.Compiler.copy(ir)
485-
nargs = length(ir.argtypes)-1
487+
# if the user didn't specify a definition MethodInstance or filename Symbol to use for the debuginfo, set a filename now
488+
ir.debuginfo.def === nothing && (ir.debuginfo.def = :var"generated IR for OpaqueClosure")
489+
nargtypes = length(ir.argtypes)
490+
nargs = nargtypes-1
486491
sig = compute_oc_signature(ir, nargs, isva)
487492
rt = compute_ir_rettype(ir)
488493
src = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
489-
src.slotnames = Base.fill(:none, nargs+1)
490-
src.slotflags = Base.fill(zero(UInt8), length(ir.argtypes))
494+
if slotnames === nothing
495+
src.slotnames = Base.fill(:none, nargtypes)
496+
else
497+
length(slotnames) == nargtypes || error("mismatched `argtypes` and `slotnames`")
498+
src.slotnames = slotnames
499+
end
500+
src.slotflags = Base.fill(zero(UInt8), nargtypes)
491501
src.slottypes = copy(ir.argtypes)
492-
src.rettype = rt
493502
src = Core.Compiler.ir_to_codeinf!(src, ir)
494503
config = compiler_config(device(); kernel=false)
495504
return generate_opaque_closure(config, src, sig, rt, nargs, isva, env...)
496505
end
497506

498-
function OpaqueClosure(src::CodeInfo, @nospecialize env...)
499-
src.inferred || throw(ArgumentError("Expected inferred src::CodeInfo"))
500-
mi = src.parent::Core.MethodInstance
501-
sig = Base.tuple_type_tail(mi.specTypes)
502-
method = mi.def::Method
503-
nargs = method.nargs-1
504-
isva = method.isva
507+
function OpaqueClosure(src::CodeInfo, @nospecialize env...; rettype, sig, nargs, isva=false)
505508
config = compiler_config(device(); kernel=false)
506-
return generate_opaque_closure(config, src, sig, src.rettype, nargs, isva, env...)
509+
return generate_opaque_closure(config, src, sig, rettype, nargs, isva, env...)
507510
end
508511

509512
function generate_opaque_closure(config::CompilerConfig, src::CodeInfo,
@@ -529,8 +532,20 @@ function generate_opaque_closure(config::CompilerConfig, src::CodeInfo,
529532
job = CompilerJob(mi, config) # this captures the current world age
530533

531534
# create a code instance and store it in the cache
532-
ci = CodeInstance(mi, rt, C_NULL, src, Int32(0), meth.primary_world, typemax(UInt),
533-
UInt32(0), UInt32(0), nothing, UInt8(0))
535+
interp = GPUCompiler.get_interpreter(job)
536+
owner = Core.Compiler.cache_owner(interp)
537+
exctype = Any
538+
inferred_const = C_NULL
539+
const_flags = Int32(0)
540+
min_world = meth.primary_world
541+
max_world = typemax(UInt)
542+
ipo_effects = UInt32(0)
543+
effects = UInt32(0)
544+
analysis_results = nothing
545+
relocatability = UInt8(0)
546+
ci = CodeInstance(mi, owner, rt, exctype, inferred_const, const_flags,
547+
const_flags, min_world, max_world, ipo_effects, effects,
548+
analysis_results, relocatability, src.debuginfo)
534549
Core.Compiler.setindex!(GPUCompiler.ci_cache(job), ci, mi)
535550

536551
id = length(GPUCompiler.deferred_codegen_jobs) + 1

0 commit comments

Comments
 (0)