<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:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:"Calibri Light";
        panose-1:2 15 3 2 2 2 4 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:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:24.0pt;
        font-family:"Times New Roman",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;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Calibri Light",sans-serif;
        color:#2E74B5;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:894850261;
        mso-list-type:hybrid;
        mso-list-template-ids:-474820770 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@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:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@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:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@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: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-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Mehdi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I wasn’t familiar with IPRA before, thank you for bringing it up.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">After studying it, I have to say that IPRA is a wonderful idea and is well implemented.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I tried to reuse the mechanism for the last couple of days.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I implemented a solution using IPRA mechanism and encountered few issues:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span dir="LTR"></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">IPRA uses immutable analysis pass called “PhysicalRegisterUsageInfo”. The usage of such passes should be optimization only. In
 my case, this is a functional issue. The analysis must run in order to be compatible with other compilers.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span dir="LTR"></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">IPRA passes are not enabled by default and when they are enabled many tests fail due to various reasons (mainly because the CallGraph
 bottom up approach).<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span style="mso-list:Ignore">3.<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span dir="LTR"></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The manipulated RegMasks generated using RegUsageInfoCollector are very different than the manipulated RegMasks that I need.
 It will be an abuse to change the current pass implementation. So new pass is required.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><span style="mso-list:Ignore">4.<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span dir="LTR"></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">When dumping the MIR after running IPRA passes, assertion is raised because the RegMask name is unknown (same issue that I face
 with my solution – see “open Issue”).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I might reuse the analysis pass of IPRA instead of saving the RegMask inside the Machine Function but as mentioned by #1 it is not recommended.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thus I believe that using my current suggestion is more suitable for the issue I am resolving.<o:p></o:p></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Best Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Oren<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> mehdi.amini@apple.com [mailto:mehdi.amini@apple.com]
<br>
<b>Sent:</b> Monday, January 09, 2017 18:38<br>
<b>To:</b> Ben Simhon, Oren <oren.ben.simhon@intel.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] RFC: Dynamically Allocated "Callee Saved Registers" Lists<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Jan 9, 2017, at 1:09 AM, Ben Simhon, Oren via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<h1 style="mso-margin-top-alt:12.0pt;margin-right:0cm;margin-bottom:0cm;margin-left:0cm;margin-bottom:.0001pt;line-height:16.95pt;page-break-after:avoid">
<span style="font-size:16.0pt;font-family:"Calibri Light",sans-serif;color:#2E74B5;font-weight:normal">Dynamically Allocated “Callee Saved Registers” Lists<o:p></o:p></span></h1>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Each Calling convention (CC) defines a static list of registers that should be preserved by a callee function. All other registers
 should be saved by the caller.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Some CCs use additional condition: If the register is used for passing/returning arguments – the caller needs to save it - even
 if it is part of the Callee Saved Registers (CSR) list.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">For example consider the following function:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;text-indent:36.0pt;line-height:11.65pt">
<i><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">void __regcall func(int a, int b, int c, int d, int e);</span></i><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">According to RegCall CC, parameters<span class="apple-converted-space"> </span><i>d</i><span class="apple-converted-space"> </span>and<span class="apple-converted-space"> </span><i>e</i><span class="apple-converted-space"> </span>should
 reside in registers EDI and ESI. The problem is that these registers also appear in the CSR list of RegCall calling convention. So, since the registers were used to pass arguments the callee doesn’t have to preserve their values.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The current LLVM implementation doesn’t support it. It will save a register if it is part of the static CSR list and will not
 care if the register is passed/returned by the callee.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">There are two types of static CSR lists:<span class="apple-converted-space"> </span><o:p></o:p></span></p>
<div style="margin-left:36.0pt">
<p class="MsoNormal" style="text-indent:-18.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">1.</span><span style="font-size:7.0pt">     <span class="apple-converted-space"> </span></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">register
 mask array of the CSRs (including register aliases)<o:p></o:p></span></p>
</div>
<div style="margin-left:36.0pt">
<p class="MsoNormal" style="text-indent:-18.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">2.</span><span style="font-size:7.0pt">     <span class="apple-converted-space"> </span></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">register
 CSR list<o:p></o:p></span></p>
</div>
<div style="margin-left:36.0pt">
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The proposed solution is to dynamically allocate the CSR lists (Only for these CCs). The lists will be updated with actual registers that should
 be saved by the callee.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Since we need the allocated lists to live as long as the function exists, the list should reside inside the Machine Register Info (MRI) which is
 a property of the Machine Function and managed by it (and has the same life span).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The lists should be saved in the MRI and populated upon LowerCall and LowerFormalArguments.<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Have you looked at how IPRA is implemented? It needs to dynamically allocate the register mask as well, so unless there is something fundamentally different I’m missing, we should share the mechanism.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">— <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mehdi<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoListParagraph" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:8.0pt;margin-left:0cm;line-height:11.65pt">
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<h1 style="mso-margin-top-alt:12.0pt;margin-right:0cm;margin-bottom:0cm;margin-left:0cm;margin-bottom:.0001pt;line-height:16.95pt;page-break-after:avoid">
<span style="font-size:16.0pt;font-family:"Calibri Light",sans-serif;color:#2E74B5;font-weight:normal">Open Issue<o:p></o:p></span></h1>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Machine Instructions (MI) have intermediate representation that can be printed and later on parsed to recreate the MIs.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">MI printer and parser expect the Register Mask array pointer to point to a predefined (static) list of RegMasks. Those lists
 are retrieved from auto generated file x86GenRegisterInfo.inc using the functions: getRegMasks() and getRegMaskNames().<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">However, since we create a dynamically allocated register mask, its pointer will not reside in the static lists and no corresponding
 name could be found.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">In that case, the MIPrinter will fail to emit the RegMask Name.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">I would appreciate the community opinion regarding my solution and regarding possible solutions to the open issue.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:8.0pt;line-height:11.65pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;font-variant-caps: normal;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">---------------------------------------------------------------------<br>
Intel Israel (74) Limited<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;font-variant-caps: normal;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">_______________________________________________<br>
LLVM Developers mailing list<br>
</span><a href="mailto:llvm-dev@lists.llvm.org"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#954F72">llvm-dev@lists.llvm.org</span></a><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif"><br>
</span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#954F72">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>

<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>