Skip to content

Commit

Permalink
small refactor of renumber_stuff! (JuliaLang#27688)
Browse files Browse the repository at this point in the history
* move changemap preprocessing/check into renumbering method

* give renumber_stuff! a better name
  • Loading branch information
jrevels committed Jun 21, 2018
1 parent f90d674 commit 3477f29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
10 changes: 8 additions & 2 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,13 @@ function is_known_call_p(e::Expr, @nospecialize(pred), src, spvals)
return (isa(f, Const) && pred(f.val)) || (isType(f) && pred(f.parameters[1]))
end

function renumber_stuff!(body::Vector{Any}, changemap::Vector{Int})
function renumber_ir_elements!(body::Vector{Any}, changemap::Vector{Int}, preprocess::Bool = true)
if preprocess
for i = 2:length(changemap)
changemap[i] += changemap[i - 1]
end
end
changemap[end] != 0 || return
for i = 1:length(body)
el = body[i]
if isa(el, GotoNode)
Expand All @@ -510,7 +516,7 @@ function renumber_stuff!(body::Vector{Any}, changemap::Vector{Int})
tgt = el.args[1]::Int
el.args[1] = tgt + changemap[tgt]
elseif !is_meta_expr_head(el.head)
renumber_stuff!(el.args, changemap)
renumber_ir_elements!(el.args, changemap, false)
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ function just_construct_ssa(ci::CodeInfo, code::Vector{Any}, nargs::Int, spvals:
idx += 1
oldidx += 1
end
for i = 2:length(changemap)
changemap[i] += changemap[i-1]
end
if changemap[end] != 0
renumber_stuff!(code, changemap)
end
renumber_ir_elements!(code, changemap)

inbounds_depth = 0 # Number of stacked inbounds
meta = Any[]
Expand Down
7 changes: 1 addition & 6 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,7 @@ function type_annotate!(sv::InferenceState)
end

if run_optimizer
for i = 2:length(changemap)
changemap[i] += changemap[i - 1]
end
if changemap[end] != 0
renumber_stuff!(body, changemap)
end
renumber_ir_elements!(body, changemap)
end

# finish marking used-undef variables
Expand Down

0 comments on commit 3477f29

Please sign in to comment.