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

During kernel state rewrite, handle functions passed as arguments. #474

Merged
merged 1 commit into from
Jun 19, 2023
Merged
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
During kernel state rewrite, handle functions passed as arguments.
  • Loading branch information
maleadt committed Jun 19, 2023
commit d731d7976e137c2fc2c686e9f0ab4a93d27d9b6f
23 changes: 21 additions & 2 deletions src/irgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,27 @@ function add_kernel_state!(mod::LLVM.Module)
@assert isempty(uses(val))
unsafe_delete!(LLVM.parent(val), val)
elseif val isa LLVM.CallBase
# the function is being passed as an argument, which we'll just permit,
# because we expect to have rewritten the call down the line separately.
# the function is being passed as an argument. to avoid having to
# rewrite the target function, instead case the rewritten function to
# the old stateless type.
# XXX: we won't have to do this with opaque pointers.
position!(builder, val)
target_ft = called_type(val)
new_args = map(zip(parameters(target_ft),
arguments(val))) do (param_typ, arg)
if value_type(arg) != param_typ
const_bitcast(arg, param_typ)
else
arg
end
end
new_val = call!(builder, called_type(val), called_value(val), new_args,
operand_bundles(val))
callconv!(new_val, callconv(val))

replace_uses!(val, new_val)
@assert isempty(uses(val))
unsafe_delete!(LLVM.parent(val), val)
elseif val isa LLVM.StoreInst
# the function is being stored, which again we'll permit like before.
elseif val isa ConstantExpr
Expand Down
Loading