-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support lowering VAArgOp #865
Conversation
CC @ghehg @sitio-couto since I can't add reviewers. |
Just fixed that. |
Thanks for fixing this, we indeed need that op in the LLVM dialect to make progress. We are very afraid of the technical debt though, specially the ones outside CIR stuff. The LLVM part should be done upstream first and cherry-picked here. It should also be in a different PR from the actual EDIT: perhaps this won't be needed at all. |
Thanks for working on this. This is necessary along right direction. I agree with @bcardosolopes, it might be better if we have LLVM dialect part of change landed in upstream first, then other parts of this PR can just rebase on it, and go. This way we don't have to sync changes of upstream PR and that of this PR. Let me know what you think. |
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.
Hey @ChuanqiXu9!
I really like this approach—it's clean and a great contribution to the LLVM Dialect.
I don't think we should handle different architecture in clangir.
AFAIK, we need to handle targets in CIR to some extent, since LLVM IR doesn’t cover all the details. Still, this is a good abstraction.
One concern I have is that, for some reason, the OG Clang doesn’t use the LLVM va_arg
instruction when lowering C/C++.
Maybe it's just technical debt. Maybe it's something more complex, like optimizations (choosing between reg or mem like the example above).
By emitting a different IR than the original CodeGen, we might be abstracting something we shouldn’t, like an optimization or argument-passing correctness.
Just something to keep in mind, otherwise LGTM!
Yea, same feedback in the issue. The PR should work along the lines of Aarch64 here. |
Agreed. The upstreaming process looks good. I didn't find the fact that we don't use va_arg for lowering X86 just now. It is a surprise to me too. I just tried the following example in x86-64:
with clangir's pipeline and it builds and runs well. So at least va_arg can work in X86-64. I agree with it will be better to make the lowering code to be more consistent with the traditional code gen part. (but I feel it may not be a requirement or a goal to make the generated LLVM code the same. Since we will have optimizations in clang ir. So it won't be the same.) But I am wondering if it is good to leave this patch as a fall back mechanism. I mean, this patch won't be conflicting later if we want to introduce the almost the same structure for X86-64 targets. It will be pretty helpful for people who like to run clangir on real world workloads like I am doing : ) |
I find there is no LLVMOp corresponding to LLVM's [va_arg instruction](https://llvm.org/docs/LangRef.html#va-arg-instruction) so I tried to add one. This is helpful for clangir (llvm/clangir#865). New to MLIR and not sure who are the appropriate reviewers. Appreciated in ahead for reviewing and triaging.
That has been part of the project's goal - it doesn't need to be exact same, but if it's deviating we should have a good reason and/or plan to fix it, I don't think it's the case here.
My preference is that we do the right thing, right away and do not need to revisit this, specially for x86-64, which is a super popular target. Btw, does any other target fallback to that llvm instruction?
It's great to hear that you're trying it on real world workloads. We're doing the same at Meta, and with that in mind we've been driving the goals and development of ClangIR. However, I don't understand why it's profitable to generate code that our vanilla clang compiler has moved away from almost a decade ago - feels like a questionable shortcut to me. |
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.
Reflect status from latest discussion
I sent #1088 after I failed to reopen this PR. |
Close #862
I made this by introducing VaArgOp to mlir and use that op in clangir. I feel this is the most natural way to do this. I don't think we should handle different architecture in clangir. It is the job of LLVM or MLIR. I understand that we hope we don't touch any other workdirs except CIR. But it looks pretty better to do the proper thing in the proper places.
I'll try to upstream the patch to support MLIR later.