@@ -487,6 +487,50 @@ function CC.abstract_call_known(interp::GPUInterpreter, @nospecialize(f),
487
487
max_methods:: Int )
488
488
end
489
489
490
+ # Customize the optimization pipeline
491
+ Base. iterate (compact:: CC.IncrementalCompact , state= nothing ) = CC. iterate (compact, state)
492
+ Base. getindex (compact:: CC.IncrementalCompact , idx) = CC. getindex (compact, idx)
493
+
494
+ function deferred_pass! (ir)
495
+ compact = CC. IncrementalCompact (ir)
496
+ for ((old_idx, idx), stmt) in compact
497
+ if CC. is_known_call (stmt, var"gpuc.deferred" , compact)
498
+ @safe_show stmt
499
+ end
500
+ end
501
+ CC. non_dce_finish! (compact)
502
+ CC. simple_dce! (compact)
503
+ ir = CC. complete (compact)
504
+ return ir
505
+ end
506
+
507
+ function CC. optimize (interp:: GPUInterpreter , opt:: CC.OptimizationState , caller:: CC.InferenceResult )
508
+ CC. @timeit " optimizer" ir = CC. run_passes (opt. src, opt, caller)
509
+ # Customizing the ipo_safe pipeline is a pain
510
+ ir = deferred_pass! (ir)
511
+ @static if VERSION >= v " 1.11.0-"
512
+ CC. ipo_dataflow_analysis! (interp, ir, caller)
513
+ end
514
+ return CC. finish (interp, opt, ir, caller)
515
+ end
516
+
517
+ function CC. typeinf_ircode (interp:: GPUInterpreter , mi:: CC.MethodInstance ,
518
+ optimize_until:: Union{Integer,AbstractString,Nothing} )
519
+ start_time = ccall (:jl_typeinf_timing_begin , UInt64, ())
520
+ frame = CC. typeinf_frame (interp, mi, false )
521
+ if frame === nothing
522
+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
523
+ return nothing , Any
524
+ end
525
+ (; result) = frame
526
+ opt = CC. OptimizationState (frame, interp)
527
+ ir = CC. run_passes (opt. src, opt, result, optimize_until)
528
+ ir = deferred_pass! (ir)
529
+ rt = CC. widenconst (CC. ignorelimited (result. result))
530
+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
531
+ return ir, rt
532
+ end
533
+
490
534
# # world view of the cache
491
535
using Core. Compiler: WorldView
492
536
0 commit comments