<div dir="ltr">I don't really know the history, but I was just looking at this and wondering if I could rip out that entire infrastructure since it seems to be rather complex dead-code.<div><br></div><div>There's an abandoned follow-on patch <a href="https://reviews.llvm.org/D34396">https://reviews.llvm.org/D34396</a> that may be helpful to look at.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 22, 2019 at 11:52 AM Davis, Alan via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></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">
<div class="gmail-m_8070015094872264444WordSection1">
<p class="MsoNormal"><span style="color:rgb(31,73,125)">… Replying to my own message since no one else did :-;  
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">… and hoping for a little insight on the MCCodePadding class.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">Essentially I need a way to create alignment padding whose size can be adjusted based on the content (not just the address) of other MCFragments. (MCAlignFragments don’t quite fit the bill because they only look
 at the next Fragment’s Offset, not its contents.) It seems like this sort of aligns with the purpose of MCCodePadder, which adjusts the size of an MCPaddingFragment based on other fragments. But MCCodePadder is an enigma. No targets seem to use it; it has
 virtual methods as if it’s intended for targets to override it MCAssembler is hardwired to construct the base class; its addPolicy() is also protected from target access; and it’s not clear what it’s actually intending to do – in particular I don’t get the
 “window” concept.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">Can anyone shed light on how this is supposed to work?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">-Alan <u></u><u></u></span></p>
<p class="MsoNormal"><a name="m_8070015094872264444__MailEndCompose"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></a></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"> Davis, Alan
<br>
<b>Sent:</b> Wednesday, November 20, 2019 5:07 PM<br>
<b>To:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> [MCAssembler] changing layout in assembler backend<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Our target has a perhaps unique problem relating to code alignment. Like other targets, it wants to insert NOPs for an FT_Align fragment. The unique part is that it has a way to “fold” these NOPs into the previous instruction packet, so
 that when falling through to the aligned label there is no execution penalty. Doing so requires re-encoding the previous packet, which “enlarges” it such that no actual NOPs are needed.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So I’d like to do this in the target-specific MCAsmBackend, in the finishLayout hook which is called after the MCAssembler finishes the layout pass. The idea is to look for FT_Align fragments, see how much padding they generate, find the
 previous packet, and re-encode it. The problem is that doing so changes the layout – sort of. Actually, it just changes the offset of the FT_Align fragment because the previous packet is larger. I could just do that directly… but the Offset member is private
 to the Fragment and only settable by its friend the MCAsmLayout class.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I looked at doing this via relaxation but there is not enough context. In particular the backend’s relaxation API does not have access to the fragment list.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Also I noticed there is an interesting looking mechanism called MCCodePadder, but it’s super obtuse and no in-tree targets seem to use it.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">For now I just made MCFragment’s Offset public and modified it directly from finishLayout. But that seems like it significantly undermines the design. Ideally I think the MCAsmBackend should have authority to do whatever it needs to do,
 including adjusting the layout (especially in an API called “finishLayout”) but currently that is not the case. I’m looking for advice on how to make this work with minimal changes to the existing APIs.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-Alan<u></u><u></u></p>
</div>
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>