<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Aug 17, 2020, at 4:06 PM, James Y Knight via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="auto" class=""><div dir="auto" class="">It looks to me as if at least examples 1, 2, and 4 are places that should <i class="">not</i> be changed to use the "AIX preferred" alignment, because they are inquiring about the guaranteed alignment of an existing pointer, which may well not have been placed at the preferred alignment. I haven't dug into the code beyond your snippet so I'm not sure about examples 3 and 5.</div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="auto" class=""><div dir="auto" class=""></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Are you saying you think all 5 of these examples should be using the AIX preferred alignment? Or are you just listing locations that call getTypeAlign and therefore need to be examined?</div></div></div></div></blockquote><div><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">I would have to think that, whatever the documentation for e.g. <span style="font-stretch: normal; line-height: normal; font-family: Menlo;" class="">getTypeAlignInChars(T)</span>, most users expect it to return T’s actual alignment for their target, whether it was determined from the ABI, or the AIX alignment scheme, or whatever.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">In fact, maybe we can go further: I would think that any valid use of type alignment which explicitly ignores AIX or other target-specific alignment schemes are probably just implementation details used only in the calculation of some composed type’s alignment under that scheme. In other words I would assume every function call in which AIX preferred alignment needed to be ignored is in the some layout-building implementation — is that right?</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">E.g. the lib/AST/RecordLayoutBuilder.cpp example you cite below fits this description — in <span style="font-stretch: normal; line-height: normal; font-family: Menlo;" class="">LayoutField(FieldDecl *D, …)</span> you propose to change the call to fetch the ABI/non-AIX type info via </div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class="">getTypeInfo(D->getType(), true/* NeedsABIAlignment */);</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">but only so that you can later tweak that info whenever <span style="font-stretch: normal; line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(27, 31, 34); background-color: rgb(255, 255, 255);" class="">DefaultsToAIXPowerAlignment==true</span>. </div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">If all the changes you would need to make are indeed similar to this, these expanded usages are really only implementation details needed to build type layouts, and thus the goal should simply be to sufficiently hide these details from common programmers who don’t need to build type layouts, only access them.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">I think your original option #2 ("add a flag"), i.e. adding new defaulted parameters to a few functions, seems to be a reasonable way to hide these new details, so long as the new parameters are well named and documented. It also seems sufficiently general to be useful for implementing other special default alignment schemes in the future.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Dave</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="auto" class=""><div dir="auto" class=""></div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Aug 12, 2020, 5:26 PM Xiangling Liao <<a href="mailto:xiangxdh@gmail.com" target="_blank" class="">xiangxdh@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="font-family:"Times New Roman",serif;color:rgb(197,90,17)" class="">1. "a real name is more readable"<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">Hi Eli, could you elaborate a little more on what real name
you are expecting?<span class=""></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span style="font-family:"Times New Roman",serif" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="font-family:"Times New Roman",serif;color:rgb(197,90,17)" class="">2. "I guess the question here is what the “default”
getTypeAlign means; either it’s the ABI alignment, and we fix all the places
that want the “AIX preferred” alignment, or it’s the “AIX preferred” alignment,
and we fix all the places that want the ABI alignment."<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span style="font-family:"Times New Roman",serif" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="font-family:"Times New Roman",serif" class="">Based on the comment on `getTypeAlignInChars`, "<i class="">Return
the ABI-specified alignment of a type, in characters. This method does not work
on incomplete types</i>.", I believe `getTypeAlignInChars` and all other
three functions I mentioned earlier(which have similar comments) are designed
for getting ABI alignment. And these functions are used pervasively in Clang
code. So we need to fix all the places where an "AIX preferred"
alignment is wanted when the target defaults to AIX power alignment. And the
problem we are trying to deal with is how do we fix those alignment issues. So
far we can think of:<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span style="font-family:"Times New Roman",serif" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="font-family:"Times New Roman",serif" class="">1) Replace "getTypeAlign" with the following all
over the places(which I think this chunk would make the code a bit ugly, and
also has migration risk)<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span style="font-family:"Times New Roman",serif" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><i class=""><span style="font-size: 10pt; font-family: "Times New Roman", serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">DefaultsToAIXPowerAlignment</span></i><span style="font-family:"Times New Roman",serif;background:rgb(217,217,217) none repeat scroll 0% 0%" class=""><span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><i class=""><span style="font-size: 10pt; font-family: "Times New Roman", serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">
? getPreferredTypeAlign</span></i><span style="font-family:"Times New Roman",serif;background:rgb(217,217,217) none repeat scroll 0% 0%" class=""><span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><i class=""><span style="font-size: 10pt; font-family: "Times New Roman", serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">
: getTypeAlign</span></i><span style="font-family:"Times New Roman",serif;background:rgb(217,217,217) none repeat scroll 0% 0%" class=""><span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">2) Wrap above with a new function with
migration risk as I stated before<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">3) Add a flag as I stated before<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span lang="EN-US" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">Any other ideas are also welcome.</span><span style="font-family:"Times New Roman",serif" lang="EN-US" class=""><span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="color:rgb(197,90,17)" class="">3. “</span><span style="font-family:"Times New Roman",serif;color:rgb(197,90,17)" class="">please specify what the other cases are that need to change</span><span style="color:rgb(197,90,17)" class="">”<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span style="" class="">The usage of
those functions are way too many to be listed all here(probably at least 50
spots), so I just picked several residing on the common path for all targets.</span><span style="" lang="EN-US" class=""><span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span style="color:rgb(197,90,17)" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">Eg.1:<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><lib/Sema/SemaChecking.cpp><span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">static CharUnits getPresumedAlignmentOfPointer(const Expr
*E, Sema &S) {<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class=""> </span>// See if we can
compute the alignment of a VarDecl and an offset from it.<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class="">
</span>Optional<std::pair<CharUnits, CharUnits>> P =<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class="">
</span>getBaseAlignmentAndOffsetFromPtr(E, S.Context);<span class=""></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span class=""> </span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class=""> </span>if (P)<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class=""> </span>return
P->first.alignmentAtOffset(P->second);<span class=""></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span class=""> </span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class=""> </span>// If that failed,
return the type's alignment.<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span class=""> </span>return S.Context.<span style="color:rgb(197,90,17)" class="">getTypeAlignInChars</span>(E->getType()->getPointeeType());<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">}<span class=""></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span class=""> </span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">Eg.2:<span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><lib/Sema/SemaChecking.cpp><span lang="EN-US" class=""><span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">void
Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>E = E->IgnoreParens();<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>if (!T->isPointerType() &&
!T->isIntegerType())<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>return;<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>if (isa<UnaryOperator>(E) &&<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class="">
</span>cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>auto *Op =
cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>if (isa<MemberExpr>(Op)) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>auto MA = llvm::find(MisalignedMembers,
MisalignedMember(Op));<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>if (MA != MisalignedMembers.end()
&&<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>(T->isIntegerType() ||<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>(T->isPointerType() &&
(T->getPointeeType()->isIncompleteType() ||<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>Context.<span style="color:rgb(197,90,17)" class="">getTypeAlignInChars</span>(<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class="">
</span>T->getPointeeType()) <= MA->Alignment))))<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>MisalignedMembers.erase(MA);<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>}<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>}<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">}<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span lang="EN-US" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">Eg.3:<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">< lib/CodeGen/CGOpenMPRuntime.cpp><span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">Address
CGOpenMPRuntime::getOrCreateDefaultLocation(unsigned Flags) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>CharUnits Align = CGM.getContext().<span style="color:rgb(197,90,17)" class="">getTypeAlignInChars</span>(IdentQTy);<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>unsigned Reserved2Flags =
getDefaultLocationReserved2Flags();<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span><span class=""> </span>...<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">}<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span lang="EN-US" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">Eg.4:<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">< lib/CodeGen/CGAtomic.cpp><span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">static void<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">AddDirectArgument(CodeGenFunction
&CGF, CallArgList &Args,<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>bool UseOptimizedLibcall,
llvm::Value *Val, QualType ValTy,<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>SourceLocation Loc, CharUnits
SizeInChars) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>if (UseOptimizedLibcall) {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>// Load value and pass it to the function
directly.<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>CharUnits Align = CGF.getContext().<span style="color:rgb(197,90,17)" class="">getTypeAlignInChars</span>(ValTy);<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">...<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">}<span class=""></span></span></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span lang="EN-US" class=""><span class=""> </span></span></p><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">Eg.5:<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">< lib/CodeGen/TargetInfo.cpp><span class=""></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">ABIArgInfo
ABIInfo::getNaturalAlignIndirect(QualType Ty, bool ByVal,<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class="">
</span>bool Realign,<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span><span class=""> </span>llvm::Type
*Padding) const {<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>return ABIArgInfo::getIndirect(getContext().<span style="color:rgb(197,90,17)" class="">getTypeAlignInChars</span>(Ty),
ByVal,<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class=""><span class=""> </span>Realign,
Padding);<span class=""></span></span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><span lang="EN-US" class="">}</span></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class=""><br class=""></div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">Thank you,</div><div style="margin: 0cm; font-size: 12pt; font-family: Georgia, serif;" class="">Xiangling<br class=""></div><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:"Georgia",serif"><span lang="EN-US" class=""><span class=""></span></span></p>
</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 12, 2020 at 3:08 PM James Y Knight <<a href="mailto:jyknight@google.com" rel="noreferrer" target="_blank" class="">jyknight@google.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Agree with Eli -- please specify what the other cases are that need to change, besides the alignment used for "new".</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 12, 2020 at 2:46 PM Eli Friedman <<a href="mailto:efriedma@quicinc.com" rel="noreferrer" target="_blank" class="">efriedma@quicinc.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US" class="">
<div class=""><p class="MsoNormal">I don’t think using a boolean argument is appropriate here; nobody is going to pass in anything other than constant true/false, so a real name is more readable.<u class=""></u><u class=""></u></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p><p class="MsoNormal">I guess the question here is what the “default” getTypeAlign means; either it’s the ABI alignment, and we fix all the places that want the “AIX preferred” alignment, or it’s the “AIX preferred” alignment, and we fix all the places that
want the ABI alignment. I think it’s essentially a numbers game: which one is actually more commonly used? Please give more examples.<u class=""></u><u class=""></u></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p><p class="MsoNormal">-Eli<u class=""></u><u class=""></u></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in" class=""><p class="MsoNormal" style="margin-left:0.5in"><b class="">From:</b> Xiangling Liao <<a href="mailto:xiangxdh@gmail.com" rel="noreferrer" target="_blank" class="">xiangxdh@gmail.com</a>>
<br class="">
<b class="">Sent:</b> Wednesday, August 12, 2020 10:56 AM<br class="">
<b class="">To:</b> <a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class="">
<b class="">Cc:</b> <a href="mailto:hubert.reinterpretcast@gmail.com" rel="noreferrer" target="_blank" class="">hubert.reinterpretcast@gmail.com</a>; <a href="mailto:jasonliu.development@gmail.com" rel="noreferrer" target="_blank" class="">jasonliu.development@gmail.com</a>; Eli Friedman <<a href="mailto:efriedma@quicinc.com" rel="noreferrer" target="_blank" class="">efriedma@quicinc.com</a>>; James Y Knight <<a href="mailto:jyknight@google.com" rel="noreferrer" target="_blank" class="">jyknight@google.com</a>>; Reid Kleckner <<a href="mailto:rnk@google.com" rel="noreferrer" target="_blank" class="">rnk@google.com</a>><br class="">
<b class="">Subject:</b> [EXT] [RFC] Use preferred alignment instead of ABI alignment for complete object when applicable<u class=""></u><u class=""></u></p>
</div><p class="MsoNormal" style="margin-left:0.5in"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">On some targets, preferred alignment is larger than ABI alignment in some cases. For example, on AIX we have special power alignment rules which would cause
that. The full discussion details can be found here if interested: <a href="http://lists.llvm.org/pipermail/cfe-dev/2020-April/065304.html" rel="noreferrer" target="_blank" class="">
<span style="color:rgb(5,99,193)" class="">http://lists.llvm.org/pipermail/cfe-dev/2020-April/065304.html</span></a> .</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Previously, to support those cases, we added a “PreferredAlignment” field in the `RecordLayout` to store the AIX special alignment values in “PreferredAlignment”
as the community suggested. It makes sure both `_alignof` and `alignof` return correct values for AIX objects. (The related patch is here:
<a href="https://reviews.llvm.org/D79719" rel="noreferrer" target="_blank" class=""><span style="color:rgb(220,161,13);text-decoration:none" class="">https://reviews.llvm.org/D79719</span></a> .)</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p style="margin-right:0in;margin-left:0.5in;margin-bottom:0.0001pt" class="">
<span style="font-size:12pt;font-family:Times,serif" class="">However, that patch alone is not enough. With AIX’s special alignment rule, we need to use “PreferredAlignment” for a majority of the places where ABI alignment are currently used in .</span><span style="font-size:10pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p style="margin-right:0in;margin-left:0.5in;margin-bottom:0.0001pt" class="">
<span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:10pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Take the cookie size for array new operator calculation for example, the clang invokes `<i class="">getTypeAlignInChars`
</i>to get ABI alignment value:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">CharUnits ItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // The array cookie is a size_t; pad that up to the element alignment.</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // The cookie is actually right-justified in that space.</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> return std::max(CharUnits::fromQuantity(CGM.SizeSizeInBytes),</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">
<b class="">CGM.getContext().getTypeAlignInChars(elementType));</b></span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">}</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p>
<div class=""><p class="MsoNormal" style="margin-left:0.5in"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">So far, we identify that there are 4 functions returning ABI alignment:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">1) getTypeAlignInChars [invokes getTypeAlign]</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">2) getTypeAlign <=> getTypeInfo(T).<a href="https://clang.llvm.org/doxygen/structclang_1_1TypeInfo.html#af98dcefc364629eff868a1bb4010ebd8" rel="noreferrer" target="_blank" class=""><span style="color:rgb(220,161,13)" class="">Align</span></a></span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">3) getTypeInfo [ invokes ‘getTypeInfoImpl’]</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">4) getTypeInfoInChars</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size:12pt;font-family:Times,serif" class=""> </span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Some possible ways we can think of are:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size:12pt;font-family:Times,serif" class="">1. Create a new function to be invoked instead</span></b><span style="font-size:12pt;font-family:Times,serif" class="">, e.g:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// getTypeProperAlignInChars - Return the ABI-specified alignment of a type, in</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// characters. Except on AIX, return the preferred type alignment instead when</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// under power alignment rules.</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">CharUnits ASTContext::getTypeProperAlignInChars(QualType T) const {</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> if (Target->defaultsToAIXPowerAlignment())</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> return toCharUnitsFromBits(getPreferredTypeAlign(T.getTypePtr()));</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> </span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> return getTypeAlignInChars(T);</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">}</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size:12pt;font-family:Times,serif" class=""> </span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Take the calculation of cookie size for array new operator for example, we need:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">CharUnits ItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // The array cookie is a size_t; pad that up to the element alignment.</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // The cookie is actually right-justified in that space.</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> return std::max(CharUnits::fromQuantity(CGM.SizeSizeInBytes),</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">- CGM.getContext().getTypeAlignInChars(elementType));</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ CGM.getContext().getTypeProperAlignInChars(elementType));</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">}</span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><i class=""><span style="font-size:12pt;font-family:Times,serif" class=""> </span></i><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><i class=""><span style="font-size:12pt;font-family:Times,serif" class="">Cons:</span></i></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">The migration risk is high. We cannot guarantee in the future the developers would know this is the interface they should use as always for any common path
code. So it seems this is not a viable method.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size:12pt;font-family:Times,serif" class="">2. Add a flag
</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Adding a flag like the following can help us:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">e.g.1 – getTypeAlignInChars</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// If `<b class=""> NeedsABIAlignment
</b>` is false, this function will smartly return preferred alignment </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// or ABI alignment depends on if the target defaults to AIX power alignment or not;</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">/// Set `<b class=""> NeedsABIAlignment
</b>` as true if an ABI alignment is needed no matter what target is.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">CharUnits ASTContext::getTypeAlignInChars(QualType T, <b class="">bool NeedsABIAlignment = false</b>) const {<br class="">
if (NeedsABIAlignment)<br class="">
return toCharUnitsFromBits(getTypeAlign(T));<br class="">
if (Target->defaultsToAIXPowerAlignment())<br class="">
return toCharUnitsFromBits(getPreferredTypeAlign(T.getTypePtr())); </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> return toCharUnitsFromBits(getTypeAlign(T));<br class="">
}</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Take cookie size for array new operator calculation for example again, we don’t need to make any change anymore.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">e.g.2 - getTypeInfoImpl</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">TypeInfo ASTContext::getTypeInfoImpl(const Type *T,
<b class="">bool NeedsABIAlignment = false</b>) const {</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">...</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> switch (T->getTypeClass()) {</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">...</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> case Type::Record:</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> const auto *RT = cast<RecordType>(TT);</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> const RecordDecl *RD = RT->getDecl();</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> const ASTRecordLayout &Layout = getASTRecordLayout(RD);</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> Width = toBits(Layout.getSize());</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ if (NeedsABIAlignment)</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ Align = toBits(Layout.getAlignment());</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ else if (</span></i></b><b class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">Target->defaultsToAIXPowerAlignment()<i class="">)</i></span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ Align = toBits(Layout.getPreferredAlignment());</span></i></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><i class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ else</span></i></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> Align = toBits(Layout.getAlignment());</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> AlignIsRequired = RD->hasAttr<AlignedAttr>();</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> break;</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> }</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">...</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">}</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size:12pt;font-family:Georgia,serif" class="">An usage example on the call site:</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><Clang/ lib/AST/RecordLayoutBuilder.cpp><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> auto setDeclInfo = [&](bool IsIncompleteArrayType) {</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">- TypeInfo TI = Context.getTypeInfo(D->getType());</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class="">+ TypeInfo TI = Context.getTypeInfo(D->getType(), true/* NeedsABIAlignment */);</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> FieldAlign = Context.toCharUnitsFromBits(TI.Align);</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // Flexible array members don't have any size, but they have to be</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> // aligned appropriately for their element type.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> EffectiveFieldSize = FieldSize =</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> IsIncompleteArrayType ? CharUnits::Zero()</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> : Context.toCharUnitsFromBits(TI.Width);</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> AlignIsRequired = TI.AlignIsRequired;</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size: 12pt; font-family: Times, serif; background-image: none; background-attachment: scroll; background-color: rgb(217, 217, 217); background-position: 0% 0%; background-repeat: repeat repeat;" class=""> };</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size:12pt;font-family:Times,serif" class="">Pros:</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">1) By adding a flag like above, we can minimize the changes needed to make. The scope of changes will be shortened to only a few spots where an ABI alignment
is necessary even when AIX special alignment is set.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">2) Letting people consciously pass `true` in if needed is another benefit. Then targets like AIX don’t need to worry about things going wrong accidentally
in the future.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><b class=""><span style="font-size:12pt;font-family:Times,serif" class="">cons:</span></b><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class="">Those four functions I mentioned above won’t return ABI-specified alignment values all the time anymore.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class="">I would like to see how people think about our proposal. Any concerns? Or any other ideas to suggest?</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class="">Please let me know if there are any questions about our current proposal and design. Your feedback is appreciated.</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class="">Regards,</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class=""> </span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal" style="margin-left:0.5in;text-align:justify"><span style="font-size:12pt;font-family:Times,serif" class="">Xiangling Liao</span><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u><u class=""></u></span></p>
</div><p class="MsoNormal" style="margin-left:0.5in"><span style="font-size:12pt;font-family:Georgia,serif" class=""><u class=""></u> <u class=""></u></span></p>
</div>
</div>
</div>
</blockquote></div>
</blockquote></div>
</blockquote></div></div></div>
</div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>