Implementation of formal arguments lowering in the IRTranslator for the M68k backend
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/CodeGen/M68k/GlobalISel/irtranslator-ret.ll | ||
---|---|---|
12 | Should add checks for the parameters |
llvm/test/CodeGen/M68k/GlobalISel/irtranslator-ret.ll | ||
---|---|---|
178 | add more tests with parameters of various types: aggregate types, non-aggregate types, combination of those |
Title of this patch is not clear enough, perhaps something like [M68k] [GlobalISel] Formal arguments lowering in IRTranslator.
Also, I just realized this is only for i32 values so far. I think it should be easily extensible across any primitive type. Thoughts @myhsu ?
llvm/lib/Target/M68k/GlSel/M68kCallLowering.cpp | ||
---|---|---|
82 | I think you're trying to say either "Value should be assigned to reg" or "Value was not assigned to reg?" right? | |
97 | You can just put "unimeplemented" here. Since the stack trace will tell you which function triggers this unreachable statement | |
104 | ditto | |
llvm/lib/Target/M68k/GlSel/M68kCallLowering.h | ||
70 | (nit) please use struct instead and remove "public" in the following line | |
llvm/lib/Target/M68k/M68kISelLowering.h | ||
174 | The function name is a little confusing, maybe something like "getCCAssignGnForCall"? |
llvm/test/CodeGen/M68k/GlobalISel/irtranslator-ret.ll | ||
---|---|---|
39 | Shorter variable name instead of G_FRAME_INDEX, replaces uses and should not be reused for a different register |
LGTM, please wait for approval from at least one more reviewer before we merge this patch in. Great work @sushmaunnibhavi !
I'm curious if the test pass on your side. When I applied this patch on tip-of-tree, the newly-added test case triggered unreachable statement on line 87 of lib/Target/M68k/GlSel/M68kCallLowering.cpp (i.e. M68kIncomingValueHandler::getStackAddress was called).
Can you double check if this patch works on tip-of-tree? (of course please make sure you have assertion enabled in your build)
llvm/lib/Target/M68k/GlSel/M68kCallLowering.h | ||
---|---|---|
68 | please use struct instead and remove "public" in this line as well as the empty line above |
no, I didn't say it fail the build, I said it failed the test after this patch was applied.
In other words, ninja check-llvm-codegen-m68k fails (or replace ninja with whatever build system you're using). Can you verify whether that command fails on your side?
Also, since M68k's calling convention uses stack to pass incoming parameters, I'm not surprised M68kIncomingValueHandler::getStackAddress was called by GlobalISel to generate proper MIR instructions.
I suggest you to use i386 (a.k.a 32-bit X86) as a reference to see how thing works there and how they implement IncomingValueHandler. Since i386 is also using stack to pass incoming parameters.
Hmmm...alright, let's see how the buildbot will say
llvm/lib/Target/M68k/GlSel/M68kCallLowering.h | ||
---|---|---|
68 | still outstanding |
I'm afraid the build fails: https://lab.llvm.org/staging/#/builders/180/builds/132
More specifically, here is the error details on the test case added by this patch: https://lab.llvm.org/staging/#/builders/180/builds/132/steps/5/logs/FAIL__LLVM__irtranslator-ret_ll
Which is identical to the assertion failure I pointed out earlier in this review.
@sushmaunnibhavi I'm afraid I need to temporarily revert the commit (since it is the only test case relates to the patch, it doesn't make sense to only mark the test XFAIL)
Here are my guesses of why you couldn't reproduce the failure:
- Your local changes are not sync with the patch presented here.
- You didn't turn on assertion. Please open <your build folder>/CMakeCache.txt. If the CMAKE_BUILD_TYPE variable is "Debug" then you're fine, if it's something else, make sure LLVM_ENABLE_ASSERTIONS is ON (in case you don't know, you can directly change the variable value in that file and CMake will reconfigure on the next build).
Regarding the root cause of the crash, M68k's calling convention relies on pushing parameters to the stack, so only implementing register assignment is not enough. As I suggested before, i386's implementation of GlobalISel might be a good reference.
Last but not the least, commits got reverted all the time in LLVM so please don't mind :-) You're almost there and I definitely appreciate your contribution here!
llvm/lib/Target/M68k/GlSel/M68kCallLowering.cpp | ||
---|---|---|
81 | Is there any specific reason to extract these code into a separate lambda if there is only one callsite | |
llvm/test/CodeGen/M68k/GlobalISel/irtranslator-ret.ll | ||
15 | Git told me that there are trailing white spaces after every G_FRAME_INDEX line in this file, please remove them |
Basically looks good to me now. Please address the minor issue I point out in the inlined comments.
llvm/lib/Target/M68k/GlSel/M68kCallLowering.cpp | ||
---|---|---|
81 | Yeah, this isn't necessary. |
please use struct instead and remove "public" in this line as well as the empty line above