Skip to content

Commit 280550e

Browse files
committed
more tree work
1 parent b04fbcd commit 280550e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

SnoopCompileCore/src/snoop_inference.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ struct InferenceTimingNode
8888
end
8989

9090
function timingtree(cis, backtraces)
91-
remaining = Set(cis)
9291
root = InferenceTimingNode(Core.Compiler.Timings.ROOTmi.cache, nothing)
9392
# the cis are added in the order children-before-parents, we need to be able to reverse that
9493
# We index on MethodInstance rather than CodeInstance, because constprop can result in a distinct
@@ -97,52 +96,56 @@ function timingtree(cis, backtraces)
9796
backedges = [Int[] for _ in eachindex(cis)]
9897
for (i, ci) in pairs(cis)
9998
for e in ci.edges
99+
e isa CodeInstance || continue
100100
eidx = get(miidx, methodinstance(e), nothing)
101101
if eidx !== nothing
102102
push!(backedges[eidx], i)
103103
end
104104
end
105105
end
106106
# backtraces = Dict{MethodInstance,Any}(backtrace_log[i] => backtrace_log[i+1] for i in 1:2:length(backtrace_log))
107-
addchildren!(root, remaining, cis, backedges, miidx, backtraces)
107+
addchildren!(root, cis, backedges, miidx, backtraces)
108108
return root
109109
end
110110

111-
function addchildren!(parent::InferenceTimingNode, remaining::Set{CodeInstance}, miidx)
111+
function addchildren!(parent::InferenceTimingNode, handled::Set{CodeInstance}, miidx)
112112
for ci in parent.ci.edges
113+
ci isa CodeInstance || continue
113114
haskey(miidx, methodinstance(ci)) || continue
115+
ci handled && continue
114116
child = InferenceTimingNode(ci, nothing, parent)
115-
delete!(remaining, ci)
116-
addchildren!(child, remaining, miidx)
117+
push!(handled, ci)
118+
addchildren!(child, handled, miidx)
117119
end
118120
return parent
119121
end
120122

121-
function addchildren!(parent::InferenceTimingNode, remaining::Set{CodeInstance}, cis, backedges, miidx, backtraces)
123+
function addchildren!(parent::InferenceTimingNode, cis, backedges, miidx, backtraces)
124+
handled = Set{CodeInstance}()
122125
for (i, ci) in pairs(cis)
123-
ci remaining || continue
126+
ci handled && continue
124127
# Follow the backedges to the root
125128
j = i
126129
be = ci
127130
while true
128131
found = false
129132
for k in backedges[j]
130133
be = cis[k]
131-
if be remaining
134+
if be handled
132135
j = k
133136
found = true
134137
break
135138
end
136139
end
137140
found || break
138141
end
142+
be handled && continue
139143
# bt1, bt2 = get(backtraces, Core.Compiler.get_ci_mi(be), (nothing, nothing))
140144
# child = InferenceTimingNode(be, make_stacktrace(bt1, bt2), parent)
141145
child = InferenceTimingNode(be, get(backtraces, be, nothing), parent)
142-
delete!(remaining, be)
143-
addchildren!(child, remaining, miidx)
146+
push!(handled, be)
147+
addchildren!(child, handled, miidx)
144148
end
145-
# `remaining` may not be empty if there is constprop
146149
return parent
147150
end
148151

0 commit comments

Comments
 (0)