Skip to content

Commit

Permalink
inlining improvement that helps #10527
Browse files Browse the repository at this point in the history
this avoids inserting temporary variable copies of local variables
unless they might be assigned by an inner function.

Conflicts:
	base/inference.jl
  • Loading branch information
JeffBezanson committed Mar 18, 2015
1 parent 8c98205 commit 65c9d89
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type StaticVarInfo
sp::Tuple # static parameters tuple
cenv::ObjectIdDict # types of closed vars
vars::Array{Any,1} # names of args and locals
vinfo::Array{Any,1} # variable properties
label_counter::Int # index of the current highest label for this function
end

Expand Down Expand Up @@ -75,6 +76,14 @@ end

is_local(sv::StaticVarInfo, s::Symbol) = contains_is(sv.vars, s)
is_closed(sv::StaticVarInfo, s::Symbol) = haskey(sv.cenv, s)
function is_assigned_inner(sv::StaticVarInfo, s::Symbol)
for vi in sv.vinfo
if vi[1] === s
return (vi[3]&4) != 0
end
end
return false
end
is_global(sv::StaticVarInfo, s::Symbol) =
!is_local(sv,s) && !is_closed(sv,s) && !is_static_parameter(sv,s)

Expand Down Expand Up @@ -1412,7 +1421,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)

# types of closed vars
cenv = ObjectIdDict()
for vi = ((ast.args[2][3])::Array{Any,1})
for vi in (ast.args[2][3])::Array{Any,1}
vi::Array{Any,1}
vname = vi[1]
vtype = vi[2]
Expand All @@ -1430,7 +1439,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
s[1][vname] = vtype
end
end
sv = StaticVarInfo(sparams, cenv, vars, label_counter(body))
sv = StaticVarInfo(sparams, cenv, vars, vinflist, label_counter(body))
frame.sv = sv

recpts = IntSet() # statements that depend recursively on our value
Expand Down Expand Up @@ -1990,15 +1999,17 @@ end
function effect_free(e::ANY, sv, allow_volatile::Bool)
if isa(e,SymbolNode)
allow_volatile && return true
if is_global(sv, (e::SymbolNode).name)
if is_assigned_inner(sv, (e::SymbolNode).name) || is_global(sv, (e::SymbolNode).name)
return false
end
return true
end
if isa(e,Symbol)
allow_volatile && return true
if is_global(sv, e::Symbol)
if is_assigned_inner(sv, e::Symbol) || is_global(sv, e::Symbol)
return false
end
return true
end
if isa(e,Number) || isa(e,AbstractString) ||
isa(e,TopNode) || isa(e,QuoteNode) || isa(e,Type) || isa(e,Tuple)
Expand Down

0 comments on commit 65c9d89

Please sign in to comment.