<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 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 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";}
@font-face
        {font-family:"Meiryo UI";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:JA;}
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:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:JA;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"MS PGothic",sans-serif;
        mso-fareast-language:JA;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Meiryo UI";
        color:black;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:89358133;
        mso-list-type:hybrid;
        mso-list-template-ids:1882993286 873005071 873005081 873005083 873005071 873005081 873005083 873005071 873005081 873005083;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></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-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span 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 style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span 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 style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span 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 style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">-Eli<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> 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></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">Hi All,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">Expected Target ASM output for i64 function call with i64 return type:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">1    push qr0                    ;; 64-bit parameter pushed into the stack<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">2    mov er0, fp                ;; Assign the frame pointer into er0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">3    add er0, #-32            ;; Add the frame pointer offset to er0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">4    bl _fn                        ;; Function call fn<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">5    add sp, #8                 ;; SP adjustment<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">In function fn:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">1 ;; function prologue processing here...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";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 lang="EN-PH" style="font-family:"Meiryo UI";color:black">6 ;; function epilogue processing here...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";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$B!G(Bm wrong.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">My questions are:<o:p></o:p></span></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoListParagraph" style="color:black;margin-left:0in;mso-list:l0 level1 lfo2">
<span lang="EN-PH" style="font-family:"Meiryo UI"">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="MsoListParagraph" style="color:black;margin-left:0in;mso-list:l0 level1 lfo2">
<span lang="EN-PH" style="font-family:"Meiryo UI"">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="MsoListParagraph" style="color:black;margin-left:0in;mso-list:l0 level1 lfo2">
<span lang="EN-PH" style="font-family:"Meiryo UI"">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="MsoListParagraph" style="color:black;margin-left:0in;mso-list:l0 level1 lfo2">
<span lang="EN-PH" style="font-family:"Meiryo UI"">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 lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">Thank you very much in advance for your help!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">Sincerely,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" style="font-family:"Meiryo UI";color:black">Miguel Inigo J. Manalac<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-PH" 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 lang="EN-PH" 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>
</body>
</html>