<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-8859-1">
<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:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
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:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1367947718;
        mso-list-type:hybrid;
        mso-list-template-ids:-176097674 69009425 69009433 69009435 69009423 69009433 69009435 69009423 69009433 69009435;}
@list l0:level1
        {mso-level-text:"%1\)";
        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;}
@list l1
        {mso-list-id:1753307015;
        mso-list-type:hybrid;
        mso-list-template-ids:577809842 69009431 69009433 69009435 69009423 69009433 69009435 69009423 69009433 69009435;}
@list l1:level1
        {mso-level-number-format:alpha-lower;
        mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1: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="SV" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">In MCRegisterClass (and TargetRegisterClass) there is a method getSize.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">According to the comments it should return both the size of “the register” (I assume that means “any register in the class”)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">which is assumed to be the same as the size needed on the stack when spilling such a register.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The definition looks like this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  /// getSize - Return the size of the register in bytes, which is also the size<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  /// of a stack slot allocated to hold a spilled copy of this register.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">  unsigned getSize() const { return RegSize; }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">To me it seems like the primary use of getSize has been to get the SpillSize, but some users<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(GlobalISel?) also use this to get the register size. Note that the variable actually is called<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">SpillSize in tablegen (CodeGenRegisters/RegisterInfoEmitter). But for some reason the<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">MCRegisterClass renames it to RegSize and claims that it also denotes the register size.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Some problems I see:<br>
<br>
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l1 level1 lfo1"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">a)<span style="font:7.0pt "Times New Roman"">      
</span></span></span><![endif]><span lang="EN-US">Is always register size and spill size the same?
<br>
(It is not for my downstream, out-of-tree, target.)<br>
<br>
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l1 level1 lfo1"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">b)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Is always the register size in bits a multiple of the byte size?<br>
No, lots of targets implement 1-bit registers. So what is the size in bytes for such a register?<br>
<br>
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l1 level1 lfo1"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">c)<span style="font:7.0pt "Times New Roman"">      
</span></span></span><![endif]><span lang="EN-US">When defining register classes in <Target>RegisterInfo.td the spill size can be given explicitly<br>
(by using “Size = <size in bits>”). If not given (or rather if Size=0), then the SpillSize is derived<o:p></o:p></span></p>
<p class="MsoListParagraph"><span lang="EN-US">from the first value type that is mapped to the register class.<br>
In tablegen this size is denoted SpillSize and it is given in bits. But tablegen<br>
will convert this to bytes by simply dividing by 8 (remainder is truncated).<br>
<br>
So, for example, one bit registers (exists for several targets) will get a spill size of zero bytes,<br>
unless Size is explicitly set.<br>
<br>
This is not easy to understand. Neither when looking at the RegisterClass definitions, nor as<br>
a user of MCRegisterClass::getSize (which according to the comment should return both size
<br>
of register and spill size). Well, a 1-bit register is not a full byte, so maybe it is obvious that<o:p></o:p></span></p>
<p class="MsoListParagraph"><span lang="EN-US">the size in bytes is zero?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Some examples:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">PPC has a register class CRBITRC that has one bit registers, but it sets Size=32.<br>
So for this register class MCRegisterClass::getSize() will return 4 bytes. So that is the spill size,<br>
but if a user of getSize() expects to get the register size it is definitely not the same as the spill size!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Hexagon has the UsrBits register class with one bit registers. It does not set Size, but it sets<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">isAllocatable=0 so it will not be used for virtual register (and thus never spilled). So a derived spill<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">size of 0 is probably expected. But still, is it expected that the size of the register is 0 bytes, or<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">do we want to round up the size to 1 byte?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">One idea to get this more general, and less confusing, could be as follows:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">1)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Let tablegen save both SpillSize and RegSize for each register class.<br>
We should preferably keep the size in bits here. At least for the RegSize. This makes it possible for a user<br>
of the information to determine by itself it size should be rounded up/down if a conversion to bytes is needed.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">2)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Add new methods in MCRegisterClass (and TargetRegisterClass) to getSpillSize() and getRegSizeInBits().<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">3)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Tablegen could assert that spill size is a multiple of the byte size.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">4)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Mark the old getSize() as deprecated (and let it return the spill size until it can be removed).<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">5)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><![endif]><span lang="EN-US">Start replacing uses of getSize() by the new methods, depending on if the register size or the spill size is of interest.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Another improvement would be to rename Size to SpillSize when defining register classes in <Target>RegisterInfo.td files.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">If SpillSize isn’t explicitly given it should be derived from the value type. If it is explicitly given it should be allowed to set it<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">to zero wihout tablegen replacing it by deriving size from value type.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Any comments on this are welcome!<o:p></o:p></span></p>
</div>
</body>
</html>