-
Notifications
You must be signed in to change notification settings - Fork 57
add_input_arguments! for other backends #718
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
Conversation
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/irgen.jl b/src/irgen.jl
index 2d19961..d8ce883 100644
--- a/src/irgen.jl
+++ b/src/irgen.jl
@@ -922,8 +922,10 @@ function kernel_state_to_reference!(@nospecialize(job::CompilerJob), mod::LLVM.M
end
end
-function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
- entry::LLVM.Function, kernel_intrinsics::Dict)
+function add_input_arguments!(
+ @nospecialize(job::CompilerJob), mod::LLVM.Module,
+ entry::LLVM.Function, kernel_intrinsics::Dict
+ )
entry_fn = LLVM.name(entry)
# figure out which intrinsics are used and need to be added as arguments
@@ -976,7 +978,7 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
for (arg, new_arg) in zip(parameters(f), parameters(new_f))
LLVM.name!(new_arg, LLVM.name(arg))
end
- for (intr_fn, new_arg) in zip(used_intrinsics, parameters(new_f)[end-nargs+1:end])
+ for (intr_fn, new_arg) in zip(used_intrinsics, parameters(new_f)[(end - nargs + 1):end])
LLVM.name!(new_arg, kernel_intrinsics[intr_fn].name)
end
@@ -994,8 +996,10 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
end
value_map[f] = new_f
- clone_into!(new_f, f; value_map,
- changes=LLVM.API.LLVMCloneFunctionChangeTypeLocalChangesOnly)
+ clone_into!(
+ new_f, f; value_map,
+ changes = LLVM.API.LLVMCloneFunctionChangeTypeLocalChangesOnly
+ )
# we can't remove this function yet, as we might still need to rewrite any called,
# but remove the IR already
@@ -1011,7 +1015,7 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
# update other uses of the old function, modifying call sites to pass the arguments
function rewrite_uses!(f, new_f)
# update uses
- @dispose builder=IRBuilder() begin
+ return @dispose builder = IRBuilder() begin
for use in uses(f)
val = user(use)
if val isa LLVM.CallInst || val isa LLVM.InvokeInst || val isa LLVM.CallBrInst
@@ -1019,9 +1023,11 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
# forward the arguments
position!(builder, val)
new_val = if val isa LLVM.CallInst
- call!(builder, function_type(new_f), new_f,
- [arguments(val)..., parameters(callee_f)[end-nargs+1:end]...],
- operand_bundles(val))
+ call!(
+ builder, function_type(new_f), new_f,
+ [arguments(val)..., parameters(callee_f)[(end - nargs + 1):end]...],
+ operand_bundles(val)
+ )
else
# TODO: invoke and callbr
error("Rewrite of $(typeof(val))-based calls is not implemented: $val")
@@ -1064,7 +1070,7 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
val = user(use)
callee_f = LLVM.parent(LLVM.parent(val))
if val isa LLVM.CallInst || val isa LLVM.InvokeInst || val isa LLVM.CallBrInst
- replace_uses!(val, parameters(callee_f)[end-nargs+i])
+ replace_uses!(val, parameters(callee_f)[end - nargs + i])
else
error("Cannot rewrite unknown use of function: $val")
end |
3632069
to
07a039a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## tb/kernel_state_reference #718 +/- ##
=============================================================
- Coverage 74.30% 72.73% -1.57%
=============================================================
Files 24 24
Lines 3585 3584 -1
=============================================================
- Hits 2664 2607 -57
- Misses 921 977 +56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dce63fc
to
e9ad136
Compare
8dc09a1
to
a4143c5
Compare
Otherwise LGTM. |
Allows other backends to pass additional hidden arguments that can be accessed through intrinsics. Required for OpenCL device-side RNG support, where additional shared memory must be passed as arguments to the kernel. Replaces #717
a4143c5
to
26defb9
Compare
Allows other backends to pass additional hidden arguments that can be accessed through intrinsics. Required for OpenCL device-side RNG support, where additional shared memory must be passed as arguments to the kernel.
Allows other backends to pass additional hidden arguments that can be accessed through intrinsics. Required for OpenCL device-side RNG support, where additional shared memory must be passed as arguments to the kernel.
* Convert the kernel state back to a reference when needed. We're currently passing the kernel state object by value, disregarding the typical Julia calling convention, because there's known issues with `byval` lowering on NVPTX. For compatibility with back-ends that do not support passing kernel arguments by actual values, provide a pass that's conceptually the inverse of `lower_byval`, instead rewriting the kernel state object to be passed by reference, and loading from it at the beginning of the kernel. * `add_input_arguments!` for other backends (#718) Allows other backends to pass additional hidden arguments that can be accessed through intrinsics. Required for OpenCL device-side RNG support, where additional shared memory must be passed as arguments to the kernel. Co-authored-by: Simeon David Schaub <[email protected]>
Allows other backends to pass additional hidden arguments that can be accessed through intrinsics. Required for OpenCL device-side RNG support, where additional shared memory must be passed as arguments to the kernel.
Replaces #717