<div dir="ltr">Hi Brendon,<div><br></div><div>Thanks so much for this. The explanation really helped. Please do take a look at the new version of my refactor - I think it's a load cleaner than before and now *does* handle all of the weird phi special cases. It's great that the Hexagon lit tests contain so many of these!</div><div><br></div><div>PTAL. It's not 100% ready, but if you like the direction I think this is something we can put in under a flag while we finish out the last few issues.</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 17 Jul 2019 at 20:15, Brendon Cahoon <<a href="mailto:bcahoon@quicinc.com">bcahoon@quicinc.com</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_1625284680028286442WordSection1">
<p class="MsoNormal">Hi James,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">My initial attempt at generating the prolog, kernel, and epilog was quite simple as well. But, as the pipeliner attempted to work on more complex loop structures, the logic got complicated pretty quickly.  This is most evident in the generateExistingPhis
 function, which is a mess.  I wanted this function to be general, but it evolved over time into a sequence of special cases.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">> To dig a little deeper, one thing I don't understand right now (and this is inhibiting me from making effective refactoring) is what it actually means to "schedule" a loop-carried PHI.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This is a good question. I don’t think the Phis need to be scheduled, but even if the Phis aren’t scheduled, we still need to generate new Phis in the prolog and epilog. And, we need to refer to the original Phi to find the incoming values,
 and to maintain the map from original names to new names.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The stage that a Phi is scheduled in is related to the stage(s) where the uses are scheduled, and the stage for the loop definition. The code uses the Phi stage to determine the total number of new Phis to generate. We probably could use
 the stages for the definition and uses to calculate values that we use the Phi for – for example, the number of stages, or copies, needed between the definition and a use.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">If a Phi has the loop definition scheduled in stage 1, and uses of the Phi scheduled in stages 1 and 2, then the Phi will be scheduled in stage 1 most likely.  The kernel will require two new Phis to represent the values used and generated
 in stages 1 and 2. We probably could ignore the stage in which the Phi is scheduled, and compute the number of new Phis based upon the schedule stages for the loop definition and uses.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I don’t believe any of this is described in the SMS paper though.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">> The big thing I'm trying to wrap my head around is the logic in the generateExistingPhis() function<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Yeah, me too sometimes.  The role of this function is to generate new Phis in the kernel and epilogs for each Phi that occurred in the original loop.  This function also updates the mapping between old and new names, VRMap, and updates
 register names used in other instructions.  The function generates the Phis for the kernel, and epilogs at the start.  It needs to determine:<u></u><u></u></p>
<ul style="margin-top:0in" type="disc">
<li class="gmail-m_1625284680028286442MsoListParagraph" style="margin-left:0in">How many new Phis to generate based upon the schedule stages for the definition and uses.<u></u><u></u></li><li class="gmail-m_1625284680028286442MsoListParagraph" style="margin-left:0in">Which stage contains the incoming values, and which block is holding the value for that stage<u></u><u></u></li><li class="gmail-m_1625284680028286442MsoListParagraph" style="margin-left:0in">Rewrite previously scheduled uses, if needed<u></u><u></u></li></ul>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Determining the number of new Phis is straightforward, most of the time.  There are some special cases when a Phi use is scheduled in an earlier cycle, but later stage, than the Phi loop definition.  For example,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">   = a                  cycle 0, stage 1<u></u><u></u></p>
<p class="MsoNormal">   a = phi(b, c)  cycle 1, stage 0<u></u><u></u></p>
<p class="MsoNormal">   c =                  cycle 2, stage 0<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In this case, only 1 new Phi is needed.  If the use of a is scheduled after the definition of c, but still in stage 1, then 2 Phis are needed.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Also, there are some special cases when generating the Phis in the epilog. This happens because the code computes the maximum number of Phis needed, but that value decreases as the number of epilogs generated increases.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Computing the block that contains the incoming values is most of the code in this function. Much of this code attempts to handle various related to Phis that refer to other Phis.  For example,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">   a = phi(b, c)<u></u><u></u></p>
<p class="MsoNormal">   c = phi(d, e)<u></u><u></u></p>
<p class="MsoNormal">      = a<u></u><u></u></p>
<p class="MsoNormal">      = c<u></u><u></u></p>
<p class="MsoNormal">   e =<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The number of dependent phis can be more than 2.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The calculation for the correct block depends on if we’re generating code for the kernel or epilog too.  For example, in the kernel the second Phi operand always comes from the kernel, but in the epilog, the second Phi operand may come
 from the kernel, or a previous epilog block.  The epilog block will never have a Phi that depends on a Phi from the same block (like the case shown above).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In the simplest case, the stage with the incoming value is the difference between the schedule stage of the use and definition.  The extra computation occurs when the Phi or loop definition is not scheduled in stage 0. Then, adjustments
 are made to find the stage and block with the correct value.  If a Phi loop definition is scheduled in stage 1, then the first occurrence of the instruction appears in the kernel (for a 2 stage pipeline). This also means that a Phi is needed in the epilog
 for that value. When extended to schedules with multiple stages, it calculations get trickier.  For example, in a 3 stage pipeline, a Phi loop definition is scheduled in stage 1 appears in the 2<sup>nd</sup> prolog, the kernel, and the 2<sup>nd</sup> epilog. 
 If scheduled in stage 2, it appears in the kernel, 1<sup>st</sup> epilog and 2<sup>nd</sup> epilog.  When rewriting the uses of that Phi, the calculation of the block with the correct value depends its schedule stage (and if the use appears before/after the
 Phi in the schedule).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Let me try to enumerate some more of the special cases in the code.  You’re correct in that we just need to answer a fairly straightforward question about which stage and block contains the value we’re looking for.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Brendon<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b>From:</b> James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>> <br>
