Skip to content

Commit 22198e7

Browse files
committed
safe juia hackathon work
1 parent 30da248 commit 22198e7

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/jlgen.jl

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,31 @@ function CC.handle_call!(todo::Vector{Pair{Int,Any}},
516516
return nothing
517517
end
518518

519+
struct DeferredEdges
520+
edges::Vector{MethodInstance}
521+
end
522+
523+
function CC.ipo_dataflow_analysis!(interp::AbstractGPUInterpreter, ir::CC.IRCode, caller::CC.InferenceResult)
524+
edges = MethodInstance[]
525+
# @aviateks: Can we add this instead in handle_call
526+
for stmt in ir.stmts
527+
inst = stmt[:inst]
528+
@show inst
529+
inst isa Expr || continue
530+
expr = inst::Expr
531+
if expr.head === :foreigncall &&
532+
expr.args[1] == "extern gpuc.lookup"
533+
deferred_mi = expr.args[6]
534+
push!(edges, deferred_mi)
535+
end
536+
end
537+
unique!(edges)
538+
if !isempty(edges)
539+
CC.stack_analysis_result!(caller, DeferredEdges(edges))
540+
end
541+
@invoke CC.ipo_dataflow_analysis!(interp::CC.AbstractInterpreter, ir::CC.IRCode, caller::CC.InferenceResult)
542+
end
543+
519544
## world view of the cache
520545
using Core.Compiler: WorldView
521546

@@ -834,20 +859,16 @@ function compile_method_instance(@nospecialize(job::CompilerJob), compiled::IdDi
834859
compiled[mi] = (; ci, func=llvm_func, specfunc=llvm_specfunc)
835860
end
836861

837-
# We don't control the interp that codegen constructs for us above.
838-
# So we have to scan the IR manually.
862+
# Collect the deferred edges
839863
outstanding = Any[]
840864
for mi in method_instances
841865
ci = compiled[mi].ci
842-
src = @atomic :monotonic ci.inferred
843-
if src isa String
844-
src = Core.Compiler._uncompressed_ir(mi.def, src)
866+
edges = CC.traverse_analysis_results(ci) do @nospecialize result
867+
return result isa DeferredEdges ? result : return
845868
end
846-
for expr in src.code
847-
expr isa Expr || continue
848-
if expr.head === :foreigncall &&
849-
expr.args[1] == "extern gpuc.lookup"
850-
deferred_mi = expr.args[6]
869+
@show edges
870+
if edges !== nothing
871+
for deferred_mi in (edges::DeferredEdges).edges
851872
if !haskey(compiled, deferred_mi)
852873
push!(outstanding, deferred_mi)
853874
end

0 commit comments

Comments
 (0)