LLVM 20.0.0git
|
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient output IR, including which branches, basic-blocks and output IR instructions to generate, and their cost. More...
#include "Transforms/Vectorize/VPlan.h"
Public Member Functions | |
VPlan (VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader) | |
Construct a VPlan with Entry to the plan and with ScalarHeader wrapping the original header of the scalar loop. | |
VPlan (VPBasicBlock *Entry, VPValue *TC, VPIRBasicBlock *ScalarHeader) | |
Construct a VPlan with Entry entering the plan, trip count TC and with ScalarHeader wrapping the original header of the scalar loop. | |
VPlan (Loop *L) | |
Construct a VPlan for L . | |
~VPlan () | |
void | setEntry (VPBasicBlock *VPBB) |
void | prepareToExecute (Value *TripCount, Value *VectorTripCount, VPTransformState &State) |
Prepare the plan for execution, setting up the required live-in values. | |
void | execute (VPTransformState *State) |
Generate the IR code for this VPlan. | |
InstructionCost | cost (ElementCount VF, VPCostContext &Ctx) |
Return the cost of this plan. | |
VPBasicBlock * | getEntry () |
const VPBasicBlock * | getEntry () const |
VPBasicBlock * | getVectorPreheader () |
Returns the preheader of the vector loop region. | |
VPRegionBlock * | getVectorLoopRegion () |
Returns the VPRegionBlock of the vector loop. | |
const VPRegionBlock * | getVectorLoopRegion () const |
const VPBasicBlock * | getMiddleBlock () const |
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar tail loop or the exit block from the loop latch. | |
VPBasicBlock * | getMiddleBlock () |
VPBasicBlock * | getScalarPreheader () const |
Return the VPBasicBlock for the preheader of the scalar loop. | |
VPIRBasicBlock * | getScalarHeader () const |
Return the VPIRBasicBlock wrapping the header of the scalar loop. | |
auto | getExitBlocks () |
Return an iterator range over the VPIRBasicBlock wrapping the exit blocks of the VPlan, that is leaf nodes except the scalar header. | |
VPValue * | getTripCount () const |
The trip count of the original loop. | |
void | resetTripCount (VPValue *NewTripCount) |
Resets the trip count for the VPlan. | |
VPValue * | getOrCreateBackedgeTakenCount () |
The backedge taken count of the original loop. | |
VPValue & | getVectorTripCount () |
The vector trip count. | |
VPValue & | getVF () |
Returns the VF of the vector loop region. | |
VPValue & | getVFxUF () |
Returns VF * UF of the vector loop region. | |
void | addVF (ElementCount VF) |
void | setVF (ElementCount VF) |
bool | hasVF (ElementCount VF) |
bool | hasScalableVF () |
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > | vectorFactors () const |
Returns an iterator range over all VFs of the plan. | |
bool | hasScalarVFOnly () const |
bool | hasUF (unsigned UF) const |
unsigned | getUF () const |
void | setUF (unsigned UF) |
std::string | getName () const |
Return a string with the name of the plan and the applicable VFs and UFs. | |
void | setName (const Twine &newName) |
VPValue * | getOrAddLiveIn (Value *V) |
Gets the live-in VPValue for V or adds a new live-in (if none exists yet) for V . | |
VPValue * | getLiveIn (Value *V) const |
Return the live-in VPValue for V , if there is one or nullptr otherwise. | |
void | printLiveIns (raw_ostream &O) const |
Print the live-ins of this VPlan to O . | |
void | print (raw_ostream &O) const |
Print this VPlan to O . | |
void | printDOT (raw_ostream &O) const |
Print this VPlan in DOT format to O . | |
LLVM_DUMP_METHOD void | dump () const |
Dump the plan to stderr (for debugging). | |
VPCanonicalIVPHIRecipe * | getCanonicalIV () |
Returns the canonical induction recipe of the vector loop. | |
VPValue * | getSCEVExpansion (const SCEV *S) const |
void | addSCEVExpansion (const SCEV *S, VPValue *V) |
VPlan * | duplicate () |
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clones, and return it. | |
Static Public Member Functions | |
static VPlanPtr | createInitialVPlan (Type *InductionTy, PredicatedScalarEvolution &PSE, bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop) |
Create initial VPlan, having an "entry" VPBasicBlock (wrapping original scalar pre-header) which contains SCEV expansions that need to happen before the CFG is modified (when executing a VPlan for the epilogue vector loop, the original entry needs to be replaced by a new one); a VPBasicBlock for the vector pre-header, followed by a region for the vector loop, followed by the middle VPBasicBlock. | |
Friends | |
class | VPlanPrinter |
class | VPSlotTracker |
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient output IR, including which branches, basic-blocks and output IR instructions to generate, and their cost.
VPlan holds a Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry VPBasicBlock.
|
inline |
Construct a VPlan with Entry
to the plan and with ScalarHeader
wrapping the original header of the scalar loop.
Definition at line 3818 of file VPlan.h.
References assert(), and llvm::VPBlockBase::getNumSuccessors().
|
inline |
VPlan::VPlan | ( | Loop * | L | ) |
Construct a VPlan for L
.
This will create VPIRBasicBlocks wrapping the original preheader and scalar header of L
, to be used as entry and scalar header blocks of the new VPlan.
Definition at line 824 of file VPlan.cpp.
References llvm::VPIRBasicBlock::fromBasicBlock().
VPlan::~VPlan | ( | ) |
Definition at line 829 of file VPlan.cpp.
References llvm::Block, llvm::VPBlockBase::deleteCFG(), and llvm::vp_depth_first_shallow().
Definition at line 4023 of file VPlan.h.
References assert(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::contains().
Referenced by llvm::vputils::getOrCreateVPValueForSCEVExpr().
|
inline |
Definition at line 3935 of file VPlan.h.
References llvm::SetVector< T, Vector, Set, N >::insert().
InstructionCost VPlan::cost | ( | ElementCount | VF, |
VPCostContext & | Ctx | ||
) |
Return the cost of this plan.
Definition at line 1078 of file VPlan.cpp.
References llvm::VPTransformState::VF.
|
static |
Create initial VPlan, having an "entry" VPBasicBlock (wrapping original scalar pre-header) which contains SCEV expansions that need to happen before the CFG is modified (when executing a VPlan for the epilogue vector loop, the original entry needs to be replaced by a new one); a VPBasicBlock for the vector pre-header, followed by a region for the vector loop, followed by the middle VPBasicBlock.
If a check is needed to guard executing the scalar epilogue loop, it will be added to the middle block, together with VPBasicBlocks for the scalar preheader and exit blocks. InductionTy
is the type of the canonical induction and used for related values, like the trip count expression.
Definition at line 851 of file VPlan.cpp.
References assert(), llvm::VPInstruction::BranchOnCond, llvm::VPTransformState::Builder, llvm::VPBlockUtils::connectBlocks(), llvm::VPIRBasicBlock::fromBasicBlock(), llvm::Type::getContext(), getEntry(), llvm::Type::getInt1Ty(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), getOrAddLiveIn(), llvm::vputils::getOrCreateVPValueForSCEVExpr(), getScalarHeader(), llvm::PredicatedScalarEvolution::getSE(), llvm::PredicatedScalarEvolution::getSymbolicMaxBackedgeTakenCount(), llvm::BasicBlock::getTerminator(), getTripCount(), llvm::ScalarEvolution::getTripCountFromExitCount(), llvm::ConstantInt::getTrue(), llvm::SCEV::getType(), llvm::LoopBase< BlockT, LoopT >::getUniqueLatchExitBlock(), getVectorTripCount(), llvm::CmpInst::ICMP_EQ, llvm::VPBlockUtils::insertBlockAfter(), and llvm::VPTransformState::Plan.
LLVM_DUMP_METHOD void VPlan::dump | ( | ) | const |
Dump the plan to stderr (for debugging).
Definition at line 1183 of file VPlan.cpp.
References llvm::dbgs(), and llvm::print().
VPlan * VPlan::duplicate | ( | ) |
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clones, and return it.
Definition at line 1224 of file VPlan.cpp.
References assert(), cloneFrom(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::contains(), llvm::find_if(), Name, remapOperands(), llvm::VPTransformState::VF, and llvm::vp_depth_first_shallow().
Referenced by llvm::LoopVectorizePass::processLoop().
void VPlan::execute | ( | VPTransformState * | State | ) |
Generate the IR code for this VPlan.
Generate the code inside the preheader and body of the vectorized loop.
Assumes a single pre-header basic-block was created for this. Introduce additional basic-blocks as needed, and fill them all.
Definition at line 977 of file VPlan.cpp.
References llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(), assert(), llvm::Block, llvm::VPTransformState::Builder, llvm::VPTransformState::CFG, llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::VPTransformState::CFGState::DTU, llvm::dump(), llvm::Instruction::eraseFromParent(), llvm::VPTransformState::CFGState::ExitBB, llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::flush(), GEP, llvm::VPTransformState::get(), llvm::BasicBlock::getContext(), llvm::VPBlockBase::getExitingBasicBlock(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getPrevNode(), llvm::BasicBlock::getSingleSuccessor(), llvm::BasicBlock::getTerminator(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), IV, LLVM_DEBUG, llvm::Instruction::moveBefore(), llvm::VPTransformState::CFGState::PrevBB, llvm::VPTransformState::CFGState::PrevVPBB, replaceVPBBWithIRVPBB(), llvm::IRBuilderBase::SetInsertPoint(), llvm::User::setOperand(), llvm::VPTransformState::VF, and llvm::VPTransformState::CFGState::VPBB2IRBB.
Referenced by llvm::LoopVectorizationPlanner::executePlan().
|
inline |
Returns the canonical induction recipe of the vector loop.
Definition at line 4010 of file VPlan.h.
References llvm::VPBasicBlock::begin(), llvm::VPBasicBlock::empty(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPBlockBase::getSingleSuccessor(), and getVectorLoopRegion().
Referenced by llvm::VPlanTransforms::addActiveLaneMask(), addExitUsersForFirstOrderRecurrences(), addScalarResumePhis(), addVPLaneMaskPhiAndUpdateExitBranch(), collectAllHeaderMasks(), llvm::VPRecipeBuilder::createHeaderMask(), createScalarIVSteps(), removeRedundantCanonicalIVs(), simplifyRecipes(), transformRecipestoEVLRecipes(), llvm::VPlanTransforms::truncateToMinimalBitwidths(), llvm::VPlanTransforms::tryAddExplicitVectorLength(), and willGenerateVectors().
|
inline |
Definition at line 3869 of file VPlan.h.
Referenced by addReplicateRegions(), llvm::VPlanTransforms::convertToConcreteRecipes(), createInitialVPlan(), llvm::VPlanPrinter::dump(), llvm::EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck(), llvm::LoopVectorizationPlanner::executePlan(), llvm::InnerLoopVectorizer::fixNonInductionPHIs(), llvm::DomTreeNodeTraits< VPBlockBase >::getEntryNode(), llvm::vputils::getOrCreateVPValueForSCEVExpr(), mergeBlocksIntoPredecessors(), mergeReplicateRegionsIntoSuccessors(), preparePlanForEpilogueVectorLoop(), llvm::VPlanTransforms::removeDeadRecipes(), removeRedundantExpandSCEVRecipes(), llvm::VPBlockBase::setPlan(), simplifyRecipes(), sinkScalarOperands(), and llvm::VPlanTransforms::unrollByUF().
|
inline |
|
inline |
Return an iterator range over the VPIRBasicBlock wrapping the exit blocks of the VPlan, that is leaf nodes except the scalar header.
Defined in VPlanHCFG, as the definition of the type needs access to the definitions of VPBlockShallowTraversalWrapper.
Definition at line 309 of file VPlanCFG.h.
References llvm::VPBlockBase::getNumSuccessors(), getScalarHeader(), getVectorLoopRegion(), llvm::make_filter_range(), and llvm::vp_depth_first_shallow().
Referenced by collectUsersInExitBlocks().
Return the live-in VPValue for V
, if there is one or nullptr otherwise.
Definition at line 3993 of file VPlan.h.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup().
|
inline |
Definition at line 3887 of file VPlan.h.
References getScalarPreheader().
|
inline |
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar tail loop or the exit block from the loop latch.
Definition at line 3884 of file VPlan.h.
References getScalarPreheader().
Referenced by addExitUsersForFirstOrderRecurrences(), addUsersInExitBlocks(), collectUsersInExitBlocks(), llvm::LoopVectorizationPlanner::executePlan(), llvm::InnerLoopVectorizer::fixVectorizedLoop(), and llvm::VPlanTransforms::handleUncountableEarlyExit().
std::string VPlan::getName | ( | ) | const |
Return a string with the name of the plan and the applicable VFs and UFs.
Definition at line 1153 of file VPlan.cpp.
References llvm::drop_begin(), Name, and llvm::VPTransformState::VF.
Referenced by llvm::VPlanPrinter::dump().
Gets the live-in VPValue for V
or adds a new live-in (if none exists yet) for V
.
Definition at line 3976 of file VPlan.h.
References assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::VPValue::isLiveIn(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by addCanonicalIVRecipes(), addExitUsersForFirstOrderRecurrences(), addScalarResumePhis(), addUsersInExitBlocks(), llvm::InnerLoopVectorizer::createInductionResumeVPValue(), llvm::InnerLoopVectorizer::createInductionResumeVPValues(), createInitialVPlan(), llvm::VPlanTransforms::createInterleaveGroups(), llvm::vputils::getOrCreateVPValueForSCEVExpr(), llvm::VPRecipeBuilder::getVPValueOrAddLiveIn(), legalizeAndOptimizeInductions(), llvm::VPlanTransforms::optimizeForVFAndUF(), preparePlanForEpilogueVectorLoop(), transformRecipestoEVLRecipes(), and llvm::VPlanTransforms::tryAddExplicitVectorLength().
|
inline |
The backedge taken count of the original loop.
Definition at line 3920 of file VPlan.h.
Referenced by llvm::VPRecipeBuilder::createHeaderMask(), and llvm::vputils::isHeaderMask().
|
inline |
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition at line 3897 of file VPlan.h.
Referenced by addScalarResumePhis(), llvm::InnerLoopVectorizer::createInductionResumeVPValues(), createInitialVPlan(), getExitBlocks(), and getScalarPreheader().
|
inline |
Return the VPBasicBlock for the preheader of the scalar loop.
Definition at line 3892 of file VPlan.h.
References getScalarHeader().
Referenced by addExitUsersForFirstOrderRecurrences(), addScalarResumePhis(), llvm::InnerLoopVectorizer::createInductionResumeVPValues(), getMiddleBlock(), and introduceCheckBlockInVPlan().
Definition at line 4019 of file VPlan.h.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup().
Referenced by llvm::InnerLoopVectorizer::fixupIVUsers(), and llvm::vputils::getOrCreateVPValueForSCEVExpr().
|
inline |
The trip count of the original loop.
Definition at line 3906 of file VPlan.h.
References assert().
Referenced by llvm::VPlanTransforms::addActiveLaneMask(), addVPLaneMaskPhiAndUpdateExitBranch(), createInitialVPlan(), llvm::LoopVectorizationPlanner::executePlan(), llvm::vputils::isHeaderMask(), llvm::VPlanTransforms::optimizeForVFAndUF(), preparePlanForEpilogueVectorLoop(), llvm::LoopVectorizationPlanner::selectEpilogueVectorizationFactor(), and llvm::VPlanTransforms::tryAddExplicitVectorLength().
|
inline |
Definition at line 3958 of file VPlan.h.
References assert(), and llvm::SetVector< T, Vector, Set, N >::size().
Referenced by llvm::VPWidenPointerInductionRecipe::execute(), llvm::LoopVectorizationPlanner::executePlan(), and llvm::VPTransformState::setDebugLocFrom().
VPRegionBlock * VPlan::getVectorLoopRegion | ( | ) |
Returns the VPRegionBlock of the vector loop.
Definition at line 1084 of file VPlan.cpp.
References B, and llvm::vp_depth_first_shallow().
Referenced by addCanonicalIVRecipes(), addExitUsersForFirstOrderRecurrences(), addVPLaneMaskPhiAndUpdateExitBranch(), llvm::VPlanTransforms::adjustFixedOrderRecurrences(), llvm::VPlanTransforms::clearReductionWrapFlags(), collectAllHeaderMasks(), llvm::collectEphemeralRecipesForVPlan(), llvm::EpilogueVectorizerMainLoop::createEpilogueVectorizedLoopSkeleton(), llvm::VPRecipeBuilder::createHeaderMask(), createScalarIVSteps(), llvm::LoopVectorizationPlanner::executePlan(), llvm::InnerLoopVectorizer::fixVectorizedLoop(), getCanonicalIV(), getExitBlocks(), getVectorPreheader(), llvm::VPlanTransforms::handleUncountableEarlyExit(), legalizeAndOptimizeInductions(), licm(), llvm::VPlanTransforms::optimizeForVFAndUF(), planContainsAdditionalSimplifications(), preparePlanForEpilogueVectorLoop(), removeRedundantCanonicalIVs(), removeRedundantInductionCasts(), llvm::VPlanTransforms::truncateToMinimalBitwidths(), llvm::VPlanTransforms::tryAddExplicitVectorLength(), llvm::VPlanTransforms::unrollByUF(), llvm::VPInterleavedAccessInfo::VPInterleavedAccessInfo(), and willGenerateVectors().
const VPRegionBlock * VPlan::getVectorLoopRegion | ( | ) | const |
Definition at line 1092 of file VPlan.cpp.
References B, and llvm::vp_depth_first_shallow().
|
inline |
Returns the preheader of the vector loop region.
Definition at line 3873 of file VPlan.h.
References getVectorLoopRegion().
Referenced by addVPLaneMaskPhiAndUpdateExitBranch(), llvm::VPTransformState::get(), introduceCheckBlockInVPlan(), licm(), and llvm::VPlanTransforms::truncateToMinimalBitwidths().
|
inline |
The vector trip count.
Definition at line 3927 of file VPlan.h.
Referenced by addCanonicalIVRecipes(), llvm::InnerLoopVectorizer::createInductionResumeVPValues(), and createInitialVPlan().
|
inline |
Returns the VF of the vector loop region.
Definition at line 3930 of file VPlan.h.
Referenced by createWidenInductionRecipes(), and transformRecipestoEVLRecipes().
|
inline |
Returns VF * UF of the vector loop region.
Definition at line 3933 of file VPlan.h.
Referenced by addCanonicalIVRecipes().
|
inline |
Definition at line 3944 of file VPlan.h.
References llvm::any_of(), and llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable().
Referenced by legalizeAndOptimizeInductions().
|
inline |
Definition at line 3954 of file VPlan.h.
References llvm::SetVector< T, Vector, Set, N >::size().
Referenced by sinkScalarOperands().
Definition at line 3956 of file VPlan.h.
References llvm::SetVector< T, Vector, Set, N >::contains(), and llvm::SetVector< T, Vector, Set, N >::empty().
Referenced by llvm::LoopVectorizationPlanner::executePlan(), llvm::VPlanTransforms::optimizeForVFAndUF(), and setUF().
|
inline |
Definition at line 3943 of file VPlan.h.
References llvm::SetVector< T, Vector, Set, N >::count().
Referenced by llvm::LoopVectorizationPlanner::executePlan(), llvm::LoopVectorizationPlanner::getPlanFor(), legalizeAndOptimizeInductions(), llvm::VPlanTransforms::optimizeForVFAndUF(), and setVF().
void VPlan::prepareToExecute | ( | Value * | TripCount, |
Value * | VectorTripCount, | ||
VPTransformState & | State | ||
) |
Prepare the plan for execution, setting up the required live-in values.
Definition at line 930 of file VPlan.cpp.
References assert(), llvm::VPTransformState::Builder, llvm::VPTransformState::CFG, llvm::IRBuilderBase::CreateMul(), llvm::createStepForVF(), llvm::IRBuilderBase::CreateSub(), llvm::getRuntimeVF(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::VPTransformState::CFGState::PrevBB, and llvm::VPTransformState::VF.
Referenced by llvm::LoopVectorizationPlanner::executePlan().
LLVM_DUMP_METHOD void VPlan::print | ( | raw_ostream & | O | ) | const |
Print this VPlan to O
.
Definition at line 1136 of file VPlan.cpp.
References llvm::Block, and getName().
Referenced by llvm::operator<<(), and llvm::LoopVectorizationPlanner::printPlans().
LLVM_DUMP_METHOD void VPlan::printDOT | ( | raw_ostream & | O | ) | const |
Print this VPlan in DOT format to O
.
Definition at line 1177 of file VPlan.cpp.
References llvm::Metadata::dump(), and Printer.
Referenced by llvm::LoopVectorizationPlanner::printPlans().
void VPlan::printLiveIns | ( | raw_ostream & | O | ) | const |
Print the live-ins of this VPlan to O
.
Definition at line 1100 of file VPlan.cpp.
References llvm::VPTransformState::VF.
Referenced by llvm::VPlanPrinter::dump().
|
inline |
Resets the trip count for the VPlan.
The caller must make sure all uses of the original trip count have been replaced.
Definition at line 3913 of file VPlan.h.
References assert(), and llvm::VPValue::getNumUsers().
Referenced by preparePlanForEpilogueVectorLoop().
|
inline |
Definition at line 3839 of file VPlan.h.
References llvm::VPBlockBase::setPlan().
Referenced by llvm::EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck().
Definition at line 3972 of file VPlan.h.
References Name, and llvm::Twine::str().
Referenced by llvm::VPlanHCFGBuilder::buildHierarchicalCFG().
|
inline |
Definition at line 3963 of file VPlan.h.
References assert(), llvm::SetVector< T, Vector, Set, N >::clear(), hasUF(), and llvm::SetVector< T, Vector, Set, N >::insert().
Referenced by llvm::VPlanTransforms::optimizeForVFAndUF(), llvm::VPlanTransforms::tryAddExplicitVectorLength(), and llvm::VPlanTransforms::unrollByUF().
|
inline |
Definition at line 3937 of file VPlan.h.
References assert(), llvm::SetVector< T, Vector, Set, N >::clear(), hasVF(), and llvm::SetVector< T, Vector, Set, N >::insert().
Referenced by llvm::VPlanTransforms::optimizeForVFAndUF().
|
inline |
Returns an iterator range over all VFs of the plan.
Definition at line 3950 of file VPlan.h.
References llvm::SetVector< T, Vector, Set, N >::begin(), and llvm::SetVector< T, Vector, Set, N >::end().
Referenced by llvm::LoopVectorizationPlanner::computeBestVF().
|
friend |
|
friend |