<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=utf-8">
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        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.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:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></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">Also note that “most efficient” depends on the application and use case.  On x86-64, for error handling use cases where you want to return the same struct of two pointers up several calls, I found that using the non-trivial ABI (struct
 is on the stack, pointer to the struct is in a register) was faster than the trivial ABI (object is returned in two registers).  You will need to benchmark to see which is best for your anticipated use cases.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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>David Blaikie via llvm-dev<br>
<b>Sent:</b> Thursday, October 17, 2019 2:49 PM<br>
<b>To:</b> Levo DeLellis <levo.delellis@gmail.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [EXTERNAL] Re: [llvm-dev] Most efficient way for a function to return two types?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I'd probably do it the same way clang does for<br>
<br>
struct str { char* ptr; int64_t length; };<br>
str itoa(...);<br>
<br>
But realize that LLVM IR isn't ABI neutral - Clang may generate significantly different IR when targeting different architectures to match their ABI. Even if you don't need to match these ABIs (you don't need your code to be able to call into/be called from
 C or C++ source code compiled with Clang or GCC, etc), just getting the machine code you desire (what parts of a struct get passed in which registers (or memory), etc) may require various per-architecture handling on your part/in how you generate the IR.<br>
<br>
- Dave<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Oct 17, 2019 at 10:51 AM Levo DeLellis via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">I apologize if this is the wrong list. I'm writing a language and outputting llvm-ir instead of using the c api. I looked at clang's output a few times but I'm a little unsure what to do in this case<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">As an example I have a function called itoa which takes an int and returns a string. Strings in my language has 2 fields, the pointer and byte length. On a 64bit machine it'd be returning a 64bit pointer and 64bit int value. My question
 is HOW should I do this if I want to generate fast code? And a follow up is should I do it that way if I want to support most architectures?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Currently my function signature is `define {i8*, i64} @itoa(i64) {`. Should I return an i8* instead and have an int pointer? (i64*). I don't see an 'out' parameter attributes or anything to hint to the optimizer the value at the address
 can be uninitialized. <a href="https://urldefense.com/v3/__https:/llvm.org/docs/LangRef.html*parameter-attributes__;Iw!fqWJcnlTkjM!5pdaNOSppnqMF2XpDF-fjW07YEi48PCkcmonerD66XjCLNuCatIIW4w1UmXN$" target="_blank">
https://llvm.org/docs/LangRef.html#parameter-attributes</a>. If I pass in a string should I do it the same way as returning? Currently I do. I pass in {i8*, i64} as a parameter and been thinking I can pass in i8* and i64 instead (note that i64 is not a pointer
 this time. It may be if the variable is mutable).<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev__;!fqWJcnlTkjM!5pdaNOSppnqMF2XpDF-fjW07YEi48PCkcmonerD66XjCLNuCatIIW1UEcPQN$" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>