This is an archive of the discontinued LLVM Phabricator instance.

[MIPS GlobalISel] Add lowerCall
ClosedPublic

Authored by Petar.Avramovic on Apr 13 2018, 9:48 AM.

Details

Summary

Add the minimal support to lower function calls.
Support only functions with arguments/return that go through registers, and have type i32.

Diff Detail

Repository
rL LLVM

Event Timeline

Does anybody have any comment?

I've only gone through the ABI side of things (and from memory) but I have a couple comments.

lib/Target/Mips/MipsCallLowering.cpp
279 ↗(On Diff #142426)

I assume it's O32 you're implementing based on the magic number here. IIRC, there's a function in the Mips target that returns 0 or 16 as appropriate for the ABI. If it used that instead then I suspect this patch may support N32/N64 too.

test/CodeGen/Mips/GlobalISel/llvm-ir/call.ll
6 ↗(On Diff #142426)

I would suggest not using the first two arguments so that code is emitted to put the arguments in the right place. This test will currently emit the right assembly even if argument passing isn't handled. If you added two dummy arguments in front of these then there would be a mov instruction you can check for.

21 ↗(On Diff #142426)

Similarly, I'd suggest modifying the result before passing it back to the caller so that code using $v0 is emitted. Then you'd be able to check the register is correct.

sdardis added inline comments.May 2 2018, 2:28 AM
lib/Target/Mips/MipsCallLowering.cpp
222 ↗(On Diff #142426)

Fallback if we have more than 4 arguments, var-args or the calling convention is not supported.

224 ↗(On Diff #142426)

Test that we have no 'byval' arguments here, they require some MIPS-specific special handling. See D44296 for the details on how to handle this, but note that clang doesn't currently produce function calls with 'byval'. 'sret' arguments should also provoke fallback as well.

236 ↗(On Diff #142426)

FIXME: Add support for pic calling sequences, long call sequences for O32, N32 and N64.

279 ↗(On Diff #142426)

The MipsABIInfo class knows the fixed portion of the outing argument area, GetCalleeAllocdArgSizeInBytes().

Addressed review comments

Petar.Avramovic marked 3 inline comments as done.May 8 2018, 5:15 AM
Petar.Avramovic added inline comments.
lib/Target/Mips/MipsCallLowering.cpp
222 ↗(On Diff #142426)

Add fallback if calling convention is not the default one (CallingConv::C).
If we get more then 4 arguments fallback happens in MipsCallLowering::MipsHandler::assign (MipsCallLowering.cpp line 30) as those arguments will end up on stack.
As for var-arg functions, there is no work to be done in lowerCall. They are handled in lowerFormalArguments, we will have to copy argument from registers to stack (if any) and store address of startig location of var-args in MipsFunctionInfo object (using setVarArgsFrameIndex). Remaining work is done with custom legalization in legalizer.

236 ↗(On Diff #142426)

Add FIXME comment pic and long call. And as we are adding this comment also add fallback if callee is not a symbol since we have to support callee in register (pointer to function) first.

279 ↗(On Diff #142426)

When we add support for arguments on stack in lowerCall, GetCalleeAllocdArgSizeInBytes will be used to AllocateStack in MipsCCState so it can be used correctly. There is similar work to be done in lowerFormalArguments too.
In the meantime we will use ABI.GetCalleeAllocdArgSizeInBytes() instead of 16 in ADJCALLSTACK... instructions.

test/CodeGen/Mips/GlobalISel/llvm-ir/call.ll
6 ↗(On Diff #142426)

Tests are modified so that we can see move from a2,a3($6,$7) to a0,a1($4,$5) when we are preparing arguments for call of function f.

21 ↗(On Diff #142426)

Return value of f is doubled in order to see if value in register v0($2) is used in add instruction.

Does anybody have any comment?

sdardis accepted this revision.Jun 4 2018, 8:59 AM

LGTM.

This revision is now accepted and ready to land.Jun 4 2018, 8:59 AM
This revision was automatically updated to reflect the committed changes.