<div dir="ltr">Weird calling convention, but I see that's as documented at e.g. <div><br></div><div><a href="https://software.intel.com/en-us/node/522787">https://software.intel.com/en-us/node/522787</a><br></div><div><br></div><div>Silly question:</div><div><br></div><div>Is there any calling convention, on any supported platform, that requires the callee to preserve a register that was used to pass an argument?</div><div><br></div><div>Of course someone *could* define such a CC, but if there isn't currently one, then we don't need to support that possibility *yet*.</div><div><br></div><div>If no one has done that then no need to add a whole new special case just for IA32 __regcall. We could just for every function do something like (assuming a bitmap representation):</div><div><br></div><div>fnCalleeSavedRegs = archCSR & ~fnArgs</div><div>fnScratchRegs = ~fnCalleeSavedRegs & ~archSpecialRegs; // if not included in CSR</div><div><br></div><div>This is simple enough to be calculated whenever it's needed, not stored.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 9, 2017 at 12:09 PM, Ben Simhon, Oren via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_5192472948617456788WordSection1">
<h1>Dynamically Allocated “Callee Saved Registers” Lists<u></u><u></u></h1>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal">For example consider the following function:<u></u><u></u></p>
<p class="MsoNormal" style="text-indent:36.0pt"><i>void __regcall func(int a, int b, int c, int d, int e);<u></u><u></u></i></p>
<p class="MsoNormal">According to RegCall CC, parameters <i>d</i> and <i>e</i> 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.<u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">There are two types of static CSR lists: <u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpFirst">
<u></u><span>1.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>register mask array of the CSRs (including register aliases)<u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle">
<u></u><span>2.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>register CSR list<u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle"><u></u> <u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle" style="margin-left:0cm">
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.<u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle" style="margin-left:0cm">
<u></u> <u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle" style="margin-left:0cm">
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).<u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle" style="margin-left:0cm">
<u></u> <u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpMiddle" style="margin-left:0cm">
The lists should be saved in the MRI and populated upon LowerCall and LowerFormalArguments.<u></u><u></u></p>
<p class="m_5192472948617456788MsoListParagraphCxSpLast" style="margin-left:0cm"><u></u> <u></u></p>
<h1>Open Issue<u></u><u></u></h1>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Machine Instructions (MI) have intermediate representation that can be printed and later on parsed to recreate the MIs.<u></u><u></u></p>
<p class="MsoNormal">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().<u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal">In that case, the MIPrinter will fail to emit the RegMask Name.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I would appreciate the community opinion regarding my solution and regarding possible solutions to the open issue.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p>------------------------------<wbr>------------------------------<wbr>---------<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></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>