Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.

Commit 355184f

Browse files
authored
Merge pull request #3 from JuliaDebug/vc/preprocess
add preprocess function
2 parents dbf706a + 09b88a6 commit 355184f

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

src/TypedCodeUtils.jl

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ canreflect(c::Callsite) = canreflect(c.callinfo)
5252
reflect(c::Callsite; optimize=true, params=current_params()) = reflect(c.callinfo, optimize=optimize, params=params)
5353

5454
include("process.jl")
55+
include("preprocess.jl")
5556

5657
##
5758
# Utils

src/preprocess.jl

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if VERSION >= v"1.1.0-DEV.215"
2+
function dce!(ci, mi)
3+
argtypes = Core.Compiler.matching_cache_argtypes(mi, nothing)[1]
4+
ir = Compiler.inflate_ir(ci, sptypes_from_meth_instance(mi),
5+
argtypes)
6+
compact = Core.Compiler.IncrementalCompact(ir, true)
7+
# Just run through the iterator without any processing
8+
Core.Compiler.foreach(x -> nothing, compact)
9+
ir = Core.Compiler.finish(compact)
10+
11+
Core.Compiler.replace_code_newstyle!(ci, ir, length(argtypes)-1)
12+
end
13+
else
14+
function dce!(ci, mi)
15+
end
16+
end
17+
18+
function preprocess!(::Consumer, ref::Reflection, optimize)
19+
if optimize
20+
# if the optimizer hasn't run, the IR hasn't been converted
21+
# to SSA form yet and dce is not legal
22+
dce!(ref.CI, ref.mi)
23+
end
24+
end

test/runtests.jl

+27-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ f(x, y) = x + y
1818

1919
# Cthulhu's inner loop
2020
function cthulhu(ref::Reflection)
21-
callsites = Callsite[]
2221

23-
invokes = filter((c)->lookthrough(identify_invoke, c), ref.CI.code)
24-
calls = filter((c)->lookthrough(identify_call, c), ref.CI.code)
22+
invokes = filter((c)->lookthrough(identify_invoke, c), ref.CI.code)
23+
calls = filter((c)->lookthrough(identify_call, c), ref.CI.code)
2524

2625
invokes = map((arg) -> process_invoke(DefaultConsumer(), ref, arg...), invokes)
27-
append!(callsites, invokes)
28-
calls = map((arg) -> process_call(DefaultConsumer(), ref, arg...), calls)
29-
append!(callsites, calls)
30-
26+
calls = map((arg) -> process_call( DefaultConsumer(), ref, arg...), calls)
27+
28+
callsites = append!(invokes, calls)
29+
@show callsites
3130
sort!(callsites, by=(c)->c.id)
3231
return callsites
3332
end
@@ -50,3 +49,24 @@ ref = reflect(h, Tuple{Int}, params=params)
5049
calls = cthulhu(ref)
5150
nextrefs = collect(reflect(c) for c in calls if TypedCodeUtils.canreflect(c))
5251

52+
if VERSION >= v"1.1.0-DEV.215" && Base.JLOptions().check_bounds == 0
53+
Base.@propagate_inbounds function f(x)
54+
@boundscheck error()
55+
end
56+
g(x) = @inbounds f(x)
57+
58+
params = TypedCodeUtils.current_params()
59+
ref = reflect(g, Tuple{Vector{Float64}}, params=params)
60+
@show ref.CI.code
61+
calls = cthulhu(ref)
62+
@test !isempty(calls)
63+
64+
TypedCodeUtils.preprocess!(DefaultConsumer(), ref, true)
65+
calls = cthulhu(ref)
66+
@test isempty(calls)
67+
68+
end
69+
70+
71+
72+

0 commit comments

Comments
 (0)