<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.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri",sans-serif;}
.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="MsoPlainText">Reply inline. (Sorry about the formatting; I can't figure out how to avoid destroying it in Outlook.)<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">From: Reid Kleckner <rnk@google.com> <o:p></o:p></p>
<p class="MsoPlainText">Sent: Monday, January 27, 2020 4:58 PM<o:p></o:p></p>
<p class="MsoPlainText">To: Eli Friedman <efriedma@quicinc.com><o:p></o:p></p>
<p class="MsoPlainText">Cc: llvm-dev <llvm-dev@lists.llvm.org><o:p></o:p></p>
<p class="MsoPlainText">Subject: [EXT] Re: [llvm-dev] [RFC] Replacing inalloca with llvm.call.setup and preallocated<o:p></o:p></p>
<p class="MsoPlainText"> <o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">>> “llvm.call.setup must have exactly one corresponding call site”: Normal IR rules would allow cloning the call site (in jump threading), or erasing the call site (if there’s a noreturn call in an argument). 
 What’s the benefit of enforcing this rule, as opposed to just saying all the call sites must have the same signature?<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in"> <o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">> I think we could cope with unreachable code elimination deleting a paired call site (zero or one), but code duplication creating a second call site could be problematic. The call setup doesn't describe the
 prototype of the main call site, so if there were multiple call sites, the backend would have to pick one call site arbitrarily or compare the call sites when setting up the call. If there are zero call sites, the backend can create static allocas of the appropriate
 type to satisfy the allocations. Of course, an IR pass (instcombine?) should do this transform first if it sees it. Maybe we could have CGP take care of it, too.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">It doesn’t seem like multiple call sites should be a problem if they’re sufficiently similar?  If the argument layout for each callsite is the same, it doesn’t matter which callsite the backend chooses to compute the layout.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">> Nested setup is OK, but the verifier rule that there must be a paired call site should make it impossible to do in a loop. I guess we should have some rule to reject the following:<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">%cs1 = llvm.call.setup()<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">%cs2 = llvm.call.setup()<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">call void @cs1() [ "callsetup"(token %cs1) ]<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">call void @cs2() [ "callsetup"(token %cs2) ]<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">I think in general, there can be arbitrary control flow between a token and its uses, as long as the definition dominates the use.  So you could call llvm.call.setup repeatedly in a loop, then call some function using the callsetup token
 in a different loop, unless some rule specific to callsetup forbids it.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">It would be nice to make the rules strong enough to ensure we can statically compute the size of the stack frame at any point (assuming no dynamic allocas).  Code generated by clang would be statically well-nested, I think; not sure
 how hard it would be to ensure optimizations maintain that invariant.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Connecting nested llvm.call.setups using tokens might make it easier for passes to reason about the nesting, since the region nest would be explicitly encoded.<o:p></o:p></p>
<p class="MsoPlainText"><o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">>> How does this interact with other dynamic stack allocations?  Should we switch VLAs to use a similar mechanism?  (The problems with dynamic alloca in general aren’t as terrible, but it might still benefit:
 for example, it’s much easier to transform a dynamic allocation into a static allocation.)<o:p></o:p></p>
<p class="MsoPlainText" style="margin-left:.5in"><o:p> </o:p></p>
<p class="MsoPlainText" style="margin-left:.5in">> VLAs could use something like this, but they are generally of unknown size while call sites have a known fixed size. I think that makes them pretty different.<o:p></o:p></p>
<p class="MsoPlainText"> <o:p></o:p></p>
<p class="MsoPlainText">I don’t think we need to implement it at the same time, but the systems would interact, so it might be worth planning out.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">-Eli<o:p></o:p></p>
</div>
</body>
</html>