Repository navigation
Lower Julia types in any library's context, validate CPU names and options, select an ABI - #734
Merged
Merged
Conversation
Contributor
|
Documentation preview: https://juliallvm.github.io/LLVM.jl/previews/PR734/ |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #734 +/- ##
==========================================
- Coverage 94.70% 94.40% -0.31%
==========================================
Files 59 59
Lines 9950 10020 +70
==========================================
+ Hits 9423 9459 +36
- Misses 527 561 +34
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
convert(LLVMType, T) refused contexts of libraries other than Julia's, as Julia's code generator only creates types in a context of its own LLVM. Lower the type in a temporary context of Julia's LLVM instead, and rebuild the result (literal types only) in the active context, so that code moved to another library, e.g. libLLVMGPU, can keep using the same call. isboxed uses the same temporary context, which is created and disposed of directly so that it is also freed while an exception is being handled.
Add LLVM.processors and LLVM.isprocessor, backed by new LLVMExtra functions around MCSubtargetInfo's processor table and isCPUStringValid. LLVM only warns about an unknown CPU name and falls back to a default processor, so callers that want to reject such names otherwise need their own table of processors.
LLVM.clopts used LLVMParseCommandLineOptions, which ignores parse failures, so an unknown option or an invalid value went unnoticed. Use LLVMParseCommandLineOptionsWithError (LLVM 24) instead, which LLVMExtra provides for older versions, and throw an LLVMException with its message.
Add an `abi` keyword to the TargetMachine constructor, which sets the ABI name of the machine's options (LLVM 18 and later), like `llc -target-abi`. Back-ends that support several ABIs select one this way, e.g., an AMDGPU back-end that keeps the 8-byte alignment of i128 that Julia needs before 1.12. Without it, the machine is created as before, also on older versions of LLVM.
maleadt
force-pushed
the
tb/interop-libraries
branch
2 times, most recently
from
November 26, 2026 14:10
adf4bde to
8a56a3b
Compare
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are the APIs that GPUCompiler needs once a top-level job moves its module to libLLVMGPU (JuliaGPU/GPUCompiler.jl#1122). Today GPUCompiler covers for them with tables and raw C API calls.
convert(LLVMType, T)andisboxed(T)in a context of any library. Julia's code generator only lowers types into a context of Julia's LLVM, soconvertrefused other contexts. It now lowers the type in a scratch context of Julia's LLVM and rebuilds it in the active context. That works becausejl_type_to_llvmonly produces literal types (void, integers, floating point, pointers, arrays, vectors, literal structs), on 1.10 up to master. In a context with typed pointers, types that contain pointers also need Julia's LLVM to support typed pointers (LLVM 16 or older). The rebuild costs about 2 µs. GPUCompiler can then delete its ownjulia_llvm_type, and Metal.jl'sconvertcalls keep working after the move.LLVM.processors(sti)andLLVM.isprocessor(sti, name), from new LLVMExtra functions aroundMCSubtargetInfo's processor table andisCPUStringValid. LLVM only warns about an unknown CPU and then ignores it, so callers that want to reject a bad CPU name currently keep their own table of processors (GPUCompiler has one for GCN).LLVM.cloptsthrows anLLVMExceptionwhen parsing fails. It usesLLVMParseCommandLineOptionsWithError, which LLVM 24 adds ([llvm-c] Add LLVMParseCommandLineOptionsWithError llvm/llvm-project#238461) and LLVMExtra backports to older versions. Before this, an unknown option or an invalid value was silently ignored. A failed call can still have set some options, as the docstring says.res/wrap.jlonly knows LLVM 15..23, so the generated wrapper always calls LLVMExtra. Regenerating once LLVM 24 is supported adds the branch to LLVM's own function.TargetMachine(t, triple; abi)sets the ABI name, likellc -target-abi. It usesLLVMCreateTargetMachineWithOptionsand so needs LLVM 18; below that it throws anArgumentError. With an emptyabithe machine is created as before. GPUCompiler uses it with libLLVMGPU's AMDGPU back-end (abi="i128:64", which keeps the 8-bytei128alignment that Julia needs before 1.12) instead of calling the options API directly.Each commit adds its NEWS entry under 10.8.
lib/andres/ABI.mdwere regenerated withres/wrap.jlin the commits that changeLLVMExtra.h. A release needs a new LLVMExtra_jll (and LLVMGPU_jll) built from this branch's merge commit, followed by the usual "Bump LLVMExtra, and the version to 10.8.0" commit.Validation (pegasus, locally built LLVMExtra):
Pkg.test()on Julia 1.12 (10957 pass) and 1.10 (9956 pass); 1.10 withLLVM_TEST_LIBRARYset to a standalone LLVM 23 (10026 pass).test/standalone/runtests.jlwith standalone LLVM 16 and 23 (185 + 12 pass); docs build on 1.12.LLVM_TEST_LIBRARYset to libLLVMGPU 1.4.1: the only failures (17 fail, 10 error) are tests that call the new LLVMExtra functions, which that build doesn't contain yet.res/wrap.jlregenerateslib/andres/ABI.mdwithout changes.abi="i128:64"with libLLVMGPU's AMDGPU back-end addsi128:64to the data layout. The test suite checks the ABI name with WebAssembly'sexperimental-mv(LLVM 19+), and the forwarding of the other options with X86.