<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;}
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">Assuming I’m understanding the rule correctly, it doesn’t actually affect “alignment” of the type in the sense we would normally understand it. A struct with a double as the first member can be stored at an address with four-byte alignment.
The rule only involves inserting extra padding at the end of the struct. In particular, from the way you’re describing the rule, I think the special alignment rule isn’t supposed to affect the result of _Alignof. Does that seem right?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Given that, do you actually need to store anything in the RecordLayout at all? You could just write a check like “if the first member of the struct is a double (or recursively, a struct where the first member is a double), round up the
size of the struct to a multiple of 8”.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Also, probably worth checking the layout for a testcase like the following, to check the interaction between the extra padding and the nvsize:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">class A { double a; int b; };<o:p></o:p></p>
<p class="MsoNormal">class B : A { int c; };<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Eli<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Xiangling Liao via cfe-dev<br>
<b>Sent:</b> Friday, April 24, 2020 6:21 AM<br>
<b>To:</b> cfe-dev@lists.llvm.org<br>
<b>Subject:</b> [EXT] [cfe-dev] [RFC] Adding AIX power alignment rule in clang front end<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Currently we are trying to implement AIX special alignment rule on the top of Itanium ABI in Clang. On AIX, in aggregates, the
first member of double/long double is aligned according to its natural alignment value; subsequent double/long double of the aggregate are aligned on 4-byte boundaries.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">This rule is recursive. It applies all the way to the inner most nested members. An example is as the following:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0in;margin-bottom:3.0pt;margin-left:.5in">
<span style="font-size:9.0pt;font-family:"Courier New";color:black">struct D {<br>
double d;<br>
int i;<br>
};</span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0in;margin-bottom:3.0pt;margin-left:.5in">
<span style="font-size:9.0pt;font-family:"Courier New";color:black"> </span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0in;margin-bottom:3.0pt;margin-left:.5in">
<span style="font-size:9.0pt;font-family:"Courier New";color:black">struct IntFirst {<br>
int i;<br>
struct D d;<br>
};</span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;color:black"> </span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;color:black">The size of struct D is 16, class alignment is 8;</span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;color:black">The size of struct IntFirst is 20, class alignment is 4;</span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">So our current idea is to have an alignment field to record nested struct info and pass the special alignment value all the way
back to the ourter most aggregate.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">And based on this idea, there are two possible ways.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">1.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">The first one is that we introduced a new field in class
<i>ASTRecordLayout</i><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Called `<i>AIXOffsetAlignment</i>` which represents the special AIX alignment for the object that<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">contains floating-point member or sub-member. This is for AIX-ABI only.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">The proposed change has been put on Phabricator under review:
<a href="https://reviews.llvm.org/D78563" target="_blank"><span style="color:#0563C1">https://reviews.llvm.org/D78563</span></a>
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><b><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Pros:</span></b><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- The design is cleaner. It is clear that such field is for AIX and it does not affect any other target
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> in terms of functionality.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in;text-align:justify">
<span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Cons:</span></b><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- All other targets using ItaniumRecordLayoutBuilder will also have to pay the price to keep
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> updating this `<i>AIXOffsetAlignment`
</i>along the common code path by using <i>`UpdateAlignment</i>`. <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">2.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">The second possible way we have in mind is to overload the usage of current Microsoft-ABI only alignment field
<i>`RequiredAlignment</i>` and rename it to `<i>TargetSpecialAlignment</i>` instead of the above first way to create a new alignment field.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">This alignment field will function the same in Itanium ABI part for AIX. Meanwhile, because the current `RequiredAlignment` is
only used in MS code, renaming will not affect MS code path functionally.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Pro:</span></b><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- Class ASTRecordLayout does not need to construct one more field `AIXOffsetAlignment` compared to the method one.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
<span style="font-size:12.0pt;font-family:"Times New Roman",serif">- Instead of having each target add new fields for their special alignment rules, we could have one field that handles all the potential alignment differences for every target.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:39.0pt;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:39.0pt;text-align:justify"><b><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Cons:</span></b><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- Still, all other targets using ItaniumRecordLayoutBuilder will also have to pay the price to <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> keep updating this `TargetSpecialAlignment` along the common code path by using
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> `UpdateAlignment`.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- By overloading the usage, it may create confusion when more targets try to utilize it in the
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> future.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">- The degree of willingness of sharing this current MS-only alignment field is unknown.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">I would like to see how people think about the above two ways. Which one is better? Any concerns about either one? Or any other
ideas to suggest?<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Please let me know if there are any questions about my current proposal and design. Your feedback is appreciated.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">Regards,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;color:#888888"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in;text-align:justify"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;color:#888888">Xiangling Liao<o:p></o:p></span></p>
</div>
</div>
</body>
</html>