-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[VPlan] Introduce all loop regions as VPlan transform. (NFC) #129402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d5ba9a3
9854453
a88f03e
646a112
29f6ddf
2a500dd
cc81801
2a8344e
67a30f1
3b1618e
2d3f087
c6903d6
decf567
29b7487
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -46,9 +46,10 @@ getPreheaderAndLatch(VPBlockBase *HeaderVPB, const VPDominatorTree &VPDT) { | |||||||
return std::nullopt; | ||||||||
} | ||||||||
|
||||||||
/// Create a new VPRegionBlock if there is a loop starting at \p HeaderVPB. | ||||||||
static void createLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB, | ||||||||
VPDominatorTree &VPDT) { | ||||||||
/// Try to create a new VPRegionBlock if there is a loop starting at \p | ||||||||
/// HeaderVPB. | ||||||||
static void tryToCreateLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB, | ||||||||
VPDominatorTree &VPDT) { | ||||||||
auto Res = getPreheaderAndLatch(HeaderVPB, VPDT); | ||||||||
if (!Res) | ||||||||
return; | ||||||||
|
@@ -93,14 +94,15 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy, | |||||||
VPDominatorTree VPDT; | ||||||||
VPDT.recalculate(Plan); | ||||||||
for (VPBlockBase *HeaderVPB : vp_depth_first_shallow(Plan.getEntry())) | ||||||||
createLoopRegion(Plan, HeaderVPB, VPDT); | ||||||||
tryToCreateLoopRegion(Plan, HeaderVPB, VPDT); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done thanks! |
||||||||
|
||||||||
VPRegionBlock *TopRegion = Plan.getVectorLoopRegion(); | ||||||||
auto *OrigExiting = TopRegion->getExiting(); | ||||||||
VPBasicBlock *LatchVPBB = Plan.createVPBasicBlock("vector.latch"); | ||||||||
VPBlockUtils::insertBlockAfter(LatchVPBB, OrigExiting); | ||||||||
TopRegion->setExiting(LatchVPBB); | ||||||||
TopRegion->setName("vector loop"); | ||||||||
TopRegion->getEntryBasicBlock()->setName("vector.body"); | ||||||||
|
||||||||
// Create SCEV and VPValue for the trip count. | ||||||||
// We use the symbolic max backedge-taken-count, which works also when | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -99,8 +99,6 @@ void PlainCFGBuilder::fixHeaderPhis() { | |||||||
assert(VPPhi->getNumOperands() == 0 && | ||||||||
"Expected VPInstruction with no operands."); | ||||||||
assert(isHeaderBB(Phi->getParent(), LI->getLoopFor(Phi->getParent()))); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks |
||||||||
// For header phis, make sure the incoming value from the loop | ||||||||
// predecessor is the first operand of the recipe. | ||||||||
assert(Phi->getNumOperands() == 2 && | ||||||||
"header phi must have exactly 2 operands"); | ||||||||
for (BasicBlock *Pred : predecessors(Phi->getParent())) | ||||||||
|
@@ -109,10 +107,6 @@ void PlainCFGBuilder::fixHeaderPhis() { | |||||||
} | ||||||||
} | ||||||||
|
||||||||
static bool isHeaderVPBB(VPBasicBlock *VPBB) { | ||||||||
return VPBB->getParent() && VPBB->getParent()->getEntry() == VPBB; | ||||||||
} | ||||||||
|
||||||||
// Create a new empty VPBasicBlock for an incoming BasicBlock or retrieve an | ||||||||
// existing one if it was already created. | ||||||||
VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) { | ||||||||
|
@@ -122,7 +116,7 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) { | |||||||
} | ||||||||
|
||||||||
// Create new VPBB. | ||||||||
StringRef Name = isHeaderBB(BB, TheLoop) ? "vector.body" : BB->getName(); | ||||||||
StringRef Name = BB->getName(); | ||||||||
LLVM_DEBUG(dbgs() << "Creating VPBasicBlock for " << Name << "\n"); | ||||||||
VPBasicBlock *VPBB = Plan.createVPBasicBlock(Name); | ||||||||
BB2VPBB[BB] = VPBB; | ||||||||
|
@@ -325,10 +319,7 @@ void PlainCFGBuilder::buildPlainCFG( | |||||||
auto *BI = cast<BranchInst>(BB->getTerminator()); | ||||||||
unsigned NumSuccs = succ_size(BB); | ||||||||
if (NumSuccs == 1) { | ||||||||
auto *Successor = getOrCreateVPBB(BB->getSingleSuccessor()); | ||||||||
VPBB->setOneSuccessor(isHeaderVPBB(Successor) | ||||||||
? Successor->getParent() | ||||||||
: static_cast<VPBlockBase *>(Successor)); | ||||||||
VPBB->setOneSuccessor(getOrCreateVPBB(BB->getSingleSuccessor())); | ||||||||
continue; | ||||||||
} | ||||||||
assert(BI->isConditional() && NumSuccs == 2 && BI->isConditional() && | ||||||||
|
@@ -341,8 +332,8 @@ void PlainCFGBuilder::buildPlainCFG( | |||||||
|
||||||||
// Don't connect any blocks outside the current loop except the latches for | ||||||||
// inner loops. | ||||||||
if (LoopForBB && | ||||||||
(LoopForBB == TheLoop || BB != LoopForBB->getLoopLatch())) { | ||||||||
// TODO: Also connect exit blocks during initial VPlan construction. | ||||||||
if (LoopForBB == TheLoop || BB != LoopForBB->getLoopLatch()) { | ||||||||
if (!LoopForBB->contains(IRSucc0)) { | ||||||||
VPBB->setOneSuccessor(Successor1); | ||||||||
continue; | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!