24#define DEBUG_TYPE "loop-vectorize"
67 : VPDT(VPDT), TypeInfo(TypeInfo), VerifyLate(VerifyLate) {}
73bool VPlanVerifier::verifyPhiRecipes(
const VPBasicBlock *VPBB) {
74 auto RecipeI = VPBB->
begin();
75 auto End = VPBB->
end();
76 unsigned NumActiveLaneMaskPhiRecipes = 0;
78 while (RecipeI != End && RecipeI->isPhi()) {
80 NumActiveLaneMaskPhiRecipes++;
84 errs() <<
"Found non-header PHI recipe in header VPBB";
85#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
93 errs() <<
"Found header PHI recipe in non-header VPBB";
94#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
105 errs() <<
"Phi-like recipe with different number of operands and "
116 if (!VerifyLate && NumActiveLaneMaskPhiRecipes > 1) {
117 errs() <<
"There should be no more than one VPActiveLaneMaskPHIRecipe";
121 while (RecipeI != End) {
123 errs() <<
"Found phi-like recipe after non-phi recipe";
125#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
129 std::prev(RecipeI)->dump();
138bool VPlanVerifier::verifyEVLRecipe(
const VPInstruction &EVL)
const {
140 errs() <<
"verifyEVLRecipe should only be called on "
141 "VPInstruction::ExplicitVectorLength\n";
144 auto VerifyEVLUse = [&](
const VPRecipeBase &
R,
145 const unsigned ExpectedIdx) ->
bool {
147 unsigned UseCount =
count(
Ops, &EVL);
148 if (UseCount != 1 ||
Ops[ExpectedIdx] != &EVL) {
149 errs() <<
"EVL is used as non-last operand in EVL-based recipe\n";
154 return all_of(EVL.
users(), [
this, &VerifyEVLUse](VPUser *U) {
155 return TypeSwitch<const VPUser *, bool>(U)
156 .Case<VPWidenIntrinsicRecipe>([&](const VPWidenIntrinsicRecipe *S) {
157 return VerifyEVLUse(*S, S->getNumOperands() - 1);
159 .Case<VPWidenStoreEVLRecipe, VPReductionEVLRecipe,
160 VPWidenIntOrFpInductionRecipe, VPWidenPointerInductionRecipe>(
161 [&](
const VPRecipeBase *S) {
return VerifyEVLUse(*S, 2); })
162 .Case<VPScalarIVStepsRecipe>([&](
auto *R) {
163 if (
R->getNumOperands() != 3) {
164 errs() <<
"Unrolling with EVL tail folding not yet supported\n";
167 return VerifyEVLUse(*R, 2);
169 .Case<VPWidenLoadEVLRecipe, VPVectorEndPointerRecipe,
170 VPInterleaveEVLRecipe>(
171 [&](
const VPRecipeBase *R) {
return VerifyEVLUse(*R, 1); })
172 .Case<VPInstructionWithType>(
173 [&](
const VPInstructionWithType *S) {
return VerifyEVLUse(*S, 0); })
174 .Case<VPInstruction>([&](
const VPInstruction *
I) {
175 if (
I->getOpcode() == Instruction::PHI ||
176 I->getOpcode() == Instruction::ICmp ||
177 I->getOpcode() == Instruction::Sub)
178 return VerifyEVLUse(*
I, 1);
179 switch (
I->getOpcode()) {
180 case Instruction::Add:
182 case Instruction::UIToFP:
183 case Instruction::Trunc:
184 case Instruction::ZExt:
185 case Instruction::Mul:
186 case Instruction::FMul:
191 errs() <<
"EVL used by unexpected VPInstruction\n";
196 errs() <<
"EVL used by unexpected VPInstruction\n";
201 using namespace llvm::VPlanPatternMatch;
203 I->getNumUsers() != 1 &&
204 (
I->getNumUsers() != 2 ||
207 errs() <<
"EVL is used in VPInstruction with multiple users\n";
211 errs() <<
"Result of VPInstruction::Add with EVL operand is "
212 "not used by VPEVLBasedIVPHIRecipe\n";
217 .
Default([&](
const VPUser *U) {
218 errs() <<
"EVL has unexpected user\n";
224bool VPlanVerifier::verifyVPBasicBlock(
const VPBasicBlock *VPBB) {
225 if (!verifyPhiRecipes(VPBB))
229 DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
231 for (
const VPRecipeBase &R : *VPBB)
232 RecipeNumbering[&
R] = Cnt++;
234 for (
const VPRecipeBase &R : *VPBB) {
236 errs() <<
"VPIRInstructions ";
237#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
241 errs() <<
"not in a VPIRBasicBlock!\n";
244 for (
const VPValue *V :
R.definedValues()) {
249 errs() <<
"Failed to infer scalar type!\n";
253 for (
const VPUser *U :
V->users()) {
256 for (
const auto &[IncomingVPV, IncomingVPBB] :
257 Phi->incoming_values_and_blocks()) {
258 if (IncomingVPV != V)
264 errs() <<
"Incoming def does not dominate incoming block!\n";
265#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
266 VPSlotTracker Tracker(VPBB->getPlan());
267 IncomingVPV->getDefiningRecipe()->print(
errs(),
" ", Tracker);
268 errs() <<
"\n does not dominate " << IncomingVPBB->getName()
270 UI->print(
errs(),
" ", Tracker);
282 if (UI->getParent() == VPBB) {
283 if (RecipeNumbering[UI] >= RecipeNumbering[&R])
286 if (VPDT.
dominates(VPBB, UI->getParent()))
290 errs() <<
"Use before def!\n";
291#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
292 VPSlotTracker Tracker(VPBB->getPlan());
293 UI->print(
errs(),
" ", Tracker);
294 errs() <<
"\n before\n";
295 R.print(
errs(),
" ", Tracker);
303 !verifyEVLRecipe(*EVL)) {
304 errs() <<
"EVL VPValue is not used correctly\n";
314 if (!WrappedIRBBs.
insert(IRBB->getIRBasicBlock()).second) {
315 errs() <<
"Same IR basic block used by multiple wrapper blocks!\n";
326 for (
const auto *
Block : VPBlockVec) {
333bool VPlanVerifier::verifyBlock(
const VPBlockBase *VPB) {
338 (VPBB && VPBB->getParent() && VPBB->isExiting() &&
339 !VPBB->getParent()->isReplicator())) {
340 if (!VPBB || !VPBB->getTerminator()) {
341 errs() <<
"Block has multiple successors but doesn't "
342 "have a proper branch recipe!\n";
346 if (VPBB && VPBB->getTerminator()) {
347 errs() <<
"Unexpected branch recipe!\n";
358 errs() <<
"Multiple instances of the same successor.\n";
362 for (
const VPBlockBase *Succ : Successors) {
364 const auto &SuccPreds = Succ->getPredecessors();
366 errs() <<
"Missing predecessor link.\n";
377 errs() <<
"Multiple instances of the same predecessor.\n";
381 for (
const VPBlockBase *Pred : Predecessors) {
383 if (Pred->getParent() != VPB->
getParent()) {
384 errs() <<
"Predecessor is not in the same region.\n";
389 const auto &PredSuccs = Pred->getSuccessors();
391 errs() <<
"Missing successor link.\n";
395 return !VPBB || verifyVPBasicBlock(VPBB);
398bool VPlanVerifier::verifyBlocksInRegion(
const VPRegionBlock *Region) {
402 errs() <<
"VPBlockBase has wrong parent\n";
406 if (!verifyBlock(VPB))
412bool VPlanVerifier::verifyRegion(
const VPRegionBlock *Region) {
414 const VPBlockBase *Exiting =
Region->getExiting();
417 if (
Entry->hasPredecessors()) {
418 errs() <<
"region entry block has predecessors\n";
422 errs() <<
"region exiting block has successors\n";
426 return verifyBlocksInRegion(Region);
429bool VPlanVerifier::verifyRegionRec(
const VPRegionBlock *Region) {
431 return verifyRegion(Region) &&
433 [
this](
const VPBlockBase *VPB) {
434 const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
435 return !SubRegion || verifyRegionRec(SubRegion);
439bool VPlanVerifier::verify(
const VPlan &Plan) {
441 [
this](
const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
449 if (!verifyRegionRec(TopRegion))
453 errs() <<
"VPlan Top Region should have no parent.\n";
459 errs() <<
"VPlan entry block is not a VPBasicBlock\n";
464 errs() <<
"VPlan vector loop header does not start with a "
465 "VPCanonicalIVPHIRecipe\n";
471 errs() <<
"VPlan exiting block is not a VPBasicBlock\n";
475 if (Exiting->
empty()) {
476 errs() <<
"VPlan vector loop exiting block must end with BranchOnCount or "
477 "BranchOnCond VPInstruction but is empty\n";
484 errs() <<
"VPlan vector loop exit must end with BranchOnCount or "
485 "BranchOnCond VPInstruction\n";
496 VPlanVerifier
Verifier(VPDT, TypeInfo, VerifyLate);
497 return Verifier.verify(Plan);
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
This file implements the TypeSwitch template, which mimics a switch() statement whose cases are type ...
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
This file contains the declarations of different VPlan-related auxiliary helpers.
static bool hasDuplicates(const SmallVectorImpl< VPBlockBase * > &VPBlockVec)
Utility function that checks whether VPBlockVec has duplicate VPBlockBases.
This file declares the class VPlanVerifier, which contains utility functions to check the consistency...
This file contains the declarations of the Vectorization Plan base classes:
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Implements a dense probed hash-table based set with some number of buckets stored inline.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
iterator begin()
Recipe iterator methods.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
VPRegionBlock * getParent()
size_t getNumSuccessors() const
size_t getNumPredecessors() const
const VPBlocksTy & getPredecessors() const
const VPBlocksTy & getSuccessors() const
static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop header, based on regions or VPDT in their absence.
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
This is a concrete Recipe that models a single VPlan-level instruction.
unsigned getOpcode() const
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
const VPBlockBase * getExiting() const
An analysis for type-inference for VPValues.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPBasicBlock * getEntry()
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
std::pair< iterator, bool > insert(const ValueT &V)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
MatchFunctor< Val, Pattern > match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
VPInstruction_match< VPInstruction::BranchOnCount, Op0_t, Op1_t > m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI_FOR_TEST bool verifyVPlanIsValid(const VPlan &Plan, bool VerifyLate=false)
Verify invariants for general VPlans.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< df_iterator< VPBlockShallowTraversalWrapper< VPBlockBase * > > > vp_depth_first_shallow(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.