[llvm-dev] Function Return Legalization

Miguel Inigo J. Manalac via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 12 00:32:00 PST 2020


Hi All,

In the target we are implementing, function return for i64 and f64 types has a different processing.

For types i8 to i32, and f32, the return values are stored in their designated return registers (like how other targets does it).

For i64 and f64 types, in the function call, after pushing the function parameters into the stack, the address of the allocated return memory space is assigned to a 16-bit register (In our case, ER0). This is done by assigning the frame pointer register into ER0 and then adding the offset to it. So the output assembly code would somewhat look like the following:

Expected Target ASM output for i64 function call with i64 return type:
1    push qr0                    ;; 64-bit parameter pushed into the stack
2    mov er0, fp                ;; Assign the frame pointer into er0
3    add er0, #-32            ;; Add the frame pointer offset to er0
4    bl _fn                        ;; Function call fn
5    add sp, #8                 ;; SP adjustment

In function fn:
1 ;; function prologue processing here...
2 mov er8, er0                 ;; frame pointer location of retval is transferred to er8 (will be used at line 4)
3 ;; function processing here... Assuming that the i64 value to be returned is stored at qr0...
4 lea [er8]                       ;;  i64 return processing starts here. Load effective address from [er8]
5 st qr0, [ea]                   ;; Store the i64 value into the effective address memory location.
6 ;; function epilogue processing here...

>From my investigations so far, i64 types should call a custom function in the calling convention for processing this return type. Also, that LowerCall should be modified to have the assigning of frame pointer into er0 and that LowerReturn should be modified in order to store qr0 into the effective address. Please correct me if I'm wrong.

My questions are:

1.    Are there any target examples that also has this kind of behavior? If there are please let me know so I could study on it.

2.    Where does the assigning of frame pointer+offset(frame index?) fall? I am currently suspecting that it should be in the LowerCall function.

3.    If my assumption that question #2 falls in LowerCall function is correct, how do I retrieve the created frame index from the LowerCall function in the LowerReturn function?

4.    I also suspect that the affected functions are not limited to LowerCall and LowerReturn, if you have suggestions on which ISelLowering Class functions I should investigate on, please let me know.

Thank you very much in advance for your help!

Sincerely,
Miguel Inigo J. Manalac

JAPANESE: ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ENGLISH: This e-mail is intended for the person(s) to which it is addressed. If you have received it by mistake, please notify the sender and delete the received email. In addition, our company shall not assume any responsibility even if it causes any inconvenience, such as loss of mail, inconsistencies, delays, etc., due to the inclusion of computer viruses.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200212/dfcac9c4/attachment.html>


More information about the llvm-dev mailing list