<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Meiryo UI";
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"MS PGothic";
        panose-1:2 11 6 0 7 2 5 8 2 4;}
@font-face
        {font-family:"\@MS PGothic";
        panose-1:2 11 6 0 7 2 5 8 2 4;}
@font-face
        {font-family:"\@Meiryo UI";
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"MS PGothic","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Meiryo UI","sans-serif";
        color:black;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Meiryo UI","sans-serif";
        color:black;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:828522955;
        mso-list-template-ids:-1242535808;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-PH" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Hello Eli,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">I think your second suggestion is the correct way of implementing this for our target. Thank you very much for your suggestions, this has greatly helped us in our development!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">I am currently trying to implement it for our target.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Cheers,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Miguel<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Eli Friedman [mailto:efriedma@quicinc.com]
<br>
<b>Sent:</b> February 13, 2020 9:46 AM<br>
<b>To:</b> Miguel Inigo J. Manalac; llvm-dev<br>
<b>Subject:</b> RE: [llvm-dev] Function Return Legalization<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">LLVM calls a pointer that$B!G(Bs used to return a value indirectly, like you$B!G(Bre describing, an $B!H(Bsret$B!I(B argument.  There are sort of two ways to go about generating one. First, you can edit
 the call lowering code in clang (clang/lib/CodeGen/TargetInfo.cpp) so the pointer is represented explicitly in IR.  Second, you can make the target-independent backend code generate an sret argument in SelectionDAG, by making your target$B!G(Bs $B!H(BCanLowerReturn$B!I(B
 return false.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Probably making CanLowerReturn return false for i64 makes sense for your target.  If you$B!G(Bre using TableGen$B!G(Bed calling conventions (*CallingConv.td), the TableGen$B!G(Bed code will handle
 this automatically; otherwise, you can write it out explicitly in C++. If you want an example of how this works in practice, try something like $B!H(Becho 'define i128 @foo() { ret i128 3 }' | llc -mtriple=i686$B!I(B.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">If you need to stick the sret pointer into a special register, you can use CCIfSRet in TableGen.  (Or if you$B!G(Bre not using a TableGen$B!G(Bed calling convention, you can check IsSRet in C++.)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">-Eli<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> llvm-dev <llvm-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Miguel Inigo J. Manalac via llvm-dev<br>
<b>Sent:</b> Wednesday, February 12, 2020 12:32 AM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [EXT] [llvm-dev] Function Return Legalization<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Hi All,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">In the target we are implementing, function return for i64 and f64 types has a different processing.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">For types i8 to i32, and f32, the return values are stored in their designated return registers (like how other targets does it).
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">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:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Expected Target ASM output for i64 function call with i64 return type:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">1    push qr0                    ;; 64-bit parameter pushed into the stack<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">2    mov er0, fp                ;; Assign the frame pointer into er0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">3    add er0, #-32            ;; Add the frame pointer offset to er0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">4    bl _fn                        ;; Function call fn<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">5    add sp, #8                 ;; SP adjustment<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">In function fn:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">1 ;; function prologue processing here...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">2 mov er8, er0                 ;; frame pointer location of retval is transferred to er8 (will be used at line 4)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">3 ;; function processing here... Assuming that the i64 value to be returned is stored at qr0...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">4 lea [er8]                       ;;  i64 return processing starts here. Load effective address from [er8]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">5 st qr0, [ea]                   ;; Store the i64 value into the effective address memory location.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">6 ;; function epilogue processing here...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">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<span lang="JA">$B!G(B</span>m wrong.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">My questions are:<o:p></o:p></span></p>
<ol style="margin-top:0cm" start="1" type="1">
<li class="MsoNormal" style="color:black;mso-list:l0 level1 lfo1"><span style="font-family:"Meiryo UI","sans-serif"">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.<o:p></o:p></span></li><li class="MsoNormal" style="color:black;mso-list:l0 level1 lfo1"><span style="font-family:"Meiryo UI","sans-serif"">Where does the assigning of frame pointer+offset(frame index?) fall? I am currently suspecting that it should be in the LowerCall function.
<o:p></o:p></span></li><li class="MsoNormal" style="color:black;mso-list:l0 level1 lfo1"><span style="font-family:"Meiryo UI","sans-serif"">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?<o:p></o:p></span></li><li class="MsoNormal" style="color:black;mso-list:l0 level1 lfo1"><span style="font-family:"Meiryo UI","sans-serif"">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.<o:p></o:p></span></li></ol>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Thank you very much in advance for your help!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Sincerely,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Meiryo UI","sans-serif";color:black">Miguel Inigo J. Manalac<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"MS PGothic","sans-serif"">JAPANESE:
</span><span lang="JA" style="font-size:12.0pt;font-family:"MS PGothic","sans-serif"">$B$3$N%a!<%k$O!"08@h$K=q$+$l$F$$$kJ}$N$_$KAw?.$9$k$3$H$r0U?^$7$F$*$j$^$9!#8m$C$F$=$l0J30$NJ}$KAw?.$5$l$?>l9g$O!"?=$7Lu$4$6$$$^$;$s$,!"Aw?.<T$^$G$*CN$i$;$$$?$@$-!"<u?.$5$l$?%a!<%k$r:o=|$7$F$$$?$@$-$^$9$h$&$*4j$$$$$?$7$^$9!#$^$?!"%3%s%T%e!<%?!&%&%#%k%9$N:.F~Ey$K$h$C$F%a!<%k$N7gMn!&IT@09g!&CYBZEy$,H/@8$7!"2?$i$N$4ITJX$r$*$+$1$9$k$3$H$,@8$8$F$bJ@<R$O$=$N@UG$$rIi$$$^$;$s!#(B</span><span style="font-size:12.0pt;font-family:"MS PGothic","sans-serif"">
 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.
<o:p></o:p></span></p>
</div>
</div>
JAPANESE: $B$3$N%a!<%k$O!"08@h$K=q$+$l$F$$$kJ}$N$_$KAw?.$9$k$3$H$r0U?^$7$F$*$j$^$9!#8m$C$F$=$l0J30$NJ}$KAw?.$5$l$?>l9g$O!"?=$7Lu$4$6$$$^$;$s$,!"Aw?.<T$^$G$*CN$i$;$$$?$@$-!"<u?.$5$l$?%a!<%k$r:o=|$7$F$$$?$@$-$^$9$h$&$*4j$$$$$?$7$^$9!#$^$?!"%3%s%T%e!<%?!&%&%#%k%9$N:.F~Ey$K$h$C$F%a!<%k$N7gMn!&IT@09g!&CYBZEy$,H/@8$7!"2?$i$N$4ITJX$r$*$+$1$9$k$3$H$,@8$8$F$bJ@<R$O$=$N@UG$$rIi$$$^$;$s!#(B 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.
</body>
</html>