diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 6ddbfcf0ecfe58b..4247d20cb0e5304 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -863,10 +863,10 @@ VPlan::~VPlan() { delete BackedgeTakenCount; } -static VPIRBasicBlock *createVPIRBasicBlockFor(BasicBlock *BB) { - auto *VPIRBB = new VPIRBasicBlock(BB); +VPIRBasicBlock *VPIRBasicBlock::fromBasicBlock(BasicBlock *IRBB) { + auto *VPIRBB = new VPIRBasicBlock(IRBB); for (Instruction &I : - make_range(BB->begin(), BB->getTerminator()->getIterator())) + make_range(IRBB->begin(), IRBB->getTerminator()->getIterator())) VPIRBB->appendRecipe(new VPIRInstruction(I)); return VPIRBB; } @@ -875,7 +875,8 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy, PredicatedScalarEvolution &PSE, bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop) { - VPIRBasicBlock *Entry = createVPIRBasicBlockFor(TheLoop->getLoopPreheader()); + VPIRBasicBlock *Entry = + VPIRBasicBlock::fromBasicBlock(TheLoop->getLoopPreheader()); VPBasicBlock *VecPreheader = new VPBasicBlock("vector.ph"); auto Plan = std::make_unique(Entry, VecPreheader); @@ -915,7 +916,7 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy, // we unconditionally branch to the scalar preheader. Do nothing. // 3) Otherwise, construct a runtime check. BasicBlock *IRExitBlock = TheLoop->getUniqueExitBlock(); - auto *VPExitBlock = createVPIRBasicBlockFor(IRExitBlock); + auto *VPExitBlock = VPIRBasicBlock::fromBasicBlock(IRExitBlock); // The connection order corresponds to the operands of the conditional branch. VPBlockUtils::insertBlockAfter(VPExitBlock, MiddleVPBB); VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH); @@ -991,7 +992,7 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV, /// have a single predecessor, which is rewired to the new VPIRBasicBlock. All /// successors of VPBB, if any, are rewired to the new VPIRBasicBlock. static void replaceVPBBWithIRVPBB(VPBasicBlock *VPBB, BasicBlock *IRBB) { - VPIRBasicBlock *IRVPBB = createVPIRBasicBlockFor(IRBB); + VPIRBasicBlock *IRVPBB = VPIRBasicBlock::fromBasicBlock(IRBB); for (auto &R : make_early_inc_range(*VPBB)) { assert(!R.isPhi() && "Tried to move phi recipe to end of block"); R.moveBefore(*IRVPBB, IRVPBB->end()); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index c4567362eaffc7f..8392aec8ad396e2 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -3318,6 +3318,10 @@ class VPIRBasicBlock : public VPBasicBlock { return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC; } + /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all + /// instructions in \p IRBB, except its terminator which is managed in VPlan. + static VPIRBasicBlock *fromBasicBlock(BasicBlock *IRBB); + /// The method which generates the output IR instructions that correspond to /// this VPBasicBlock, thereby "executing" the VPlan. void execute(VPTransformState *State) override;