455
455
function compute_ir_rettype (ir:: IRCode )
456
456
rt = Union{}
457
457
for i = 1 : length (ir. stmts)
458
- stmt = ir. stmts[i ][:inst ]
458
+ stmt = ir[Core . SSAValue (i) ][:stmt ]
459
459
if isa (stmt, Core. Compiler. ReturnNode) && isdefined (stmt, :val )
460
460
rt = Core. Compiler. tmerge (Core. Compiler. argextype (stmt. val, ir), rt)
461
461
end
@@ -479,31 +479,34 @@ function compute_oc_signature(ir::IRCode, nargs::Int, isva::Bool)
479
479
return Tuple{argtypes... }
480
480
end
481
481
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 )
483
485
# NOTE: we need ir.argtypes[1] == typeof(env)
484
486
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
486
491
sig = compute_oc_signature (ir, nargs, isva)
487
492
rt = compute_ir_rettype (ir)
488
493
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)
491
501
src. slottypes = copy (ir. argtypes)
492
- src. rettype = rt
493
502
src = Core. Compiler. ir_to_codeinf! (src, ir)
494
503
config = compiler_config (device (); kernel= false )
495
504
return generate_opaque_closure (config, src, sig, rt, nargs, isva, env... )
496
505
end
497
506
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 )
505
508
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... )
507
510
end
508
511
509
512
function generate_opaque_closure (config:: CompilerConfig , src:: CodeInfo ,
@@ -529,8 +532,20 @@ function generate_opaque_closure(config::CompilerConfig, src::CodeInfo,
529
532
job = CompilerJob (mi, config) # this captures the current world age
530
533
531
534
# 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)
534
549
Core. Compiler. setindex! (GPUCompiler. ci_cache (job), ci, mi)
535
550
536
551
id = length (GPUCompiler. deferred_codegen_jobs) + 1
0 commit comments