[PATCH] D22959: MachineLoopInfo: add methods findLoopPreheader and getExitingBlock

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 07:12:53 PDT 2016


SjoerdMeijer added inline comments.

================
Comment at: lib/CodeGen/MachineLoopInfo.cpp:84
@@ +83,3 @@
+
+  MachineBasicBlock *HB = L->getHeader(), *LB = L->getLoopLatch();
+  if (HB->pred_size() != 2 || HB->hasAddressTaken())
----------------
kparzysz wrote:
> This part is finding a block that can enter the loop header, but may also go somewhere else.  On Hexagon we can use it to put the hardware loop setup here, since it can be safely speculated.  Code that cannot be speculated cannot be placed here.
> Maybe you could add a parameter to let the caller decide whether they want just the regular preheader, or a speculative one.
> 
> On a different note, have you checked how many potential users for this are there?  Is there a demand for this?
Thanks for reviewing! I will start making these changes.

About users for this: what I actually want is to have the "getLoopTripCount" available on the MachineLoop level, and the refactoring in this patch is the first exercise or groundwork to achieve that.  It looks like you have done most of the hard work already in the Hexagon backend; looking at the getLoopTripCount implementation, there is actually very little Hexagon specific, only one place checks for Hexagon add instruction opcodes (which I think is not hard to nicely hide in a target hook). I think these MachineLoop utility functions such as getLoopTripCount, findLoopPreheader, getExitBlocks, etc., are mostly target independent and really nice to have (and I would definitely like to use them). In fact, for implementing more loop transformations on Machine blocks, these functions are required...



https://reviews.llvm.org/D22959





More information about the llvm-commits mailing list