@@ -491,6 +491,31 @@ function CC.handle_call!(todo::Vector{Pair{Int,Any}},
491491 return nothing
492492end
493493
494+ struct DeferredEdges
495+ edges:: Vector{MethodInstance}
496+ end
497+
498+ function CC. ipo_dataflow_analysis! (interp:: AbstractGPUInterpreter , ir:: CC.IRCode , caller:: CC.InferenceResult )
499+ edges = MethodInstance[]
500+ # @aviateks: Can we add this instead in handle_call
501+ for stmt in ir. stmts
502+ inst = stmt[:inst ]
503+ @show inst
504+ inst isa Expr || continue
505+ expr = inst:: Expr
506+ if expr. head === :foreigncall &&
507+ expr. args[1 ] == " extern gpuc.lookup"
508+ deferred_mi = expr. args[6 ]
509+ push! (edges, deferred_mi)
510+ end
511+ end
512+ unique! (edges)
513+ if ! isempty (edges)
514+ CC. stack_analysis_result! (caller, DeferredEdges (edges))
515+ end
516+ @invoke CC. ipo_dataflow_analysis! (interp:: CC.AbstractInterpreter , ir:: CC.IRCode , caller:: CC.InferenceResult )
517+ end
518+
494519# # world view of the cache
495520using Core. Compiler: WorldView
496521
@@ -768,20 +793,16 @@ function compile_method_instance(@nospecialize(job::CompilerJob), compiled::IdDi
768793 compiled[mi] = (; ci, func= llvm_func, specfunc= llvm_specfunc)
769794 end
770795
771- # We don't control the interp that codegen constructs for us above.
772- # So we have to scan the IR manually.
796+ # Collect the deferred edges
773797 outstanding = Any[]
774798 for mi in method_instances
775799 ci = compiled[mi]. ci
776- src = @atomic :monotonic ci. inferred
777- if src isa String
778- src = Core. Compiler. _uncompressed_ir (mi. def, src)
800+ edges = CC. traverse_analysis_results (ci) do @nospecialize result
801+ return result isa DeferredEdges ? result : return
779802 end
780- for expr in src. code
781- expr isa Expr || continue
782- if expr. head === :foreigncall &&
783- expr. args[1 ] == " extern gpuc.lookup"
784- deferred_mi = expr. args[6 ]
803+ @show edges
804+ if edges != = nothing
805+ for deferred_mi in (edges:: DeferredEdges ). edges
785806 if ! haskey (compiled, deferred_mi)
786807 push! (outstanding, deferred_mi)
787808 end
0 commit comments