<b>Sent:</b> Tuesday, July 16, 2019 9:02 AM<br>
<b>To:</b> Brendon Cahoon <<a href="mailto:bcahoon@quicinc.com" target="_blank">bcahoon@quicinc.com</a>><br>
<b>Cc:</b> Jinsong Ji <<a href="mailto:jji@us.ibm.com" target="_blank">jji@us.ibm.com</a>>; Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>>; LLVM Dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [EXT] Re: MachinePipeliner refactoring<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi Brendon,<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for the in-depth reply!<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">> Loop carried Phis are hard.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I think the whole thing can be summarized like this :) The data flow between prolog, kernel and epilog would be fairly trivial to handle without these (and this is demonstrated by my prototype being ~300 lines of code).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">To dig a little deeper, one thing I don't understand right now (and this is inhibiting me from making effective refactoring) is what it actually means to "schedule" a loop-carried PHI. In my naive head, things would be a lot simpler if
 all phis were scheduled in stage zero. Given that they are free, is the idea behind them being in a non-zero stage purely for register allocation? (I'm aware the answer to this may well be "read the SMS literature more carefully"!)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">The big thing I'm trying to wrap my head around is the logic in the generateExistingPhis() function. I feel that everything else seems fairly easy to refactor; it's the logic here that's tied closely to the concepts of prologs and epilogs.
 It feels like we should be able to answer the question "Given this loop-carried PHI, what instruction in what stage (as an offset from the current stage) generates this value?"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">If we could answer that question, generating the tree of phis to plumb the values through seems, while not trivial, an orthogonal task.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for answering my newbie questions!<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">James<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, 16 Jul 2019 at 01:35, Brendon Cahoon <<a href="mailto:bcahoon@quicinc.com" target="_blank">bcahoon@quicinc.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi James,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I also think that refactoring the code generation part is a great idea.  That code is very complicated and difficult to maintain. I’ve wanted to rewrite that code for a long time,
 but just have never got to it.  There are quite a few edge cases to handle (at least in the current code). I’ll take a deeper look at your patch.  The abstractions that you mention, Stage and Block, are good ones. I think you’ll need to account for the cycle,
 or position within a Stage as well. It is a complex problem with a lot different edge cases when dealing with Phis, though I think they can be dealt with much better than the existing code.  <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Generating code for the 3 main parts, the prolog, kernel, and epilog, can be challenging because each has a unique difference that made is hard to generalize the code.  For example,
 the prologs will not have an Phis, but the code generation needs to be aware of when the Phis occur in the sequence in order to get the correct remapped name. In the kernel, values may come from a previous iteration of the kernel. In the epilog, values can
 come from the same epilog block, the kernel, or a prolog block.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">It would be great to be able to generate the compact representation that you describe, so that a prolog/epilog do not need to be generated. Hexagon has a special hardware loop instruction,
 spNloop, specifically for this. Although, the compiler does not generate that instruction currently.  Perhaps it would be easier to generate this form first, and then convert it to a prolog(s), kernel, epilog(s) sequence.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">There are a lot of subtle rules when dealing with the Phi instructions depending on when they are scheduled relative to uses. There are two different factors to account for – the
 stage and cycle when the Phi is scheduled.  For example, a use of a Phi can be scheduled at an earlier cycle, but later stage. Several different combinations can occur, and each use of the Phi can have a different stage/cycle.  Maintaining the map between
 new and old virtual registers depends on the stage, cycle, and the current block (prolog, kernel, or epilog).<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">The epilogs are generated in reverse order due to the way the instructions need to be laid out. The first epilog block after the kernel is going to have instructions scheduled in
 the last stage only, then the next epilog block, if needed, will have instructions from LastStage-1 first, then the LastStage.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Let’s say we have instructions x, y, z, that are scheduled in different iterations/stage, x in stage0, y in stage1, and z in stage2, and x generates a value used by y, which generates
 a value used by z. The generated code will look like:<u></u><u></u></p>
<p class="MsoNormal">Prolog 0 (this block ends with a conditional jump to Epilog 0):<u></u><u></u></p>
<p class="MsoNormal">  X<u></u><u></u></p>
<p class="MsoNormal">Prolog 1 (this block ends with a conditional jump to Epilog 1):<u></u><u></u></p>
<p class="MsoNormal">  Y<u></u><u></u></p>
<p class="MsoNormal">  X<u></u><u></u></p>
<p class="MsoNormal">Kernel:<u></u><u></u></p>
<p class="MsoNormal">  Z, Y, X<u></u><u></u></p>
<p class="MsoNormal">Epilog 0:<u></u><u></u></p>
<p class="MsoNormal">  Z<u></u><u></u></p>
<p class="MsoNormal">Epilog 1:<u></u><u></u></p>
<p class="MsoNormal">  Y<u></u><u></u></p>
<p class="MsoNormal">  Z<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">The instructions in the prolog and epilog are generate in original program order within each stage, but in the last epilog stage, the instruction Y generates a value used by the
 subsequent Z.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">The reduceLoopCount function is needed for an architecture that has a hardware loop instruction like Hexagon’s LOOP0.  For each prolog generated, the loop counter in the instruction
 needs to be decremented. This could have been done only in the last prolog block, but it’s done every time a prolog block is generated instead (initially, I thought that would be easier since the prolog generation code wouldn’t need to know which block was
 the last one).  But, later, I added code to handle the case when the loop can be removed completely. It seems reasonable to change this so that it’s updated only once, especially since find the loop instruction can require searching through the CFG.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Loop carried Phis are hard. Initially, I tried handling the cases for adding new Phis and existing Phis with one function. But, it turned out that adding new Phis, when a instruction
 use is generated in an earlier cycle, but later stage, doesn’t cause as many special cases as handling the different edge cases for an existing Phis.  There are less combinations when adding a new Phis.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Yes, you’re correct about the use of “iteration” vs. “stage” (I even used them together earlier).  The use of term stage comes from the paper, but I often use iteration when talking
 to others about software pipelining, especially if they have read the paper.  I agree that we should be more consistent with using the terms.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Let me think some more about the questions you’ve asked. I do think it’s worthwhile to spend some time on creating a good abstraction and improving the code. I appreciate that you’ve
 started to think/work on this problem, so I’d like to help out to pursue this direction.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Brendon<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><b>From:</b> James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>>
<br>
<b>Sent:</b> Monday, July 15, 2019 11:05 AM<br>
<b>To:</b> Jinsong Ji <<a href="mailto:jji@us.ibm.com" target="_blank">jji@us.ibm.com</a>><br>
<b>Cc:</b> Brendon Cahoon <<a href="mailto:bcahoon@quicinc.com" target="_blank">bcahoon@quicinc.com</a>>; Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>>; LLVM Dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [EXT] Re: MachinePipeliner refactoring<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hi Jingsong,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for testing out the prototype! I'm not surprised there are errors in that version; it's not 100% ready yet (mainly a demonstrator for the path I'd like to take). I'm really
 trying to work out if it makes sense to try and incrementally get from the current state of the world to that prototype incrementally, or if it's just so far away that a full-on refactor (or two code paths) is required. I suspect only Brendan really has the
 context to give insight there!<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">James<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, 15 Jul 2019 at 16:32, Jinsong Ji <<a href="mailto:jji@us.ibm.com" target="_blank">jji@us.ibm.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<p><span style="font-family:"Times New Roman",serif">Hi James:</span><br>
<br>
<span style="font-family:"Times New Roman",serif">Personally, I like the idea of refactoring and more abstraction, </span><br>
<span style="font-family:"Times New Roman",serif">But unfortunately, I don't know enough about the edges cases either.</span><br>
<br>
<span style="font-family:"Times New Roman",serif">BTW: the prototype is still causing quite some Asseertions in PowerPC - some nodes are not generated in correct order.</span><br>
<br>
<br>
<span style="font-size:10pt">Best,<br>
<br>
Jinsong Ji (</span><span style="font-size:10pt;font-family:"Microsoft JhengHei",sans-serif">纪金松</span><span style="font-size:10pt">), PhD.<br>
<br>
XL/LLVM on Power Compiler Development <br>
E-mail: <a href="mailto:jji@us.ibm.com" target="_blank">jji@us.ibm.com</a></span><br>
<br>
<img border="0" width="16" height="16" style="width: 0.1666in; height: 0.1666in;" id="gmail-m_1625284680028286442gmail-m_2225239062625164941_x005f_x0000_i1025" src="cid:16c3d8107944cdccc1" alt="Inactive hide details for James Molloy ---07/15/2019 06:16:22 AM---Hi Brendan (and friends of MachinePipeliner, +llvm-dev for o"><span style="font-size:10pt;color:rgb(66,66,130)">James
 Molloy ---07/15/2019 06:16:22 AM---Hi Brendan (and friends of MachinePipeliner, +llvm-dev for openness), Over the past week or so I've</span><br>
<br>
<span style="font-size:10pt;color:rgb(95,95,95)">From: </span><span style="font-size:10pt">James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>></span><br>
<span style="font-size:10pt;color:rgb(95,95,95)">To: </span><span style="font-size:10pt">LLVM Dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>,
<a href="mailto:jji@us.ibm.com" target="_blank">jji@us.ibm.com</a>, <a href="mailto:bcahoon@quicinc.com" target="_blank">
bcahoon@quicinc.com</a>, Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span><br>
<span style="font-size:10pt;color:rgb(95,95,95)">Date: </span><span style="font-size:10pt">07/15/2019 06:16 AM</span><br>
<span style="font-size:10pt;color:rgb(95,95,95)">Subject: </span><span style="font-size:10pt">[EXTERNAL] MachinePipeliner refactoring</span><u></u><u></u></p>
<div>
<div class="MsoNormal">
<hr size="2" width="100%" noshade style="color:rgb(128,145,165)" align="left">
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12pt"><br>
<br>
<br>
Hi Brendan (and friends of MachinePipeliner, +llvm-dev for openness),<br>
<br>
Over the past week or so I've been attempting to extend the MachinePipeliner to support different idioms of code generation. To make this a bit more concrete, there are two areas where the currently generated code could be improved depending on architecture:<br>
<br>
  1) The epilog blocks peel off the final iterations in reverse order. This means that the overall execution of loop iterations isn't in a perfectly pipelined order. For architectures that have hardware constructs that insist on a first-in-first-out order (queues),
 the currently generated code cannot be used.<br>
  2) For architectures (like Hexagon) that have dedicated predicate register files, we can generate a compact representation of the loop by predicating stages of the loop kernel independently. In this case we can either have a prolog, epilog, or neither (wrapping
 the prolog and epilog inside the kernel by using PHIs of predicates).<br>
<br>
At the moment, a lot of the code generation helper code in MachinePipeliner is tightly fit to its current code generation strategy ("If we're in the epilog, to this, else do this"). I'm keen to try and make some of the complex calculations it does, such as
 where PHIs should come from, more abstract so they can be reused and composed.<br>
<br>
<a href="https://reviews.llvm.org/D64665" target="_blank">https://reviews.llvm.org/D64665</a> is my current best-effort. This generates perfect code for PowerPC, but causes a load of problems for Hexagon. It's become apparent that I don't know enough about
 some of the edge cases in the MachinePipeliner code to refactor this from scratch. I'm therefore looking for direction in factoring in an incremental fashion.<br>
<br>
I think there are a couple of areas that I'd like to change, and I'd appreciate your ideas and opinions because I clearly don't know enough about the edge cases here.<br>
<br>
  a) TII->reduceLoopCount() is hard to understand. Understanding the intended semantics of this hook from the documentation, I've found, is hard. Its use appears to be strongly fit to Hexagon (there is even a comment about the removal of LOOP0 in the MachinePipeliner
 target agnostic code, which really shouldn't be there). Why it's called multiple times I don't understand (why can't we just call it once with the total number of iterations to peel?).<br>
  b) Understanding how loop-carried PHIs are linked together is really hard. There are two functions dedicated to this with many edge cases, which are linked with the prolog and epilog schedule. It'd be great to somehow factor these such that they are independent
 of the code generation strategy. Note that this is really important for some of the code gen strategies I mention at the beginning, because loop-carried PHIs in this case may actually end up being selects or uses of predicated instructions.<br>
  c) There is a slight conflation of "iteration" and "stage" in the documentation that makes it hard to follow what VRMap contains and the invariants between functions.<br>
<br>
My intent in D64665 was to create two abstractions: "Stage" and "Block". Instead of referring to stages by index (VRMap), each Stage would take a prior Stage as input. Stages are contained inside Blocks, which handles predecessors and successors. I feel that
 arranging the code generation in this CFG-like way will make the flow of data much easier to analyze. Of course, a Stage doesn't just depend on a prior Stage - their loop carried inputs could come from any other Stage (and while I think I understand how this
 works, I clearly don't get all the edge cases).<br>
<br>
What do you think of this abstraction? do you think it's doomed to failure because it's too simplistic to cover all the cases?<br>
<br>
Do you have any suggestions of areas where we can start to factor out without a large-scale code breakage? I'm finding this hard to get my teeth into as the proposed code structure is so different from its current form.<br>
<br>
Thanks for any opinions or suggestions!<br>
<br>
Cheers,<br>
<br>
James<u></u><u></u></p>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>

</blockquote></div>