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

Enable getting non-boxed LLVM type from Julia Type #56890

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wsmoses
Copy link
Contributor

@wsmoses wsmoses commented Dec 23, 2024

The current method :jl_type_to_llvm takes a pointer-to-bool parameter isboxed, which if non-null, is set to true if the Julia Type requires boxing. However, one may want to know the julia type without boxing and there is no mechanism for doing so. If the isboxed parameter is null and cannot be set, we can return the LLVM struct inside the jlvaluet as a way of returning the information.

Users like LLVM.jl, GPUCompiler.jl, and ClangCompiler.jl always request the isboxed parameter set to a non-null value and would not be affected: https://github.com/maleadt/LLVM.jl/blob/ff15977666b313c25e0b66302fa789898e00279e/src/interop/base.jl#L74C25-L74C40 https://github.com/maleadt/GPUCompiler.jl/blob/8fb9b50d85df93183aba852c59dd7ae8e58c0abc/src/driver.jl#L65 https://github.com/Gnimuc/ClangCompiler.jl/blob/0e503fe94dff1b6965a6b43d9527258ba0c9593c/src/utils.jl#L2 and an old commit of staticcompiler.jl (https://github.com/el-oso/StaticCompiler.jl/blob/145ef4ad788acb0dc2928ded53827636fdf37563/src/utils.jl#L5).

There are other users of this function on github

The current method :jl_type_to_llvm takes a pointer-to-bool parameter isboxed, which if non-null, is set to true if the Julia Type requires boxing. However, one may want to know the julia type without boxing and there is no mechanism for doing so. If the isboxed parameter is null and cannot be set, we can return the LLVM struct inside the jlvaluet as a way of returning the information.

Users like LLVM.jl, GPUCompiler.jl, and ClangCompiler.jl always request the isboxed parameter set to a non-null value and would not be affected: https://github.com/maleadt/LLVM.jl/blob/ff15977666b313c25e0b66302fa789898e00279e/src/interop/base.jl#L74C25-L74C40 https://github.com/maleadt/GPUCompiler.jl/blob/8fb9b50d85df93183aba852c59dd7ae8e58c0abc/src/driver.jl#L65 https://github.com/Gnimuc/ClangCompiler.jl/blob/0e503fe94dff1b6965a6b43d9527258ba0c9593c/src/utils.jl#L2 and an old commit of staticcompiler.jl (https://github.com/el-oso/StaticCompiler.jl/blob/145ef4ad788acb0dc2928ded53827636fdf37563/src/utils.jl#L5).

There are other users of this function on github
@wsmoses wsmoses requested review from gbaraldi and vtjnash December 23, 2024 05:30
@wsmoses wsmoses added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Dec 23, 2024
@vtjnash
Copy link
Member

vtjnash commented Dec 23, 2024

Why aren't you calling julia_struct_to_llvm if you want the C-API-semantics version of this function (rather than the Julia-semantics version normal here). The pointer-to-bool argument has been (nearly) deprecated for quite a few years now (since 0.6 IIRC), since it merely tests whether the caller is using the function correctly, but does not provide correct information back to the user.

@wsmoses
Copy link
Contributor Author

wsmoses commented Dec 23, 2024

Why aren't you calling julia_struct_to_llvm if you want the C-API-semantics version of this function (rather than the Julia-semantics version normal here). The pointer-to-bool argument has been (nearly) deprecated for quite a few years now (since 0.6 IIRC), since it merely tests whether the caller is using the function correctly, but does not provide correct information back to the user.

Iirc it’s not exported, though I can export it if that would be reasonable?

@vtjnash
Copy link
Member

vtjnash commented Dec 23, 2024

Yeah, that could be exported, though seems very rare someone should call that

@wsmoses
Copy link
Contributor Author

wsmoses commented Dec 23, 2024

Yeah, that could be exported, though seems very rare someone should call that

Okay made a version for export.

The reason we need it is essentially to avoid a GC error by figuring out the correct location of GC'd pointers in a gc_alloc call [and place atomic stores of nothing there rahter than undef]

@vtjnash
Copy link
Member

vtjnash commented Dec 23, 2024

Those properties are normally queried by calling jl_ptr_offset (in C). The julia_struct_to_llvm class of functions does call that, so it will usually derive similar info, but it requires some recursion and non-trivial extra computational effort to re-compute the byte offsets

@wsmoses
Copy link
Contributor Author

wsmoses commented Dec 23, 2024

jl_ptr_offset

our recursive fixer requires the llvm version of the type [to cast to and recurses through the LLVM Type with geps to find the GC objects]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants