-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Upgrade to LLVM 14 #11274
Comments
Preview of ongoing changes: #11374 |
I've hit an issue, which I don't quite understand zig0 fails to compile stage1:
This happen when trying to compile the Lines 648 to 650 in 5466e87
IIUC we are transforming this function of 0 arguments to a function that takes a pointer to return the value, then we are trying to add an attribute to this new parameter, but we crash because we are writing to the attribute array at a non exisiting offset. void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) {
CallInst *call_inst = unwrap<CallInst>(Call);
Type *llvm_type = unwrap<Type>(return_type);
// fixed to 0 ???
call_inst->addParamAttr(1, Attribute::getWithStructRetType(call_inst->getContext(), llvm_type));
}
LLVM_NODISCARD AttributeList addParamAttribute(
LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const {
return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
} |
I think my change of attribute argument was indeed correct. I also had to change the corresponding AddSretArg to also modify the first argument. I need to run the tests for the stage1 and see what's going on, but enough for today. |
Relevant video from Nikita Popov Opaque Pointers Are Coming My own take on the video:
Zig LLVM-backend isn't too much impacted AFAICT because we already store the pointee type in ZIR, we just need to pass the type down to LLVM. The "hard" part is just to pass the correct type in the correct place. And we should also be able to remove some pointer bitcast instructions. The transition should be smooth:
|
Status update, after replacing most #11587 prevents me from running the vector related tests: (vector.zig, select.zig, shuffle.zig and math.zig) There also seems to be some changes to Assembly in LLVM14 preventing me from running I also had to replace the call to Next steps for me:
Then I'll dig deeper into the |
This is off-by-one: Opaque pointers are the default in LLVM 15, and typed pointers will be removed in LLVM 16. LLVM 14 doesn't have production-ready opaque pointers support yet. The deprecations in LLVM 14 are preparatory work -- the new APIs are compatible with both typed and opaque pointers, while the old ones only support typed pointers. |
I've hit two issues which are related to a change of behavior between LLVM 13 and LLVM 14. First one I believe it's a bug on LLVM side related to constant vector of bools. I've opened an issue there: llvm/llvm-project#55522 The second one is about the saturating left shift arithmetic (implemented in #9679) zig/test/behavior/saturating_arithmetic.zig Line 212 in eff6bef
Under LLVM13, To reproduce: sat.ll ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare i8 @llvm.ushl.sat.i8(i8 %0, i8 %1) #3
define i8 @main() {
Entry:
%lhs_var = alloca i8, align 1
store i8 1, i8* %lhs_var, align 1
%0 = load i8, i8* %lhs_var, align 1
%1 = call i8 @llvm.ushl.sat.i8(i8 %0, i8 7)
ret i8 %1
}
So what should be the Zig behavior for Tagging @andrewrk who approved #1284 and @travisstaloch who worked on the implementation. |
Thanks for looking into this @gwenzek.
The Zig language definition of saturating arithmetic is that there is no possibility of undefined or poison. Any kind of overflow or large value will saturate the destination type. In cases where that cannot lower directly to LLVM saturating arithmetic, the LLVM backend must emit different instructions that maintain the Zig semantics. In this case, the lowering will need to be different depending on whether the RHS is comptime known or not. If it is comptime known and the value does not exceed the number of bits of the LHS, then it can be lowered with %a = call i8 @llvm.ushl.sat.i8(i8 %lhs, i8 %rhs)
%b = icmp gt i8 %rhs, 8
%result = select i1 %b, i8 255, i8 %a I suspect when using the LLVM IR Builder API, it will do the comptime logic for us automatically with basic constant folding. |
I've been working a bit more on this. The result are visible on gwenzek#4 But there are more important / harder blocker where I could need help.
|
I pushed a few commits to the The biggest problem I'm dealing with now is getting a ton of these:
when running the behavior tests. Is this your issue (4) above? Unfortunately for llvm/llvm-project#55522 we did not follow one crucial procedure which is ask the release manager to add the issue into the 14 milestone. So they are now done with 14 and will not be releasing any more bug fix releases. We have to live with this regression now. |
Wow thanks a lot Andrew for your help. I believe that the relocation errors you're seeing are a symptom of llvm/llvm-project#55522 I'm sorry about not following the procedure, but I didn't knew about it. I spent some time to reduce the issue and make it easy to reproduce. How long as 14.0.6 been out? It does seem something important enough, can we reach out to the release manager ? Who are they? |
No problem! It is me who should be thanking you since I looked at your diff for inspiration, especially on the SRet one.
Good to know, thank you!
This is entirely my fault. I was overwhelmed with trying to polish the self-hosted compiler that I dropped the ball on the LLVM 14 upgrade.
Here is a conversation I had on IRC with Tom Stellard:
After this I sent an email to Chris Lattner asking for permissions to edit milestones in the LLVM organization. I think that we are stuck with LLVM as it is until at least 15.0.0. My suggestion is that we should work around this bug in LLVM by lowering vector constants as if they were array constants. |
OK, I'll try that. I'm moving next week so I won't have a lot of time for Zig in the next 10 days. |
I hope the move goes well! I think in the meantime, I will take on this task and drive it to completion. |
Sorry, might be an uninformed comment here. But I think even if patches to fix zig on LLVM 14 can't get accepted into next point release, I am sure some distro maintainers would still include include them, so they can get rid of LLVM 13. |
Congrats @andrewrk on your work here ! IIUC LLVM14 migration is over, but I still need to work on the opaque pointer deprecation. I will create a new issue for that. Is there a list of LLVM bugs we want to be fixed for LLVM 15 (branch cutoff is next week) ? |
we've been contributing to the official list now here https://github.com/llvm/llvm-project/milestone/11 |
Relevant LLVM doc: https://llvm.org/docs/OpaquePointers.html
This lead to the deprecation of a number of C API function that now required to be given both the pointer LLVMValueRef and the pointee LLVMTypeRef:
codegen.cpp
make extensive use of all the above functions so a number of changes need to happen there.Trying to compile Zig with LLVM14 currentlly yield 200 warnings and 20 errors which look all related to the above changes.
I've started working on some changes, but I'm not really familiar with
codegen.cpp
and I'm afraid of making errors and passing the wrong types. But hopefully doing the most of the refactoring myself will allow @andrewrk to focus on the semantic.The text was updated successfully, but these errors were encountered: