@@ -462,6 +462,50 @@ function CC.abstract_call_known(interp::GPUInterpreter, @nospecialize(f),
462462 max_methods:: Int )
463463end
464464
465+ # Customize the optimization pipeline
466+ Base. iterate (compact:: CC.IncrementalCompact , state= nothing ) = CC. iterate (compact, state)
467+ Base. getindex (compact:: CC.IncrementalCompact , idx) = CC. getindex (compact, idx)
468+
469+ function deferred_pass! (ir)
470+ compact = CC. IncrementalCompact (ir)
471+ for ((old_idx, idx), stmt) in compact
472+ if CC. is_known_call (stmt, var"gpuc.deferred" , compact)
473+ @safe_show stmt
474+ end
475+ end
476+ CC. non_dce_finish! (compact)
477+ CC. simple_dce! (compact)
478+ ir = CC. complete (compact)
479+ return ir
480+ end
481+
482+ function CC. optimize (interp:: GPUInterpreter , opt:: CC.OptimizationState , caller:: CC.InferenceResult )
483+ CC. @timeit " optimizer" ir = CC. run_passes (opt. src, opt, caller)
484+ # Customizing the ipo_safe pipeline is a pain
485+ ir = deferred_pass! (ir)
486+ @static if VERSION >= v " 1.11.0-"
487+ CC. ipo_dataflow_analysis! (interp, ir, caller)
488+ end
489+ return CC. finish (interp, opt, ir, caller)
490+ end
491+
492+ function CC. typeinf_ircode (interp:: GPUInterpreter , mi:: CC.MethodInstance ,
493+ optimize_until:: Union{Integer,AbstractString,Nothing} )
494+ start_time = ccall (:jl_typeinf_timing_begin , UInt64, ())
495+ frame = CC. typeinf_frame (interp, mi, false )
496+ if frame === nothing
497+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
498+ return nothing , Any
499+ end
500+ (; result) = frame
501+ opt = CC. OptimizationState (frame, interp)
502+ ir = CC. run_passes (opt. src, opt, result, optimize_until)
503+ ir = deferred_pass! (ir)
504+ rt = CC. widenconst (CC. ignorelimited (result. result))
505+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
506+ return ir, rt
507+ end
508+
465509# # world view of the cache
466510using Core. Compiler: WorldView
467511
0 commit comments