@@ -773,8 +773,27 @@ function add_kernel_state!(mod::LLVM.Module)
773
773
@assert isempty (uses (val))
774
774
unsafe_delete! (LLVM. parent (val), val)
775
775
elseif val isa LLVM. CallBase
776
- # the function is being passed as an argument, which we'll just permit,
777
- # because we expect to have rewritten the call down the line separately.
776
+ # the function is being passed as an argument. to avoid having to
777
+ # rewrite the target function, instead case the rewritten function to
778
+ # the old stateless type.
779
+ # XXX : we won't have to do this with opaque pointers.
780
+ position! (builder, val)
781
+ target_ft = called_type (val)
782
+ new_args = map (zip (parameters (target_ft),
783
+ arguments (val))) do (param_typ, arg)
784
+ if value_type (arg) != param_typ
785
+ const_bitcast (arg, param_typ)
786
+ else
787
+ arg
788
+ end
789
+ end
790
+ new_val = call! (builder, called_type (val), called_value (val), new_args,
791
+ operand_bundles (val))
792
+ callconv! (new_val, callconv (val))
793
+
794
+ replace_uses! (val, new_val)
795
+ @assert isempty (uses (val))
796
+ unsafe_delete! (LLVM. parent (val), val)
778
797
elseif val isa LLVM. StoreInst
779
798
# the function is being stored, which again we'll permit like before.
780
799
elseif val isa ConstantExpr
0 commit comments