-
Notifications
You must be signed in to change notification settings - Fork 340
Move llvmlite to LLVM 20 #1092
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
base: main
Are you sure you want to change the base?
Move llvmlite to LLVM 20 #1092
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
ffi/core.cpp
Outdated
auto context = LLVMGetGlobalContext(); | ||
LLVMContextSetOpaquePointers(context, enableOpaquePointers); | ||
// Opaque pointer support dropped https://reviews.llvm.org/D139441 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you meant "Typed pointer support dropped"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, thanks for spotting! Will update :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove these comments (and the same below).
ffi/core.cpp
Outdated
LLVMContextRef context = LLVMContextCreate(); | ||
LLVMContextSetOpaquePointers(context, enableOpaquePointers); | ||
// Opaque pointer support dropped https://reviews.llvm.org/D139441 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same as above.)
Hi, I found time to try and work on getting llvmlite to build with a version of llvm that's in Debian. I took this pull request and rebased it against 0.44.0, and then collapse the branch into a single diff to apply to the a Debian 0.44.0 version of the llvmlite package. I pushed what I've manage to get done to https://github.com/detrout/llvmlite/tree/llvm19 I noticed there's a bunch of code removed this pull request in a migration from passmanager to newpassmanager, though the llvmlite HEAD branch currently has both passmanager and newpassmanager modules. I don't know if it's intended to remove passmanager or not? The merged code almost works (at least on Debian unstable on a x86 cpu with python 3.13.2 and llvm-19.1.7) it's down to two test failures.
I did try running the build under arm64 using qemu and funny story, all the tests passed.
|
I'd also managed to run the two test failures in pdb, and for the llvmlite.tests.test_binding.TestObjectFile.test_object_file I found a possibly useful thing that there was a .text segment that had no contents. Though there were other text segments like (I think) .ltext that had some contents |
I am deep into places I don't understand and could use help. This is the test failure from test_binding.py::TestObjectFile.test_object_file() on an older x86_64 cpu I figured out how to print the assembly code. This is with llvm-19 and there's a .section section that the llvm-15 version doesn't use
This is what was generated from llvm 15.0.7 from conda.
|
Hi @detrout, thanks for looking into this! The pull request is due a rebase/merge of main for a long time now. The time I created this pull request all tests were passing which obviously isn't the case right now. May I know what are you trying to do with these changes? Meanwhile let me try running the tests again locally. |
What's going on is Debian is coming close to a freeze and our release team dropped our llvm-15 for having too many unfixed bugs. which then removed llvmlite, and that removes numba, and that breaks a whole bunch of scientific python packages. We do have llvm-19 and I when I saw this pull request and thought I'd take a stab at merging it. What I did was to take the original pull request and rebase it against the 0.44.0 release of llvmlite, to try and get something that might be reasonable for Debian to ship. So that's why I was aiming for the release version of llvmlite instead of HEAD. At this point I made progress more out of stubbornness than any deep understanding of llvm. Though I'm learning bits as I try to figure out whats going on. I pushed my updated debian package to https://salsa.debian.org/diane/llvmlite Though unlike the github version that has a flattened version of the llvm-19 compatibility patch. |
I'm not sure if this helps but llvmlite v0.44 do support LLVM 16 out of the box https://llvmlite.readthedocs.io/en/latest/release-notes.html |
It seems that the minimum version available in Debian testing is llvm-18 |
@detrout I looked the assembly assertion error and also reproduced it locally. It doesn't look like anything is wrong, just a slight update in the code layout I'm not exactly sure why. You can just update the test and move on |
I added 2 commits to deal with the test failures with llvm-19 at https://github.com/detrout/llvmlite/commits/llvm19/ what would you like next? try to rebase that change set against HEAD? |
For this PR? I don't think a rebase is required, I did merge the main branch into it. We would have to wait for the reviews to move forward. Right now numba/numba#9676 is the first hurdle before this can be merged. |
I'm happy to hear Debian's planning to ship an updated llvmlite+llvm release! 😄
I think this should work in principle, but I'd suggest rebasing this against HEAD instead. This PR precedes a few others where we improved support for LLVM opaque pointers. Without them, some of the code paths in Numba may not work with LLVM 17+. Alternatively, you could cherry-pick these PRs onto the 0.44 release, which I believe should work as the changes are mostly self-contained. The relevant PRs are #1159, #1158 and #1160 (merged in this order). Please let me know if you'd like some help with this. |
@yashssh Will numba/numba#9676 also be needed in Numba for it to work with LLVM >= 17? Would @detrout need to grab that and incorporate it into the Debian sources? |
Yes that's correct. @detrout if you are cherrypicking the changes on top of last release you will also need #1163 in addition to what Ricardo mentioned (perhaps it's easier to rebase on top of main). numba/numba#9676 introduces a switch to use either the Legacy or the New pass manager in Numba(defaulting to the new PM). That merge request is supposed to be followed by another code cleanup change that drops support for the legacy pass manager entirely in Numba. Post those changes we can merge this change in llvmlite. For simplifying things I have consolidated all required Numba changes in this draft pull request, which should allow you to move forward in Numba with a single patch. |
My first stab at building debianianized numba 0.61.0 with this patched version of llvmlite 0.44 didn't work and I need to figure out why. Thank you all for highlighting more pull requests that might be needed, hopefully I'll have some time soon to try and start plugging them together. |
@detrout we have rebased the required llvmlite LLVM19 changes on top of last release (v0.44) #1182 combined with necessary numba changes numba/numba#10011 should allow you to build and test everything with LLVM19. You might still have to add workarounds for the x86 failures you saw. |
llvmlite build on x86_64 and on arm64 (under qemu) with the recommend numba patch numba/numba#10011 and https://github.com/numba/numba/commit/1e2fb1d1c81880a645345991eb48e39b578e119d.patch I was able to get numba to build using llvmlite 0.44 with llvm-19. it built and ran it's tests under x86_64 but I got a timeout error for arm64 under qemu.... Though I know that numba tests take forever. |
List of changes in this MR - Delete legacy pass manager code - Delete typed pointer code - Update APIs that needs updating for llvm19 - Update refprune pass and its tests
I have rebased the changes on top of main since #1091 was merged. |
ffi/build.py
Outdated
elif version != 15: | ||
|
||
msg = ("Building llvmlite requires LLVM 15, got " | ||
if version not in (17, 18, 19): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're not going to be trying to do any testing with LLVM 17 or 18, so it'd probably be better to mandate 19 here. If someone wants to try 17, 18, 20, or whatever on their system / distribution, they should add their own patch here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the check to only be valid for v20 and throw warning for higher LLVM versions
@@ -1192,84 +1185,21 @@ class RefNormalizePass : public PassInfoMixin<RefNormalizePass> { | |||
RefNormalizePass() = default; | |||
|
|||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { | |||
RefNormalize().runOnFunction(F); | |||
if (RefNormalize().runOnFunction(F)) { | |||
return PreservedAnalyses::none(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit suspect that run()
previously always returned PreservedAnalyses::all()
... Out of interest, did you notice any particular problem during testing, or is this just added to ensure correctness in general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice any issue while testing. I assumed since we are making good changes to the underlying IR not preserving the analyses made more sense
#define LLVMLITE_ALIGN Align | ||
#define GET_ALIGN_VALUE(align) align.value() | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably replace uses of LLVMLITE_ALIGN
and GET_ALIGN_VALUE
with Align
and <align>.value()
now, and that would bring the code closer back to upstream. I initially needed to add these macros so that we could support different LLVM versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I don't think this is a critical issue for this PR though... Happy for it to be left as-is... one day I'd like to imagine we're moved over to OrcJIT and JITLink so that this code is no longer needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a small change, I'll update it
ffi/orcjit.cpp
Outdated
llvm::orc::SymbolMap sym_map; | ||
sym_map[mangled] = symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be unused - does it have some side-effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't recall how it ended up here, will remove
5: "Wasm", | ||
6: "XCOFF", | ||
} | ||
_object_formats = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Historically this got out of sync with Triple.h
in LLVM., I've just checked - this still matches the ObjectFormatType
enum in Triple.h
in LLVM 19.
if version == 20: | ||
pass | ||
elif version > 20: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit funny. I think we can change it to:
if version == 20: | |
pass | |
elif version > 20: | |
if version > 20: |
with a corresponding change below:
|
||
msg = ("Building llvmlite requires LLVM 15, got " | ||
"{!r}. Be sure to set LLVM_CONFIG to the right executable " | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponding change to the above:
else: | |
elif version < 20: |
With this PR and the package built by #1226, I get:
@yashssh Have you run on x86 as well? I presume you have not encountered segfaults in the test suite so far? |
Depends and contains changes introduced with #1091List of changes in this MR
StandardIntrumentations
checks function analysis invalidation in module passes as well: https://reviews.llvm.org/D146160TargetParser.getHostCPUFeatures()
returns aStringMap
: [llvm][TargetParser] Return StringMap from getHostCPUFeatures llvm/llvm-project#97824CodeGenOpt::Level
turned into an enum class: [NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes llvm/llvm-project#66295TODO:
and pass timer featureshave to be added(edited by @gmarkall to link to relevant review for dropping initialization APIs)