This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] support ilp32e Calling Convention
Needs ReviewPublic

Authored by xudaliang.pku on Mar 20 2019, 1:12 AM.

Details

Reviewers
asb
Summary

This patch adds ilp32e Calling Convention support by using -target-abi=ilp32e. It is decoupled with rv32e arch. You can use -march=rv32i -target-abi=ilp32e.
This patch support for :

  1. stack align = 4
  2. only use a0-a5 argument register
  3. callee saved register s0-s1

according to

https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#rv32e-calling-convention

Diff Detail

Event Timeline

xudaliang.pku created this revision.Mar 20 2019, 1:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2019, 1:12 AM
xudaliang.pku removed a project: Restricted Project.Mar 20 2019, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2019, 7:21 AM
xudaliang.pku removed a project: Restricted Project.Mar 20 2019, 7:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2019, 7:22 AM
apazos added inline comments.Mar 20 2019, 3:32 PM
lib/Target/RISCV/RISCVRegisterInfo.cpp
137

Double check the mask, should not be the interrupt mask

xudaliang.pku marked an inline comment as done.Mar 21 2019, 5:51 AM
xudaliang.pku added inline comments.
lib/Target/RISCV/RISCVRegisterInfo.cpp
137

It seems the check is done by RISCVRegisterInfo::getCalleeSavedRegs, So I don't need to do it again

asb added a comment.Mar 28 2019, 7:26 AM

Hi Daliang., thanks for the submission. One problem I think you'll find once you extend the tests is that support for realigning the stack is going to be required - e.g. if passing a double (8-byte aligned) on the stack (4-byte aligned).

xudaliang.pku marked an inline comment as not done.Mar 30 2019, 3:44 AM
In D59592#1445996, @asb wrote:

Hi Daliang., thanks for the submission. One problem I think you'll find once you extend the tests is that support for realigning the stack is going to be required - e.g. if passing a double (8-byte aligned) on the stack (4-byte aligned).

Oh ,I see , I will try the related tests soon.

lebedev.ri retitled this revision from support ilp32e Calling Convention to [RISCV] support ilp32e Calling Convention.Mar 30 2019, 3:53 AM
  1. fix the bug on double check the interrupt mask
  2. give a test of passing a double (8-byte aligned) on the stack (4-byte aligned) in calling-conv-ilp32e.ll for func: caller_double_on_stack and callee_double_on_stack
In D59592#1445996, @asb wrote:

Hi Daliang., thanks for the submission. One problem I think you'll find once you extend the tests is that support for realigning the stack is going to be required - e.g. if passing a double (8-byte aligned) on the stack (4-byte aligned).

I have made a new test for passing a double (8-byte aligned) on the stack (4-byte aligned) in calling-conv-ilp32e.ll for func: caller_double_on_stack and callee_double_on_stack.
It seems the realigning the stack is done.
In this example . the i32 %d and double %e are passed by the stack. And the test shows that the the stack is align at 8 bytes. The %d is in 0(sp) using only 4 bytes and %e is in 8(sp) using 8 bytes. The pos 4(sp) is not used. So ,is that means the stack is realigned or just aligned for 8 bytes. Is that right?
Did I understand clearly that when passing the double variable, the stack should align at 8 bytes rather than 4 bytes ?

lenary added a subscriber: lenary.Jul 31 2019, 9:03 AM