|
8 | 8 |
|
9 | 9 | #include "VPlanUtils.h" |
10 | 10 | #include "VPlanCFG.h" |
| 11 | +#include "VPlanDominatorTree.h" |
11 | 12 | #include "VPlanPatternMatch.h" |
12 | 13 | #include "llvm/ADT/TypeSwitch.h" |
13 | 14 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
@@ -253,3 +254,29 @@ vputils::getRecipesForUncountableExit(VPlan &Plan, |
253 | 254 |
|
254 | 255 | return UncountableCondition; |
255 | 256 | } |
| 257 | + |
| 258 | +bool VPBlockUtils::isHeader(const VPBlockBase *VPB, |
| 259 | + const VPDominatorTree &VPDT) { |
| 260 | + auto *VPBB = dyn_cast<VPBasicBlock>(VPB); |
| 261 | + if (!VPBB) |
| 262 | + return false; |
| 263 | + |
| 264 | + // If VPBB is in a region R, VPBB is a loop header if R is a loop region with |
| 265 | + // VPBB as its entry, i.e., free of predecessors. |
| 266 | + if (auto *R = VPBB->getParent()) |
| 267 | + return !R->isReplicator() && !VPBB->hasPredecessors(); |
| 268 | + |
| 269 | + // A header dominates its second predecessor (the latch), with the other |
| 270 | + // predecessor being the preheader |
| 271 | + return VPB->getPredecessors().size() == 2 && |
| 272 | + VPDT.dominates(VPB, VPB->getPredecessors()[1]); |
| 273 | +} |
| 274 | + |
| 275 | +bool VPBlockUtils::isLatch(const VPBlockBase *VPB, |
| 276 | + const VPDominatorTree &VPDT) { |
| 277 | + // A latch has a header as its second successor, with its other successor |
| 278 | + // leaving the loop. A preheader OTOH has a header as its first (and only) |
| 279 | + // successor. |
| 280 | + return VPB->getNumSuccessors() == 2 && |
| 281 | + VPBlockUtils::isHeader(VPB->getSuccessors()[1], VPDT); |
| 282 | +} |
0 commit comments