Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NewOptimizer] Port #26826 to new optimizer #26981

Merged
merged 7 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions base/compiler/ssair/inlining2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,6 @@ function analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv,
return ConstantCase(quoted(linfo.inferred_const), method, Any[methsp...], metharg)
end

# Handle vararg functions
isva = na > 0 && method.isva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isva is used below still.

if isva
@assert length(atypes) >= na - 1
va_type = tuple_tfunc(Tuple{Any[widenconst(atypes[i]) for i in 1:length(atypes)]...})
atypes = Any[atypes[1:(na - 1)]..., va_type]
end

# Go see if we already have a pre-inferred result
res = find_inferred(linfo, atypes, sv)
res === nothing && return nothing

Expand Down Expand Up @@ -627,7 +618,8 @@ function analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv,
#verify_ir(ir2)

return InliningTodo(idx,
isva, isinvoke, isapply, na,
na > 0 && method.isva,
isinvoke, isapply, na,
method, Any[methsp...], metharg,
inline_linetable, ir2, linear_inline_eligible(ir2))
end
Expand Down Expand Up @@ -694,7 +686,6 @@ function handle_single_case!(ir, stmt, idx, case, isinvoke, todo)
end
end


function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::OptimizationState)
# todo = (inline_idx, (isva, isinvoke, isapply, na), method, spvals, inline_linetable, inline_ir, lie)
todo = Any[]
Expand Down Expand Up @@ -761,11 +752,13 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
# As a special case, if we can see the tuple() call, look at it's arguments to find
# our types. They can be more precise (e.g. f(Bool, A...) would be lowered as
# _apply(f, tuple(Bool)::Tuple{DataType}, A), which might not be precise enough to
# get a good method match. This pattern is used in the array code a bunch.
# get a good method match). This pattern is used in the array code a bunch.
if isa(def, SSAValue) && is_tuple_call(ir, ir[def])
for tuparg in ir[def].args[2:end]
push!(new_atypes, exprtype(tuparg, ir, ir.mod))
end
elseif isa(def, Argument) && def.n === length(ir.argtypes) && !isempty(sv.result_vargs)
append!(new_atypes, sv.result_vargs)
else
append!(new_atypes, typ.parameters)
end
Expand Down
12 changes: 5 additions & 7 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1536,9 +1536,9 @@ x26826 = rand()

apply26826(f, args...) = f(args...)

f26826(x) = apply26826(Base.getproperty, Foo26826(1, x), :b)
# We use getproperty to drive these tests because it requires constant
# propagation in order to lower to a well-inferred getfield call.
f26826(x) = apply26826(Base.getproperty, Foo26826(1, x), :b)

@test @inferred(f26826(x26826)) === x26826

Expand All @@ -1554,12 +1554,10 @@ g26826(x) = getfield26826(x, :a, :b)
# InferenceResult cache properly for varargs methods.
typed_code = Core.Compiler.code_typed(f26826, (Float64,))[1].first.code
found_well_typed_getfield_call = false
for stmnt in typed_code
if Meta.isexpr(stmnt, :(=)) && Meta.isexpr(stmnt.args[2], :call)
lhs = stmnt.args[2]
if lhs.args[1] == GlobalRef(Base, :getfield) && lhs.typ === Float64
global found_well_typed_getfield_call = true
end
for stmt in typed_code
lhs = Meta.isexpr(stmt, :(=)) ? stmt.args[2] : stmt
if Meta.isexpr(lhs, :call) && lhs.args[1] == GlobalRef(Base, :getfield) && lhs.typ === Float64
global found_well_typed_getfield_call = true
end
end

Expand Down