Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
willtebbutt committed Jul 31, 2024
1 parent 58edeff commit 38b09ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/interpreter/ir_normalisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function normalise!(ir::IRCode, spnames::Vector{Symbol})
inst = splatnew_to_call(inst)
inst = intrinsic_to_function(inst)
inst = lift_getfield_and_others(inst)
inst = invoke_to_invoke_wrapper(inst)
ir.stmts.inst[n] = inst
end
return ir
Expand Down Expand Up @@ -182,3 +183,25 @@ end
__get_arg(x::GlobalRef) = getglobal(x.mod, x.name)
__get_arg(x::QuoteNode) = x.value
__get_arg(x) = x

"""
invoke_wrapper(f, TT, x::Vararg{Any, N}) where {N}
Equivalent to `invoke(f, TT, x...)`, but is a primitive that won't get lowered / inlined
away.
"""
invoke_wrapper(f, TT, x::Vararg{Any, N}) where {N} = invoke(f, TT, x...)

@is_primitive MinimalCtx Tuple{typeof(invoke_wrapper), Vararg}

"""
invoke_to_invoke_wrapper(inst)
Replaces `:call`s to `Core.invoke` with calls to `Tapir.invoke_wrapper`. This done to
prevent such calls being inlined / lowered away during optimisation, as access to them is
required later on.
"""
function invoke_to_invoke_wrapper(inst)
(Meta.isexpr(inst, :call) && inst.args[1] == invoke) || return inst
return Expr(:call, invoke_wrapper, inst.args[2:end]...)
end
2 changes: 2 additions & 0 deletions src/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,8 @@ end

test_for_invoke(x::Float64, y::Float64, z::Float64...) = x + sum(y)

inlinable_invoke_call(x::Float64) = invoke(test_for_invoke, Tuple{Float64}, x)

function generate_test_functions()
return Any[
(false, :allocs, nothing, const_tester),
Expand Down

0 comments on commit 38b09ef

Please sign in to comment.